Skip to content

Commit bd664b3

Browse files
committed
Minor bugfixes
1 parent 2e6122b commit bd664b3

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

bidscoin/bids.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ def __repr__(self):
710710
def __eq__(self, other):
711711
"""A shallow test if the DataType name is equal (so irrespective whether their runitems differ)"""
712712

713-
if isinstance(other, Union[DataType, str]):
713+
if isinstance(other, DataType) or isinstance(other, str):
714714
return str(self) == str(other)
715715
else:
716716
return NotImplemented
@@ -867,10 +867,14 @@ def remove_datatype(self, datatype: Union[str, DataType]):
867867
self._data.pop(datatype, None)
868868
LOGGER.bcdebug(f"The '{datatype}' datatype was removed from {self}")
869869

870-
def delete_runs(self, datatype: Union[str, DataType]):
871-
"""Delete all run-items from the datatype section"""
870+
def delete_runs(self, datatype: Union[str, DataType]=''):
871+
"""Delete all run-items from the dataformat or only from a datatype section"""
872872

873-
self._data[str(datatype)] = []
873+
if not datatype:
874+
for datatype in self.datatypes:
875+
self.delete_runs(datatype)
876+
else:
877+
self._data[str(datatype)] = []
874878

875879

876880
class BidsMap:
@@ -1461,8 +1465,7 @@ def delete_runs(self):
14611465
"""Delete all run-items from the bidsmap"""
14621466

14631467
for dataformat in self.dataformats:
1464-
for datatype in dataformat.datatypes:
1465-
dataformat.delete_runs(datatype)
1468+
dataformat.delete_runs()
14661469

14671470
def insert_run(self, runitem: RunItem, position: int=None):
14681471
"""
@@ -1751,7 +1754,7 @@ def get_dicomfield(tagname: str, dicomfile: Path) -> Union[str, int]:
17511754
17521755
Another hack is to get 'PhaseEncodingDirection` (see https://neurostars.org/t/determining-bids-phaseencodingdirection-from-dicom/612/10)
17531756
1754-
:param tagname: DICOM attribute name (e.g. 'SeriesNumber') or Pydicom-style tag number (e.g. '0x00200011', '(0x20,0x11)', '(0020, 0011)')
1757+
:param tagname: DICOM attribute name (e.g. 'SeriesNumber') or Pydicom-style tag number (e.g. '0x00200011', '(0x20,0x11)', '(0020,0011)')
17551758
:param dicomfile: The full pathname of the dicom-file
17561759
:return: Extracted tag-values as a flat string
17571760
"""
@@ -1810,7 +1813,7 @@ def get_dicomfield(tagname: str, dicomfile: Path) -> Union[str, int]:
18101813
# XA enhanced DICOM hack: Catch missing EchoNumbers from the private ICE_Dims field (0x21, 0x1106)
18111814
if tagname in ('EchoNumber', 'EchoNumbers') and not value:
18121815
for elem in dicomdata.iterall():
1813-
if elem.tag == (0x21, 0x1106):
1816+
if elem.tag == (0x21,0x1106):
18141817
value = elem.value.split('_')[1] if '_' in elem.value else ''
18151818
LOGGER.bcdebug(f"Parsed `EchoNumber(s)` from Siemens ICE_Dims `{elem.value}` as: {value}")
18161819
break

bidscoin/utilities/physio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def readphysio(fn: Union[str,Path]) -> dict:
209209
LOGGER.verbose(f"Reading physio DICOM file: {fn}")
210210
dicomdata = dcmread(fn, force=True) # The DICM tag may be missing for anonymized DICOM files
211211
manufacturer = dicomdata.get('Manufacturer')
212-
physiotag = tag.Tag(0x7fe1, 0x1010) # A private Siemens tag
212+
physiotag = tag.Tag(0x7FE1,0x1010) # A private Siemens tag
213213
if manufacturer and 'SIEMENS' not in manufacturer.upper():
214214
LOGGER.warning(f"Unsupported manufacturer: '{manufacturer}', this function is designed for SIEMENS advanced physiological logging data")
215215
if (dicomdata.get('ImageType')==['ORIGINAL','PRIMARY','RAWDATA','PHYSIO'] and dicomdata.get(physiotag).private_creator=='SIEMENS CSA NON-IMAGE') or \

