Пример #1
0
def _calibration(img, calibration, calib_ref_fp=None, **kwargs):
    """Engine for performing calibration on a image with geometry
    correction software. current backend is ``pyFAI``.

    Parameters
    ----------
    img : ndarray
        image will be used for calibration process.
    calibration : pyFAI.calibration.Calibration instance
        Calibration instance with wavelength, calibrant and
        detector configured.
    calib_ref_fp : str
        full file path to where the native pyFAI calibration information
        will be saved.
    kwargs:
        additional keyword argument for calibration. please refer to
        pyFAI documentation for all options.
    """
    from pyFAI.calibration import PeakPicker
    from pyFAI.gui.utils import update_fig

    print("{:=^20}".format("INFO: you are able to perform calibration, "
                           "please refer to pictorial guide here:\n"))
    print("{:^20}".format(
        "http://xpdacq.github.io/usb_Running.html#calib-manual\n"))
    # default params
    interactive = True
    # calibration
    c = calibration  # shorthand notation
    timestr = _timestampstr(time.time())
    c.gui = interactive
    # annoying pyFAI logic, you need valid fn to start calibration
    _is_tmp_dir = False
    if calib_ref_fp is None:
        _is_tmp_dir = True
        td = TemporaryDirectory()
        calib_ref_fp = os.path.join(td.name, "from_calib_func")
    basename, ext = os.path.splitext(calib_ref_fp)
    poni_fn = basename + ".npt"
    c.basename = basename
    c.pointfile = poni_fn
    c.peakPicker = PeakPicker(img,
                              reconst=True,
                              pointfile=c.pointfile,
                              calibrant=c.calibrant,
                              wavelength=c.wavelength,
                              **kwargs)
    c.peakPicker.gui(log=True, maximize=True, pick=True)
    update_fig(c.peakPicker.fig)
    c.gui_peakPicker()
    # TODO: open issue at pyFAI on this crazyness
    c.ai.setPyFAI(**c.geoRef.getPyFAI())
    c.ai.wavelength = c.geoRef.wavelength
    if _is_tmp_dir:
        td.cleanup()

    return c, timestr
Пример #2
0
def _calibration(img, calibration, calib_ref_fp, **kwargs):
    """engine for performing calibration on a image with geometry
    correction software. current backend is ``pyFAI``.

    Parameters
    ----------
    img : ndarray
        image will be used for calibration process.
    calibration : pyFAI.calibration.Calibration instance
        Calibration instance with wavelength, calibrant and
        detector configured.
    calib_ref_fp : str
        full file path to where the native pyFAI calibration information
        will be saved.
    kwargs:
        additional keyword argument for calibration. please refer to
        pyFAI documentation for all options.
    """
    print('{:=^20}'.format("INFO: you are able to perform calibration, "
                           "please refer to pictorial guide here:\n"))
    print('{:^20}'
          .format("http://xpdacq.github.io/usb_Running.html#calib-manual\n"))
    # default params
    interactive = True
    # calibration
    c = calibration  # shorthand notation
    timestr = _timestampstr(time.time())
    c.gui = interactive
    # annoying pyFAI logic, you need valid fn to start calibration
    # TODO: send to tmp folder then delete tmp folder
    if calib_ref_fp is None:
        calib_ref_fp = os.path.join(os.getcwd(), 'from_calib_func')
    basename, ext = os.path.splitext(calib_ref_fp)
    poni_fn = basename + ".npt"
    c.basename = basename
    c.pointfile = poni_fn
    c.peakPicker = PeakPicker(img, reconst=True,
                              pointfile=c.pointfile,
                              calibrant=c.calibrant,
                              wavelength=c.wavelength,
                              **kwargs)
    c.peakPicker.gui(log=True, maximize=True, pick=True)
    update_fig(c.peakPicker.fig)
    c.gui_peakPicker()

    return c, timestr