Utility API

These selected standalone functions are useful for file loading and understanding traversal geometry. For routine loading, prefer fourdenoise.HyperData; it carries calibration and metadata.

fourdenoise.read_4D(fname, dp_dims=(128, 130), trim_dims=(128, 128), trim_meta=None, clip=False, hdf5_dataset=None, repair_nans=False, raw_shape=None, raw_dtype=<class 'numpy.float32'>, raw_order='C', mat_variable=None)[source]

Read array data from a .raw, .mat, .npy, .h5, .hdf5, or .hdf file.

Function written by Chuqiao Shi (2022) See on GitHub: Chuqiao2333/Hierarchical_Clustering

Modified by Adan J Mireles (April, 2024) - Addition of ‘dp_dims’, ‘trim_dims’, and ‘trim_meta’ - Modified ‘print’ statement

Parameters:
  • fname (str or pathlib.Path) – Path to the input file.

  • hdf5_dataset (str or pathlib.Path or None, optional) – HDF5 dataset path to load. Generic HDF5 files containing exactly one numeric multidimensional dataset are selected automatically. This argument is required when a file contains multiple candidates.

  • mat_variable (str or pathlib.Path or None, optional) – Name of a numeric array in a MATLAB .mat file. For MATLAB v7.3 (HDF5) files, a nested dataset path is also accepted. When omitted, the only numeric array with at least two dimensions is selected; multiple candidates require an explicit choice.

  • raw_shape (tuple of 2 to 4 ints or None, optional) – Full shape stored in a raw file, in array axis order. For 4D-STEM, specify (Ry, Rx, Ky, Kx). If omitted, the legacy EMPAD layout uses dp_dims and requires a square scan grid.

  • raw_dtype (numpy dtype, optional) – Stored raw scalar type, including byte order (for example '>u2'). Defaults to float32. Used only for .raw files.

  • raw_order ({'C', 'F'}, optional) – Storage order of raw values. Defaults to NumPy row-major order.

  • trim_meta (bool or None, optional) – Crop the raw detector axes to trim_dims. None keeps the historical crop for inferred EMPAD layouts and disables it for explicit raw_shape, so an explicit shape is loaded without hidden trimming.

  • clip (bool, optional) – Replace values below 1 with 1. Disabled by default to preserve raw detector counts, including zeros and negative values.

  • repair_nans (bool, optional) – Replace patterns containing NaNs with neighbor averages (or replace NaNs with zero for 2D images). Disabled by default.

  • Return – dp : numpy array

  • 2024) (Function modified by Adan Mireles to make '.mat' file reading more general (July)

fourdenoise.plot_traversals(method='all', grid_shape=(64, 64), *, ncols=3, cmap='turbo', linewidth=1.5, show_grid=True, mark_endpoints=True, show=True)[source]

Plot one or all implemented 2D unfolding traversal paths.

grid_shape is the maximum requested grid, not a promise that every method uses every cell. Full-shape methods traverse it entirely. Curve and block methods traverse their largest compatible centered crop within it; shaded cells are excluded. Each title shows both the used and maximum grid shapes. This visualizer does not resize data or require a HyperData.

Parameters:
  • method (str, optional) – An implemented traversal name or 'all'. The latter plots the ten implemented canonical methods in registry order. 'z_order' and 'meander_4'/'meander_5' are accepted aliases for single plots. 'moore' is not yet implemented; 'coordinate_aligned' is an axis rearrangement rather than a 2D traversal.

  • grid_shape (int or tuple[int, int], optional) – Maximum grid height and width, in (y, x) order. An integer requests a square. Compatible curves may use only a centered part of this grid.

  • ncols (int, optional) – Maximum number of subplot columns. A single method uses one column.

  • cmap (str or Colormap, optional) – Matplotlib colormap for the path’s normalized start-to-end progress.

  • linewidth (float, optional) – Width of the colored traversal line in points.

  • show_grid (bool, optional) – Draw cell boundaries and colored start/end markers, respectively.

  • mark_endpoints (bool, optional) – Draw cell boundaries and colored start/end markers, respectively.

  • show (bool, optional) – Display the figure with matplotlib.pyplot.show when True.

Returns:

Matplotlib figure and a 2D array of axes. Unused axes in 'all' mode are hidden. A block method that cannot fit inside grid_shape gets an explanatory panel in 'all' mode; a single-method request raises the underlying size error.

Return type:

tuple[Figure, ndarray]

Examples

>>> fig, axes = plot_traversals('all', (64, 64), ncols=3)
>>> fig, axes = plot_traversals('peano', 81, linewidth=2, show=False)