From f8f4ca5419268b045dfdce3094ce6b4fdd20fe20 Mon Sep 17 00:00:00 2001 From: noahg-neuroimage <134336793+noahg-neuroimage@users.noreply.github.com> Date: Tue, 20 Feb 2024 12:06:03 -0600 Subject: [PATCH] =?UTF-8?q?[Ecat2Nii]=20Only=20apply=20ECAT=5FCALIBRATION?= =?UTF-8?q?=5FFACTOR=20if=20it=20has=20not=20already=20b=E2=80=A6=20(#268)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Ecat2Nii] Only apply ECAT_CALIBRATION_FACTOR if it has not been applied; check CALIBRATION_UNITS to see if calibration has been applied, if it has, return input image, otherwise multiply by calibration factor. !!!!!!!!IMPORTANT NOTE!!!!!!!!!!! CALIBRATION_UNITS=1 -> Multiply the image by the ECAT_CALIBRATION_FACTOR. CALIBRATION_UNITS=0 -> Do not multiply the image by the ECAT_CALIBRATION_FACTOR. This change will correctly account for whether the calibration factor has already been applied to Ecat data. In the current version of PET2BIDS, ecat2nii will erroneously reapply the calibration factor on data that has already been calibrated, resulting in Nifti files with incorrect data objects. Remove extra scaling applied again via nifti `scl_slope`, this was the precipitating error that led to the discovery of the above. Thank you to @noahg-neuroimage for discovering and creating this PR to fix. --------- Co-authored-by: Anthony Galassi <28850131+bendhouseart@users.noreply.github.com> --- pypet2bids/pypet2bids/ecat2nii.py | 8 ++++++-- pypet2bids/pyproject.toml | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pypet2bids/pypet2bids/ecat2nii.py b/pypet2bids/pypet2bids/ecat2nii.py index bb50aeac..e9e3d792 100644 --- a/pypet2bids/pypet2bids/ecat2nii.py +++ b/pypet2bids/pypet2bids/ecat2nii.py @@ -132,7 +132,11 @@ def ecat2nii(ecat_main_header=None, prompts.append(0) randoms.append(0) - final_image = img_temp * main_header['ECAT_CALIBRATION_FACTOR'] + ecat_cal_units = main_header['CALIBRATION_UNITS'] # Header field designating whether data has already been calibrated + if ecat_cal_units==1: # Calibrate if it hasn't been already + final_image = img_temp * main_header['ECAT_CALIBRATION_FACTOR'] + else: # And don't calibrate if CALIBRATION_UNITS is anything else but 1 + final_image = img_temp qoffset_x = -1 * ( ((sub_headers[0]['X_DIMENSION'] * sub_headers[0]['X_PIXEL_SIZE'] * 10 / 2) - sub_headers[0][ @@ -187,7 +191,7 @@ def ecat2nii(ecat_main_header=None, # TODO img_nii.header['scl_slope'] # this is a NaN array by default but apparently it should be the dose calibration # factor img_nii.header['scl_inter'] # defaults to NaN array - img_nii.header['scl_slope'] = main_header['ECAT_CALIBRATION_FACTOR'] + img_nii.header['scl_slope'] = 0 img_nii.header['scl_inter'] = 0 img_nii.header['slice_end'] = 0 img_nii.header['slice_code'] = 0 diff --git a/pypet2bids/pyproject.toml b/pypet2bids/pyproject.toml index 8f0b0c00..4ea990d4 100644 --- a/pypet2bids/pyproject.toml +++ b/pypet2bids/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pypet2bids" -version = "1.3.3" +version = "1.3.4" description = "A python implementation of an ECAT to BIDS converter." authors = ["anthony galassi <28850131+bendhouseart@users.noreply.github.com>"] license = "MIT"