-
Notifications
You must be signed in to change notification settings - Fork 124
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
RFC: PyBIDS 1.0 layout API #989
Comments
Is the |
Dropping |
Question for the group: Do we want to architect this as abstract base classes, to facilitate reimplementation, or keep everything concrete for now? |
From a typing perspective, the most flexible (and Pythonic?) would probably be a |
Okay. I'll try coding it up as a collection of protocols. I've only used them as a hack before, I'm curious to try this. |
Realizing I should have tagged @erdalkaraca and @ghisvail on this. I suspect you will have opinions. |
Often I am wanting to query and compare at the conceptual level of images instead of having to deal with particular files and their extensions. To this end, something I would find useful is a Rough example of what I'm thinking: class BIDSImage():
# least common denominator of source entities
entities: dict[Entity, Value | Index]
# suffix of the root image
suffix: str | None
def __init__(root_image: BIDSFile, related_files: BIDSFile): pass
# Return path to the root image file
def get_root_file() -> Path: pass
# Return list of all files this class was derived from
def get_files() -> list[Path]: pass
# Shared metadata from all files aggregated
def metadata(self) -> dict[str, Any]: pass |
Thanks for the feedback! I'm not sure that we want this additional abstraction in pybids; more new classes is more cognitive overhead for downstream users. But making sure you have the tools to quickly build it yourself if it is useful to you is in scope. |
Add a higher level `BIDSTable` interface inspired by the [proposed PyBIDS API redesign](bids-standard/pybids#989). * Move entities module one level up * Move `join_bids_path()` helper into `entities` * Add `BIDSTable` subclass of `DataFrame` Add `BIDSTable` subclass of `DataFrame` with convenience methods for accessing subtables and flattened metadata. * Add long names to entities field metadata * Add table `filter()` method Add `BIDSTable.filter()` which filters rows according to a condition applied to a single column. The supported conditions follow `pandas.Series.filter()`. * Add `files` property returning list of `BIDSFile`s Also change `file` column group to `finfo` to try to limit possible confusion. * Update example and bug fixes Bug fixes: - Set the index of `flat_metadata` to the parent table's index. - Treat NA in the row mask as False in `filter()`. * Add properties for subjects, datatypes, etc * Add `sort_entities()` * Upgrade required python to >=3.8 * Add `filter_multi` method and documentation PyBIDS supports querying a layout with multiple filters specified as keyword arguments. This is a nice interface, and is also useful for programmatic filtering. Here we add a `filter_multi()` method to do something similar. * Flatten JSON metadata only to first level * Fix mypy error * Move some things around * Add `func` arg to `filter()` Add a `func` arg option to `filter` for arbitrary lambda function filtering. Also move `join_bids_path()` into the `table` module. * More moving around * Don't use `removeprefix` * Yet more moving around * Update example * Add a comment on the filter api * Change arg name output -> index_path Having the argument be `output` in `bids2table` was confusing when you only want to load a table.
Context: Over the last year or so, we've looked into replacing the SQLAlchemy-based
BIDSLayout
with one based on ANCP-BIDS. In the process, we've found issues in the current API where we are forced to decide whether it's worth shimming the old behavior in to avoid breaking things for users (if there are any).Ultimately, we've decided that the API is too large and has features that seem to have more maintenance burden than value to users. So we want to propose a new API.
We would like this API to be:
PyBIDS 1.0 layout API
Base types (see PaddedInt):
Data structures:
It can be useful to group multiple datasets into a single logical layout, for example, when querying raw data and derivatives together. Therefore we also propose an explicit collection of layouts, such that each method/property is implemented by aggregating over all of the collected layouts.
layout.utils
A module will be provided to provide utilities that only rely on the
BIDSLayout
API. The goal is to provide implementations of common tasks that will survive refactors and serve as exemplar code for working with the API.Some (potentially layout-free) parsing/creation seems useful:
Please let us know if there are things you need to do that cannot be done with this API. We recognize that this will break things, but if there are features you use that require more than 10-20 lines of code to reimplement without access to
BIDSLayout
internals, please let us know.The text was updated successfully, but these errors were encountered: