From 2c4c9eb3f47dc0e225ee77d2fa120fd97a4bd54c Mon Sep 17 00:00:00 2001 From: MarsMellow Date: Mon, 16 Sep 2024 19:41:15 +0200 Subject: [PATCH] Bugfixes --- bidscoin/bids.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/bidscoin/bids.py b/bidscoin/bids.py index 5b3a6910..44e2dca9 100644 --- a/bidscoin/bids.py +++ b/bidscoin/bids.py @@ -375,7 +375,7 @@ def __init__(self, dataformat: str='', datatype: str='', data: dict=None, dataso super().__setattr__('_data', data or {'provenance': '', 'properties': {}, 'attributes': {}, 'meta': {}}) # Set the regular attributes - self.datasource = datasource = copy.deepcopy(datasource) if datasource else DataSource(self.provenance, plugins, dataformat, options) + self.datasource = datasource = copy.deepcopy(datasource) if datasource else DataSource(data.get('provenance') if data else '', plugins, dataformat, options) """The DataSource object that is deepcopied or created from the run-item provenance""" datasource.subprefix = options['subprefix'] if options else datasource.subprefix datasource.sesprefix = options['sesprefix'] if options else datasource.sesprefix @@ -389,7 +389,7 @@ def __init__(self, dataformat: str='', datatype: str='', data: dict=None, dataso """The plugin dictionaries with their options""" # Set the default data attributes - self.provenance = data['provenance'] if data else str(datasource.path) + self.provenance = data.get('provenance','') if data else str(datasource.path) """The file path of the data source""" self.properties = Properties({'filepath': '', 'filename': '', 'filesize': '', 'nrfiles': None}) """The file system properties from the data source that can be matched against other data sources""" @@ -713,6 +713,10 @@ def __eq__(self, other): else: return NotImplemented + def __hash__(self): + + return hash(self.datatype) + @property def runitems(self) -> List[RunItem]: """Returns a list of the RunItem objects for this datatype""" @@ -805,6 +809,10 @@ def __eq__(self, other): else: return NotImplemented + def __hash__(self): + + return hash(self.datatype) + @property def subject(self) -> str: """The regular expression for extracting the subject identifier""" @@ -930,7 +938,6 @@ def __init__(self, yamlfile: Path, folder: Path=templatefolder, plugins: Iterabl """Gets a list of the DataFormat objects in the bidsmap (e.g. DICOM)""" # Add missing provenance info, run dictionaries and bids entities - runitem_ = RunItem() for dataformat in self.dataformats: for datatype in dataformat.datatypes: for index, runitem in enumerate(datatype.runitems or []): @@ -949,11 +956,6 @@ def __init__(self, yamlfile: Path, folder: Path=templatefolder, plugins: Iterabl LOGGER.bcdebug(f"Updating provenance: {provenance} -> {store}") runitem.provenance = str(store) - # Add default data dictionaries if they are missing (e.g. "meta" or "properties") - for attr in ('properties', 'attributes', 'bids', 'meta'): - datadict = getattr(runitem, attr) - datadict = datadict or getattr(runitem_, attr) - # Add missing bids entities suffix = runitem.bids.get('suffix') if runitem.datasource.has_plugin():