From 6bc7cc6cd1872b4dcb042f1dc15eafaab14b8187 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 17 Jun 2024 22:13:55 +0000 Subject: [PATCH 1/4] Bump urllib3 from 2.0.7 to 2.2.2 Bumps [urllib3](https://github.com/urllib3/urllib3) from 2.0.7 to 2.2.2. - [Release notes](https://github.com/urllib3/urllib3/releases) - [Changelog](https://github.com/urllib3/urllib3/blob/main/CHANGES.rst) - [Commits](https://github.com/urllib3/urllib3/compare/2.0.7...2.2.2) --- updated-dependencies: - dependency-name: urllib3 dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements-doc.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-doc.txt b/requirements-doc.txt index 359c22b7..3201a98a 100644 --- a/requirements-doc.txt +++ b/requirements-doc.txt @@ -33,6 +33,6 @@ regex==2023.6.3 requests==2.32.0 six==1.16.0 smmap==5.0.0 -urllib3==2.0.7 +urllib3==2.2.2 verspec==0.1.0 watchdog==3.0.0 From b66bf98259b2d2547e5e68f6f1e6c4801d157d31 Mon Sep 17 00:00:00 2001 From: arnaudbore Date: Thu, 27 Jun 2024 15:35:52 -0400 Subject: [PATCH 2/4] working version --- dcm2bids/acquisition.py | 15 ++++++++++++--- dcm2bids/dcm2bids_gen.py | 3 ++- dcm2bids/sidecar.py | 37 ++++++++++++++++++++++++++++++------- dcm2bids/utils/utils.py | 10 ++++++---- 4 files changed, 50 insertions(+), 15 deletions(-) diff --git a/dcm2bids/acquisition.py b/dcm2bids/acquisition.py index cba30c76..c20841b6 100644 --- a/dcm2bids/acquisition.py +++ b/dcm2bids/acquisition.py @@ -4,6 +4,7 @@ import logging from os.path import join as opj +from os import sep from dcm2bids.utils.utils import DEFAULT from dcm2bids.version import __version__ @@ -30,6 +31,7 @@ def __init__( id=None, src_sidecar=None, sidecar_changes=None, + bids_uri=None, **kwargs ): self.logger = logging.getLogger(__name__) @@ -43,6 +45,7 @@ def __init__( self.suffix = suffix self.custom_entities = custom_entities self.src_sidecar = src_sidecar + self.bids_uri = bids_uri if sidecar_changes is None: self.sidecar_changes = {} @@ -277,10 +280,16 @@ def dstSidecarData(self, idList): else: values.append(idList.get(val, val)) if values[-1] != val: - if isinstance(values[-1], list): - values[-1] = ["bids::" + img_dest for img_dest in values[-1]] + if self.bids_uri == DEFAULT.bids_uri: + if isinstance(values[-1], list): + values[-1] = ["bids::" + img_dest for img_dest in values[-1]] + else: + values[-1] = "bids::" + values[-1] else: - values[-1] = "bids::" + values[-1] + if isinstance(values[-1], list): + values[-1] = [img_dest.replace(self.participant.name + sep, "") for img_dest in values[-1]] + else: + values[-1] = values[-1].replace(self.participant.name + sep, "") # handle if nested list vs str flat_value_list = [] diff --git a/dcm2bids/dcm2bids_gen.py b/dcm2bids/dcm2bids_gen.py index ae5e4065..b6c57ec1 100644 --- a/dcm2bids/dcm2bids_gen.py +++ b/dcm2bids/dcm2bids_gen.py @@ -102,7 +102,8 @@ def run(self): self.config.get("search_method", DEFAULT.search_method), self.config.get("case_sensitive", DEFAULT.case_sensitive), self.config.get("dup_method", DEFAULT.dup_method), - self.config.get("post_op", DEFAULT.post_op) + self.config.get("post_op", DEFAULT.post_op), + self.config.get("bids_uri", DEFAULT.bids_uri) ) parser.build_graph() parser.build_acquisitions(self.participant) diff --git a/dcm2bids/sidecar.py b/dcm2bids/sidecar.py index b0c344c0..592eae52 100644 --- a/dcm2bids/sidecar.py +++ b/dcm2bids/sidecar.py @@ -11,7 +11,8 @@ from dcm2bids.acquisition import Acquisition from dcm2bids.utils.io import load_json -from dcm2bids.utils.utils import DEFAULT, convert_dir, combine_dict_extractors, splitext_ +from dcm2bids.utils.utils import (DEFAULT, convert_dir, combine_dict_extractors, + splitext_) compare_float_keys = ["lt", "gt", "le", "ge", "btw", "btwe"] @@ -99,11 +100,13 @@ def __init__(self, search_method=DEFAULT.search_method, case_sensitive=DEFAULT.case_sensitive, dup_method=DEFAULT.dup_method, - post_op=DEFAULT.post_op): + post_op=DEFAULT.post_op, + bids_uri=DEFAULT.bids_uri): self.logger = logging.getLogger(__name__) self._search_method = "" self._dup_method = "" self._post_op = "" + self._bids_uri = "" self.graph = OrderedDict() self.acquisitions = [] self.extractors = extractors @@ -114,6 +117,7 @@ def __init__(self, self.case_sensitive = case_sensitive self.dup_method = dup_method self.post_op = post_op + self.bids_uri = bids_uri @property def search_method(self): @@ -218,6 +222,25 @@ def post_op(self, value): raise ValueError("post_op is not defined correctly. " "Please check the documentation.") + @property + def bids_uri(self): + return self._bids_uri + + @bids_uri.setter + def bids_uri(self, value): + """ + Checks if the method bids_uri is using is implemented + Warns the user if not and fall back to default + """ + if value in DEFAULT.bids_uri_choices: + self._bids_uri = value + else: + self.bids_uri = DEFAULT.bids_uri + self.logger.warning( + "BIDS URI methods implemented: %s", DEFAULT.bids_uri_choices) + self.logger.warning(f"{value} is not a bids URI method implemented.") + self.logger.warning(f"Falling back to default: {DEFAULT.bids_uri}.") + @property def case_sensitive(self): return self._case_sensitive @@ -393,9 +416,10 @@ def build_acquisitions(self, participant): if len(valid_descriptions) == 1: desc = valid_descriptions[0] desc, sidecar = self.searchDcmTagEntity(sidecar, desc) - acq = Acquisition(participant, - src_sidecar=sidecar, **desc) + src_sidecar=sidecar, + bids_uri=self.bids_uri, + **desc) acq.setDstFile() if acq.id: @@ -414,6 +438,7 @@ def build_acquisitions(self, participant): self.logger.warning(f"Several Pairing <- {sidecarName}") for desc in valid_descriptions: acq = Acquisition(participant, + bids_uri=self.bids_uri, **desc) self.logger.warning(f" -> {acq.suffix}") @@ -438,7 +463,6 @@ def searchDcmTagEntity(self, sidecar, desc): if self.auto_extract_entities: self.extractors = combine_dict_extractors(self.extractors, DEFAULT.auto_extractors) - for dcmTag in self.extractors: if dcmTag in sidecar.data.keys(): dcmInfo = sidecar.data.get(dcmTag) @@ -473,12 +497,11 @@ def searchDcmTagEntity(self, sidecar, desc): if left_auto_entities: self.logger.warning(f"{left_auto_entities} have not been found for datatype '{descWithTask['datatype']}' " f"and suffix '{descWithTask['suffix']}'.") - + entities = list(entities) + list(auto_entities) entities = list(set(entities)) descWithTask["custom_entities"] = entities - for curr_entity in entities: if curr_entity in concatenated_matches.keys(): if curr_entity == 'dir': diff --git a/dcm2bids/utils/utils.py b/dcm2bids/utils/utils.py index fd9426c1..45bf61aa 100644 --- a/dcm2bids/utils/utils.py +++ b/dcm2bids/utils/utils.py @@ -59,7 +59,7 @@ class DEFAULT(object): "func_bold": ["task"], "func_sbref": ["task"], "fmap_epi": ["dir"]} - + compKeys = ["AcquisitionTime", "SeriesNumber", "SidecarFilename"] search_methodChoices = ["fnmatch", "re"] search_method = "fnmatch" @@ -67,6 +67,8 @@ class DEFAULT(object): dup_method = "run" runTpl = "_run-{:02d}" dupTpl = "_dup-{:02d}" + bids_uri_choices = ["URI", "relative"] + bids_uri = "URI" case_sensitive = True # Entity table: @@ -143,15 +145,15 @@ def convert_dir(dir): def combine_dict_extractors(d1, d2): - """ combine dict + """ combine dict Args: d1 (dic): dictionary d2 (dic): dictionary - + Returns: dict: dictionary with combined information if d1 d2 use the same keys, return dict will return a list of items. - """ + """ return { k: [d[k][0] for d in (d1, d2) if k in d] for k in set(d1.keys()) | set(d2.keys()) From 75399f9e8c95e4c15e4fc322ccc33ec01a67c7fc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 6 Jul 2024 00:28:12 +0000 Subject: [PATCH 3/4] Bump certifi from 2023.7.22 to 2024.7.4 Bumps [certifi](https://github.com/certifi/python-certifi) from 2023.7.22 to 2024.7.4. - [Commits](https://github.com/certifi/python-certifi/compare/2023.07.22...2024.07.04) --- updated-dependencies: - dependency-name: certifi dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements-doc.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-doc.txt b/requirements-doc.txt index 3201a98a..39902dd2 100644 --- a/requirements-doc.txt +++ b/requirements-doc.txt @@ -1,5 +1,5 @@ Babel==2.12.1 -certifi==2023.7.22 +certifi==2024.7.4 charset-normalizer==3.2.0 click==8.1.4 colorama==0.4.6 From 5a00d3f3356a6f6ddea2aba340e483de8e01c38a Mon Sep 17 00:00:00 2001 From: arnaudbore Date: Wed, 17 Jul 2024 11:01:47 -0400 Subject: [PATCH 4/4] add data test --- ...est_multiple_intendedfor_uri_relative.json | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/data/config_test_multiple_intendedfor_uri_relative.json diff --git a/tests/data/config_test_multiple_intendedfor_uri_relative.json b/tests/data/config_test_multiple_intendedfor_uri_relative.json new file mode 100644 index 00000000..2c3e9053 --- /dev/null +++ b/tests/data/config_test_multiple_intendedfor_uri_relative.json @@ -0,0 +1,34 @@ +{ + "search_method": "fnmatch", + "extractors": {"SeriesDescription": ["task-(?P[a-zA-Z0-9]+)"]}, + "bids_uri": "relative", + "descriptions": [ + { + "id": "localizer", + "datatype": "localizer", + "suffix": "localizer", + "criteria": { + "SeriesDescription": "locali*" + } + }, + { + "id": "T1", + "datatype": "anat", + "suffix": "T1w", + "criteria": { + "SidecarFilename": "*MPRAGE*" + } + }, + { + "datatype": "fmap", + "suffix": "fmap", + "criteria": { + "EchoNumber": 1, + "EchoTime": 0.00492 + }, + "sidecar_changes": { + "IntendedFor": ["localizer", "T1"] + } + } + ] +}