Exemple #1
0
    def load(self, target_graph):
        if self.config[self.KEYS.LORS_PATH].endswith(".npy"):
            lors = np.load(self.config[self.KEYS.LORS_PATH])
        elif self.config[self.KEYS.LORS_PATH].endswith(".h5"):
            data = load_h5(self.config[self.KEYS.LORS_PATH])
            lors_point = np.hstack((data['fst'], data['snd']))
            lors = np.hstack(
                (lors_point, data['tof'].reshape(data['tof'].size, 1)))

        # tof_sigma2 = (limit**2)/9
        lors = recon_process(lors, self.config[self.KEYS.TOF_RES])
        lors = {k: lors[str2axis(k)] for k in ('x', 'y', 'z')}
        projection_data = ListModeDataSplit(
            **{
                k: ListModeData(lors[k], np.ones([lors[k].shape[0]],
                                                 np.float32))
                for k in lors
            })
        emap = Image(
            np.load(self.config[self.KEYS.EMAP_PATH]).astype(np.float32),
            self.config[self.KEYS.CENTER], self.config[self.KEYS.SIZE])
        result = {'projection_data': projection_data, 'efficiency_map': emap}
        if self.psf_flag:
            psf_xy, psf_z = self._load_psf()
            result.update({'psf_xy': psf_xy, 'psf_z': psf_z})
        return result, ()
Exemple #2
0
def lm2bin(config, target):
    path_file = config['input']['listmode']['path_file']
    data = load_h5(path_file)
    coo_data = np.hstack((data['fst'], data['snd']))
    bin_data = np.hstack(
        (coo_data, data['weight'].reshape(data['weight'].size, 1)))
    out = bin_data.astype(np.float32)
    out.tofile((Path(target) + 'input.txt').abs)
    f = open((Path(target) + 'input.txt.hdr').abs, 'w')
    f.write(str(out.shape[0]))
Exemple #3
0
    def run(cls, kernel_xy_para_dir, kernel_z_para_dir, grid: list,
            voxsize: list, refined_factor, output_mat_dir: str,
            output_kernel_dir: str, map_file: str, psf_map_file: str,
            epsilon: float):
        from srf.io.listmode import load_h5
        grid = np.array(grid)
        voxsize = np.array(voxsize)
        kernel_xy_dict = load_h5(kernel_xy_para_dir)
        kernel_z_dict = load_h5(kernel_z_para_dir)
        print("step 1/3: making xy kernel...")
        cls().xy_main(kernel_xy_dict, grid[0:2], voxsize[0:2], refined_factor,
                      output_mat_dir)

        print("step 2/3: making z kernel...")
        cls().z_main(kernel_z_dict, grid[2], voxsize[2], output_kernel_dir)
        print("step 3/3: generating psf efficiency map...")
        cls().map_process(output_mat_dir, output_kernel_dir, map_file,
                          psf_map_file, epsilon)
        print("Task complete!")
Exemple #4
0
 def load(self, target_graph):
     if self.config[self.KEYS.LORS_PATH].endswith(".npy"):
         lors = np.load(self.config[self.KEYS.LORS_PATH])
     elif self.config[self.KEYS.LORS_PATH].endswith(".h5"):
         data = load_h5(self.config[self.KEYS.LORS_PATH])
         lors_point = np.hstack((data['fst'], data['snd']))
         lors = np.hstack(
             (lors_point, data['weight'].reshape(data['weight'].size, 1)))
     projection_data = ListModeData(lors,
                                    np.ones([lors.shape[0]], np.float32))
     return {'projection_data': projection_data}, ()
Exemple #5
0
def generate_data_and_header(config, target):
    with open(config, 'r') as fin:
        c = json.load(fin)
    scanner = get_scanner(c['scanner']['petscanner'])
    path_data = Path(target)
    gen_sino_script(c['scanner']['petscanner'], (path_data.abs + 'sinogram'))
    path_file = c['input']['listmode']['path_file']
    data = load_h5(path_file)
    lor = List(
        LoR(PositionEvent(data['fst'][i, ]),
            PositionEvent(data['snd'][i, ]),
            weight=data['weight'][i]) for i in range(0, data['weight'].size))
    lm2sino(scanner, lor, (path_data.abs + '/sinogram.s'))
Exemple #6
0
    def load(self, target_graph):
        if self.config[self.KEYS.LORS_PATH].endswith(".npy"):
            lors = np.load(self.config[self.KEYS.LORS_PATH])
        elif self.config[self.KEYS.LORS_PATH].endswith(".h5"):
            data = load_h5(self.config[self.KEYS.LORS_PATH])
            lors_point = np.hstack((data['fst'], data['snd']))
            lors = np.hstack(
                (lors_point, data['weight'].reshape(data['weight'].size, 1)))
        listmode = ListModeData(lors, np.ones([lors.shape[0]], np.float32))
        # sino = np.load('sinogram_data.npy')
        sino = _listMode2Sino(listmode, self.config[self.KEYS.PJ_CONFIG])
        # np.save('sinogram_data.npy', sino)

        emap = Image(
            np.load(self.config[self.KEYS.EMAP_PATH]).astype(np.float32),
            self.config[self.KEYS.CENTER], self.config[self.KEYS.SIZE])
        return {'projection_data': sino, 'efficiency_map': emap}, ()
Exemple #7
0
    def load(self, target_graph):
        if self.config[self.KEYS.LORS_PATH].endswith(".npy"):
            lors = np.load(self.config[self.KEYS.LORS_PATH])
        elif self.config[self.KEYS.LORS_PATH].endswith(".h5"):
            data = load_h5(self.config[self.KEYS.LORS_PATH])
            lors_point = np.hstack((data['fst'], data['snd']))
            if 'tof' in data.keys():
                lors = np.hstack(
                    (lors_point, data['tof'].reshape(data['tof'].size, 1)))
                projection_data = ListModeData(lors, lors[:, 6])
            else:
                lors = np.hstack((lors_point, np.ones(
                    (lors_point.shape[0], 1))))
                projection_data = ListModeData(lors, lors[:, 6])

        emap = Image(
            np.load(self.config[self.KEYS.EMAP_PATH]).astype(np.float32),
            self.config[self.KEYS.CENTER], self.config[self.KEYS.SIZE])
        result = {'projection_data': projection_data, 'efficiency_map': emap}
        if self.psf_flag:
            psf_xy, psf_z = self._load_psf()
            result.update({'psf_xy': psf_xy, 'psf_z': psf_z})
        return result, ()