From 8f13d39702a323d19159c738ec532ff6115847f0 Mon Sep 17 00:00:00 2001 From: vsoch Date: Fri, 16 Oct 2020 10:21:15 -0600 Subject: [PATCH 1/2] adding stop_before_pixels to read_file of dicom parser Signed-off-by: vsoch --- CHANGELOG.md | 1 + deid/dicom/header.py | 11 +++++++++-- deid/dicom/parser.py | 6 ++++-- deid/version.py | 2 +- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e374ef84..6787feb1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and **Merged pull requests**. Critical items to know are: Referenced versions in headers are tagged on Github, in parentheses are for pypi. ## [vxx](https://github.com/pydicom/deid/tree/master) (master) + - adding stop_before_pixels to read_file in parser (0.2.24) - removing verbosity of debug logger (0.2.23) - changing iteration technique through fields to properly add nested uids [#153](https://github.com/pydicom/deid/issues/153) (0.2.22) - change to return results from detect when recipe does not contain filters [#155](https://github.com/pydicom/deid/issues/155) diff --git a/deid/dicom/header.py b/deid/dicom/header.py index 3d4dd24d..ebf904d4 100644 --- a/deid/dicom/header.py +++ b/deid/dicom/header.py @@ -44,7 +44,12 @@ def get_identifiers( - dicom_files, force=True, config=None, strip_sequences=False, remove_private=False + dicom_files, + force=True, + config=None, + strip_sequences=False, + remove_private=False, + stop_before_pixels=False, ): """extract all identifiers from a dicom image. This function returns a lookup by file name, where each value indexed @@ -74,7 +79,9 @@ def get_identifiers( # Parse each dicom file for dicom_file in dicom_files: - parser = DicomParser(dicom_file, force=force) + parser = DicomParser( + dicom_file, force=force, stop_before_pixels=stop_before_pixels + ) lookup[parser.dicom_file] = parser.get_fields() return lookup diff --git a/deid/dicom/parser.py b/deid/dicom/parser.py index 25c050fb..cfc7a874 100644 --- a/deid/dicom/parser.py +++ b/deid/dicom/parser.py @@ -79,7 +79,7 @@ def __str__(self): def __repr__(self): return self.__str__() - def load(self, dicom_file, force=True): + def load(self, dicom_file, force=True, stop_before_pixels=False): """Ensure that the dicom file exists, and use full path. Here we load the file, and save the dicom, dicom_file, and dicom_name. """ @@ -94,7 +94,9 @@ def load(self, dicom_file, force=True): # If we must read the file, the path must exist if not os.path.exists(dicom_file): bot.exit("%s does not exist." % dicom_file) - self.dicom = read_file(dicom_file, force=force) + self.dicom = read_file( + dicom_file, force=force, stop_before_pixels=stop_before_pixels + ) # Set class variables that might be helpful later self.dicom_file = os.path.abspath(self.dicom.filename) diff --git a/deid/version.py b/deid/version.py index aa37e549..8502d7bd 100644 --- a/deid/version.py +++ b/deid/version.py @@ -22,7 +22,7 @@ """ -__version__ = "0.2.23" +__version__ = "0.2.24" AUTHOR = "Vanessa Sochat" AUTHOR_EMAIL = "vsochat@stanford.edu" NAME = "deid" From b24b14dac5140f3b68a147adf17f2f9672715018 Mon Sep 17 00:00:00 2001 From: vsoch Date: Fri, 16 Oct 2020 10:44:57 -0600 Subject: [PATCH 2/2] stop_before_pixels needs to be added to init Signed-off-by: vsoch --- deid/dicom/header.py | 4 +--- deid/dicom/parser.py | 6 ++++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/deid/dicom/header.py b/deid/dicom/header.py index ebf904d4..a96bd984 100644 --- a/deid/dicom/header.py +++ b/deid/dicom/header.py @@ -79,9 +79,7 @@ def get_identifiers( # Parse each dicom file for dicom_file in dicom_files: - parser = DicomParser( - dicom_file, force=force, stop_before_pixels=stop_before_pixels - ) + parser = DicomParser(dicom_file, force=force) lookup[parser.dicom_file] = parser.get_fields() return lookup diff --git a/deid/dicom/parser.py b/deid/dicom/parser.py index cfc7a874..16e420ae 100644 --- a/deid/dicom/parser.py +++ b/deid/dicom/parser.py @@ -53,7 +53,9 @@ class DicomParser: file. For each, we store the element and child elements """ - def __init__(self, dicom_file, recipe=None, config=None, force=True): + def __init__( + self, dicom_file, recipe=None, config=None, force=True, stop_before_pixels=False + ): # Lookup for the dicom self.lookup = {} @@ -70,7 +72,7 @@ def __init__(self, dicom_file, recipe=None, config=None, force=True): # Deid can be a recipe or filename if not isinstance(recipe, DeidRecipe): recipe = DeidRecipe(recipe) - self.load(dicom_file, force=force) + self.load(dicom_file, force=force, stop_before_pixels=stop_before_pixels) self.recipe = recipe def __str__(self):