Skip to content

Commit

Permalink
[FIX] Permitting desc for channels and events (#2043)
Browse files Browse the repository at this point in the history
Co-authored-by: Christopher J. Markiewicz <[email protected]>
  • Loading branch information
neuromechanist and effigies authored Feb 5, 2025
1 parent d5d4467 commit 88f3e14
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 5 deletions.
54 changes: 54 additions & 0 deletions src/schema/rules/files/deriv/preprocessed_data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,54 @@ beh_noncontinuous_common:
space: optional
description: optional

channels_channels_common:
$ref: rules.files.raw.channels.channels
entities:
$ref: rules.files.raw.channels.channels.entities
description: optional

channels_channels__meg_common:
$ref: rules.files.raw.channels.channels__meg
entities:
$ref: rules.files.raw.channels.channels__meg.entities
description: optional

channels_channels__motion_common:
$ref: rules.files.raw.channels.channels__motion
entities:
$ref: rules.files.raw.channels.channels__motion.entities
description: optional

channels_coordsystem_common:
$ref: rules.files.raw.channels.coordsystem
entities:
$ref: rules.files.raw.channels.coordsystem.entities
description: optional

channels_coordsystem__eeg_common:
$ref: rules.files.raw.channels.coordsystem__eeg
entities:
$ref: rules.files.raw.channels.coordsystem__eeg.entities
description: optional

channels_electrodes_common:
$ref: rules.files.raw.channels.electrodes
entities:
$ref: rules.files.raw.channels.electrodes.entities
description: optional

channels_electrodes__meg_common:
$ref: rules.files.raw.channels.electrodes__meg
entities:
$ref: rules.files.raw.channels.electrodes__meg.entities
description: optional

channels_electrodes_optodes_common:
$ref: rules.files.raw.channels.optodes
entities:
$ref: rules.files.raw.channels.optodes.entities
description: optional

dwi_dwi_common:
$ref: rules.files.raw.dwi.dwi
entities:
Expand Down Expand Up @@ -229,3 +277,9 @@ pet_blood_common:
$ref: rules.files.raw.pet.blood.entities
space: optional
description: optional

task_events_common:
$ref: rules.files.raw.task.events
entities:
$ref: rules.files.raw.task.events.entities
description: optional
21 changes: 16 additions & 5 deletions tools/schemacode/src/bidsschematools/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,21 @@ def _find(obj, predicate):
yield from _find(item, predicate)


def _dereference(namespace, base_schema):
# In-place, recursively dereference objects
# This allows a referenced object to itself contain a reference
# A dependency graph could be constructed, but would likely be slower
# to build than to duplicate a couple dereferences
for struct in _find(namespace, lambda obj: "$ref" in obj):
target = base_schema.get(struct["$ref"])
if target is None:
raise ValueError(f"Reference {struct['$ref']} not found in schema.")
if isinstance(target, Mapping):
struct.pop("$ref")
_dereference(target, base_schema)
struct.update({**target, **struct})


def dereference(namespace, inplace=True):
"""Replace references in namespace with the contents of the referred object.
Expand All @@ -109,11 +124,7 @@ def dereference(namespace, inplace=True):
if not inplace:
namespace = deepcopy(namespace)

for struct in _find(namespace, lambda obj: "$ref" in obj):
target = namespace.get(struct["$ref"])
if isinstance(target, Mapping):
struct.pop("$ref")
struct.update({**target, **struct})
_dereference(namespace, namespace)

# At this point, any remaining refs are one-off objects in lists
for struct in _find(namespace, lambda obj: any("$ref" in sub for sub in obj)):
Expand Down

0 comments on commit 88f3e14

Please sign in to comment.