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

Add .get_entities() method to BIDSLayout #346

Closed
effigies opened this issue Jan 16, 2019 · 5 comments · Fixed by #432
Closed

Add .get_entities() method to BIDSLayout #346

effigies opened this issue Jan 16, 2019 · 5 comments · Fixed by #432

Comments

@effigies
Copy link
Collaborator

Currently, you can get valid entities by running BIDSLayout(bids_root).entities and a little parsing. It would be nice to have a helper function such as bids.layout.list_entities():

def list_entities(domains=('bids',)):
    res = []
    for domain in domains:
        res.extend(...)  # Parse the entities from the JSON files
    return res

The reason this comes up is that, currently, nipype.interfaces.io.BIDSDataGrabber manually parses the JSON files, found in a path relative to bids.__file__. This isn't great.

@tyarkoni
Copy link
Collaborator

Grabbit's Layout has a .get_domain_entities() method that may do what you want. The name reflects the fact that it takes an optional domains argument (so, e.g., you can get all and only derivatives entities), but we could easily add an alias in pybids if you think it's worth it.

@effigies
Copy link
Collaborator Author

If this is a classmethod, then that works just fine. The main thing is we need access to this information without necessarily populating a layout.

@tyarkoni
Copy link
Collaborator

It's an instance method at the moment, but in the interest of preserving the API and not adding new methods, we can make it a static method and pull the entities directly from the JSON. Unfortunately this isn't entirely straightforward because of the way Domains are currently initialized (through the Layout, for reasons not worth getting into). So it'll require a bit of refactoring. But it's probably worth doing anyway, because the resulting code will be a bit cleaner in other places too.

@tyarkoni tyarkoni changed the title API access to valid entities Add .get_entities() method to BIDSLayout Mar 19, 2019
@tyarkoni
Copy link
Collaborator

Following up on this, in 0.8, you can do Config.load('bids') to get back a Config object that has a dictionary of entities only valid for that config. This doesn't require populating a layout, but it only works for a single config at a time. So at this point it would be very straightforward to add a static method in BIDSLayout that takes a list of config names and returns the union of available entities across all resulting Config objects.

@tyarkoni
Copy link
Collaborator

0.9 adds a get_entities() method that accepts scope and is_metadata arguments, where the former controls where to look for entities, and the latter allows you to restrict to only metadata or non-metadata entities if desired.

@tyarkoni tyarkoni mentioned this issue Apr 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants