Example #1
0
File: id9.py Project: mlevant/trx
def doFolder_dataRed(azavStorage,
                     funcForAveraging=np.nanmean,
                     outStorageFile='auto',
                     reference='min',
                     chi2_0_max='auto',
                     saveTxt=True,
                     first=None,
                     last=None):
    """ azavStorage if a DataStorage instance or the filename to read 
  """

    if isinstance(azavStorage, DataStorage):
        azav = azavStorage
        folder = azavStorage.folder
    elif os.path.isfile(azavStorage):
        folder = os.path.dirname(azavStorage)
        azav = DataStorage(azavStorage)
    else:
        # assume is just a folder name
        folder = azavStorage
        azavStorage = folder + "/pyfai_1d" + default_extension
        azav = DataStorage(azavStorage)

    if last is not None or first is not None:
        idx = slice(first, last)
        azav.log.delay = azav.log.delay[idx]
        azav.data_norm = azav.data_norm[idx]
        azav.err_norm = azav.err_norm[idx]

    # calculate differences
    tr = dataReduction.calcTimeResolvedSignal(
        azav.log.delay,
        azav.data_norm,
        err=azav.err_norm,
        q=azav.q,
        reference=reference,
        funcForAveraging=funcForAveraging,
        chi2_0_max=chi2_0_max)

    tr.folder = folder
    tr.twotheta_rad = azav.twotheta_rad
    tr.twotheta_deg = azav.twotheta_deg
    tr.info = azav.pyfai_info

    if outStorageFile == 'auto':
        if not os.path.isdir(folder): folder = "./"
        outStorageFile = folder + "/diffs" + default_extension
    tr.filename = outStorageFile

    # save txt and npz file
    if saveTxt: dataReduction.saveTxt(folder, tr, info=azav.pyfai_info)

    tr.save(outStorageFile)

    return tr
Example #2
0
def doFolder_dataRed(azavStorage,
                     funcForAveraging=np.nanmean,
                     outStorageFile='auto',
                     reference='min',
                     chi2_0_max='auto',
                     saveTxt=True,
                     first=None,
                     last=None,
                     idx=None,
                     split_angle=False):
    """ azavStorage if a DataStorage instance or the filename to read 
  """

    if isinstance(azavStorage, DataStorage):
        azav = azavStorage
        folder = azavStorage.folder
    elif os.path.isfile(azavStorage):
        folder = os.path.dirname(azavStorage)
        azav = DataStorage(azavStorage)
    else:
        # assume is just a folder name
        folder = azavStorage
        azavStorage = folder + "/pyfai_1d" + default_extension
        azav = DataStorage(azavStorage)

    if split_angle:
        angles = np.unique(azav.log.angle)
        diffs = []
        for angle in angles:
            idx = azav.log.angle == angle
            diffs.append(
                doFolder_dataRed(azav,
                                 funcForAveraging=funcForAveraging,
                                 outStorageFile=None,
                                 reference=reference,
                                 chi2_0_max=chi2_0_max,
                                 saveTxt=False,
                                 idx=idx,
                                 split_angle=False))
        ret = DataStorage(angles=angles, diffs=diffs)
        if outStorageFile == 'auto':
            if not os.path.isdir(folder): folder = "./"
            outStorageFile = folder + "/diffs" + default_extension
        if outStorageFile is not None:
            ret.save(outStorageFile)
        return ret

    azav = copy.deepcopy(azav)

    if last is not None or first is not None and idx is None:
        idx = slice(first, last)

    if idx is not None:
        azav.log.delay = azav.log.delay[idx]
        azav.data_norm = azav.data_norm[idx]
        azav.err_norm = azav.err_norm[idx]

    # laser off is saved as -10s, if using the automatic "min"
    # preventing from using the off images
    # use reference=-10 if this is what you want
    if reference == "min":
        reference = azav.log.delay[azav.log.delay != -10].min()

    # calculate differences
    tr = dataReduction.calcTimeResolvedSignal(
        azav.log.delay,
        azav.data_norm,
        err=azav.err_norm,
        q=azav.q,
        reference=reference,
        funcForAveraging=funcForAveraging,
        chi2_0_max=chi2_0_max)

    tr.folder = folder
    tr.twotheta_rad = azav.twotheta_rad
    tr.twotheta_deg = azav.twotheta_deg
    tr.info = azav.pyfai_info

    if outStorageFile == 'auto':
        if not os.path.isdir(folder): folder = "./"
        outStorageFile = folder + "/diffs" + default_extension
    tr.filename = outStorageFile

    # save txt and npz file
    if saveTxt: dataReduction.saveTxt(folder, tr, info=azav.pyfai_info)

    if outStorageFile is not None:
        tr.save(outStorageFile)

    return tr