Skip to content

Commit

Permalink
[Ecat2Nii] Only apply ECAT_CALIBRATION_FACTOR if it has not already b… (
Browse files Browse the repository at this point in the history
#268)

* [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>
  • Loading branch information
noahg-neuroimage and bendhouseart authored Feb 20, 2024
1 parent d860701 commit f8f4ca5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions pypet2bids/pypet2bids/ecat2nii.py
Original file line number Diff line number Diff line change
Expand Up @@ -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][
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pypet2bids/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit f8f4ca5

Please sign in to comment.