From 0419bc1b950f50bbfaddb9fac224c6b9d2f64b6b Mon Sep 17 00:00:00 2001 From: wtclarke Date: Fri, 25 Oct 2024 16:24:21 +0100 Subject: [PATCH 1/2] Initial special casing for dkd_svs_mslaser_msspnav --- requirements.yml | 2 +- spec2nii/Siemens/dicomfunctions.py | 66 +++++++++++++++++++++++++++--- 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/requirements.yml b/requirements.yml index 6dc58c3..03eea99 100644 --- a/requirements.yml +++ b/requirements.yml @@ -7,4 +7,4 @@ dependencies: - scipy==1.13.* - brukerapi>=0.1.8 - pandas - - nifti-mrs>=1.3.0 + - nifti-mrs>=1.3.2 diff --git a/spec2nii/Siemens/dicomfunctions.py b/spec2nii/Siemens/dicomfunctions.py index 7e3ad91..33ed38c 100644 --- a/spec2nii/Siemens/dicomfunctions.py +++ b/spec2nii/Siemens/dicomfunctions.py @@ -177,8 +177,7 @@ def multi_file_dicom(files_in, fname_out, tag, verbose): print(f'Output groups: {group_ind}') nifti_mrs_out, fnames_out = [], [] - for idx, gr in enumerate(group_ind): - + for gr in group_ind: # If data shape, orientation, dwelltime match then # proceed def not_equal(lst): @@ -205,9 +204,8 @@ def not_equal(lst): else: combined_data = data_in_gr[0] - # Add dimension information (if not None for default) - if tag: - meta_used.set_dim_info(0, tag) + # Special cases and dim tagging + combined_data, meta_used = special_case_sequences(combined_data, meta_used, img, tag, reference[gr[0]]) # Create NIFTI MRS object. try: @@ -702,7 +700,9 @@ def set_standard_def(nifti_mrs_key, location, key, cast=None): def identify_integrated_references(img, inst_num): '''Heuristics for identifying integrated reference scans in known sequences. - Sequences handled: CMRR svs_slaserVOI_dkd(2) + Sequences handled: + - CMRR svs_slaserVOI_dkd(2) + - dkd_svs_(m)slaser_msspnav :param img: nibable dicom image @@ -771,5 +771,59 @@ def identify_integrated_references(img, inst_num): return 1, '_vapor_ovs_rfoff' else: return 0, '' + elif (re.search(r'dkd_svs_mslaser_msspnav$', seq_file_name) + and xprot[('sSpecPara', 'lAutoRefScanMode')] == 8.0): + num_ref = int(xprot[('sSpecPara', 'lAutoRefScanNo')]) + num_dyn = int(xprot[('lAverages',)]) + if True: + # This True should be replaced with the flag to control MEGA + total_dyn = num_dyn * 2 + (num_ref * 4) + else: + total_dyn = num_dyn + (num_ref * 4) + + # Note instance number indexes from 1 + if inst_num <= num_ref: + # print(f'case 1: {inst_num} <= {num_ref}') + # Start references + return 1, '_ws_ovs_off' + elif (inst_num > (num_dyn + num_ref)) and (inst_num < (num_dyn + num_ref * 4)): + # print(f'case 2: {inst_num}') + # Empty scans, all zeros + return 2, '_empty_data' + elif inst_num > (total_dyn - num_ref): + # print(f'case 1: {inst_num} > {(total_dyn - num_ref)}') + # End references + return 1, '_ws_ovs_off' + else: + # print(f'no case: {inst_num}') + return 0, '' else: return 0, '' + + +def special_case_sequences(combined_data, meta_used, img, tag, ref_status): + + fullcsa = csar.get_csa_header(img.dcm_data, csa_type='series') + xprot = parse_buffer(fullcsa['tags']['MrPhoenixProtocol']['items'][0]) + seq_file_name = xprot[('tSequenceFileName',)].strip('"').lower() + + if re.search(r'dkd_svs_mslaser_msspnav$', seq_file_name)\ + and ref_status == 0: + ''' + The dkd_svs_mslaser_msspnav sequence + This sequence contains both MEGA j-difference editing and metabolite cycling + ''' + combined_data = np.reshape( + combined_data, + combined_data.shape[:4] + (2, -1, 2,) + ) + print(combined_data.shape) + meta_used.set_dim_info(0, 'DIM_EDIT') + meta_used.set_dim_info(2, 'DIM_METCYCLE') + meta_used.set_dim_info(1, 'DIM_DYN') + + else: + # Add dimension information (if not None for default) + if tag: + meta_used.set_dim_info(0, tag) + return combined_data, meta_used From f396ba83f7580aa6590adeea841e031a3da76b4b Mon Sep 17 00:00:00 2001 From: wtclarke Date: Fri, 25 Oct 2024 16:56:14 +0100 Subject: [PATCH 2/2] Fix special case function for XA --- spec2nii/Siemens/dicomfunctions.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spec2nii/Siemens/dicomfunctions.py b/spec2nii/Siemens/dicomfunctions.py index 33ed38c..b81363d 100644 --- a/spec2nii/Siemens/dicomfunctions.py +++ b/spec2nii/Siemens/dicomfunctions.py @@ -804,8 +804,11 @@ def identify_integrated_references(img, inst_num): def special_case_sequences(combined_data, meta_used, img, tag, ref_status): fullcsa = csar.get_csa_header(img.dcm_data, csa_type='series') - xprot = parse_buffer(fullcsa['tags']['MrPhoenixProtocol']['items'][0]) - seq_file_name = xprot[('tSequenceFileName',)].strip('"').lower() + if fullcsa is not None: + xprot = parse_buffer(fullcsa['tags']['MrPhoenixProtocol']['items'][0]) + seq_file_name = xprot[('tSequenceFileName',)].strip('"').lower() + else: + seq_file_name = '' if re.search(r'dkd_svs_mslaser_msspnav$', seq_file_name)\ and ref_status == 0: @@ -817,7 +820,6 @@ def special_case_sequences(combined_data, meta_used, img, tag, ref_status): combined_data, combined_data.shape[:4] + (2, -1, 2,) ) - print(combined_data.shape) meta_used.set_dim_info(0, 'DIM_EDIT') meta_used.set_dim_info(2, 'DIM_METCYCLE') meta_used.set_dim_info(1, 'DIM_DYN')