def read_aps_32id(fname, exchange_rank=0, proj=None, sino=None, dtype=None): """ Read APS 32-ID standard data format. Parameters ---------- fname : str Path to hdf5 file. exchange_rank : int, optional exchange_rank is added to "exchange" to point tomopy to the data to reconstruct. if rank is not set then the data are raw from the detector and are located under exchange = "exchange/...", to process data that are the result of some intemedite processing step then exchange_rank = 1, 2, ... will direct tomopy to process "exchange1/...", proj : {sequence, int}, optional Specify projections to read. (start, end, step) sino : {sequence, int}, optional Specify sinograms to read. (start, end, step) dtype : numpy datatype, optional Convert data to this datatype on read if specified. Returns ------- ndarray 3D tomographic data. ndarray 3D flat field data. ndarray 3D dark field data. ndarray 1D theta in radian. """ if exchange_rank > 0: exchange_base = 'exchange{:d}'.format(int(exchange_rank)) else: exchange_base = "exchange" tomo_grp = '/'.join([exchange_base, 'data']) flat_grp = '/'.join([exchange_base, 'data_white']) dark_grp = '/'.join([exchange_base, 'data_dark']) theta_grp = '/'.join([exchange_base, 'theta']) tomo = dxreader.read_hdf5(fname, tomo_grp, slc=(proj, sino), dtype=dtype) flat = dxreader.read_hdf5(fname, flat_grp, slc=(None, sino), dtype=dtype) dark = dxreader.read_hdf5(fname, dark_grp, slc=(None, sino), dtype=dtype) theta = dxreader.read_hdf5(fname, theta_grp, slc=None) if (theta is None): theta_size = dxreader.read_dx_dims(fname, 'data')[0] theta = np.linspace(0., np.pi, theta_size) else: theta = theta * np.pi / 180. return tomo, flat, dark, theta
def _read_theta_size(params): if (str(params.file_format) in {'dx', 'aps2bm', 'aps7bm', 'aps32id'}): theta_size = dxreader.read_dx_dims(params.file_name, 'data')[0] else: log.error(" *** %s is not a supported file format" % params.file_format) exit() return theta_size
def _read_theta_size(params): if (str(params.file_type) in {'dx', 'aps2bm', 'aps7bm', 'aps32id'}): theta_size = dxreader.read_dx_dims(params.file_name, 'data')[0] # elif: # # add here other reader of theta size for other formats # log.info(" *** %s is a valid xxx file format" % params.file_name) else: log.error(" *** %s is not a supported file format" % params.file_format) exit() return theta_size
def dump_hdf5_item_structure(g, file_name, offset=' '): """Prints the input file/group/dataset (g) name and begin iterations on its content""" if isinstance(g, h5py.File): print(g.file, 'File:', g.name) elif isinstance(g, h5py.Dataset): #print ('Dataset: ', g.name) #, g.dtype if g.name == '/exchange/theta': print('theta array', file_name, g.name, dxreader.read_dx_dims(file_name, "theta")) elif g.name == '/exchange/data': print('data array', file_name, g.name, dxreader.read_dx_dims(file_name, "data")) elif g.name == '/exchange/data_white': print('data white', file_name, g.name, dxreader.read_dx_dims(file_name, "data_white")) elif g.name == '/exchange/data_dark': print('data dark', file_name, g.name, dxreader.read_dx_dims(file_name, "data_dark")) else: # print (file_name, g.name, '=', read_hdf5(file_name, g.name)) read_hdf5(file_name, g.name) elif isinstance(g, h5py.Group): print('Group:', g.name) else: print('WARNING: UNKNOWN ITEM IN HDF5 FILE', g.name) sys.exit("EXECUTION IS TERMINATED") if isinstance(g, h5py.File) or isinstance(g, h5py.Group): # for key,val in dict(g).iteritems() : for key, val in dict(g).items(): subg = val #print (offset, key )#," ", subg.name #, val, subg.len(), type(subg), dump_hdf5_item_structure(subg, file_name, offset + ' ')
def read_tomo(sino, params): if params.hdf_file_type == 'standard': # Read APS 32-BM raw data. log.info(" *** loading a stardard data set: %s" % params.hdf_file) proj, flat, dark, theta = dxchange.read_aps_32id(params.hdf_file, sino=sino) elif params.hdf_file_type == 'flip_and_stich': log.info(" *** loading a 360 deg flipped data set: %s" % params.hdf_file) proj360, flat360, dark360, theta360 = dxchange.read_aps_32id( params.hdf_file, sino=sino) proj, flat, dark = flip_and_stitch(variableDict, proj360, flat360, dark360) theta = theta360[:len(theta360) // 2] # take first half else: # params.hdf_file_type == 'mosaic': log.error(" *** loading a mosaic data set is not supported yet") exit() if params.reverse: log.info(" *** correcting for 180-0 data collection") step_size = (theta[1] - theta[0]) theta_size = dxreader.read_dx_dims(params.hdf_file, 'data')[0] theta = np.linspace(np.pi, (0 + step_size), theta_size) if params.blocked_views: log.info(" *** correcting for blocked view data collection") miss_angles = [params.missing_angles_start, params.missing_angle_end] # Manage the missing angles: proj = np.concatenate( (proj[0:miss_angles[0], :, :], proj[miss_angles[1] + 1:-1, :, :]), axis=0) theta = np.concatenate( (theta[0:miss_angles[0]], theta[miss_angles[1] + 1:-1])) # new missing projection handling # if params.blocked_views: # log.warning(" *** new missing angle handling") # miss_angles = [params.missing_angles_start, params.missing_angle_end] # data = patch_projection(data, miss_angles) proj, flat, dark = binning(proj, flat, dark, params) rotation_axis = params.rotation_axis / np.power(2, float(params.binning)) log.info(" *** rotation center: %f" % rotation_axis) return proj, flat, dark, theta, rotation_axis
def read_aps_32id(fname, exchange_rank=0, proj=None, sino=None, dtype=None): """ Read APS 32-ID standard data format. Parameters ---------- fname : str Path to hdf5 file. exchange_rank : int, optional exchange_rank is added to "exchange" to point tomopy to the data to reconstruct. if rank is not set then the data are raw from the detector and are located under exchange = "exchange/...", to process data that are the result of some intemedite processing step then exchange_rank = 1, 2, ... will direct tomopy to process "exchange1/...", proj : {sequence, int}, optional Specify projections to read. (start, end, step) sino : {sequence, int}, optional Specify sinograms to read. (start, end, step) dtype : numpy datatype, optional Convert data to this datatype on read if specified. Returns ------- ndarray 3D tomographic data. ndarray 3D flat field data. ndarray 3D dark field data. ndarray 1D theta in radian. """ if exchange_rank > 0: exchange_base = 'exchange{:d}'.format(int(exchange_rank)) else: exchange_base = "exchange" tomo_grp = '/'.join([exchange_base, 'data']) flat_grp = '/'.join([exchange_base, 'data_white']) dark_grp = '/'.join([exchange_base, 'data_dark']) theta_grp = '/'.join([exchange_base, 'theta']) tomo = dxreader.read_hdf5(fname, tomo_grp, slc=(proj, sino), dtype=dtype) flat = dxreader.read_hdf5(fname, flat_grp, slc=(None, sino), dtype=dtype) dark = dxreader.read_hdf5(fname, dark_grp, slc=(None, sino), dtype=dtype) theta = dxreader.read_hdf5(fname, theta_grp, slc=None) if (theta is None): theta_size = dxreader.read_dx_dims(fname, 'data')[0] logger.warn('Generating "%s" [0-180] deg angles for missing "exchange/theta" dataset' % (str(theta_size))) theta = np.linspace(0. , np.pi, theta_size) else: theta = theta * np.pi / 180. return tomo, flat, dark, theta