Skip to content

Commit

Permalink
added alignment functionality using PET as reference
Browse files Browse the repository at this point in the history
  • Loading branch information
pjmark committed Jan 5, 2024
1 parent ce3803b commit 3088063
Show file tree
Hide file tree
Showing 2 changed files with 189 additions and 74 deletions.
2 changes: 0 additions & 2 deletions amypet/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ def align_frames(
it is SPM ('spm'), alternatively it can be DIPY ('dipy').
saved4d: if True, saves aligned frames into a one 4D NIfTI file.
f4d: the file name of the 4D output NIfTI file.
reg_fwhm: FWHM of the smoothing used for reference and floating
images in registration.
reg_costfun:the registration cost function, by default the normalised
mutual information, 'nmi'.
"""
Expand Down
261 changes: 189 additions & 72 deletions amypet/align_brkdyn_ct.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,45 @@



def align_break_petct(niidat, cts, Cnt, qcpth=None):
def align_break_petct(niidat, cts, Cnt, qcpth=None, refpetidx=None):

Check failure on line 22 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L22

E303 too many blank lines (3)
Raw output
amypet/align_brkdyn_ct.py:22:1: E303 too many blank lines (3)
'''
Align PET images in break dynamic acquisition
using the CT for aligning all frames within each acquisition
followed by CT-to-CT registration and overall alignment.
Arguemnts:
Arguments:
----------
niidat: dictionary of PET NIfTIs and DICOM info for each frame
cts: sorted list of CT scans for each acquisition

Check failure on line 30 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L30

W291 trailing whitespace
Raw output
amypet/align_brkdyn_ct.py:30:61: W291 trailing whitespace
Cnt: Constants for processing data
refpetidx: reference PET frame indices if intended to use PET
frames for each acquisition instead of CTs. CTs
are used only for the alignment between the two
break acquisitions. For example, when using the first
two or last two PET frames, the call would be:
refpetidx=[0,0] or refpetidx=[-1,-1], respectively;
if refpetidx=None (default), then CT acquisitions are
used as reference instead.
'''

# > reference images based on CT
fref = [None, None]
# > number of frames for break dynamic acquisitions A and B
nfrmA = len(niidat['series'][0])
nfrmB = len(niidat['series'][1])

# > sort out the correct index for PET reference frame
if refpetidx is not None:
if any([refpetidx[0]<-nfrmA, refpetidx[1]<-nfrmB, refpetidx[0]>=nfrmA, refpetidx[1]>=nfrmB]):

Check failure on line 48 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L48

E225 missing whitespace around operator
Raw output
amypet/align_brkdyn_ct.py:48:29: E225 missing whitespace around operator

Check failure on line 48 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L48

E225 missing whitespace around operator
Raw output
amypet/align_brkdyn_ct.py:48:50: E225 missing whitespace around operator

Check failure on line 48 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L48

E225 missing whitespace around operator
Raw output
amypet/align_brkdyn_ct.py:48:71: E225 missing whitespace around operator

Check failure on line 48 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L48

E225 missing whitespace around operator
Raw output
amypet/align_brkdyn_ct.py:48:92: E225 missing whitespace around operator

Check failure on line 48 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L48

E501 line too long (101 > 99 characters)
Raw output
amypet/align_brkdyn_ct.py:48:100: E501 line too long (101 > 99 characters)
raise ValueError('wrong selection of PET reference frame - outside of range')

if refpetidx[0]<0:

Check failure on line 51 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L51

E225 missing whitespace around operator
Raw output
amypet/align_brkdyn_ct.py:51:24: E225 missing whitespace around operator
refpetidx[0] += nfrmA

if refpetidx[1]<0:

Check failure on line 54 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L54

E225 missing whitespace around operator
Raw output
amypet/align_brkdyn_ct.py:54:24: E225 missing whitespace around operator
refpetidx[1] += nfrmB


#fmus = [None, None]
# > reference images based on CT

Check failure on line 58 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L58

E303 too many blank lines (2)
Raw output
amypet/align_brkdyn_ct.py:58:5: E303 too many blank lines (2)
fctref = [None, None]
fpetref = [None, None]

# > sum PET images
fsum = [None, None]
Expand All @@ -55,6 +78,10 @@ def align_break_petct(niidat, cts, Cnt, qcpth=None):
qcpth = opth/'QC-output'
nimpa.create_dir(qcpth)

nacq = len(niidat['series'])
if nacq!=2:

Check failure on line 82 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L82

E225 missing whitespace around operator
Raw output
amypet/align_brkdyn_ct.py:82:12: E225 missing whitespace around operator
raise ValueError(f'The number of acquisitions (in niidat) should be two, but given {nacq}')

for i_acq, acq in enumerate(niidat['series']):

# > output path for part alignment
Expand All @@ -68,7 +95,7 @@ def align_break_petct(niidat, cts, Cnt, qcpth=None):
#--------------------------------------------

Check failure on line 95 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L95

E265 block comment should start with '# '
Raw output
amypet/align_brkdyn_ct.py:95:9: E265 block comment should start with '# '

#--------------------------------------------

Check failure on line 97 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L97

E265 block comment should start with '# '
Raw output
amypet/align_brkdyn_ct.py:97:9: E265 block comment should start with '# '
# > CT-based PET reference and CoM correction
# > CT reference and CoM correction for registration
mudct = nimpa.getnii(cts[i_acq], output='all')
mu = nimpa.ct2mu(mudct['im'])
fmu = algnpth/('ct2mu_{}.nii.gz'.format(i_acq+1))
Expand All @@ -89,99 +116,186 @@ def align_break_petct(niidat, cts, Cnt, qcpth=None):
fres = Path(fres)
#~~~~~~~~~~~~~~~~~~~~

Check failure on line 117 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L117

E265 block comment should start with '# '
Raw output
amypet/align_brkdyn_ct.py:117:9: E265 block comment should start with '# '

# > centre of mass (CoM)
fcom = fres.parent/(fres.name.split('.nii')[0]+'_CoM-modified.nii')
nimpa.centre_mass_corr(fres, fout=fcom)
print('Modified CoM:', fcom)
fref[i_acq] = fcom
# > CT centre of mass (CoM)
fctcom = fres.parent/(fres.name.split('.nii')[0]+'_CoM-modified.nii')
nimpa.centre_mass_corr(fres, fout=fctcom)
log.info(f'Modified CoM (CT): {fctcom}')

# > CT reference image for CT registration and optionally PET
fctref[i_acq] = fctcom
#--------------------------------------------

Check failure on line 126 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L126

E265 block comment should start with '# '
Raw output
amypet/align_brkdyn_ct.py:126:9: E265 block comment should start with '# '

#--------------------------------------------

Check failure on line 128 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L128

E265 block comment should start with '# '
Raw output
amypet/align_brkdyn_ct.py:128:9: E265 block comment should start with '# '
# > pick the reference for the two break PET dynamic acquisitions
if refpetidx is None:
fpetref[i_acq] = fctcom
else:
if refpetidx[i_acq] in range(len(niidat['series'][i_acq])):
#> get the name of the selected reference frame

Check failure on line 134 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L134

E265 block comment should start with '# '
Raw output
amypet/align_brkdyn_ct.py:134:17: E265 block comment should start with '# '
fnm = niidat['descr'][i_acq]['frms'][refpetidx[i_acq]]
fpref = niidat['series'][i_acq][fnm]['fnii']
fpetcom = fpref.parent/(fpref.name.split('.nii')[0]+'_CoM-modified.nii')
nimpa.centre_mass_corr(fpref, fout=fpetcom)
log.info(f'Modified CoM (PET): {fpetcom}')
fpetref[i_acq] = fpetcom
else:
raise ValueError('incorrect frame index for PET reference frame!')

#--------------------------------------------

Check failure on line 144 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L144

E265 block comment should start with '# '
Raw output
amypet/align_brkdyn_ct.py:144:9: E265 block comment should start with '# '

#--------------------------------------------

Check failure on line 146 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L146

E265 block comment should start with '# '
Raw output
amypet/align_brkdyn_ct.py:146:9: E265 block comment should start with '# '
# > ALIGNMENT TO CT
algn_frm[i_acq] = align_frames(imfrms, imtime, fref[i_acq], Cnt,
# > ALIGNMENT TO REFERENCE
algn_frm[i_acq] = align_frames(imfrms, imtime, fpetref[i_acq], Cnt,
reg_tool='spm', spm_com_corr=True, outpath=algnpth)

Check failure on line 149 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L149

E128 continuation line under-indented for visual indent
Raw output
amypet/align_brkdyn_ct.py:149:13: E128 continuation line under-indented for visual indent
#--------------------------------------------

Check failure on line 150 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L150

E265 block comment should start with '# '
Raw output
amypet/align_brkdyn_ct.py:150:9: E265 block comment should start with '# '

Check failure on line 151 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L151

W293 blank line contains whitespace
Raw output
amypet/align_brkdyn_ct.py:151:1: W293 blank line contains whitespace
#--------------------------------------------

Check failure on line 152 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L152

E265 block comment should start with '# '
Raw output
amypet/align_brkdyn_ct.py:152:9: E265 block comment should start with '# '
# > PET sum of aligned frames
refdct = nimpa.getnii(fref[i_acq], output='all')
fsum[i_acq] = qcpth/('PET_algn_sum_{}.nii.gz'.format(i_acq+1))
refdct = nimpa.getnii(fpetref[i_acq], output='all')
fsum[i_acq] = qcpth/('PET_aligned_avg_part{}.nii.gz'.format('A'*(i_acq==0)+'B'*(i_acq==1)))

Check failure on line 155 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L155

E225 missing whitespace around operator
Raw output
amypet/align_brkdyn_ct.py:155:79: E225 missing whitespace around operator

Check failure on line 155 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L155

E225 missing whitespace around operator
Raw output
amypet/align_brkdyn_ct.py:155:94: E225 missing whitespace around operator
nimpa.array2nii(
np.sum(algn_frm[i_acq]['im4d'],axis=0),
np.sum(algn_frm[i_acq]['im4d'],axis=0)/algn_frm[i_acq]['im4d'].shape[0],

Check failure on line 157 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L157

E231 missing whitespace after ','
Raw output
amypet/align_brkdyn_ct.py:157:43: E231 missing whitespace after ','
refdct['affine'],
fsum[i_acq],
trnsp=refdct['transpose'], flip=refdct['flip'])
#--------------------------------------------

Check failure on line 161 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L161

E265 block comment should start with '# '
Raw output
amypet/align_brkdyn_ct.py:161:9: E265 block comment should start with '# '

#--------------------------------------------

Check failure on line 163 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L163

E265 block comment should start with '# '
Raw output
amypet/align_brkdyn_ct.py:163:5: E265 block comment should start with '# '
# > co-register CTs with the second (as in static imaging) acting as the reference
ct_reg = nimpa.coreg_spm(fref[1], fref[0], outpath=algnFpth, costfun='nmi', fwhm_ref=2., fwhm_flo=2.)
ct_reg = nimpa.coreg_spm(fctref[1], fctref[0], outpath=algnFpth, costfun='nmi', fwhm_ref=2., fwhm_flo=2.)

Check failure on line 165 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L165

E501 line too long (110 > 99 characters)
Raw output
amypet/align_brkdyn_ct.py:165:100: E501 line too long (110 > 99 characters)

frct = nimpa.resample_spm(fref[1], fref[0], ct_reg['affine'],
fimout=algnFpth/(fref[0].name.split('.nii')[0]+'_registered-to-CT.nii.gz'),
frct = nimpa.resample_spm(fctref[1], fctref[0], ct_reg['affine'],
fimout=algnFpth/(fctref[0].name.split('.nii')[0]+'_registered-to-CT-B.nii.gz'),

Check failure on line 168 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L168

E128 continuation line under-indented for visual indent
Raw output
amypet/align_brkdyn_ct.py:168:9: E128 continuation line under-indented for visual indent
del_ref_uncmpr=True, del_flo_uncmpr=True, del_out_uncmpr=True)
#--------------------------------------------

Check failure on line 170 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L170

E265 block comment should start with '# '
Raw output
amypet/align_brkdyn_ct.py:170:5: E265 block comment should start with '# '


#--------------------------------------------

Check failure on line 172 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L172

E265 block comment should start with '# '
Raw output
amypet/align_brkdyn_ct.py:172:5: E265 block comment should start with '# '
# > the first part of the acquisition
# > the index of acquisition to be aligned (first)
i_acq = 0
faligned = []
faffines = []

for fi, f in enumerate(algn_frm[i_acq]['fnii_com']):
print(f)

# > get the affine from the first registration to the appropriate CT
aff0 = np.loadtxt(algn_frm[i_acq]['affines'][fi])

# > combine the affine with the CT-to-CT registration affine
#affF = np.matmul(ct_reg['affine'], aff0)
affF = np.matmul(aff0, ct_reg['affine'])

faff = affsF/(Path(f).name.split('.nii')[0]+'_affine.txt')
np.savetxt(faff, affF)
faffines.append(faff)

# > resample the frame to the overall alignment
frpet = nimpa.resample_spm(fref[1], f, affF,
fimout=algnFpth/(f.name.split('.nii')[0]+'_full_reg.nii.gz'),
del_ref_uncmpr=True, del_flo_uncmpr=True, del_out_uncmpr=True)
# > When PET frames are used as reference for alignment
if refpetidx is not None:
# > register CT to average PET frames
petct_Areg = nimpa.coreg_spm(
fctref[0],
fsum[0],
outpath=algnFpth,
fcomment='_petct_partA',
costfun='nmi',
fwhm_ref=2., fwhm_flo=2.)

petct_Breg = nimpa.coreg_spm(
fsum[1],
fctref[1],
outpath=algnFpth,
fcomment='_petct_partB',
costfun='nmi',
fwhm_ref=2., fwhm_flo=2.)

faligned = []
faffines = []

for fi, f in enumerate(algn_frm[0]['fnii_com']):
print(f)

# > get the affine from the first registration to the appropriate reference PET frame
affF = np.loadtxt(algn_frm[0]['affines'][fi])

# > get it to CT space in acquisition part A
affF = np.matmul(affF, petct_Areg['affine'])

# > combine the affine with the CT-to-CT registration affine
affF = np.matmul(affF, ct_reg['affine'])

# > and now add the CT-to-PET part B
affF = np.matmul(affF, petct_Breg['affine'])

faff = affsF/(Path(f).name.split('.nii')[0]+'_affine.txt')
np.savetxt(faff, affF)
faffines.append(faff)

# > resample the frame to the overall alignment
frpet = nimpa.resample_spm(fpetref[1], f, affF,
fimout=algnFpth/(f.name.split('.nii')[0]+'_full_reg.nii.gz'),

Check failure on line 216 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L216

E128 continuation line under-indented for visual indent
Raw output
amypet/align_brkdyn_ct.py:216:17: E128 continuation line under-indented for visual indent
del_ref_uncmpr=True, del_flo_uncmpr=True, del_out_uncmpr=True)

faligned.append(Path(frpet))

# > the second part of the acquisition (is already in the CT space of interest)
keys2 = list(niidat['series'][1].keys())
imdct = nimpa.getnii(algn_frm[1]['faligned'][0], output='all')
imur = np.zeros( imdct['shape'], dtype=np.float32)

Check failure on line 224 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L224

E201 whitespace after '('
Raw output
amypet/align_brkdyn_ct.py:224:25: E201 whitespace after '('

for fi, f in enumerate(algn_frm[1]['faligned']):
print(f)
fcopy = algnFpth/Path(f).name
shutil.copyfile(f, fcopy)
faligned.append(fcopy)

faff = affsF/(Path(f).name.split('.nii')[0]+'_affine.txt')
shutil.copyfile(algn_frm[1]['affines'][fi], faff)
faffines.append(faff)

# > create a single uptake ratio (UR) image
imur += nimpa.getnii(f)

fur = opth/'UR-PET-aligned_partB.nii.gz'
nimpa.array2nii(imur, imdct['affine'],fur, trnsp=imdct['transpose'], flip=imdct['flip'])

Check failure on line 240 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L240

E231 missing whitespace after ','
Raw output
amypet/align_brkdyn_ct.py:240:46: E231 missing whitespace after ','

#+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

Check failure on line 242 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L242

E265 block comment should start with '# '
Raw output
amypet/align_brkdyn_ct.py:242:5: E265 block comment should start with '# '
# > When CT is used for reference
else:
# > the first part of the acquisition
# > the index of acquisition to be aligned (first)
i_acq = 0
faligned = []
faffines = []

for fi, f in enumerate(algn_frm[i_acq]['fnii_com']):
print(f)

# > get the affine from the first registration to the appropriate CT
aff0 = np.loadtxt(algn_frm[i_acq]['affines'][fi])

# > combine the affine with the CT-to-CT registration affine
#affF = np.matmul(ct_reg['affine'], aff0)

Check failure on line 258 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L258

E265 block comment should start with '# '
Raw output
amypet/align_brkdyn_ct.py:258:13: E265 block comment should start with '# '
affF = np.matmul(aff0, ct_reg['affine'])

faff = affsF/(Path(f).name.split('.nii')[0]+'_affine.txt')
np.savetxt(faff, affF)
faffines.append(faff)

# > resample the frame to the overall alignment
frpet = nimpa.resample_spm(fctref[1], f, affF,
fimout=algnFpth/(f.name.split('.nii')[0]+'_full_reg.nii.gz'),

Check failure on line 267 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L267

E128 continuation line under-indented for visual indent
Raw output
amypet/align_brkdyn_ct.py:267:17: E128 continuation line under-indented for visual indent
del_ref_uncmpr=True, del_flo_uncmpr=True, del_out_uncmpr=True)

faligned.append(Path(frpet))

# > the second part of the acquisition (is already in the CT space of interest)
i_acq = 1
keys2 = list(niidat['series'][i_acq].keys())

Check failure on line 274 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L274

F841 local variable 'keys2' is assigned to but never used
Raw output
amypet/align_brkdyn_ct.py:274:9: F841 local variable 'keys2' is assigned to but never used
imdct = nimpa.getnii(algn_frm[i_acq]['faligned'][0], output='all')
imur = np.zeros( imdct['shape'], dtype=np.float32)

Check failure on line 276 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L276

E201 whitespace after '('
Raw output
amypet/align_brkdyn_ct.py:276:25: E201 whitespace after '('

for fi, f in enumerate(algn_frm[i_acq]['faligned']):
print(f)
#fnii_org.append(niidat['series'][i_acq][keys2[fi]]['fnii'])

Check failure on line 280 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L280

E265 block comment should start with '# '
Raw output
amypet/align_brkdyn_ct.py:280:13: E265 block comment should start with '# '

faligned.append(Path(frpet))
fcopy = algnFpth/Path(f).name
shutil.copyfile(f, fcopy)
faligned.append(fcopy)

# > the second part of the acquisition (is already in the CT space of interest)
i_acq = 1
keys2 = list(niidat['series'][i_acq].keys())
imdct = nimpa.getnii(algn_frm[i_acq]['faligned'][0], output='all')
imur = np.zeros( imdct['shape'], dtype=np.float32)
faff = affsF/(Path(f).name.split('.nii')[0]+'_affine.txt')
shutil.copyfile(algn_frm[i_acq]['affines'][fi], faff)
faffines.append(faff)

for fi, f in enumerate(algn_frm[i_acq]['faligned']):
print(f)
#fnii_org.append(niidat['series'][i_acq][keys2[fi]]['fnii'])

fcopy = algnFpth/Path(f).name
shutil.copyfile(f, fcopy)
faligned.append(fcopy)

faff = affsF/(Path(f).name.split('.nii')[0]+'_affine.txt')
shutil.copyfile(algn_frm[i_acq]['affines'][fi], faff)
faffines.append(faff)

# > create a single uptake ratio (UR) image
imur += nimpa.getnii(f)
# > create a single uptake ratio (UR) image
imur += nimpa.getnii(f)

fur = opth/'UR-PET-aligned.nii.gz'
nimpa.array2nii(imur, imdct['affine'],fur, trnsp=imdct['transpose'], flip=imdct['flip'])
fur = opth/'UR-PET-aligned.nii.gz'
nimpa.array2nii(imur, imdct['affine'],fur, trnsp=imdct['transpose'], flip=imdct['flip'])

Check failure on line 294 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L294

E231 missing whitespace after ','
Raw output
amypet/align_brkdyn_ct.py:294:46: E231 missing whitespace after ','
#--------------------------------------------

Check failure on line 295 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L295

E265 block comment should start with '# '
Raw output
amypet/align_brkdyn_ct.py:295:5: E265 block comment should start with '# '


#--------------------------------------------

Check failure on line 298 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L298

E303 too many blank lines (2)
Raw output
amypet/align_brkdyn_ct.py:298:5: E303 too many blank lines (2)

Check failure on line 298 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L298

E265 block comment should start with '# '
Raw output
amypet/align_brkdyn_ct.py:298:5: E265 block comment should start with '# '
# > number of frames for break dynamic acquisitions A and B
nfrmA = len(niidat['series'][0])
nfrmB = len(niidat['series'][1])

imdct = nimpa.getnii(faligned[0], output='all')

im4d = np.zeros( (len(faligned),) + imdct['shape'], dtype=np.float32)

Check failure on line 301 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L301

E201 whitespace after '('
Raw output
amypet/align_brkdyn_ct.py:301:21: E201 whitespace after '('
Expand Down Expand Up @@ -215,14 +329,17 @@ def align_break_petct(niidat, cts, Cnt, qcpth=None):
# > output dictionary

Check failure on line 329 in amypet/align_brkdyn_ct.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] amypet/align_brkdyn_ct.py#L329

E303 too many blank lines (3)
Raw output
amypet/align_brkdyn_ct.py:329:5: E303 too many blank lines (3)
outdct = {}
outdct['align_acq'] = algn_frm
outdct['ctref'] = fref
outdct['fqcsum'] = fsum
outdct['ctref'] = fctref
outdct['petref'] = fpetref
outdct['fsumAB'] = fsum
outdct['ct_reg'] = ct_reg
outdct['fct_reg'] = frct
outdct['fur'] = fur
outdct['fsum'] = fsumF
outdct['faligned'] = faligned
outdct['fpet4d'] = f4d
outdct['fpet4A'] = f4A
outdct['fpet4B'] = f4B
outdct['faffines'] = faffines
outdct['fnii_com'] = algn_frm[0]['fnii_com'] + algn_frm[1]['fnii_com']

Expand Down

0 comments on commit 3088063

Please sign in to comment.