Skip to content

Commit

Permalink
Order entities as requested.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo committed Feb 24, 2025
1 parent 38c3ac2 commit 0a2cd23
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions cubids/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,35 @@ def _entities_to_entity_set(entities):
This is a set of entities to ignore in the entity set.
The constant may be modified by the CuBIDS class, which will remove "session"
if is_longitudinal is True and acq_group_level is "session".
Examples
--------
>>> _entities_to_entity_set(
... {"subject": "01", "session": "02", "task": "rest",
... "datatype": "fmap", "acquisition": "x"}
... )
'datatype-fmap_session-02_task-rest_acquisition-x'
>>> _entities_to_entity_set(
... {"subject": "01", "session": "02", "task": "rest", "acquisition": "x"}
... )
'session-02_task-rest_acquisition-x'
>>> _entities_to_entity_set(
... {"datatype": "fmap", "subject": "01", "session": "02", "task": "rest"}
... )
'datatype-fmap_session-02_task-rest'
"""
group_keys = sorted(set(entities.keys()) - NON_KEY_ENTITIES)
# Put datatype at the beginning and acquisition at the end
if "datatype" in group_keys:
group_keys.remove("datatype")
group_keys.insert(0, "datatype")

if "acquisition" in group_keys:
group_keys.remove("acquisition")
group_keys.append("acquisition")

return "_".join([f"{key}-{entities[key]}" for key in group_keys])


Expand Down

0 comments on commit 0a2cd23

Please sign in to comment.