def tempPDFcalc(self, x, y_diff, cfg=None): if cfg == None: pg = PDFGetter(config=self.cfg) else: pg = PDFGetter(config=cfg) iqMat = [] fqMat = [] grMat = [] for i in tqdm(range(len(y_diff))): try: pg(x, y_diff[i]) except: pg(x, y_diff[0][i]) if i == 0: qGrid = pg.fq[0] rGrid = pg.gr[0] iqMat.append(pg.iq[1]) fqMat.append(pg.fq[1]) grMat.append(pg.gr[1]) iqMat = np.asarray(iqMat) fqMat = np.asarray(fqMat) grMat = np.asarray(grMat) return qGrid, iqMat, fqMat, rGrid, grMat, pg
def process_data(data: tp.Dict[str, np.ndarray], memory: tp.Dict[str, np.ndarray], lsq_comps: tp.List[str], composition: str, config: LSQConfig) -> tp.Dict[str, np.ndarray]: """Process the data from the event.""" # the interpolated target y data y = get_interp_data(data, config) # the component matrix where each row is a component data x = np.stack([memory[k] for k in lsq_comps], axis=0) # the model to decompose to a weight and the component matrix. model = Model(y, x, config.fit_config.p, xgrid=config.interp_config.x) opt.least_squares(model.cost_func, x0=model.x0) # transfer the data to PDF pdfconfig = PDFConfig(**config.trans_config, composition=composition) pdfgetter = PDFGetter(pdfconfig) pdfgetter(model.xgrid, model.yres) return { "y": model.y, "x": model.x, "w": model.w, "xgrid": model.xgrid, "yres": model.yres, "r": pdfgetter.gr[0], "g": pdfgetter.gr[1] }
def nu_fq_getter(q, iq, composition, **kwargs): """Process the data to F(Q) on a non uniform grid Parameters ---------- q : ndarray The q or tth values iq : ndarray The scattered intensity composition : str The composition kwargs: dict Additional kwargs for PDFGetter Returns ------- q : ndarray The radial values fq: ndarray The reduced structure function config: dict The PDFGetter config """ kwargs.update({'composition': composition}) # explicit qmin/qmaxinst cutting truth_values = np.where((kwargs['qmaxinst'] > q) & (q > kwargs['qmin'])) pg = PDFGetter() # remove resampling transformations (and bg sub) for t in [7, 6, 1]: pg.transformations.pop(t) pg(q[truth_values], iq[truth_values], **kwargs) res = pg.fq return res[0], res[1], pg.config
def sq_getter(x, y, composition, **kwargs): """Process the data to F(Q) Parameters ---------- x : ndarray The q or tth values y : ndarray The scattered intensity composition : str The composition kwargs: dict Additional kwargs for PDFGetter Returns ------- q : ndarray The radial values fq: ndarray The reduced structure function config: dict The PDFGetter config """ pg = PDFGetter() kwargs.update({'composition': composition}) args = (x, y) pg(*args, **kwargs) res = pg.sq return res[0], res[1], pg.config
def write_out(saving_dir: str, filename: str, pdfgetter: PDFGetter) -> dict: """Write out data in pdfgetter into files""" data_dirs = {} for out_type in pdfgetter.config.outputtypes: data_dir = Path(saving_dir).joinpath(out_type) if not data_dir.exists(): data_dir.mkdir() data_dirs.update({out_type: data_dir}) dct = {} for out_type in pdfgetter.config.outputtypes: # out_type in ('iq', 'sq', 'fq', 'gr') data_dir = data_dirs.get(out_type) out_file = data_dir.joinpath( Path(filename).with_suffix(".{}".format(out_type)).name) pdfgetter.writeOutput(str(out_file), out_type) dct.update({out_type: str(out_file)}) return dct
def pdf_getter(x, y, composition, **kwargs): """Process the data to the PDF Parameters ---------- x : ndarray The q or tth values y : ndarray The scattered intensity composition : str The composition kwargs: dict Additional kwargs for PDFGetter Returns ------- r : ndarray The radial values gr: ndarray The PDF config: dict The PDFGetter config """ pg = PDFGetter() kwargs.update({'composition': composition}) args = (x, y) res = pg(*args, **kwargs) return res[0], res[1], pg.config
def process( *, raw_img: np.ndarray, ai: AzimuthalIntegrator, dk_img: np.ndarray = None, dk_sub_bg_img: np.ndarray = None, integ_setting: dict = None, mask_setting: dict = None, pdfgetx_setting: dict = None, ) -> dict: """The function to process the data from event.""" data = dict() # dark subtraction if dk_img is None: dk_img = np.zeros_like(raw_img) dk_sub_img = np.subtract(raw_img, dk_img) data.update({"dk_sub_image": dk_sub_img}) # background subtraction if dk_sub_bg_img is None: dk_sub_bg_img = np.zeros_like(dk_sub_img) bg_sub_img = np.subtract(dk_sub_img, dk_sub_bg_img) data.update({"bg_sub_image": bg_sub_img}) # auto masking mask, _ = integ.auto_mask(bg_sub_img, ai, mask_setting=mask_setting) data.update({"mask": mask}) # integration x, y = ai.integrate1d(bg_sub_img, mask=mask, **integ_setting) chi_max_ind = np.argmax(y) data.update({ "chi_Q": x, "chi_I": y, "chi_max": y[chi_max_ind], "chi_argmax": x[chi_max_ind] }) # transformation pdfconfig = PDFConfig(dataformat="QA", **pdfgetx_setting) pdfgetter = PDFGetter(pdfconfig) pdfgetter(x, y) iq, sq, fq, gr = pdfgetter.iq, pdfgetter.sq, pdfgetter.fq, pdfgetter.gr gr_max_ind = np.argmax(gr[1]) data.update({ "iq_Q": iq[0], "iq_I": iq[1], "sq_Q": sq[0], "sq_S": sq[1], "fq_Q": fq[0], "fq_F": fq[1], "gr_r": gr[0], "gr_G": gr[1], "gr_max": gr[1][gr_max_ind], "gr_argmax": gr[0][gr_max_ind] }) return data
def make_default_pdfgetter() -> PDFGetter: """ Create a PDFgetter with default setting for Ni. """ config = PDFConfig() config.composition = "Ni" config.dataformat = "QA" config.qmin = 0. config.qmax = 24. config.qmaxinst = 25. config.rmin = 0. config.rmax = 60. config.rstep = .01 config.rpoly = 0.9 pdfgetter = PDFGetter(config) return pdfgetter
def fq_getter(*args, **kwargs): pg = PDFGetter() pg(*args, **kwargs) res = pg.fq return res[0], res[1], pg.config
def pdf_getter(*args, **kwargs): pg = PDFGetter() res = pg(*args, **kwargs) return res[0], res[1], pg.config
def make_pdfgetter(pdfconfig: PDFConfig, user_config: dict = None) -> PDFGetter: """Make the pdfgetter.""" if user_config is not None: pdfconfig.update(**user_config) pdfgetter = PDFGetter(pdfconfig) return pdfgetter
def writePDF(self, x, y_diff, info): """ """ if info[0] == True: if not os.path.exists(self.outputdir + '/' + self.stem + '/' + 'Iq'): # Create integrations folder os.makedirs(self.outputdir + '/' + self.stem + '/' + 'Iq') if info[1] == True: if not os.path.exists(self.outputdir + '/' + self.stem + '/' + 'Sq'): # Create integrations folder os.makedirs(self.outputdir + '/' + self.stem + '/' + 'Sq') if info[2] == True: if not os.path.exists(self.outputdir + '/' + self.stem + '/' + 'Fq'): # Create integrations folder os.makedirs(self.outputdir + '/' + self.stem + '/' + 'Fq') if info[3] == True: if not os.path.exists(self.outputdir + '/' + self.stem + '/' + 'Gr'): # Create integrations folder os.makedirs(self.outputdir + '/' + self.stem + '/' + 'Gr') head_name = ['# Qmax = {}'.format(self.cfg.qmax)] head_vals = [''] header = np.column_stack((head_name, head_vals)) pg = PDFGetter(config=self.cfg) print('\nWritting specified files:') for i in tqdm(range(len(y_diff))): data_gr = pg(x, y_diff[i]) if info[0] == True: saving_dat = np.column_stack((pg.iq[0], pg.iq[1])) saveThis = (np.vstack( ((header).astype(str), (saving_dat).astype(str)))) np.savetxt(self.outputdir + '/' + self.stem + '/' + 'Iq/{}_{:05d}.iq'.format(self.stem, i), saveThis, fmt='%s') if info[1] == True: saving_dat = np.column_stack((pg.sq[0], pg.sq[1])) saveThis = (np.vstack( ((header).astype(str), (saving_dat).astype(str)))) np.savetxt(self.outputdir + '/' + self.stem + '/' + 'Sq/{}_{:05d}.sq'.format(self.stem, i), saveThis, fmt='%s') if info[2] == True: saving_dat = np.column_stack((pg.fq[0], pg.fq[1])) saveThis = (np.vstack( ((header).astype(str), (saving_dat).astype(str)))) np.savetxt(self.outputdir + '/' + self.stem + '/' + 'Fq/{}_{:05d}.fq'.format(self.stem, i), saveThis, fmt='%s') if info[3] == True: saving_dat = np.column_stack((pg.gr[0], pg.gr[1])) saveThis = (np.vstack( ((header).astype(str), (saving_dat).astype(str)))) np.savetxt(self.outputdir + '/' + self.stem + '/' + 'Gr/{}_{:05d}.gr'.format(self.stem, i), saveThis, fmt='%s') return None
def extract(data, x0, pdfgetter=None, rlim=None, out_file=None, options=None): """ Extract the intermolecular signal data between molecule a and molecule b in their mixture from the PDF of mixture and single phase molecule a and molecule b. The intermolecular signal data is extracted by subtracting a linear combination of the PDFs of molecule a and molecule b from the PDF of mixture. G_inter(r) = G_ab(r) - [x_a * G_a(r) + x_b * G_b(r)] The coefficient in the linear combination is determined by minimizing the two-norm of G_inter data array after it is sliced according to rlim, which means the minimization is done to the PDF in range limited by rlim. The result will be plotted in two graphs, one graph of mixture PDF and linear combination result and their difference, the other graph of individual difference curve. Result of intermolecular signal will be save into a txt file if out_file is not None. :param data: (Tuple[Tuple[array, array], Tuple[array, array], Tuple[array, array]]) r array and g array pairs of mol a + b, mol a and mol b (order matters). :param pdfgetter: (PDFGetter) a pdfgetter to process the data. If None, there will be no process to data. Default None. :param x0: (Tuple[float, float]) Initial guess of the proportional of PDF of molecule a. Default (0.5, 0.5). :param rlim: (Tuple[float, float]) lower and higher limit of the range of r for least square. If None, the whole range of data will be used. Unit A. Default None. :param out_file: (str) path to the output file of extracted intermolecular signal. If None, the intermolecular signal data won't be saved to files. Default None. :param options: (dict) keyword arguments passed to scipy.optimize.least_square to change the options of regression. If None, the default setting of least square will be used except the bounds is set to (0, inf). Default None. :return: (Tuple[numpy.array, numpy.array, numpy.array numpy.array]) array of r values, array of data G values, array of calculated G values, array of intermolecular signal. """ # if no pdfgetter, create one pdfgetter that does nothing. if pdfgetter is None: from diffpy.pdfgetx import PDFGetter pdfgetter = PDFGetter() pdfgetter.transformations = [] # process data and record results in two list rs = [] # rs: a list of numpy array of r value gs = [] # gs: a list of numpy array of g value from diffpy.pdfgetx import loaddata for x, y in data: r, g = pdfgetter(x, y) rs.append(r) gs.append(g) # window the data in place if rlim is not None: sliced_gs = [] sliced_rs = [] for r, g in zip(rs, gs): msk = np.logical_and(r >= rlim[0], r <= rlim[1]) sliced_r = r[msk] sliced_g = g[msk] sliced_gs.append(sliced_g) sliced_rs.append(sliced_r) else: sliced_gs = gs sliced_rs = rs target = sliced_gs[0] component = np.array(sliced_gs[1:]) # get coefficient using least square def residual(x: np.array): return target - np.dot(x, component) if options is None: options = {} res = least_squares(residual, x0, bounds=(0., np.inf), **options) x_opt = res.x # optimized x value print(f"optimized x: {x_opt}") # calculate intermolecular PDF r = sliced_rs[0] g_data = sliced_gs[0] g_calc = np.dot(x_opt, sliced_gs[1:]) g_inter = g_data - g_calc # save data to file if out_file is not None: header = f"optimized x: {x_opt}\n" + \ f"rlim: {rlim}" + \ "r g" np.savetxt(out_file, np.column_stack([r, g_data, g_calc, g_inter]), fmt="%.8f", header=header) return r, g_data, g_calc, g_inter
def process( *, raw_img: np.ndarray, ai: tp.Union[None, AzimuthalIntegrator], user_mask: np.ndarray = None, auto_mask: bool = True, dk_img: np.ndarray = None, integ_setting: dict = None, mask_setting: dict = None, pdfgetx_setting: dict = None, ) -> dict: """The function to process the data from event.""" # initialize the data dictionary data = { "dk_sub_image": raw_img, "mask": np.zeros_like(raw_img), "chi_Q": np.array([0.]), "chi_I": np.array([0.]), "chi_max": np.float(0.), "chi_argmax": np.float(0.), "iq_Q": np.array([0.]), "iq_I": np.array([0.]), "sq_Q": np.array([0.]), "sq_S": np.array([0.]), "fq_Q": np.array([0.]), "fq_F": np.array([0.]), "gr_r": np.array([0.]), "gr_G": np.array([0.]), "gr_max": np.float(0.), "gr_argmax": np.float(0.) } # dark subtraction if dk_img is not None: data["dk_sub_image"] = np.subtract(raw_img, dk_img) # if no calibration, output data now if ai is None: return data # do auto masking if specified if auto_mask: data["mask"], _ = integ.auto_mask(data["dk_sub_image"], ai, mask_setting=mask_setting, user_mask=user_mask) elif user_mask is not None: data["mask"] = user_mask # integration x, y = ai.integrate1d(data["dk_sub_image"], mask=data["mask"], **integ_setting) chi_max_ind = np.argmax(y) data.update({ "chi_Q": x, "chi_I": y, "chi_max": y[chi_max_ind], "chi_argmax": x[chi_max_ind] }) # transformation if not _PDFGETX_AVAILABLE: io.server_message( "diffpy.pdfgetx is not installed. No use [0.] for all the relevant data." ) return data pdfconfig = PDFConfig(**pdfgetx_setting) pdfgetter = PDFGetter(pdfconfig) pdfgetter(x, y) iq, sq, fq, gr = pdfgetter.iq, pdfgetter.sq, pdfgetter.fq, pdfgetter.gr gr_max_ind = np.argmax(gr[1]) data.update({ "iq_Q": iq[0], "iq_I": iq[1], "sq_Q": sq[0], "sq_S": sq[1], "fq_Q": fq[0], "fq_F": fq[1], "gr_r": gr[0], "gr_G": gr[1], "gr_max": gr[1][gr_max_ind], "gr_argmax": gr[0][gr_max_ind] }) return data
def process( *, user_config: UserConfig, raw_img: np.ndarray, ai: tp.Union[None, AzimuthalIntegrator], dk_img: np.ndarray = None, dk_sub_bg_img: np.ndarray = None, integ_setting: dict = None, mask_setting: dict = None, pdfgetx_setting: dict = None, ) -> dict: """The function to process the data from event.""" # initialize the data dictionary data = { "dk_sub_image": raw_img.copy(), "bg_sub_image": raw_img.copy(), "mask": np.zeros_like(raw_img), "chi_Q": np.array([0.]), "chi_I": np.array([0.]), "chi_max": 0., "chi_argmax": 0., "iq_Q": np.array([0.]), "iq_I": np.array([0.]), "sq_Q": np.array([0.]), "sq_S": np.array([0.]), "fq_Q": np.array([0.]), "fq_F": np.array([0.]), "gr_r": np.array([0.]), "gr_G": np.array([0.]), "gr_max": 0., "gr_argmax": 0. } # dark subtraction if dk_img is not None: data["dk_sub_image"] = np.subtract(raw_img, dk_img) # background subtraction if dk_sub_bg_img is not None: data["bg_sub_image"] = np.subtract(data["dk_sub_image"], dk_sub_bg_img) # if no calibration, output data now if ai is None: return data # do auto masking if specified if user_config.do_auto_masking: data["mask"], _ = integ.auto_mask(data["bg_sub_image"], ai, mask_setting=mask_setting, user_mask=user_config.user_mask) # if user gives a mask, use it elif user_config.user_mask is not None: data["mask"] = user_config.user_mask.copy() # integration x, y = ai.integrate1d(data["bg_sub_image"], mask=data["mask"], **integ_setting) chi_max_ind = np.argmax(y) data.update({ "chi_Q": x, "chi_I": y, "chi_max": y[chi_max_ind], "chi_argmax": x[chi_max_ind] }) # transformation pdfconfig = PDFConfig(dataformat="QA", **pdfgetx_setting) pdfgetter = PDFGetter(pdfconfig) pdfgetter(x, y) iq, sq, fq, gr = pdfgetter.iq, pdfgetter.sq, pdfgetter.fq, pdfgetter.gr gr_max_ind = np.argmax(gr[1]) data.update({ "iq_Q": iq[0], "iq_I": iq[1], "sq_Q": sq[0], "sq_S": sq[1], "fq_Q": fq[0], "fq_F": fq[1], "gr_r": gr[0], "gr_G": gr[1], "gr_max": gr[1][gr_max_ind], "gr_argmax": gr[0][gr_max_ind] }) return data
def run_pipe(tiff_file: str, saving_dir: str = ".", poni_file: str = None, pdfgetter: PDFGetter = None, refine_func: Callable = None) -> dict: """ A pipeline process to integrate, transform and fit the data and return a dictionary of path to the resulting files. Parameters ---------- tiff_file Path to the tiff file. saving_dir Path to the directory where the output data files will be saved. Default "." poni_file Path to the poni file. If None, the poni file in the saving_dir will be used. pdfgetter A PDFgetter to transform the chi file to gr file. If None, a default one will be created, see make_default_pdfgetter. Default None refine_func A function func(gr_file: str) to refine the G(r) of Ni. If None, a default refine function will be used, see refine. Default None Returns ------- res_dct a dictionary that contains keys: "poni", "chi", "gr", "Rw", "csv", "fgr". """ def find_poni(dir_to_search): files_found = recfind(dir_to_search, r".*\.poni") if len(files_found) < 1: raise Exception(f"Not found poni file in {dir_to_search}") elif len(files_found) > 1: _poni_file = files_found[0] print(f"Multiple file found in {dir_to_search}.\nUse {_poni_file}") else: _poni_file = files_found[0] return _poni_file poni_file = poni_file if poni_file else find_poni(saving_dir) wl = load(poni_file)["Wavelength"] * 1e10 # unit A result = dict(poni=poni_file, wl=wl) print(f"Run pipeline with wavelength: {wl:.4f} and poni file: {poni_file}") result["chi"], _ = xpdtools_int(poni_file, tiff_file, chi_dir=saving_dir, alpha=2.0) pdfgetter = pdfgetter if pdfgetter else make_default_pdfgetter() chi_q, chi_i = loaddata(result["chi"]).T pdfgetter(chi_q, chi_i) result["gr"] = os.path.splitext(result["chi"])[0] + ".gr" pdfgetter.writeOutput(result["gr"], "gr") if refine_func: pass else: refine_func = default_refine result["Rw"], result["csv"], result["fgr"] = refine_func( result["gr"], saving_dir) return result
from pyobjcryst.molecule import Molecule from pdfstream.io import load_img, load_data NI_PONI = resource_filename('tests', 'test_data/Ni_poni_file.poni') NI_GR = resource_filename('tests', 'test_data/Ni_gr_file.gr') NI_CHI = resource_filename('tests', 'test_data/Ni_chi_file.chi') NI_FGR = resource_filename('tests', 'test_data/Ni_fgr_file.fgr') NI_IMG = resource_filename('tests', 'test_data/Ni_img_file.tiff') NI_CIF = resource_filename('tests', 'test_data/Ni_cif_file.cif') KAPTON_IMG = resource_filename('tests', 'test_data/Kapton_img_file.tiff') BLACK_IMG = resource_filename('tests', 'test_data/black_img.tiff') WHITE_IMG = resource_filename('tests', 'test_data/white_img.tiff') NI_CONFIG = PDFConfig() NI_CONFIG.readConfig(NI_GR) NI_PDFGETTER = PDFGetter(NI_CONFIG) ZRP_CIF = resource_filename('tests', 'test_data/ZrP.cif') NI_CRYSTAL = loadCrystal(NI_CIF) ZRP_CRYSTAL = loadCrystal(ZRP_CIF) NI_DIFFPY = loadStructure(NI_CIF) DB = { 'Ni_img_file': NI_IMG, 'Ni_img': load_img(NI_IMG), 'Kapton_img_file': KAPTON_IMG, 'Kapton_img': load_img(KAPTON_IMG), 'Ni_poni_file': NI_PONI, 'Ni_gr_file': NI_GR, 'Ni_chi_file': NI_CHI, 'Ni_fgr_file': NI_FGR, 'ai': pyFAI.load(NI_PONI),
def run(args): FILE = args.INPUT FILE_NO_EXTENSION = FILE[:-6] SAVE_PATH = os.getcwd() print(SAVE_PATH) if args.OUTPUT: SAVE_PATH = args.OUTPUT else: print( '!!! Warning files will be saved in the current folder because no output was defined.' ) REFERENCE_SLICE_NUMBER = 100 ### Collecting data informations ### try: inputFile = h5py.File(FILE, 'r') print("File " + FILE + " loaded") except ValueError: raise ### Creating matrix from data ### rawData = np.array(inputFile['data/data']) rawTheta = np.array(inputFile['data/theta']) dataX = np.ndarray.flatten(np.array(inputFile['data/dataX'])) theta = np.sort(rawTheta) sinogramData = np.zeros(np.shape(rawData)) ### Corrections ### #Correcting unsorted 2theta acquisition argsortVal = np.argsort(rawTheta) if not np.array_equal(theta, rawTheta): sorting = 0 while sorting < np.max(argsortVal) - 1: sinogramData[sorting, :, :] = rawData[argsortVal[sorting], :, :] progression("Sorting data................ ", np.size(argsortVal) - 2, sorting) sorting = sorting + 1 print() ##Deleting lines if args.DELETE: deleted_line = np.fromstring(args.DELETE, dtype=int, sep=',') for i in range(0, len(deleted_line)): sinogramData = np.delete(sinogramData, deleted_line[i], axis=0) theta = np.delete(theta, deleted_line[i], axis=0) progression("Deleting lines.............. ", len(deleted_line), i) print() ### Removing outlier pixels from data ### if args.OUTLIERS: for i in range(0, np.size(sinogramData, 2)): sinogramData[:, :, i] = findOutlierPixels(sinogramData[:, :, i], tolerance=10, worry_about_edges=False) progression("Correcting wrong pixels..... ", np.size(sinogramData, 2), i) print() ### Subtract air from raw data ### if args.AIR: dataAir = np.genfromtxt(args.AIR, dtype=float) FILE_NO_EXTENSION = FILE_NO_EXTENSION + '_SUBAIR' for i in range(0, np.size(sinogramData, 0)): currentAir = dataAir[:, 1] * ( 0.85 * np.average(sinogramData[i, :, 50]) / dataAir[50, 1]) for j in range(0, np.size(sinogramData, 1)): sinogramData[i, j, :] = sinogramData[i, j, :] - currentAir progression("Substacting air............. ", np.size(sinogramData, 0), i) print() ### Correcting thermal/beam drifts ### if args.CORRECT: thresholdedSinogramData = np.copy(sinogramData[:, :, REFERENCE_SLICE_NUMBER]) thresholdedSinogramData[sinogramData[:, :, REFERENCE_SLICE_NUMBER] < 40] = 0 thresholdedSinogramData[sinogramData[:, :, REFERENCE_SLICE_NUMBER] >= 40] = 1 thresholdedSinogramData = binary_fill_holes(thresholdedSinogramData) thresholdedSinogramData = imageFilterBigPart(thresholdedSinogramData) CoMThresh = centerOfMass(thresholdedSinogramData * sinogramData[:, :, REFERENCE_SLICE_NUMBER], axis=1) for i in range(0, np.size(sinogramData, 2)): sinogramData[:, :, i] = fixDrift(sinogramData[:, :, i], CoMThresh) progression("Correcting drifts........... ", np.size(sinogramData, 2), i) print() ### Subtract extra pattern from raw data ### if args.EXTRA: dataExtra = np.genfromtxt(args.EXTRA, dtype=float) FILE_NO_EXTENSION = FILE_NO_EXTENSION + '_SUBPAP' for i in range(0, np.size(sinogramData, 0)): for j in range(0, np.size(sinogramData, 1)): currentExtra = dataExtra[:, 1] * (sinogramData[i, j, 100] / dataExtra[100, 1]) sinogramData[i, j, :] = sinogramData[i, j, :] - currentExtra progression("Substacting extra........... ", np.size(sinogramData, 0), i) print() ### Extract PDF signal ### sinogramDataPdf = np.copy(sinogramData) if args.PDF: cfg = PDFConfig() cfg.readConfig(args.PDF) pdfget = PDFGetter() pdfget.configure(cfg) sinogramDataPdf = np.zeros( (np.size(sinogramData, 0), np.size(sinogramData, 1), round((cfg.rmax - cfg.rmin) / cfg.rstep) + 1)) for i in range(0, np.size(sinogramDataPdf, 0)): for j in range(0, np.size(sinogramDataPdf, 1)): currentPdfDataY = sinogramData[i, j, :] pdfget.getTransformation('gr') pdfget(dataX, currentPdfDataY) pdfResults = pdfget.results pdfResults = pdfResults[8] sinogramDataPdf[i, j, :] = pdfResults[1] progression("Extracting PDF.............. ", np.size(sinogramDataPdf, 0), i) for i in range(0, np.size(sinogramDataPdf, 2)): sinogramDataPdf[:, :, i] = np.average(sinogramData[:, :, :], axis=2) * np.copy( sinogramDataPdf[:, :, i]) sinogramData = np.copy(sinogramDataPdf) FILE_NO_EXTENSION = FILE_NO_EXTENSION + '_PDF' print() ### Saving ### if (args.OVERWRITE == True or os.path.isfile(FILE_NO_EXTENSION + '_corrected.h5') == False): saveHdf5File(sinogramData, SAVE_PATH, FILE_NO_EXTENSION + '_corrected.h5', mode='stack') else: print( '!!! Warning sinogram file exists, use command -R to overwrite it') ### Reconstruction ### if args.RECONSTRUCT: reconstructedData = np.zeros( (np.size(sinogramData, 1), np.size(sinogramData, 1), np.size(sinogramData, 2))) for i in range(0, np.size(sinogramData, 2)): reconstructedData[:, :, i] = reconstruction(sinogramData[:, :, i], theta, output_size=np.size( sinogramData, 1)) progression("Reconstructing data......... ", np.size(sinogramData, 2), i) print() if args.OVERWRITE and args.RECONSTRUCT: saveHdf5File(reconstructedData, SAVE_PATH, FILE_NO_EXTENSION + '_reconstructed_stack.h5', mode='stack') else: print( '!!! Warning reconstruction file exists, use command -R to overwrite it' )