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
示例#2
0
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]
    }
示例#3
0
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
示例#4
0
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
示例#5
0
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
示例#6
0
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
示例#7
0
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
示例#8
0
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),
示例#9
0
文件: tools.py 项目: eaculb/xpdAn
def fq_getter(*args, **kwargs):
    pg = PDFGetter()
    pg(*args, **kwargs)
    res = pg.fq
    return res[0], res[1], pg.config
示例#10
0
文件: tools.py 项目: eaculb/xpdAn
def pdf_getter(*args, **kwargs):
    pg = PDFGetter()
    res = pg(*args, **kwargs)
    return res[0], res[1], pg.config
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
示例#12
0
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
示例#13
0
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
示例#14
0
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
示例#15
0
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
示例#16
0
文件: core.py 项目: poautran/PyXRDCT
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'
        )