def recon_with_scatter(json_path, outdir): tf.enable_eager_execution() if outdir is None: outdir = os.path.dirname(os.path.abspath(json_path)) else: outdir = os.path.abspath(outdir) mlem_full_without_data = nef.io.json_load(nef.functions.MlemFull, json_path) mlem_obj = nef.io.load_all_data(mlem_full_without_data) img = nef.load(nef.Image, outdir + '/recon_image.hdf5') if mlem_obj.scatter_corr is not None: listmode = mlem_obj.scatter_corr(img, mlem_obj.atten_corr.u_map, mlem_obj.scanner, outdir) listmode = nef.ListmodeCompress(scanner)(listmode) mlem_full = nef.MlemFull(mlem_obj.n_iter, mlem_obj.image_config, mlem_obj.scanner, listmode) img = mlem_full() nef.save(img, outdir + '/recon_image_scatter.hdf5') nef.save(mlem_full_without_data, outdir + '/mlem_full_scatter.hdf5') nef.doc_gen(mlem_full_without_data, img, outdir, outdir + '/recon_doc_scatter.md') pypandoc.convert_file(outdir + '/recon_doc_scatter.md', 'pdf', outputfile=outdir + '/recon_doc_scatter.md' + '.pdf') return img
def recon_full(json_path, outdir): tf.enable_eager_execution() if outdir is None: outdir = os.path.dirname(os.path.abspath(json_path)) else: outdir = os.path.abspath(outdir) if not os.path.isdir(outdir): os.mkdir(outdir, mode=0o777) mlem_full_without_data = nef.io.json_load(nef.functions.MlemFull, json_path) mlem_obj = nef.io.load_all_data(mlem_full_without_data) img = mlem_obj() from srfnef.corrections.scattering.scatter import scatter_preprocess if mlem_obj.scatter_corr is not None: scatter_preprocess(mlem_obj.scanner, mlem_obj.listmode, img, mlem_obj.atten_corr.u_map, outdir) nef.save(img, outdir + '/recon_image.hdf5') # nef.save(mlem_full_without_data, outdir + '/mlem_full.hdf5') nef.doc_gen(mlem_full_without_data, img, outdir, outdir + '/recon_doc.md') pypandoc.convert_file(outdir + '/recon_doc.md', 'pdf', outputfile=outdir + '/recon_doc.md' + '.pdf') return img
def test_full(json_path, outdir, system): tf.compat.v1.enable_eager_execution() if outdir is None: outdir = os.path.dirname(os.path.abspath(json_path)) else: outdir = os.path.abspath(outdir) if not os.path.isdir(outdir): os.mkdir(outdir, mode=0o777) # if system == 'mct': mlem_full_without_data = nef.io.json_load(nef.functions.MlemFull, json_path) if system == '8panel': with open('/mnt/users/weijie/srfnef/mlem_full.json', 'r') as fin: dct = json.load(fin) scanner = nef.PetCylindricalScanner.from_dict(dct['scanner']) mlem_full_without_data = mlem_full_without_data.update(scanner=scanner) mlem_obj = nef.io.load_all_data(mlem_full_without_data) opt_atten = [None] if mlem_obj.atten_corr is None else [ None, mlem_obj.atten_corr ] opt_psf = [None ] if mlem_obj.psf_corr is None else [None, mlem_obj.psf_corr] for atten in opt_atten: for psf in opt_psf: out_append = '' if atten is not None: out_append += '_atten' if psf is not None: out_append += '_psf' print('*************************************************') print(out_append) mlem_ = mlem_obj.update(atten_corr=atten, psf_corr=psf, scatter_corr=None) img = mlem_() from srfnef.corrections.scattering.scatter import scatter_preprocess scatter_preprocess(mlem_obj.scanner, mlem_obj.listmode, img, mlem_obj.atten_corr.u_map, outdir, out_append=out_append) nef.save(img, outdir + f'/recon_image{out_append}.hdf5') # with open(json_path, 'r') as fin: # if 'mask' in json.load(fin): # mask_path = json.load(fin)['mask'] # else: # mask_path = None nef.doc_gen(mlem_full_without_data, img, outdir, outdir + f'/recon_doc{out_append}.md') pypandoc.convert_file(outdir + f'/recon_doc{out_append}.md', 'pdf', outputfile=outdir + f'/recon_doc{out_append}.md' + '.pdf') return img
def test_with_scatter(json_path, outdir, system): tf.enable_eager_execution() if outdir is None: outdir = os.path.dirname(os.path.abspath(json_path)) else: outdir = os.path.abspath(outdir) if not os.path.isdir(outdir): os.mkdir(outdir, mode=0o777) mlem_full_without_data = nef.io.json_load(nef.functions.MlemFull, json_path) if system == '8panel': with open('/mnt/users/weijie/srfnef/mlem_full.json', 'r') as fin: dct = json.load(fin) scanner = nef.PetCylindricalScanner.from_dict(dct['scanner']) mlem_full_without_data = mlem_full_without_data.update(scanner=scanner) mlem_obj = nef.io.load_all_data(mlem_full_without_data) opt_atten = [None] if mlem_obj.atten_corr is None else [ None, mlem_obj.atten_corr ] opt_psf = [None ] if mlem_obj.psf_corr is None else [None, mlem_obj.psf_corr] for atten in opt_atten: for psf in opt_psf: out_append = '' if atten is not None: out_append += '_atten' if psf is not None: out_append += '_psf' print('*************************************************') print("scattering") img = nef.load(nef.Image, outdir + f'/recon_image{out_append}.hdf5') listmode = mlem_obj.scatter_corr(img, mlem_obj.atten_corr.u_map, mlem_obj.scanner, outdir, out_append) mlem_ = nef.MlemFull(mlem_obj.n_iter, mlem_obj.image_config, mlem_obj.scanner, listmode) img = mlem_() out_append += '_scatter' print(out_append) nef.save(img, outdir + f'/recon_image{out_append}.hdf5') nef.doc_gen(mlem_full_without_data, img, outdir, outdir + f'/recon_doc{out_append}.md') pypandoc.convert_file(outdir + f'/recon_doc{out_append}.md', 'pdf', outputfile=outdir + f'/recon_doc{out_append}.md' + '.pdf') return img
def extract_listmode(path, nsub, outpath, system): path = path.replace('sub.0', 'sub.?') if system == 'mct': listmode = listmode_from_gate_out(path, nef.scanner_mct, int(nsub)) else: raise NotImplementedError if not outpath.endswith('.hdf5'): outdir = outpath if not os.path.isdir(outdir): os.mkdir(outdir, mode = 0o777) outpath = outdir + '/listmode_trans.hdf5' else: pass nef.save(listmode, outpath) print(outpath)
def recon_full(json_path, outdir): if outdir is None: outdir = os.path.dirname(os.path.abspath(json_path)) else: outdir = os.path.abspath(outdir) if not os.path.isdir(outdir): os.mkdir(outdir, mode=0o777) mlem_full_without_data = nef.io.json_load( nef.functions.MlemFullCylindrical, json_path) mlem_obj = nef.io.load_all_data(mlem_full_without_data) img = mlem_obj() nef.save(img, outdir + '/recon_image.hdf5') nef.save(mlem_full_without_data, outdir + '/mlem_full.hdf5') nef.doc_gen(mlem_full_without_data, img, outdir, outdir + '/recon_doc.md') pypandoc.convert_file(outdir + '/recon_doc.md', 'pdf', outputfile=outdir + '/recon_doc.md' + '.pdf') return img
def recon_simple(listmode_path, outdir, system, n_iter): listmode = nef.load(nef.Listmode, listmode_path) if system == 'mct': image_config = nef.image_config_mct scanner = nef.scanner_mct else: raise NotImplementedError mlem_full = nef.MlemFull(n_iter, image_config, scanner, listmode) mlem_full_without_data = mlem_full.update(listmode = listmode_path) img = mlem_full() if outdir == '.': pass elif not os.path.isdir(outdir): os.mkdir(outdir, mode = 0o777) nef.save(img, outdir + '/recon_image.hdf5') nef.save(mlem_full, outdir + '/mlem_full.hdf5') doc_path = nef.doc_gen(mlem_full_without_data, img, outdir, outdir + '/recon_doc.md') print('generating doc at', doc_path) pypandoc.convert_file(outdir + '/recon_doc.md', 'pdf', outputfile = outdir + '/recon_doc.md' + '.pdf') return img