|
| 1 | +from pathlib import Path |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | + |
| 6 | +@pytest.fixture |
| 7 | +def dyndir(datain, mMRpars): |
| 8 | + # definition of dynamic frames for kinetic analysis |
| 9 | + frmdef = ["def", [4, 15], [8, 30], [9, 60], [2, 180], [8, 300]] |
| 10 | + # output path |
| 11 | + opth = str(Path(datain["corepath"]).parent / "amypad" / "dyndir") |
| 12 | + |
| 13 | + res = Path(opth) / "PET" / "multiple-frames" |
| 14 | + if res.is_dir(): |
| 15 | + return res |
| 16 | + |
| 17 | + nipet = pytest.importorskip("niftypet.nipet") |
| 18 | + hst = nipet.mmrhist(datain, mMRpars) |
| 19 | + # offset for the time from which meaningful events are detected |
| 20 | + toff = nipet.lm.get_time_offset(hst) |
| 21 | + # dynamic frame timings |
| 22 | + frm_timings = nipet.lm.dynamic_timings(frmdef, offset=toff) |
| 23 | + nipet.lm.draw_frames(hst, frm_timings["timings"]) |
| 24 | + # hardware mu-map |
| 25 | + muhdct = nipet.hdw_mumap(datain, [1, 2, 4], mMRpars, outpath=opth, use_stored=True) |
| 26 | + |
| 27 | + # object mu-map with alignment |
| 28 | + mupdct = nipet.align_mumap( |
| 29 | + datain, |
| 30 | + mMRpars, |
| 31 | + outpath=opth, |
| 32 | + store=True, |
| 33 | + hst=hst, |
| 34 | + itr=2, |
| 35 | + petopt="ac", |
| 36 | + fcomment="_mu", |
| 37 | + musrc="pct", |
| 38 | + ) |
| 39 | + # object mu-map without alignment--straight from DICOM resampled to PET |
| 40 | + # muodct = nipet.obj_mumap(datain, mMRpars, outpath=opth, store=True) |
| 41 | + |
| 42 | + nipet.mmrchain( |
| 43 | + datain, |
| 44 | + mMRpars, |
| 45 | + frames=frm_timings["timings"], |
| 46 | + mu_h=muhdct, |
| 47 | + mu_o=mupdct, # muodct, |
| 48 | + itr=5, |
| 49 | + fwhm=0.0, |
| 50 | + outpath=opth, |
| 51 | + fcomment="_dyn", |
| 52 | + store_img=True, |
| 53 | + store_img_intrmd=True, |
| 54 | + ) |
| 55 | + return Path(opth) / "PET" / "multiple-frames" |
| 56 | + |
| 57 | + |
| 58 | +@pytest.mark.timeout(2 * 60 * 60) # 2h |
| 59 | +def test_rectrim(dyndir): |
| 60 | + rectrim = pytest.importorskip("amypad.rectrim") |
| 61 | + rectrim.run(dyndir) |
0 commit comments