Skip to content

Commit

Permalink
fix reorder and do not accept it with auto_extract_entities
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudbore committed Jul 17, 2024
1 parent 892f8aa commit 66c62cd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
8 changes: 5 additions & 3 deletions dcm2bids/cli/dcm2bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,19 @@ def _build_arg_parser():
default=DEFAULT.output_dir,
help="Output BIDS directory. [%(default)s]")

p.add_argument("--auto_extract_entities",
g = p.add_mutually_exclusive_group()
g.add_argument("--auto_extract_entities",
action='store_true',
help="If set, it will automatically try to extract entity"
"information [task, dir, echo] based on the suffix and datatype."
" [%(default)s]")

p.add_argument("--do_not_reorder_entities",
g.add_argument("--do_not_reorder_entities",
action='store_true',
help="If set, it will not reorder entities according to the relative "
"ordering indicated in the BIDS specification and use the "
"order defined in custom_entities by the user."
"order defined in custom_entities by the user.\n"
"Cannot be used with --auto_extract_entities. "
" [%(default)s]")

p.add_argument("--bids_validate",
Expand Down
5 changes: 5 additions & 0 deletions dcm2bids/dcm2bids_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ def __init__(
self.logLevel = log_level
self.logger = logging.getLogger(__name__)

if self.auto_extract_entities and self.do_not_reorder_entities:
raise ValueError("Auto extract entities is set to True and "
"do not reorder entities is set to True. "
"Please choose only one option.")

@property
def dicom_dirs(self):
"""List of DICOMs directories"""
Expand Down
4 changes: 3 additions & 1 deletion dcm2bids/sidecar.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,9 @@ def searchDcmTagEntity(self, sidecar, desc):

# Keep entities asked in custom_entities
# If dir found in custom_entities and concatenated_matches.keys we keep it
if "custom_entities" in desc.keys():
if "custom_entities" in desc.keys() and not self.auto_extract_entities:
entities = desc["custom_entities"]
elif "custom_entities" in desc.keys():
entities = set(concatenated_matches.keys()).intersection(set(descWithTask["custom_entities"]))

# custom_entities not a key for extractor or auto_extract_entities
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dcm2bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ def test_dcm2bids_no_reorder_entities():
os.path.join(TEST_DATA_DIR, "config_test_no_reorder.json"),
bids_dir.name,
do_not_reorder_entities=True,
auto_extract_entities=True)
auto_extract_entities=False)

app.run()

Expand Down

0 comments on commit 66c62cd

Please sign in to comment.