def set_size_object(self, in_d1, positions, pobj): positions = self.get_positions() p, r = self.parse_params() sh = p.scans.savu.data.shape r.data = np.ones((positions.shape[-1], sh, sh)) p.scans.savu.data.recipe = r P = Ptycho(p, level=2) object_shape = P.obj.storages['S00G00'].data[0].shape self.obj_shape = object_shape + (self.get_num_object_modes(), )
def pre_process(self): b = Ptycho.load_run(self.parameters['ptyr_file'],False) # load in the run but without the data p = b.p existing_scan = copy(p.scans[p.scans.keys()[0]]) p.scans.savu = existing_scan p.scans.savu.data.source = 'savu' p.scans.savu.data.recipe = u.Param() p.scan.illumination = b.probe.storages['S00G00'].data self.p = p
def setup(self): in_datasets, out_datasets = self.get_datasets() self.in_shape = in_datasets[0].get_shape() in_pData, __out_pData = self.get_plugin_datasets() in_pData[0].plugin_data_setup('PROJECTION', self.get_max_frames()) self.in_slice_dirs= np.array(in_pData[0].get_slice_directions()) self.in_core_dirs= np.sort(np.array(in_pData[0].get_core_directions()))# sort them to get in the right order self.b = Ptycho.load_run(self.parameters['ptyr_file'],False) self.p = self.b.p BasePtycho.setup(self)
def filter_frames(self, data): # idx = self.get_global_frame_index()# the current frame p = self.p p.scans.savu.data.recipe.data = data[0] positions = self.get_positions()[0]# just assume zero for now p.scans.savu.data.recipe.positions = positions.T[:600] P = Ptycho(p,level=5) object_stack = P.obj.storages['S00G00'].data.astype(np.float) probe_stack = P.probe.storages['S00G00'].data.astype(np.float) return [probe_stack, object_stack, positions]#] add fourier error, realspace error
def filter_frames(self, data): self.r.data = data[0] self.p.scans.savu.data.recipe = self.r # reconstruct P = Ptycho(self.p, level=5) # now post process object_stack = P.obj.storages['S00G00'].data.astype(np.float) probe_stack = P.probe.storages['S00G00'].data.astype(np.float) positions = self.get_positions() return [probe_stack, object_stack, positions] #] add fourier error, realspace error
def filter_frames(self, data): idx = self.get_global_frame_index()# the current frame print idx p = self.p p.scans.savu.data.recipe.data = data[0] positions = self.get_positions()[idx] p.scans.savu.data.recipe.positions = positions self.p.scans.savu.data.recipe = self.r P = Ptycho(self.p,level=5) object_stack = P.obj.storages['S00G00'].data.astype(np.float) probe_stack = P.probe.storages['S00G00'].data.astype(np.float) return [probe_stack, object_stack, positions]#] add fourier error, realspace error
def pre_process(self): b = Ptycho.load_run(self.parameters['ptyr_file'], False) # load in the run but without the data p = b.p existing_scan = copy(p.scans[p.scans.keys()[0]]) del p.scans[p.scans.keys()[0]] p.scans.savu = existing_scan p.scans.savu.data.source = 'savu' p.scans.savu.data.recipe = u.Param() if self.parameters['mask_file'] is not None: p.scans.savu.data.recipe.mask = h5.File(self.parameters['mask_file'],'r')[self.parameters['mask_entry']][...] else: p.scans.savu.data.recipe.mask = np.ones(self.in_shape[-2:]) p.scan.illumination = b.probe.storages['S00G00'].data self.p = p
def paramtree_from_json(json_file): ''' generates a ptypy param tree from a json file :param json_file: the path the json file :return: a Param based structure. ''' in_dict = json.load(open(json_file)) #, object_hook=byteify) parameters_to_run = u.Param() if in_dict['base_file'] is not None: logging.debug("Basing this scan off of the scan in {}".format( in_dict['base_file'])) previous_scan = Ptycho.load_run( in_dict['base_file'], False) # load in the run but without the data previous_parameters = previous_scan.p parameters_to_run.update(previous_parameters) if in_dict['parameter_tree'] is not None: parameters_to_run.update(in_dict['parameter_tree'], Convert=True) return parameters_to_run
'pilatus': 172e-6, 'merlin': 55e-6, 'eiger': 75e-6 }[detector] p.scans.scan00.data.min_frames = 10 p.scans.scan00.data.load_parallel = 'all' # Scan parameters: illumination p.scans.scan00.illumination = u.Param() p.scans.scan00.illumination.model = None p.scans.scan00.illumination.aperture = u.Param() p.scans.scan00.illumination.aperture.form = 'circ' p.scans.scan00.illumination.aperture.size = 500e-9 # Reconstruction parameters p.engines = u.Param() p.engines.engine00 = u.Param() p.engines.engine00.name = 'DM' p.engines.engine00.numiter = 100 p.engines.engine00.numiter_contiguous = 10 p.engines.engine01 = u.Param() p.engines.engine01.name = 'ML' p.engines.engine01.numiter = 100 p.engines.engine01.numiter_contiguous = 10 if LooseVersion(ptypy.version) < LooseVersion('0.3.0'): raise Exception('Use ptypy 0.3.0 or better!') P = Ptycho(p, level=5)
p.scans.scan01.data.shape = 20 # needs to be an EVEN number for using shifting p.scans.scan01.data.auto_center = False # #detind0 = raw_center[0] - p.scans.scan01.data.shape/2 #detind1 = raw_center[0] + p.scans.scan01.data.shape/2 #detind2 = raw_center[1] - p.scans.scan01.data.shape/2 #detind3 = raw_center[1] + p.scans.scan01.data.shape/2 #p.scans.scan01.data.detector_roi_indices = [detind0,detind1,detind2,detind3] # this one should not be needed since u have shape and center... #p.scans.scan01.data.center = (raw_center[0] - detind0,raw_center[1] - detind2) p.scans.scan01.data.psize = 55e-6 p.scans.scan01.data.energy = 15.0 p.scans.scan01.data.distance = 1.0 #? # prepare and run P = Ptycho(p, level=2) #%% # --------------------------------------------------------- # Load data, some metadata, gemetry object, and do some initial plotting #----------------------------------------------------------- import sys #to collect system path ( to collect function from another directory) sys.path.insert(0, 'C:/Users/Sanna/Documents/python_utilities') from movie_maker import movie_maker import h5py # define motorposition directory. Is this information included in P? scan_name_int = scans[2] scan_name_string = '%d' % scan_name_int
p.engine.DM.alpha = 1 # (94) Parameters that makes the difference p.engine.DM.probe_update_start = 2 # (95) Number of iterations before probe update starts p.engine.DM.update_object_first = True # (96) If False update object before probe p.engine.DM.overlap_converge_factor = 0.05 # (97) Loop overlap constraint until probe change is smaller than this fraction p.engine.DM.overlap_max_iterations = 100 # (98) Maximum iterations to be spent inoverlap constraint p.engine.DM.fourier_relax_factor = 0.1 # (99) If rms of model vs diffraction data is smaller than this fraction, Fourier constraint is met p.engine.ML = u.Param() p.engines = u.Param() # (100) empty structure to be filled with engines p.engines.engine00 = u.Param() p.engines.engine00.name = 'DM' p.engines.engine00.numiter = 100 p.engines.engine00.fourier_relax_factor = 0.05 #p.engines.engine01 = u.Param() #p.engines.engine01.name = 'ML' #p.engines.engine01.numiter = 10 p.simulation = u.Param() p.simulation.position_noise = 1e-10 # (104) p.simulation.detector = dict(dtype=np.uint32, full_well=2**32 - 1, psf=(0, 3)) ## UNCOMMENT FOR SIMULATION ### #P = sim.simulate_basic_with_pods(p,save=True) ### UNCOMMENT FOR RECONTRUCTION #### p.model.coherence.Nprobe_modes = 5 p.model.sample.source = None p.model.illumination.prop_dist = 0.0 P = Ptycho(p, level=3) P.save_run(kind='minimal')
p.engine.DM.overlap_converge_factor = 0.05 # (97) Loop overlap constraint until probe change is smaller than this fraction p.engine.DM.overlap_max_iterations = 100 # (98) Maximum iterations to be spent inoverlap constraint p.engine.DM.fourier_relax_factor = 0.1 # (99) If rms of model vs diffraction data is smaller than this fraction, Fourier constraint is met p.engine.ML = u.Param() p.engines = u.Param() # (100) empty structure to be filled with engines p.engines.engine00 = u.Param() p.engines.engine00.name = 'DM' p.engines.engine00.numiter = 100 p.engines.engine00.fourier_relax_factor = 0.05 #p.engines.engine01 = u.Param() #p.engines.engine01.name = 'ML' #p.engines.engine01.numiter = 10 p.simulation = u.Param() p.simulation.position_noise = 1e-10 # (104) p.simulation.detector = dict(dtype=np.uint32,full_well=2**32-1,psf=(0,3)) ## UNCOMMENT FOR SIMULATION ### #P = sim.simulate_basic_with_pods(p,save=True) ### UNCOMMENT FOR RECONTRUCTION #### p.model.coherence.Nprobe_modes = 5 p.model.sample.source = None p.model.illumination.prop_dist = 0.0 P = Ptycho(p,level=3) P.save_run(kind='minimal')