Пример #1
0
def _transform(
    cfg_file: str,
    data_file: str,
    output_dir: str = ".",
    plot_setting: typing.Union[str, dict] = None,
    test: bool = False,
) -> typing.Dict[str, str]:
    """Transform the data."""
    pdfconfig = load_pdfconfig(cfg_file)
    chi = load_array(data_file)
    pdfgetter = get_pdf(pdfconfig, chi, plot_setting=plot_setting)
    filename = Path(data_file).stem
    dct = write_pdfgetter(output_dir, filename, pdfgetter)
    if not test:
        plt.show()
    return dct
Пример #2
0
# do not show any figures in test otherwise they will block the tests
plt.ioff()

NI_PONI_FILE = resource_filename('tests', 'test_data/Ni_poni_file.poni')
NI_GR_FILE = resource_filename('tests', 'test_data/Ni_gr_file.gr')
NI_CHI_FILE = resource_filename('tests', 'test_data/Ni_chi_file.chi')
NI_FGR_FILE = resource_filename('tests', 'test_data/Ni_fgr_file.fgr')
NI_IMG_FILE = resource_filename('tests', 'test_data/Ni_img_file.tiff')
MASK_FILE = resource_filename("tests", "test_data/mask_file.npy")
KAPTON_IMG_FILE = resource_filename('tests', 'test_data/Kapton_img_file.tiff')
BLACK_IMG_FILE = resource_filename('tests', 'test_data/black_img.tiff')
WHITE_IMG_FILE = resource_filename('tests', 'test_data/white_img.tiff')
NI_IMG = load_img(NI_IMG_FILE)
NI_FRAMES = numpy.expand_dims(NI_IMG, 0)
KAPTON_IMG = load_img(KAPTON_IMG_FILE)
NI_GR = load_array(NI_GR_FILE)
NI_CHI = load_array(NI_CHI_FILE)
NI_FGR = load_array(NI_FGR_FILE)
NI_CONFIG = PDFConfig()
NI_CONFIG.readConfig(NI_GR_FILE)
NI_PDFGETTER = PDFGetter(NI_CONFIG)
AI = pyFAI.load(NI_PONI_FILE)
MASK = numpy.load(MASK_FILE)
BLACK_IMG = load_img(BLACK_IMG_FILE)
WHITE_IMG = load_img(WHITE_IMG_FILE)
START_DOC_FILE = resource_filename('tests', 'test_data/start.json')
with Path(START_DOC_FILE).open("r") as f:
    START_DOC = json.load(f)

