def listmode_from_gate_out(path, scanner, nb_sub): full_data = None for i in tqdm(range(nb_sub)): path_ = path.replace('?', str(i)) data = np.load(path_)[:, :7] if full_data is None: full_data = np.array(data) else: full_data = np.vstack((full_data, data)) if isinstance(scanner, nef.PetEcatScanner): lors = Lors(full_data) listmode = Listmode(np.ones((lors.length, ), dtype=np.float32), lors) row = nef.EcatCrystalPosToIndex(scanner)(lors.data[:, :3]) col = nef.EcatCrystalPosToIndex(scanner)(lors.data[:, 3:]) lors_data1 = nef.EcatIndexToCrystalPos(scanner)(row) lors_data2 = nef.EcatIndexToCrystalPos(scanner)(col) lors = np.hstack((lors_data1, lors_data2)) return Listmode(np.ones((lors.shape[0], ), dtype=np.float32), lors) elif isinstance(scanner, nef.PetCylindricalScanner): lors = Lors(full_data) listmode = Listmode(np.ones((lors.length, ), dtype=np.float32), lors) ind1 = nef.CylindricalCrystalPosToIndex(scanner)(lors.data[:, :3]) ind2 = nef.CylindricalCrystalPosToIndex(scanner)(lors.data[:, 3:]) lors_data1 = nef.CylindricalIndexToCrystalPos(scanner)(ind1) lors_data2 = nef.CylindricalIndexToCrystalPos(scanner)(ind2) lors_data = np.hstack((lors_data1, lors_data2)) return listmode.update(lors=nef.Lors(lors_data)) else: raise NotImplementedError
def __call__(self, sino: Sinogram) -> Listmode: irow_, icol_ = sino.data.nonzero() data_ = sino.data.data pos1 = EcatIndexToCrystalPos(self.scanner)(irow_) pos2 = EcatIndexToCrystalPos(self.scanner)(icol_) lors_data = np.hstack((pos1, pos2)) return Listmode(data_, Lors(lors_data))
def listmode_tof_from_gate_out(path, scanner, nb_sub): full_data = None for i in tqdm(range(nb_sub)): path_ = path.replace('?', str(i)) data = np.load(path_)[:, :7] if full_data is None: full_data = np.array(data) else: full_data = np.vstack((full_data, data)) lors = Lors(full_data) listmode = Listmode(np.ones((lors.length, ), dtype=np.float32), lors) row, col = ListmodeToId()(listmode, scanner) lors = IdToListmode()(row, col, scanner) print(lors.data.shape) print(full_data.shape) lors_tof = lors.update( data=np.append(lors.data, full_data[:, -1].reshape(-1, 1), axis=1)) return Listmode(np.ones((lors.shape[0], ), dtype=np.float32), lors_tof)
def _load_data(self, key): KC = self.KEYS.CONFIG if key == KC.EMAP_PATH: result = load(Emap, self.config.get(key)) else: listmode = load(Listmode, self.config.get(key)) len_per_sub = listmode.data.shape[0] // self.nb_workers tid = self.task_index result = Listmode( listmode.data[tid * len_per_sub:(tid + 1) * len_per_sub], Lors(listmode.lors.data[tid * len_per_sub:(tid + 1) * len_per_sub, :])) return result
def __call__(self, listmode: Listmode) -> Listmode: pos1 = listmode.lors.data[:, :3] pos2 = listmode.lors.data[:, 3:6] ind1 = CylindricalCrystalPosToIndex(self.scanner)(pos1) ind2 = CylindricalCrystalPosToIndex(self.scanner)(pos2) pos1_new = CylindricalIndexToCrystalPos(self.scanner)(ind1) pos2_new = CylindricalIndexToCrystalPos(self.scanner)(ind2) if listmode.lors.data.shape[1] == 6: lors_data_new = np.hstack((pos1_new, pos2_new)).astype(np.float32) else: tof_val = listmode.lors.data[:, -1] lors_data_new = np.hstack((pos1_new, pos2_new, tof_val.reshape(-1, 1))).astype( np.float32) return listmode.update(lors = Lors(lors_data_new))
def listmode_from_gate_out_multi_bed(path, scanner, nb_sub): full_data = {} for i in tqdm(range(nb_sub)): path_ = path.replace('?', str(i)) data = np.load(path_)[:, :7] bed_id = np.load(path_)[:, -1] for i_bed in set(bed_id): if i_bed not in full_data: full_data[i_bed] = np.array(data[bed_id == i_bed, :]) else: full_data[i_bed] = np.vstack( (full_data[i_bed], data[bed_id == i_bed, :])) listmode_out = {} for key, values in full_data.items(): lors = Lors(values) listmode = Listmode(np.ones((lors.length, ), dtype=np.float32), lors) row, col = ListmodeToId()(listmode, scanner) lors = IdToListmode()(row, col, scanner) listmode_out[key] = Listmode( np.ones((lors.shape[0], ), dtype=np.float32), lors) return listmode_out
def __call__(self, listmodes: List(Listmode)) -> Listmode: lors = Lors(np.vstack([lm.lors.data for lm in listmodes])) listmode = Listmode(np.hstack([lm.data for lm in listmodes]), lors) return listmode