Example #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
Example #2
0
    def start(self, doc):
        # Get the independent vars
        self.dim_names = [
            d[0][0] for d in doc.get("hints", {}).get("dimensions")
            if d[0][0] != "time"
        ]
        if "original_start_uid" not in doc:
            doc["original_start_uid"] = doc["uid"]
        if "original_start_time" not in doc:
            doc["original_start_time"] = doc["time"]

        # use the magic formatter to leave things behind
        self.start_template = render2(
            self._template,
            start=doc,
            human_timestamp=_timestampstr(doc["original_start_time"]),
            **doc,
            **self.kwargs,
        )
        return super().start(doc)
Example #3
0
    def start(self, doc):
        # Get the independent vars
        self.dim_names = [
            d[0][0]
            for d in doc.get("hints", {}).get("dimensions")
            if d[0][0] != "time"
        ]
        if "original_start_uid" not in doc:
            doc["original_start_uid"] = doc["uid"]
        if "original_start_time" not in doc:
            doc["original_start_time"] = doc["time"]

        # use the magic formatter to leave things behind
        self.start_template = render2(
            self._template,
            start=doc,
            human_timestamp=_timestampstr(doc["original_start_time"]),
            **doc,
            **self.kwargs,
        )
        return super().start(doc)
Example #4
0
def test_timestampstr():
    assert isinstance(_timestampstr(0), str)