docs/bidsmap.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ The run-items in the default 'bidsmap_dccn' template bidsmap have values that ar
111111
- Make a copy of the DCCN template (``[home]/.bidscoin/[version]/templates/bidsmap_dccn.yaml``) as a starting point for your own template bidsmap, and adapt it to your needs. You can set your copy as the new default template by editing the ``[home]/.bidscoin/config.toml`` file. Default templates and config file are automatically recreated from source when deleted
112112
- The power of regular expressions is nearly unlimited, you can e.g. use `negative look aheads <https://docs.python.org/3/howto/regex.html#lookahead-assertions>`__ to **not** match (exclude) certain strings
113113
- When creating new run-items, make sure to adhere to the YAML format and to the definitions in the BIDS schema files (``[path_to_bidscoin]/bidscoin/schema/datatypes``). You can test your YAML syntax using an online `YAML-validator <https://www.yamllint.com>`__ and your compliance with the BIDS standard with ``bidscoin -t your_template_bidsmap``. If all seems well you can install it using ``bidscoin -i your_template_bidsmap``.
114-
- In addition to DICOM attribute names, the more advanced/unambiguous pydicom-style `tag numbers <https://pydicom.github.io/pydicom/stable/old/base_element.html#tag>`__ can also be used for indexing a DICOM header. For instance, the ``PatientName``, ``0x00100010``, ``0x10,0x10``, ``(0x10, 0x10)``, and ``(0010, 0010)`` index keys are all equivalent.
114+
- In addition to DICOM attribute names, the more advanced/unambiguous pydicom-style `tag numbers <https://pydicom.github.io/pydicom/stable/old/base_element.html#tag>`__ can also be used for indexing a DICOM header. For instance, the ``PatientName``, ``0x00100010``, ``0x10,0x10``, ``(0x10,0x10)``, and ``(0010,0010)`` index keys are all equivalent.
115115

116116
Editing the template bidsmap
117117
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/test_bids.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ def test_dynamicvalue(self, datasource):
9393
assert datasource.dynamicvalue(r'<<PatientName:.*\^(.*?)1>>') == r'<<PatientName:.*\^(.*?)1>>'
9494
assert datasource.dynamicvalue(r'<<PatientName:.*\^(.*?)1>>', runtime=True) == 'MR'
9595
assert datasource.dynamicvalue(r'pat-<PatientName:.*\^(.*?)1>I<filename:MR_(.*?)\.dcm>') == 'patMRIsmall'
96-
assert datasource.dynamicvalue(r"<Patient's Name>") == 'CompressedSamplesMR1' # Patient's Name, 0x00100010, 0x10,0x10, (0x10, 0x10), and (0010, 0010) index keys are all equivalent
96+
assert datasource.dynamicvalue(r"<Patient's Name>") == 'CompressedSamplesMR1' # Patient's Name, 0x00100010, 0x10,0x10, (0x10,0x10), and (0010,0010) index keys are all equivalent
9797
assert datasource.dynamicvalue(r'<0x00100010>') == 'CompressedSamplesMR1'
9898
assert datasource.dynamicvalue(r'<0x10,0x10>') == 'CompressedSamplesMR1'
99-
assert datasource.dynamicvalue(r'<(0x10, 0x10)>') == 'CompressedSamplesMR1'
99+
assert datasource.dynamicvalue(r'<(0x10,0x10)>') == 'CompressedSamplesMR1'
100100
assert datasource.dynamicvalue(r'<(0010,0010)>') == 'CompressedSamplesMR1'
101101

102102

0 commit comments

Comments
 (0)