From 634d0db5ec67f864252b6074c625bfb5bb8d9af3 Mon Sep 17 00:00:00 2001 From: Nitesh639 Date: Sun, 20 Mar 2022 17:57:27 -0600 Subject: [PATCH] Added extracting Private DICOM tags fuction update --- modules/png-extraction/ImageExtractor.py | 18 +++++++++--------- modules/png-extraction/README.md | 2 ++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/modules/png-extraction/ImageExtractor.py b/modules/png-extraction/ImageExtractor.py index 32914f4..f25c9c8 100644 --- a/modules/png-extraction/ImageExtractor.py +++ b/modules/png-extraction/ImageExtractor.py @@ -25,10 +25,6 @@ import pathlib configs = {} -with open('config.json', 'r') as f: - niffler = json.load(f) - print_only_public_headers = bool(niffler['PublicHeadersOnly']) - def initialize_config_and_execute(config_values): global configs configs = config_values @@ -42,6 +38,7 @@ def initialize_config_and_execute(config_values): print_images = bool(configs['PrintImages']) print_only_common_headers = bool(configs['CommonHeadersOnly']) + print_only_public_headers = bool(configs['PublicHeadersOnly']) depth = int(configs['Depth']) processes = int(configs['UseProcesses']) # how many processes to use. flattened_to_level = configs['FlattenedToLevel'] @@ -93,7 +90,7 @@ def initialize_config_and_execute(config_values): os.makedirs(failed + "/4") logging.info("------- Values Initialization DONE -------") - final_res = execute(pickle_file, dicom_home, output_directory, print_images, print_only_common_headers, depth, + final_res = execute(pickle_file, dicom_home, output_directory, print_images, print_only_common_headers, print_only_public_headers, depth, processes, flattened_to_level, email, send_email, no_splits, is16Bit, png_destination, failed, maps_directory, meta_directory, LOG_FILENAME, metadata_col_freq_threshold, t_start) return final_res @@ -135,7 +132,7 @@ def get_tuples(plan, outlist = None, key = ""): outlist.append((key + aa, value)) # appends name, value pair for this file. these are later concatenated to the dataframe # appends the private tags - if not print_only_public_headers: + if not public_headers_bool: x = plan.keys() x = list(x) for i in x: @@ -146,7 +143,8 @@ def get_tuples(plan, outlist = None, key = ""): def extract_headers(f_list_elem): - nn,ff = f_list_elem # unpack enumerated list + global public_headers_bool + nn,ff, public_headers_bool = f_list_elem # unpack enumerated list plan = dicom.dcmread(ff, force=True) # reads in dicom file # checks if this file has an image c=True @@ -318,7 +316,7 @@ def fix_mismatch(with_VRs=['PN', 'DS', 'IS']): } -def execute(pickle_file, dicom_home, output_directory, print_images, print_only_common_headers, depth, +def execute(pickle_file, dicom_home, output_directory, print_images, print_only_common_headers, print_only_public_headers, depth, processes, flattened_to_level, email, send_email, no_splits, is16Bit, png_destination, failed, maps_directory, meta_directory, LOG_FILENAME, metadata_col_freq_threshold, t_start): err = None @@ -379,7 +377,9 @@ def execute(pickle_file, dicom_home, output_directory, print_images, print_only_ # for every item in filelist send data to a subprocess and run extract_headers func # output is then added to headerlist as they are completed (no ordering is done) with Pool(core_count) as p: - res= p.imap_unordered(extract_headers, enumerate(chunk)) + # we send here print_only_public_headers bool value + file_chunks_list = [tups + (print_only_public_headers,) for tups in enumerate(chunk)] + res= p.imap_unordered(extract_headers, file_chunks_list) for i,e in enumerate(res): headerlist.append(e) data = pd.DataFrame(headerlist) diff --git a/modules/png-extraction/README.md b/modules/png-extraction/README.md index 508db33..1011998 100644 --- a/modules/png-extraction/README.md +++ b/modules/png-extraction/README.md @@ -35,6 +35,8 @@ The below two fields can be left unmodified for most executions. The default val * *CommonHeadersOnly*: Do you want the resulting dataframe csv to contain only the common headers? Finds if less than 10% of the rows are missing this column field. To extract all the headers, default is set as _false_. +* *PublicHeadersOnly*: Do you want the resulting dataframe csv to contain only the public headers? Then set it as _true_(default). For extract all the private headers set as _false_. + ## Running the Niffler PNG Extractor ```bash