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

how to access the layout of a dataset? #223

Closed
Remi-Gau opened this issue Jan 4, 2023 · 4 comments · Fixed by #233
Closed

how to access the layout of a dataset? #223

Remi-Gau opened this issue Jan 4, 2023 · 4 comments · Fixed by #233
Labels
enhancement New feature or request

Comments

@Remi-Gau
Copy link
Contributor

Remi-Gau commented Jan 4, 2023

I have a bids apps that requires to get some "stats" about the dataset as a whole (on top of accessing some specific files).

Is there a way that snakebids "exposes" the layout so I can access it in script or should I just create a script that will reindex the dataset with pybids?

@pvandyken
Copy link
Contributor

Not yet, but this has come up before and should be low-hanging fruit. We can definitely prioritize this.

I think a reasonable API would be to just have a BidsDataset.layout property that points to the underlying layout object (trying to think of this will have any incompatibilities with future filtering apis, but I can't come up with anything).

@pvandyken pvandyken added the enhancement New feature or request label Jan 4, 2023
@Remi-Gau
Copy link
Contributor Author

Remi-Gau commented Jan 4, 2023

Thanks. For now I can still reindex the dataset but it will become a pain for large datasets.

@akhanf
Copy link
Member

akhanf commented Jan 8, 2023

Note that another workaround right now would be to use the --pybidsdb-dir option in snakebids to avoid re-indexing, and always use the same path to the pybidsdb directory (e.g. <bids_dir>/.pybids), so that your script can also be hardcoded to look in the same location (e.g. <bids_dir>/.pybids).

We also have this useful tool for generating the pybids db dir on a network file system (https://github.com/pvandyken/pybidsdb)

@pvandyken
Copy link
Contributor

pvandyken commented Feb 1, 2023

I'm actually facing a bit of an implementation detail on this, having to do with the types and the fact that, in testing, the fake Datasets I'm making will not have an associated layout.

There's two approaches to this: one is an Optional type annotation:

class BidsDataset:
    layout: Optional[BIDSLayout] = None

I don't care for this because in practice, any BidsDataset generated by generate_inputs() will indeed have a layout, so from the user perspective, layout is not really optional.

The other is to have two classes

class AbstractBidsDataset:
   ...

class BidsDataset(AbstractBidsDataset):
    layout: BIDSLayout

I'm planning on going with this approach: the implementation is invisible to the user and it solves the problem in the first approach. AbstractBidsDataset would be used in tests.

pvandyken added a commit to pvandyken/snakebids that referenced this issue Feb 4, 2023
pvandyken added a commit to pvandyken/snakebids that referenced this issue Feb 4, 2023
pvandyken added a commit to pvandyken/snakebids that referenced this issue Feb 14, 2023
pvandyken added a commit that referenced this issue Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants