diff --git a/ImageD11/sinograms/dataset.py b/ImageD11/sinograms/dataset.py index 265ef73f..020dea3e 100644 --- a/ImageD11/sinograms/dataset.py +++ b/ImageD11/sinograms/dataset.py @@ -246,7 +246,7 @@ def import_all(self, scans=None, shape=None): except: logging.info("nnz not available. Segmentation done?") - def import_from_sparse(self, hname, scans=None): + def import_from_sparse(self, hname, scans=None, shape=None): """ hname = hdf5 file containing sparse pixels (and motors) dataset = a dataset instance to import into @@ -260,12 +260,26 @@ def import_from_sparse(self, hname, scans=None): scans = list(hin["/"]) order = np.argsort([float(v) for v in scans if v.endswith(".1")]) self.scans = [scans[i] for i in order] + else: + self.scans = scans self.masterfile = hname # hacky, motors come from the sparsefile self.import_nnz_from_sparse() # must exist self.import_motors_from_master() - self.shape = self.nnz.shape + # self.guess_shape() # fails with sparse + if shape is not None: + self.shape = shape + self.nnz = np.array(self.nnz).reshape(self.shape) + else: + self.shape = self.nnz.shape self.omega = np.array(self.omega).reshape(self.shape) self.dty = np.array(self.dty).reshape(self.shape) + if len(scans) == 1 and self.shape[0]>1: + file_nums = np.arange(self.shape[0]*self.shape[1]).reshape(self.shape) + self.scans = [ + "%s::[%d:%d]" % (self.scans[0], row[0], row[-1] + 1) + for row in file_nums + ] + self.guessbins() def import_scans(self, scans=None, hname=None): @@ -525,7 +539,7 @@ def get_monitor(self, name="fpico6"): lo, hi = [int(v) for v in slc[1:-1].split(":")] mon = hin[snum]["measurement"][name][lo:hi] else: - mon = hin[snum]["measurement"][name][:] + mon = hin[scan]["measurement"][name][:] monitor.append(mon) self.monitor = np.concatenate(monitor).reshape(self.shape) return self.monitor diff --git a/ImageD11/sinograms/roi_iradon.py b/ImageD11/sinograms/roi_iradon.py index 28f765b4..98e9cc8f 100644 --- a/ImageD11/sinograms/roi_iradon.py +++ b/ImageD11/sinograms/roi_iradon.py @@ -526,8 +526,13 @@ def correct_recon_central_zingers(recon, radius=25): def run_iradon(sino, angles, pad=20, shift=0, - workers=1, mask=None, - apply_halfmask=False, mask_central_zingers=False, central_mask_radius=25): + workers=1, + mask=None, + apply_halfmask=False, + mask_central_zingers=False, + central_mask_radius=25, + filter_name='hamming', + ): """Applies an iradon to a sinogram, with an optional pad Calculates scaled-up output size from pad value Applies projection shifts of shift @@ -550,7 +555,7 @@ def run_iradon(sino, angles, pad=20, shift=0, mask=mask, output_size=outsize, projection_shifts=np.full(sino.shape, shift), - filter_name='hamming', + filter_name=filter_name, interpolation='linear', workers=workers) diff --git a/ImageD11/sinograms/sinogram.py b/ImageD11/sinograms/sinogram.py index 77ed6d2b..7aee985f 100644 --- a/ImageD11/sinograms/sinogram.py +++ b/ImageD11/sinograms/sinogram.py @@ -160,6 +160,8 @@ def build_sinogram(self, columns=('omega',)): # intensity weighted sums angs = {} for name in columns: + if name == 'sum_intensity': + continue angs[name] = np.zeros((npks, NY), 'f') ImageD11.cImageD11.put_incr64(angs[name], adr, self.cf_for_sino[name] * sig ) sinoangles = angs['omega'] .sum(axis=1) / sino.sum(axis=1) @@ -172,7 +174,13 @@ def build_sinogram(self, columns=('omega',)): self.ssino = self.sino[order].T self.proj_scale = self.proj_scale[order] if len(columns)>1: - self.angle_wt_sinos = { name : angs[name][order].T for name in columns } + self.angle_wt_sinos = { name : angs[name][order].T + for name in columns + if name != 'sum_intensity' + } + if 'sum_intensity' in columns: + self.angle_wt_sinos['sum_intensity'] = sino[order].T + self.hits = hits self.hkle = pkindices[:, order] # dims are [ (h,k,l,sign(eta)) , nprojections ] def update_lab_position_from_peaks(self, cf_4d, grain_label): @@ -252,7 +260,10 @@ def recon(self, iradon -> ImageD11.sinograms.roi_iradon.run_iradon { pad=20, shift=0, workers=1, mask=None, - apply_halfmask=False, mask_central_zingers=False, central_mask_radius=25 } + apply_halfmask=False, + mask_central_zingers=False, + central_mask_radius=25, + filter_name='hamming'} mlem : ImageD11.sinograms.roi_iradon.run_mlem { mask=None, pad=20, shift=0, workers=1, niter=20, apply_halfmask=False, mask_central_zingers=False, central_mask_radius=25 }