p.paths.run = None # (04) Name of reconstruction run p.paths.data_dir = "analysis/%(run)s/" # (05) directory where diffraction data is stored p.paths.data_file = "%(label)s.ptyd" p.paths.plot_dir = "plots/%(run)s/" # (06) directory to dump plot images p.paths.plot_file = "%(run)s_%(engine)s_%(iterations)04d.png" # (07) filename for dumping plots p.paths.plot_interval = 2 # (08) iteration interval for dumping plots p.paths.save_dir = "recons/%(run)s/" # (09) directory to save final reconstruction p.paths.save_file = "%(run)s_%(engine)s_%(iterations)04d.h5" # (10) filename for saving p.paths.dump_dir = "dumps/%(run)s/" # (11) directory to save intermediate results p.paths.dump_file = "%(run)s_%(engine)s_%(iterations)04d.h5" # (12) p.model = u.Param() p.model.source = None # (14) Address or path to data ressource. p.model.tags = "file" # (15) tags (comma seperated) describing what kind of data this is p.model.geometry = u.Param() p.model.geometry.energy = u.keV2m( 1.0) / 6.32e-7 #None # (17) Energy (in keV) p.model.geometry.lam = None # (18) wavelength p.model.geometry.z = 15e-2 # (19) distance from object to screen p.model.geometry.psize_det = 24e-6 # (20) Pixel size in Detector plane p.model.geometry.psize_sam = None # (21) Pixel size in Sample plane p.model.geometry.N = 256 # (22) Number of detector pixels p.model.geometry.prop_type = "farfield" # (23) propagation type p.model.xy = u.Param() p.model.xy.scan_type = "round_roi" # (25) None,'round', 'raster', 'round_roi','custom' p.model.xy.dr = 0.3e-3 # (26) round,round_roi :width of shell p.model.xy.nr = 10 # (27) round : number of intervals (# of shells - 1) p.model.xy.nth = 5 # (28) round,round_roi: number of points in the first shell p.model.xy.lx = 10e-3 # (29) round_roi: Width of ROI p.model.xy.ly = 5e-3 # (30) round_roi: Height of ROI p.model.xy.nx = 10 # (31) raster scan: number of steps in x
def prepare(self, scan=None, filename=None, dtype=np.uint32, **kwargs): self.p.update( kwargs) #rebin = rebin if rebin is not None else self.p.rebin scan = scan if scan is not None else self.p.scan self.read(scan, **kwargs) DS = u.Param() dark = self.dark data = self.data if dark is not None: if dark.ndim == 3: dark = dark.mean(0) dark = np.resize(dark, data.shape) flat = self.flat if flat is not None: if flat.ndim == 3: flat = flat.mean(0) flat = np.resize(flat, self.data.shape) #plt.ion(); #plt.figure();plt.imshow(dark[0]);plt.colorbar() #plt.figure();plt.imshow((flat-dark)[0]);plt.colorbar() #plt.figure();plt.imshow(data[0]);plt.colorbar() if flat is not None and dark is not None: data = (data - dark) / (flat - dark) elif dark is not None: data = data - dark else: data = data # remove negative values data[data < 0] = 0 # #plt.figure();plt.imshow(DS.data[0],vmin=0);plt.colorbar() # if self.mask is None: mask = np.ones_like(data, dtype=np.bool) # #DS.flat = self.flat #DS.dark = self.dark DS.scan_info = u.Param() s = DS.scan_info p = self.p #s.scan_number = p.scan_number s.scan_label = 'S' + self.label #'S%05d' % p.scan_number s.data_filename = self.scan #scandict['data_filename'] s.wavelength = u.keV2m(p.energy) s.energy = p.energy rebin = self.p.rebin s.detector_pixel_size = p.detector_pixel_size * rebin if p.detector_pixel_size is not None else None p.dpsize = p.dpsize / rebin s.detector_distance = p.detector_distance s.initial_ctr = self.ctr / rebin if rebin != 1: sh = data.shape data = u.rebin(data, sh[0], sh[1] / rebin, sh[2] / rebin) mask = u.rebin(mask.astype(int), sh[0], sh[1] / rebin, sh[2] / rebin).astype(bool) data = flip(data, self.p.flip) mask = flip(mask, self.p.flip) DS.data = data.astype(dtype) DS.mask = mask DS.data[np.invert(DS.mask)] = 0 #s.date_collected = scandict['date'] s.date_processed = time.asctime() s.exposure_time = self.exp #if meta is not None: s.raw_filenames = meta['filename'] s.preparation_basepath = self.base_path s.preparation_other = {} s.shape = DS.data.shape s.positions_theory = None s.scan_command = self.command motors = p.motors if self.motors is not None: Nmotors = len(motors) logger.debug('Motors are : %s' % str(p.motors)) mmult = u.expect2(p.motors_multiplier) pos_list = [ mmult[i] * np.array(self.motors[motors[i]]) for i in range(Nmotors) ] s.positions = np.array(pos_list).T else: s.positions = None self.p.scan_label = s.scan_label if filename is None: p.write_path = WRITE_PATH_PATTERN.format(**p) filename = SAVE_FILENAME_PATTERN.format(**p) s.data_filename = u.clean_path(filename) io.h5write(filename, DS) return DS
p.paths.data_dir = "analysis/%(run)s/" # (05) directory where diffraction data is stored p.paths.data_file = "%(label)s.ptyd" p.paths.plot_dir = "plots/%(run)s/" # (06) directory to dump plot images p.paths.plot_file = "%(run)s_%(engine)s_%(iterations)04d.png"# (07) filename for dumping plots p.paths.plot_interval = 2 # (08) iteration interval for dumping plots p.paths.save_dir = "recons/%(run)s/" # (09) directory to save final reconstruction p.paths.save_file = "%(run)s_%(engine)s_%(iterations)04d.h5"# (10) filename for saving p.paths.dump_dir = "dumps/%(run)s/" # (11) directory to save intermediate results p.paths.dump_file = "%(run)s_%(engine)s_%(iterations)04d.h5"# (12) p.model = u.Param() p.model.source = None # (14) Address or path to data ressource. p.model.tags = "file" # (15) tags (comma seperated) describing what kind of data this is p.model.geometry = u.Param() p.model.geometry.energy = u.keV2m(1.0)/6.32e-7 #None # (17) Energy (in keV) p.model.geometry.lam = None # (18) wavelength p.model.geometry.z = 15e-2 # (19) distance from object to screen p.model.geometry.psize_det = 24e-6 # (20) Pixel size in Detector plane p.model.geometry.psize_sam = None # (21) Pixel size in Sample plane p.model.geometry.N = 256 # (22) Number of detector pixels p.model.geometry.prop_type = "farfield" # (23) propagation type p.model.xy = u.Param() p.model.xy.scan_type = "round_roi" # (25) None,'round', 'raster', 'round_roi','custom' p.model.xy.dr = 0.3e-3 # (26) round,round_roi :width of shell p.model.xy.nr = 10 # (27) round : number of intervals (# of shells - 1) p.model.xy.nth = 5 # (28) round,round_roi: number of points in the first shell p.model.xy.lx = 10e-3 # (29) round_roi: Width of ROI p.model.xy.ly = 5e-3 # (30) round_roi: Height of ROI p.model.xy.nx = 10 # (31) raster scan: number of steps in x
def prepare(self,scan=None,filename=None,dtype=np.uint32,**kwargs): self.p.update(kwargs) #rebin = rebin if rebin is not None else self.p.rebin scan = scan if scan is not None else self.p.scan self.read( scan, **kwargs) DS = u.Param() dark = self.dark data = self.data if dark is not None: if dark.ndim == 3: dark = dark.mean(0) dark = np.resize(dark,data.shape) flat = self.flat if flat is not None: if flat.ndim == 3: flat = flat.mean(0) flat = np.resize(flat,self.data.shape) #plt.ion(); #plt.figure();plt.imshow(dark[0]);plt.colorbar() #plt.figure();plt.imshow((flat-dark)[0]);plt.colorbar() #plt.figure();plt.imshow(data[0]);plt.colorbar() if flat is not None and dark is not None: data = (data-dark )/(flat-dark) elif dark is not None: data = data - dark else: data = data # remove negative values data[data<0]=0 # #plt.figure();plt.imshow(DS.data[0],vmin=0);plt.colorbar() # if self.mask is None: mask = np.ones_like(data,dtype=np.bool) # #DS.flat = self.flat #DS.dark = self.dark DS.scan_info = u.Param() s = DS.scan_info p = self.p #s.scan_number = p.scan_number s.scan_label = 'S'+self.label #'S%05d' % p.scan_number s.data_filename = self.scan #scandict['data_filename'] s.wavelength = u.keV2m( p.energy ) s.energy = p.energy rebin = self.p.rebin s.detector_pixel_size = p.detector_pixel_size * rebin if p.detector_pixel_size is not None else None p.dpsize = p.dpsize / rebin s.detector_distance = p.detector_distance s.initial_ctr = self.ctr / rebin if rebin!=1: sh = data.shape data = u.rebin(data,sh[0],sh[1]/rebin,sh[2]/rebin) mask = u.rebin(mask.astype(int),sh[0],sh[1]/rebin,sh[2]/rebin).astype(bool) data = flip(data,self.p.flip) mask = flip(mask,self.p.flip) DS.data = data.astype(dtype) DS.mask = mask DS.data[np.invert(DS.mask)]=0 #s.date_collected = scandict['date'] s.date_processed = time.asctime() s.exposure_time = self.exp #if meta is not None: s.raw_filenames = meta['filename'] s.preparation_basepath = self.base_path s.preparation_other = {} s.shape = DS.data.shape s.positions_theory = None s.scan_command = self.command motors = p.motors if self.motors is not None: Nmotors = len(motors) logger.debug( 'Motors are : %s' % str(p.motors)) mmult = u.expect2(p.motors_multiplier) pos_list = [mmult[i]*np.array(self.motors[motors[i]]) for i in range(Nmotors)] s.positions = np.array(pos_list).T else: s.positions = None self.p.scan_label = s.scan_label if filename is None: p.write_path = WRITE_PATH_PATTERN.format(**p) filename = SAVE_FILENAME_PATTERN.format(**p) s.data_filename = u.clean_path(filename) io.h5write(filename,DS) return DS