Skip to content

Commit

Permalink
FIX: fix pydicom field name bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrzus committed Mar 18, 2024
1 parent f6e5a94 commit a86e11b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 55 deletions.
50 changes: 25 additions & 25 deletions src/dcm_classifier/dicom_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,45 +54,45 @@
"Contrast/BolusAgent", # "(0x0018, 0x0010)"
"Diffusionb-value", # Not required
"Diffusionb-valueMax", # Not required
"Echo Number(s)",
"Echo Train Length",
"Scanning Sequence",
"Sequence Variant",
"In-plane Phase Encoding Direction",
"EchoNumbers",
"EchoTrainLength",
"ScanningSequence",
"SequenceVariant",
"InPlanePhaseEncodingDirection",
"dB/dt",
"Imaging Frequency",
"MR Acquisition Type",
"Number of Averages",
"Inversion Time",
"ImagingFrequency",
"MRAcquisitionType",
"NumberOfAverages",
"InversionTime",
"Variable Flip Angle Flag",
"AcquisitionTime",
]

inference_features: list[str] = [
"Diffusionb-valueBool",
"EchoTime",
"Echo Train Length",
"EchoTrainLength",
"FlipAngle",
"HasDiffusionGradientOrientation",
"Image Type_ADC",
"Image Type_DERIVED",
"Image Type_DIFFUSION",
"Image Type_EADC",
"Image Type_FA",
"Image Type_ORIGINAL",
"Image Type_TRACEW",
"Imaging Frequency",
"Inversion Time",
"ImageType_ADC",
"ImageType_DERIVED",
"ImageType_DIFFUSION",
"ImageType_EADC",
"ImageType_FA",
"ImageType_ORIGINAL",
"ImageType_TRACEW",
"ImagingFrequency",
"InversionTime",
"Manufacturer_siemens",
"Number of Averages",
"NumberOfAverages",
"PixelBandwidth",
"RepetitionTime",
"SAR",
"Scanning Sequence_GR",
"Scanning Sequence_IR",
"Scanning Sequence_SE",
"Sequence Variant_MP",
"Sequence Variant_SP",
"ScanningSequence_GR",
"ScanningSequence_IR",
"ScanningSequence_SE",
"SequenceVariant_MP",
"SequenceVariant_SP",
"dB/dt",
"has_b0",
"has_pos_b0",
Expand Down
10 changes: 5 additions & 5 deletions src/dcm_classifier/dicom_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,11 +500,11 @@ def _make_one_study_info_mapping_from_filelist(self) -> (str, dict):
self.has_diffusion_gradient
)
if (
volume_info_dict["Image Type_DIFFUSION"] == 1
or volume_info_dict["Image Type_ADC"] == 1
or volume_info_dict["Image Type_EADC"] == 1
or volume_info_dict["Image Type_TRACEW"] == 1
or volume_info_dict["Image Type_FA"] == 1
volume_info_dict["ImageType_DIFFUSION"] == 1
or volume_info_dict["ImageType_ADC"] == 1
or volume_info_dict["ImageType_EADC"] == 1
or volume_info_dict["ImageType_TRACEW"] == 1
or volume_info_dict["ImageType_FA"] == 1
or volume_info_dict["Diffusionb-value"] > 0
or volume_info_dict["HasDiffusionGradientOrientation"] == 1
):
Expand Down
50 changes: 25 additions & 25 deletions src/dcm_classifier/utility_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,39 +456,39 @@ def sanitize_dicom_dataset(
# ):
# The contrast is required but is empty if unknown but also may not be in every dataset
dataset_dictionary[field] = "None"
elif field == "Echo Number(s)":
elif field == "EchoNumbers":
if field not in dataset_dictionary.keys():
# EchoNumber(s) is not a required field, it can be unknown
_default_inferred_value = -12345
dataset_dictionary[field] = _default_inferred_value
vprint(
f"Inferring optional {field} value of '{_default_inferred_value}' for missing field in {dicom_filename}"
)
elif field == "Echo Train Length":
elif field == "EchoTrainLength":
if field not in dataset_dictionary.keys():
# EchoTrainLength is not a required field, it can be unknown
_default_inferred_value = -12345
dataset_dictionary[field] = _default_inferred_value
vprint(
f"Inferring optional {field} value of '{_default_inferred_value}' for missing field in {dicom_filename}"
)
elif field == "Scanning Sequence":
elif field == "ScanningSequence":
if field not in dataset_dictionary.keys():
# ScanningSequence is not a required field, it can be unknown
_default_inferred_value = "UnknownScanningSequence"
dataset_dictionary[field] = _default_inferred_value
vprint(
f"Inferring optional {field} value of '{_default_inferred_value}' for missing field in {dicom_filename}"
)
elif field == "Sequence Variant":
elif field == "SequenceVariant":
if field not in dataset_dictionary.keys():
# SequenceVariant is not a required field, it can be unknown
_default_inferred_value = "UnknownSequenceVariant"
dataset_dictionary[field] = _default_inferred_value
vprint(
f"Inferring optional {field} value of '{_default_inferred_value}' for missing field in {dicom_filename}"
)
elif field == "In-plane Phase Encoding Direction":
elif field == "InPlanePhaseEncodingDirection":
if field not in dataset_dictionary.keys():
# InplanePhaseEncodingDirection is not a required field, it can be unknown
_default_inferred_value = "UnknownInplanePhaseEncodingDirection"
Expand All @@ -504,39 +504,39 @@ def sanitize_dicom_dataset(
vprint(
f"Inferring optional {field} value of '{_default_inferred_value}' for missing field in {dicom_filename}"
)
elif field == "Imaging Frequency":
elif field == "ImagingFrequency":
if field not in dataset_dictionary.keys():
# ImagingFrequency is not a required field, it can be unknown
_default_inferred_value = -12345
dataset_dictionary[field] = _default_inferred_value
vprint(
f"Inferring optional {field} value of '{_default_inferred_value}' for missing field in {dicom_filename}"
)
elif field == "MR Acquisition Type":
elif field == "MRAcquisitionType":
if field not in dataset_dictionary.keys():
# MRAcquisitionType is not a required field, it can be unknown
_default_inferred_value = "UnknownMRAcquisitionType"
dataset_dictionary[field] = _default_inferred_value
vprint(
f"Inferring optional {field} value of '{_default_inferred_value}' for missing field in {dicom_filename}"
)
elif field == "Number of Averages":
elif field == "NumberOfAverages":
if field not in dataset_dictionary.keys():
# NumberOfAverages is not a required field, it can be unknown
_default_inferred_value = -12345
dataset_dictionary[field] = _default_inferred_value
vprint(
f"Inferring optional {field} value of '{_default_inferred_value}' for missing field in {dicom_filename}"
)
elif field == "Inversion Time":
elif field == "InversionTime":
if field not in dataset_dictionary.keys():
# InversionTime is not a required field, it can be unknown
_default_inferred_value = -12345
dataset_dictionary[field] = _default_inferred_value
vprint(
f"Inferring optional {field} value of '{_default_inferred_value}' for missing field in {dicom_filename}"
)
elif field == "Variable Flip Angle Flag":
elif field == "VariableFlipAngleFlag":
if field not in dataset_dictionary.keys():
# VariableFlipAngleFlag is not a required field, it can be unknown
_default_inferred_value = "UnknownVariableFlipAngleFlag"
Expand All @@ -546,7 +546,7 @@ def sanitize_dicom_dataset(
)
elif field == "AcquisitionTime":
if field not in dataset_dictionary.keys():
# InversionTime is not a required field, it can be unknown
# AcquisitionTime is not a required field, it can be unknown
_default_inferred_value = -12345
dataset_dictionary[field] = _default_inferred_value
vprint(
Expand All @@ -565,16 +565,16 @@ def sanitize_dicom_dataset(

# organize required features
image_type_features: list[str] = [
field for field in features if ("Image Type_" in field and "ADC" not in field)
field for field in features if ("ImageType_" in field and "ADC" not in field)
]
manufacturer_features: list[str] = [
field for field in features if "Manufacturer_" in field
]
scanning_sequence_features: list[str] = [
field for field in features if "Scanning Sequence_" in field
field for field in features if "ScanningSequence_" in field
]
scanning_variant_features: list[str] = [
field for field in features if "Sequence Variant_" in field
field for field in features if "SequenceVariant_" in field
]


Expand Down Expand Up @@ -605,16 +605,16 @@ def get_coded_dictionary_elements(
lower_value_str: str = str(value).lower()
if "adc" in lower_value_str:
if "eadc" in lower_value_str:
dataset_dictionary["Image Type_EADC"] = 1
dataset_dictionary["Image Type_ADC"] = 0
dataset_dictionary["ImageType_EADC"] = 1
dataset_dictionary["ImageType_ADC"] = 0
else:
dataset_dictionary["Image Type_ADC"] = 1
dataset_dictionary["Image Type_EADC"] = 0
dataset_dictionary["ImageType_ADC"] = 1
dataset_dictionary["ImageType_EADC"] = 0
else:
dataset_dictionary["Image Type_ADC"] = 0
dataset_dictionary["Image Type_EADC"] = 0
dataset_dictionary["ImageType_ADC"] = 0
dataset_dictionary["ImageType_EADC"] = 0

throw_away: int = len("Image Type_")
throw_away: int = len("ImageType_")
for feature in image_type_features:
if feature[throw_away:].lower() in lower_value_str:
dataset_dictionary[feature] = 1
Expand All @@ -632,17 +632,17 @@ def get_coded_dictionary_elements(
dataset_dictionary[feature] = 1
else:
dataset_dictionary[feature] = 0
elif name == "Scanning Sequence":
elif name == "ScanningSequence":
lower_scanning_sequence_string: str = str(value).lower()
throw_away: int = len("Scanning Sequence_")
throw_away: int = len("ScanningSequence_")
for feature in scanning_sequence_features:
if feature[throw_away:].lower() in lower_scanning_sequence_string:
dataset_dictionary[feature] = 1
else:
dataset_dictionary[feature] = 0
elif name == "Sequence Variant":
elif name == "SequenceVariant":
lower_sequence_variant_string: str = str(value).lower()
throw_away: int = len("Sequence Variant_")
throw_away: int = len("SequenceVariant_")
for feature in scanning_variant_features:
if feature[throw_away:].lower() in lower_sequence_variant_string:
dataset_dictionary[feature] = 1
Expand Down

0 comments on commit a86e11b

Please sign in to comment.