NRSS.checkH5#

NRSS.checkH5.checkH5(filename='perp82.hd5', z_slice=0, subsample=None, outputmat=None, runquiet=False, plotstyle='light')#

Reads in morphology HDF5 file and checks that the format is consistent for CyRSoXS. Optionally plots and returns select quantities.

Parameters:
  • filename (str or path) – Name of HDF5 morphology file to check

  • z_slice (int) – Which z-slice of the array to plot.

  • subsample (int) – Number of voxels to display in X and Y

  • outputmat (int) – Number of which material to return

  • runquiet (bool) – Boolean flag for running without plotting or outputting to console

  • plotstyle (str) – Use a light or dark background for plots. ‘dark’ - dark, ‘light’ - light

Returns:

  • Vfrac (ndarray) – Volume fraction of selected material. [ Z, Y, X]

  • S (ndarray) – Fraction of alignment for selected material. [Z, Y, X]

  • theta (ndarray) – Second Euler angle (ZYZ convention). [Z, Y, X]

  • psi (ndarray) – Third Euler angle (ZYZ convention). [Z, Y, X]

NRSS.checkH5.check_NumMat(f, morphology_type)#

Checks and validates the number of materials in the HDF5 file

Parameters:
  • f (file object) –

  • morphology_type (int) – 0 - Euler, 1 - Vector

Returns:

num_mat – Number of materials in file

Return type:

int

NRSS.checkH5.inset_axes(parent_axes, width, height, loc='upper right', bbox_to_anchor=None, bbox_transform=None, axes_class=None, axes_kwargs=None, borderpad=0.5)#

Create an inset axes with a given width and height.

Both sizes used can be specified either in inches or percentage. For example,:

inset_axes(parent_axes, width='40%', height='30%', loc='lower left')

creates in inset axes in the lower left corner of parent_axes which spans over 30% in height and 40% in width of the parent_axes. Since the usage of .inset_axes may become slightly tricky when exceeding such standard cases, it is recommended to read the examples.

Notes

The meaning of bbox_to_anchor and bbox_to_transform is interpreted differently from that of legend. The value of bbox_to_anchor (or the return value of its get_points method; the default is parent_axes.bbox) is transformed by the bbox_transform (the default is Identity transform) and then interpreted as points in the pixel coordinate (which is dpi dependent).

Thus, following three calls are identical and creates an inset axes with respect to the parent_axes:

axins = inset_axes(parent_axes, "30%", "40%")
axins = inset_axes(parent_axes, "30%", "40%",
                   bbox_to_anchor=parent_axes.bbox)
axins = inset_axes(parent_axes, "30%", "40%",
                   bbox_to_anchor=(0, 0, 1, 1),
                   bbox_transform=parent_axes.transAxes)
Parameters:
  • parent_axes (matplotlib.axes.Axes) – Axes to place the inset axes.

  • width (float or str) – Size of the inset axes to create. If a float is provided, it is the size in inches, e.g. width=1.3. If a string is provided, it is the size in relative units, e.g. width=’40%’. By default, i.e. if neither bbox_to_anchor nor bbox_transform are specified, those are relative to the parent_axes. Otherwise, they are to be understood relative to the bounding box provided via bbox_to_anchor.

  • height (float or str) – Size of the inset axes to create. If a float is provided, it is the size in inches, e.g. width=1.3. If a string is provided, it is the size in relative units, e.g. width=’40%’. By default, i.e. if neither bbox_to_anchor nor bbox_transform are specified, those are relative to the parent_axes. Otherwise, they are to be understood relative to the bounding box provided via bbox_to_anchor.

  • loc (str, default: 'upper right') – Location to place the inset axes. Valid locations are ‘upper left’, ‘upper center’, ‘upper right’, ‘center left’, ‘center’, ‘center right’, ‘lower left’, ‘lower center’, ‘lower right’. For backward compatibility, numeric values are accepted as well. See the parameter loc of .Legend for details.

  • bbox_to_anchor (tuple or ~matplotlib.transforms.BboxBase, optional) – Bbox that the inset axes will be anchored to. If None, a tuple of (0, 0, 1, 1) is used if bbox_transform is set to parent_axes.transAxes or parent_axes.figure.transFigure. Otherwise, parent_axes.bbox is used. If a tuple, can be either [left, bottom, width, height], or [left, bottom]. If the kwargs width and/or height are specified in relative units, the 2-tuple [left, bottom] cannot be used. Note that, unless bbox_transform is set, the units of the bounding box are interpreted in the pixel coordinate. When using bbox_to_anchor with tuple, it almost always makes sense to also specify a bbox_transform. This might often be the axes transform parent_axes.transAxes.

  • bbox_transform (~matplotlib.transforms.Transform, optional) – Transformation for the bbox that contains the inset axes. If None, a .transforms.IdentityTransform is used. The value of bbox_to_anchor (or the return value of its get_points method) is transformed by the bbox_transform and then interpreted as points in the pixel coordinate (which is dpi dependent). You may provide bbox_to_anchor in some normalized coordinate, and give an appropriate transform (e.g., parent_axes.transAxes).

  • axes_class (~matplotlib.axes.Axes type, default: .HostAxes) – The type of the newly created inset axes.

  • axes_kwargs (dict, optional) –

    Keyword arguments to pass to the constructor of the inset axes. Valid arguments include:

    Properties: adjustable: {‘box’, ‘datalim’} agg_filter: a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image alpha: scalar or None anchor: (float, float) or {‘C’, ‘SW’, ‘S’, ‘SE’, ‘E’, ‘NE’, …} animated: bool aspect: {‘auto’, ‘equal’} or float autoscale_on: bool autoscalex_on: unknown autoscaley_on: unknown axes_locator: Callable[[Axes, Renderer], Bbox] axisbelow: bool or ‘line’ box_aspect: float or None clip_box: ~matplotlib.transforms.BboxBase or None clip_on: bool clip_path: Patch or (Path, Transform) or None facecolor or fc: color figure: ~matplotlib.figure.Figure frame_on: bool gid: str in_layout: bool label: object mouseover: bool navigate: bool navigate_mode: unknown path_effects: list of .AbstractPathEffect picker: None or bool or float or callable position: [left, bottom, width, height] or ~matplotlib.transforms.Bbox prop_cycle: ~cycler.Cycler rasterization_zorder: float or None rasterized: bool sketch_params: (scale: float, length: float, randomness: float) snap: bool or None subplotspec: unknown title: str transform: ~matplotlib.transforms.Transform url: str visible: bool xbound: (lower: float, upper: float) xlabel: str xlim: (left: float, right: float) xmargin: float greater than -0.5 xscale: unknown xticklabels: unknown xticks: unknown ybound: (lower: float, upper: float) ylabel: str ylim: (bottom: float, top: float) ymargin: float greater than -0.5 yscale: unknown yticklabels: unknown yticks: unknown zorder: float

  • borderpad (float, default: 0.5) – Padding between inset axes and the bbox_to_anchor. The units are axes font size, i.e. for a default font size of 10 points borderpad = 0.5 is equivalent to a padding of 5 points.

