From de07958a02509cd77a74ea24bcbb29ee47c4412b Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Mon, 7 Feb 2022 14:16:23 -0500 Subject: [PATCH] ENH: added populating order of entities from bids schema copy --- heudiconv/bids/schema.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 heudiconv/bids/schema.py diff --git a/heudiconv/bids/schema.py b/heudiconv/bids/schema.py new file mode 100644 index 00000000..3c271b98 --- /dev/null +++ b/heudiconv/bids/schema.py @@ -0,0 +1,30 @@ +from pathlib import Path +import yaml + + +def _load_entities_order(): + # we carry the copy of the schema + schema_p = Path(__file__).parent / "data" / "schema" + with (schema_p / "objects" / "entities.yaml").open() as f: + entities = yaml.load(f) + + with (schema_p / "rules" / "entities.yaml").open() as f: + entities_full_order = yaml.load(f) + + # map from full name to short "entity" + return [entities[e]["entity"] for e in entities_full_order] + + +class BIDSFile: + """ as defined in https://bids-specification.readthedocs.io/en/stable/99-appendices/04-entity-table.html + which might soon become machine readable + order matters + """ + + _known_entities = _load_entities_order() + + +# TEMP: just for now, could be moved/removed +def test_BIDSFile(): + assert BIDSFile._known_entities[:2] == ['sub', 'ses'] + print(BIDSFile._known_entities) \ No newline at end of file