DB = {
    'Ni_img_file': NI_IMG_FILE,
Пример #3
0
def visualize(
    data_file: str, ax: Axes = None, mode: str = "line", normal: bool = False,
    text: str = None, text_xy: tuple = None, label: str = None,
    minor_tick: int = 2, legends: tp.List[str] = None, color: tp.Iterable = None,
    show_fig: bool = True, **kwargs
) -> Axes:
    """Visualize the data in a single data file.

    The data must be multi-columns matrix in a txt file. A header can be included in the file and it won't be
    read. The visualization has different modes for different kinds of plotting. Currently, it supports

    'line' mode
        The single curve of x and y data.

    'fit' mode
        One curve for data, one curve for the fit and a difference curve below it.

    Parameters
    ----------
    data_file : file path
        The file path. The file contains column data. The required format depends on the 'mode'.
        If mode = 'line', data = (x_array, y_array)
        If mode = 'fit', data = (x_array, y_array, ycalc_array)

    kwargs : optional
        The kwargs arguments for the plotting of each data. It depends on mode.
        If mode = 'line', kwargs in ('xy_kwargs',).
        If mode = 'fit', kwargs in ('xy_kwargs', 'xycalc_kwargs', 'xydiff_kwargs', 'xyzero_kwargs',
        'fill_kwargs', 'yzero').

    mode : str
        The plotting mode.

    ax : Axes
        The axes to visualize the data. If None, use current axes. (Not used for CLI)

    normal : bool
        If True, the second and the following rows in data will be normalized by (max - min). Else, do nothing.
        Defulat False.

    text : str
        The text to annotate the curve.

    text_xy : tuple
        The tuple of x and y position of the annotation in data coordinates. If None, use the default in the
        'tools.auto_text'.

    label : str
        The label type used in automatic labeling. Acceptable types are listed in 'tools._LABELS'

    minor_tick : int
        How many parts that the minor ticks separate the space between the two adjacent major ticks. Default 2.
        If None, no minor ticks.

    legends : list
        The legend label for the curve.

    color : an iterable of colors
        The color of the plots. If None, use default color cycle in rc.

    show_fig : bool
        If True, the figure will be pop out and shown. Else, stay in the cache.

    Returns
    -------
    ax : Axes
        The axes with the plot.
    """
    data = io.load_array(data_file)
    if label is None:
        label = PurePath(data_file).suffix.replace('.', '')
    ax = vis.visualize(
        data, ax=ax, mode=mode, normal=normal, text=text, text_xy=text_xy, label=label,
        minor_tick=minor_tick, legends=legends, color=color, **kwargs)
    if show_fig:
        plt.show()
    return ax
Пример #4
0
def waterfall(
    *data_files: str, ax: Axes = None, mode: str = "line", normal: bool = True,
    stack: bool = True, gap: float = 0, texts: tp.List[str] = None, text_xy: tuple = None,
    label: str = None, minor_tick: tp.Union[int, None] = 2, legends: tp.List[str] = None,
    colors: tp.Iterable = None, show_fig: bool = True, **kwargs
) -> Axes:
    """Visualize the data in multiple data files in a waterfall or comparison plot.

    The data must be multi-columns matrix in a txt file. A header can be included in the file and it won't be
    read. The plots will be stacked in a waterfall if stack = True or overlapping together if stack = False. The
    visualization has different modes for different kinds of plotting. Currently, it supports

    'line' mode
        Each dataset is a single curve of x and y data.

    'fit' mode
        Each dataset contains three curves, one curve for data, one curve for the fit and a difference curve
        below it.

    Parameters
    ----------
    data_files : a list of file paths
        The file paths. Each file contains column data. The required format depends on the 'mode'.
        If mode = 'line', data = (x_array, y_array)
        If mode = 'fit', data = (x_array, y_array, ycalc_array)

    kwargs : optional
        The kwargs arguments for the plotting of each data. It depends on mode.
        If mode = 'line', kwargs in ('xy_kwargs',).
        If mode = 'fit', kwargs in ('xy_kwargs', 'xycalc_kwargs', 'xydiff_kwargs', 'xyzero_kwargs',
        'fill_kwargs', 'yzero').

    mode : str
        The plotting mode. Currently support 'line', 'fit'.

    ax : Axes
        The axes to visualize the data. If None, use current axes. (Not used for CLI)

    normal : bool
        If True, the second and the following rows in data will be normalized by (max - min). Else, do nothing.

    stack : bool
        If True, the second and the third rows will be shifted so that there will be a gap between data (
        waterfall plot). Else, the data will be plotted without shifting (comparison plot).

    gap : float
        The gap between the adjacent curves. It is defined by the nearest points in vertical direction.

    texts : an iterable of str
        The texts to annotate the curves. It has the same order as the curves.

    text_xy : tuple
        The tuple of x and y position of the annotation in data coordinates. If None, use the default in the
        'tools.auto_text'.

    label : str
        The label type used in automatic labeling. Acceptable types are listed in 'tools._LABELS'. If None,
        the label will be guessed according to the suffix of the fist file in the list.

    minor_tick : int
        How many parts that the minor ticks separate the space between the two adjacent major ticks. Default 2.
        If None, no minor ticks.

    legends : a list of str
        The legend labels for the curves.

    colors : an iterable of colors
        The color of the plots. If None, use default color cycle in rc.

    show_fig : bool
        If True, the figure will be pop out and shown. Else, stay in the cache.

    Returns
    -------
    ax : Axes
        The axes with the plot.
    """
    if len(data_files) == 0:
        raise ValueError("No input file.")
    dataset = (io.load_array(_) for _ in data_files)
    if label is None:
        label = PurePath(data_files[0]).suffix.replace('.', '')
    ax = vis.waterfall(
        dataset, ax=ax, mode=mode, normal=normal, stack=stack, gap=gap, texts=texts, text_xy=text_xy,
        label=label, minor_tick=minor_tick, legends=legends, colors=colors, **kwargs
    )
    if show_fig:
        plt.show()
    return ax