-
Notifications
You must be signed in to change notification settings - Fork 93
Open
Labels
category: enhancementimprovements of code or code behaviorimprovements of code or code behaviorpriority: lowalternative solution already working and/or relevant to only specific user(s)alternative solution already working and/or relevant to only specific user(s)
Milestone
Description
Hello everyone.
I'm designing a declarative way to specify requirements on an NWB 2.x file for a given plot.
The requirements are NWBDataInterfaces provided by your API:
"requirements": ["DfOverT", "processing.<ProcessingModule>.DfOverF"]
As you can see, they can be simple objects or a full path requirement.
My goal is to be able to verify if those requirements are met given any NWB 2.x, and to do that I'm trying the following:
nwb_map_id_api = {'acquisition': 'acquisition',
'analysis': 'analysis',
'epochs': 'epochs',
'processing': 'modules', # this dictionary is needed mainly because of this
'stimulus': 'stimulus',
}
def has_all_requirements(self, requirements):
"""Given a list of requirements verifies if all are meet ."""
return all(self._check_requirement(requirement)[0] for requirement in requirements)
def _check_requirement(self, requirement):
list_string = requirement.split('.')
return self._check_requirement_full_path(list_string) if len(list_string) > 1 else self._check_requirement_data_interfaces(requirement)
def _check_requirement_full_path(self, path_list):
"""Given a full_path requirement gets the initial group and expands it blindly in search of the last path
element """
group = NWBUtils.nwb_map_id_api.get(path_list[0])
if group is not None:
nodes = [getattr(self.nwbfile, group)]
for index, remaining_path in enumerate(path_list[1:]):
for node in nodes:
if index == len(path_list) - 2:
if isinstance(node, dict):
for value in list(node.values()):
if value.neurodata_type == remaining_path:
return True, value
else:
for child in node.children:
if child.neurodata_type == remaining_path:
return True, child
else:
nodes = list(node.values()) if isinstance(node, dict) else node.children
return False, None
def _check_requirement_data_interfaces(self, requirement):
"""Given a requirement looks for a match in all the nwb_data_interfaces of the nwb file """
for data_interfaces in self.nwb_data_interfaces_list:
if data_interfaces.neurodata_type == requirement:
return True, data_interfaces
return False, NoneAs my previous issue, I would like to get your opinion on this.
I wasn't able to find this feature in your API. Do you think it has any value? Would you do this any other way?
Metadata
Metadata
Assignees
Labels
category: enhancementimprovements of code or code behaviorimprovements of code or code behaviorpriority: lowalternative solution already working and/or relevant to only specific user(s)alternative solution already working and/or relevant to only specific user(s)