From e46b35ba1ff01bbbbdbb2016eea19ee50c5becea Mon Sep 17 00:00:00 2001
From: Pawel Markiewicz
Date: Tue, 9 Jan 2024 00:41:55 +0000
Subject: [PATCH] added storing dictionary in break dyanamic alignment with CT
---
amypet/align_brkdyn_ct.py | 28 ++++++++++++++++++++--------
1 file changed, 20 insertions(+), 8 deletions(-)
diff --git a/amypet/align_brkdyn_ct.py b/amypet/align_brkdyn_ct.py
index 9ef79bf1..082d47fc 100644
--- a/amypet/align_brkdyn_ct.py
+++ b/amypet/align_brkdyn_ct.py
@@ -19,7 +19,7 @@
-def align_break_petct(niidat, cts, Cnt, qcpth=None, refpetidx=None):
+def align_break_petct(niidat, cts, Cnt, qcpth=None, refpetidx=None, use_stored=False):
'''
Align PET images in break dynamic acquisition
using the CT for aligning all frames within each acquisition
@@ -39,6 +39,23 @@ def align_break_petct(niidat, cts, Cnt, qcpth=None, refpetidx=None):
used as reference instead.
'''
+ # > output path from the input dictionary
+ opth = niidat['outpath'].parent
+
+ # > output path for alignment of CTs
+ algnFpth = opth/(f'aligned_full')
+ affsF = algnFpth/'combined_affines'
+
+ nimpa.create_dir(algnFpth)
+ nimpa.create_dir(affsF)
+
+ # > output dictionary file
+ fout = algnFpth/'aligned_full_output.npy'
+ if use_stored and fout.is_file():
+ outdct = np.load(fout, allow_pickle=True)
+ outdct = outdct.item()
+ return outdct
+
# > number of frames for break dynamic acquisitions A and B
nfrmA = len(niidat['series'][0])
nfrmB = len(niidat['series'][1])
@@ -65,14 +82,7 @@ def align_break_petct(niidat, cts, Cnt, qcpth=None, refpetidx=None):
# > alignment results
algn_frm = [None, None]
- opth = niidat['outpath'].parent
-
- # > output path for alignment of CTs
- algnFpth = opth/(f'aligned_full')
- affsF = algnFpth/'combined_affines'
- nimpa.create_dir(algnFpth)
- nimpa.create_dir(affsF)
if qcpth is None:
qcpth = opth/'QC-output'
@@ -343,5 +353,7 @@ def align_break_petct(niidat, cts, Cnt, qcpth=None, refpetidx=None):
outdct['faffines'] = faffines
outdct['fnii_com'] = algn_frm[0]['fnii_com'] + algn_frm[1]['fnii_com']
+ np.save(fout, outdct)
+
return outdct