Returns:

inset_axes – Inset axes object created.

Return type:

axes_class

NRSS.checkH5.rc(group, **kwargs)#

Set the current .rcParams. group is the grouping for the rc, e.g., for lines.linewidth the group is lines, for axes.facecolor, the group is axes, and so on. Group may also be a list or tuple of group names, e.g., (xtick, ytick). kwargs is a dictionary attribute name/value pairs, e.g.,:

rc('lines', linewidth=2, color='r')

sets the current .rcParams and is equivalent to:

rcParams['lines.linewidth'] = 2
rcParams['lines.color'] = 'r'

The following aliases are available to save typing for interactive users:

Alias

Property

‘lw’

‘linewidth’

‘ls’

‘linestyle’

‘c’

‘color’

‘fc’

‘facecolor’

‘ec’

‘edgecolor’

‘mew’

‘markeredgewidth’

‘aa’

‘antialiased’

Thus you could abbreviate the above call as:

rc('lines', lw=2, c='r')

Note you can use python’s kwargs dictionary facility to store dictionaries of default parameters. e.g., you can customize the font rc as follows:

font = {'family' : 'monospace',
        'weight' : 'bold',
        'size'   : 'larger'}
rc('font', **font)  # pass in the font dict as kwargs

This enables you to easily switch between several configurations. Use matplotlib.style.use('default') or rcdefaults() to restore the default .rcParams after changes.

Notes

Similar functionality is available by using the normal dict interface, i.e. rcParams.update({"lines.linewidth": 2, ...}) (but rcParams.update does not support abbreviations or grouping).

NRSS.checkH5.readH5_euler(filename)#

Reads in Euler Morphology from HDF5 file. Checks that total material volume fractions sum to 1 for all voxels.

Parameters:

filename (str or path) –

Returns:

  • Vfrac (ndarray) – Volume fraction of all materials. [Material, Z, Y, X]

  • S (ndarray) – Fraction of alignment for each material. [Material, Z, Y, X]

  • theta (ndarray) – Second Euler angle (ZYZ convention). [Material, Z, Y, X]

  • psi (ndarray) – Third Euler angle (ZYZ convention). [Material, Z, Y, X]

NRSS.checkH5.readH5_vector(filename)#

Reads in Vector Morphology from HDF5 file and converts to Euler Morphology. Checks that total material volume fractions sum to 1 for all voxels.

Parameters:

filename (str or path) –

Returns:

  • Vfrac (ndarray) – Volume fraction of all materials. [Material, Z, Y, X]

  • S (ndarray) – Fraction of alignment for each material. [Material, Z, Y, X]

  • theta (ndarray) – Second Euler angle (ZYZ convention). [Material, Z, Y, X]

  • psi (ndarray) – Third Euler angle (ZYZ convention). [Material, Z, Y, X]