Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check existence of NWBDataInterfaces #561

Open
afonsobspinto opened this issue Jul 14, 2018 · 2 comments
Open

Check existence of NWBDataInterfaces #561

afonsobspinto opened this issue Jul 14, 2018 · 2 comments
Labels
category: enhancement improvements of code or code behavior priority: low alternative solution already working and/or relevant to only specific user(s)
Milestone

Comments

@afonsobspinto
Copy link

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, None

As 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?

@bendichter
Copy link
Contributor

Hi @afonsobspinto, thanks for working on this stuff, and thanks for communicating what you are working on. I think this may overlap with the validation module. Check it out and see if that suits your needs.

@afonsobspinto
Copy link
Author

Hey @bendichter. Thanks for the quick reply. I took a look into it and if I understood correctly I should define an extension with the attributes I require and use the validation module to check if the nwb file meets them, correct?
But besides verifying if those fields exist I will also need to access them. What would you recommend for that?

@ajtritt ajtritt added this to the Future milestone Aug 20, 2018
@stephprince stephprince added category: enhancement improvements of code or code behavior priority: low alternative solution already working and/or relevant to only specific user(s) labels Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: enhancement improvements of code or code behavior priority: low alternative solution already working and/or relevant to only specific user(s)
Projects
None yet
Development

No branches or pull requests

4 participants