Skip to content

Commit 6994398

Browse files
committed
Merge remote-tracking branch 'upstream/maint/1.10.0'
2 parents f8cac51 + c4eab99 commit 6994398

File tree

4 files changed

+85
-11
lines changed

4 files changed

+85
-11
lines changed

src/schema/objects/formats.yaml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,18 @@ datetime:
7070
display_name: Datetime
7171
description: |
7272
A datetime in the form `"YYYY-MM-DDThh:mm:ss[.000000][Z]"`,
73-
where [.000000] is an optional subsecond resolution between 1 and 6 decimal points,
74-
and [Z] is an optional, valid timezone code.
75-
pattern: '[0-9]{4}-[0-9]{2}-[0-9]{2}T(?:2[0-3]|[01][0-9]):[0-5][0-9]:[0-5][0-9](\.[0-9]{1,6})?([A-Z]{2,4})?'
73+
where `[.000000]` is an optional subsecond resolution between 1 and 6 decimal points,
74+
and `[Z]` is an optional literal character `Z` that indicates
75+
Coordinated Universal Time (UTC).
76+
pattern: "\
77+
[0-9]{4}\
78+
-(?:0[1-9]|1[0-2])\
79+
-(?:0[1-9]|[12][0-9]|3[01])\
80+
T(?:2[0-3]|[01][0-9])\
81+
:[0-5][0-9]\
82+
:(?:[0-5][0-9]|60)\
83+
(?:\\.[0-9]{1,6})?\
84+
Z?"
7685
file_relative:
7786
display_name: Path relative to the parent file
7887
description: |

src/schema/rules/files/deriv/preprocessed_data.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,54 @@ beh_noncontinuous_common:
6969
space: optional
7070
description: optional
7171

72+
channels_channels_common:
73+
$ref: rules.files.raw.channels.channels
74+
entities:
75+
$ref: rules.files.raw.channels.channels.entities
76+
description: optional
77+
78+
channels_channels__meg_common:
79+
$ref: rules.files.raw.channels.channels__meg
80+
entities:
81+
$ref: rules.files.raw.channels.channels__meg.entities
82+
description: optional
83+
84+
channels_channels__motion_common:
85+
$ref: rules.files.raw.channels.channels__motion
86+
entities:
87+
$ref: rules.files.raw.channels.channels__motion.entities
88+
description: optional
89+
90+
channels_coordsystem_common:
91+
$ref: rules.files.raw.channels.coordsystem
92+
entities:
93+
$ref: rules.files.raw.channels.coordsystem.entities
94+
description: optional
95+
96+
channels_coordsystem__eeg_common:
97+
$ref: rules.files.raw.channels.coordsystem__eeg
98+
entities:
99+
$ref: rules.files.raw.channels.coordsystem__eeg.entities
100+
description: optional
101+
102+
channels_electrodes_common:
103+
$ref: rules.files.raw.channels.electrodes
104+
entities:
105+
$ref: rules.files.raw.channels.electrodes.entities
106+
description: optional
107+
108+
channels_electrodes__meg_common:
109+
$ref: rules.files.raw.channels.electrodes__meg
110+
entities:
111+
$ref: rules.files.raw.channels.electrodes__meg.entities
112+
description: optional
113+
114+
channels_electrodes_optodes_common:
115+
$ref: rules.files.raw.channels.optodes
116+
entities:
117+
$ref: rules.files.raw.channels.optodes.entities
118+
description: optional
119+
72120
dwi_dwi_common:
73121
$ref: rules.files.raw.dwi.dwi
74122
entities:
@@ -229,3 +277,9 @@ pet_blood_common:
229277
$ref: rules.files.raw.pet.blood.entities
230278
space: optional
231279
description: optional
280+
281+
task_events_common:
282+
$ref: rules.files.raw.task.events
283+
entities:
284+
$ref: rules.files.raw.task.events.entities
285+
description: optional

tools/schemacode/src/bidsschematools/schema.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,21 @@ def _find(obj, predicate):
9090
yield from _find(item, predicate)
9191

9292

93+
def _dereference(namespace, base_schema):
94+
# In-place, recursively dereference objects
95+
# This allows a referenced object to itself contain a reference
96+
# A dependency graph could be constructed, but would likely be slower
97+
# to build than to duplicate a couple dereferences
98+
for struct in _find(namespace, lambda obj: "$ref" in obj):
99+
target = base_schema.get(struct["$ref"])
100+
if target is None:
101+
raise ValueError(f"Reference {struct['$ref']} not found in schema.")
102+
if isinstance(target, Mapping):
103+
struct.pop("$ref")
104+
_dereference(target, base_schema)
105+
struct.update({**target, **struct})
106+
107+
93108
def dereference(namespace, inplace=True):
94109
"""Replace references in namespace with the contents of the referred object.
95110
@@ -109,11 +124,7 @@ def dereference(namespace, inplace=True):
109124
if not inplace:
110125
namespace = deepcopy(namespace)
111126

112-
for struct in _find(namespace, lambda obj: "$ref" in obj):
113-
target = namespace.get(struct["$ref"])
114-
if isinstance(target, Mapping):
115-
struct.pop("$ref")
116-
struct.update({**target, **struct})
127+
_dereference(namespace, namespace)
117128

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

tools/schemacode/src/bidsschematools/tests/test_schema.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ def test_formats(schema_obj):
8585
"2022-01-05T13:16:30",
8686
"2022-01-05T13:16:30.5", # subsecond resolution is allowed
8787
"2022-01-05T13:16:30.000005", # up to 6 decimal points
88-
"2022-01-05T13:16:30UTC", # timezones are allowed
89-
"2022-01-05T13:16:30.05UTC",
88+
"2022-01-05T13:16:30Z", # UTC indicator is allowed
89+
"2022-01-05T13:16:30.05Z",
9090
],
9191
"time": [
9292
"13:16:30",
@@ -133,7 +133,7 @@ def test_formats(schema_obj):
133133
],
134134
"datetime": [
135135
"2022-01-05T13:16:30.1000005", # too many decimal points
136-
"2022-01-05T13:16:30U", # time zone too short
136+
"2022-01-05T13:16:30U", # Only Z is permitted
137137
"2022-01-05T13:16:30UTCUTC", # time zone too long
138138
"2022-01-05T34:10:10", # invalid time
139139
],

0 commit comments

Comments
 (0)