def get_input(): args, params = cmdline_config_cxi_reader.get_all('extract_array', 'exporting an array') params = params['extract_array'] print(args.filename) return args, params
def get_input(): args, params = cmdline_config_cxi_reader.get_all( 'pos_refine', 'update the sample translations according to a least squares minimisation procedure', exclude=['frames']) params = params['pos_refine'] # frames, split by frame no. roi = params['roi'] roi = (params['good_frames'], slice(roi[0], roi[1]), slice(roi[2], roi[3])) params['frames'] = MpiArray_from_h5(args.filename, params['frames'], axis=0, dtype=np.float64, roi=roi) #def MpiArray_from_h5(fnam, path, axis=0, dtype=None, roi = None): #params['frames'] = params['frames'][params['good_frames']] if rank != 0: params['R_ss_fs'] = None # offset positions if rank == 0 and params['pixel_shifts'] is not None: params['R_ss_fs'] += fm.steps_offset(params['R_ss_fs'], params['pixel_shifts']) params['R_ss_fs'] = MpiArray(params['R_ss_fs']) params['R_ss_fs'].scatter(axis=0) # set masked pixels to negative 1 for i in range(params['frames'].arr.shape[0]): params['frames'].arr[i][~params['mask']] = -1 params['whitefield'][~params['mask']] = -1 if params['pixel_shifts'] is None: params['pixel_shifts'] = np.zeros((2, ) + params['whitefield'].shape, dtype=np.float64) # add a regularization factor shape = params['whitefield'].shape reg = mk_reg(shape, params['reg']) return args, params, reg
def get_input(): args, params = cmdline_config_cxi_reader.get_all( 'update_pixel_map', 'update the pixel shifts according to a least squares minimisation procedure', exclude=['frames', 'whitefield', 'mask']) params = params['update_pixel_map'] # split by ss pixels #################### # special treatment for frames roi = params['roi'] roi = (params['good_frames'], slice(roi[0], roi[1]), slice(roi[2], roi[3])) # easy for the mask params['frames'] = MpiArray_from_h5(args.filename, params['frames'], axis=1, roi=roi, dtype=np.float64) params['mask'] = MpiArray_from_h5(args.filename, params['mask'], axis=0, roi=roi[1:], dtype=np.bool) with h5py.File(args.filename, 'r') as f: shape = f[params['whitefield']].shape if len(shape) == 2: params['whitefield'] = MpiArray_from_h5(args.filename, params['whitefield'], axis=0, roi=roi[1:], dtype=np.float64) params['whitefield'].arr[~params['mask'].arr] = -1 else: params['whitefield'] = MpiArray_from_h5(args.filename, params['whitefield'], axis=1, roi=roi, dtype=np.float64) for i in range(params['whitefield'].arr.shape[0]): params['whitefield'].arr[i][~params['mask'].arr] = -1 # set masked pixels to negative 1 for i in range(params['frames'].arr.shape[0]): params['frames'].arr[i][~params['mask'].arr] = -1 # offset positions if params['pixel_shifts'] is not None: params['R_ss_fs'] += fm.steps_offset(params['R_ss_fs'], params['pixel_shifts']) # special treatment for the pixel_shifts if params['pixel_shifts'] is None and rank == 0: params['pixel_shifts'] = np.zeros( (2, ) + params['whitefield'].shape[-2:], dtype=np.float64) if rank != 0: params['pixel_shifts'] = None params['pixel_shifts'] = MpiArray(params['pixel_shifts']) params['pixel_shifts'].scatter(axis=1) return args, params
bad = (overlap < 2.0) atlas[bad] = -1 atlas[~bad] /= (overlap[~bad] + 1.0e-5) return atlas if __name__ == '__main__': # get input ########### # get command line args and config sc = 'fit_defocus_registration' des = 'fit the sample to focus distance (and astigmatism) by registration of speckles.' args, params = cmdline_parser.parse_cmdline_args(sc, des) # now load the necessary data args, params = cmdline_config_cxi_reader.get_all(sc, des) params = params['fit_defocus_registration'] if ('pixel_shifts' in params) and (params['pixel_shifts'] is not None): pix_shifts = params['pixel_shifts'] else: pix_shifts = np.zeros((2, ) + params['whitefield'].shape[-2:], dtype=np.float64) z1 = params['defocus'] z2 = params['distance'] - params['defocus'] M = (z1 + z2) / z1 ze = z2 / M print('mag :', M) print('z effective:', ze)
if reg is not None: x = np.arange(shape[0]) - shape[0] // 2 x = np.exp(-x**2 / (2. * reg**2)) y = np.arange(shape[1]) - shape[1] // 2 y = np.exp(-y**2 / (2. * reg**2)) reg = np.outer(x, y) else: reg = 1 return reg if __name__ == '__main__': # get input ########### args, params = cmdline_config_cxi_reader.get_all( 'stitch', 'stitch frames together to form a merged view of the sample from projection images' ) params = params['stitch'] if ('pixel_shifts' in params) and (params['pixel_shifts'] is not None): pix_shifts = params['pixel_shifts'] else: pix_shifts = np.zeros((2, ) + params['whitefield'].shape[-2:], dtype=np.float64) # Do Stuff ########## # set masked pixels to negative 1 mask = params['mask'].astype(np.bool) params['frames'] = params['frames'][params['good_frames']].astype( np.float64)
def get_input(): args, params = cmdline_config_cxi_reader.get_all('make_whitefield', 'estimate the whitefield by taking the median value of every pixel') params = params['make_whitefield'] return args, params