Skip to content

Commit

Permalink
Bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelzwiers committed Sep 16, 2024
1 parent 3012926 commit 2c4c9eb
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions bidscoin/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"""
Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -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 []):
Expand All @@ -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():
Expand Down

0 comments on commit 2c4c9eb

Please sign in to comment.