X-ray Imager Position and Energy Visualizations

Plot observations from an x-ray imager.

class x_ray_imager_bagriff.position_estimation.plot.ImagerAxes

Axes with specific plotting functions for x-ray imagers.

energy_spectrum(energy, bins=None, d_energy=None, duration=None)

Plot an energy spectrum histogram.

Parameters:
  • energy (ArrayLike) – Observation energies to bin into the historgram. Expected to be in keV.

  • bins (ArrayLike | None) – Energy edges for histogram bins Default if not provided spans from 10 keV to 600 keV.

  • d_energy (ArrayLike | None) – Uncertainty for energy. Must have the same shape.

  • duration (float | None) – Total time for collecting these measurements. If provided the y-axis will be time normalized.

Return type:

BarContainer | Polygon | list[BarContainer | Polygon] | list[Line2D]

image_hist(x, y, bins=None, image_max=None, d_x=None, d_y=None, duration=None)

Create a 2D histogram of observed x-ray positions.

The shapes of x and y should match. If provided, d_x and d_y should also have that shape.

Parameters:
  • x (ArrayLike) – Observation array x-coordinate.

  • y (ArrayLike) – Observation array y-coordinate.

  • image_max (float | None) – Maximum value for image colormap.

  • bins (ArrayLike | None) – Position bin edges used for both x and y coordinates. Also sets the axis limits. If not provided, defaults to -70 mm to +70 mm in 2.5 mm bins. If d_x and d_y are provided, use a higher resolution.

  • d_x (ArrayLike | None) – Uncertainty in the x-coordinate.

  • d_y (ArrayLike | None) – Uncertainty in the y-coordinate.

  • duration (float | None) – Duration of the measurement. It is not used because intensity is given as in x-rays/bin. Would be needed if flux

Return type:

QuadMesh

set(*, adjustable=<UNSET>, agg_filter=<UNSET>, alpha=<UNSET>, anchor=<UNSET>, animated=<UNSET>, aspect=<UNSET>, autoscale_on=<UNSET>, autoscalex_on=<UNSET>, autoscaley_on=<UNSET>, axes_locator=<UNSET>, axisbelow=<UNSET>, box_aspect=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, facecolor=<UNSET>, forward_navigation_events=<UNSET>, frame_on=<UNSET>, gid=<UNSET>, in_layout=<UNSET>, label=<UNSET>, mouseover=<UNSET>, navigate=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, position=<UNSET>, prop_cycle=<UNSET>, rasterization_zorder=<UNSET>, rasterized=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, subplotspec=<UNSET>, title=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, xbound=<UNSET>, xinverted=<UNSET>, xlabel=<UNSET>, xlim=<UNSET>, xmargin=<UNSET>, xscale=<UNSET>, xticklabels=<UNSET>, xticks=<UNSET>, ybound=<UNSET>, yinverted=<UNSET>, ylabel=<UNSET>, ylim=<UNSET>, ymargin=<UNSET>, yscale=<UNSET>, yticklabels=<UNSET>, yticks=<UNSET>, zorder=<UNSET>)

Set multiple properties at once.

a.set(a=A, b=B, c=C)

is equivalent to

a.set_a(A)
a.set_b(B)
a.set_c(C)

In addition to the full property names, aliases are also supported, e.g. set(lw=2) is equivalent to set(linewidth=2), but it is an error to pass both simultaneously.

The order of the individual setter calls matches the order of parameters in set(). However, most properties do not depend on each other so that order is rarely relevant.

Supported properties are

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: float 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 or ~matplotlib.figure.SubFigure forward_navigation_events: bool or “auto” 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) xinverted: unknown xlabel: str xlim: (left: float, right: float) xmargin: float greater than -0.5 xscale: unknown xticklabels: unknown xticks: unknown ybound: (lower: float, upper: float) yinverted: unknown ylabel: str ylim: (bottom: float, top: float) ymargin: float greater than -0.5 yscale: unknown yticklabels: unknown yticks: unknown zorder: float

class x_ray_imager_bagriff.position_estimation.plot.ImagerFigure

Generic base figure for use with ImagerAxes.

__init__(*args, **kwargs)
Parameters:
  • figsize ((float, float) or (float, float, str), default: rcParams[“figure.figsize”] (default: [6.4, 4.8])) –

    The figure dimensions. This can be

    • a tuple (width, height, unit), where unit is one of “in” (inch), “cm” (centimenter), “px” (pixel).

    • a tuple (width, height), which is interpreted in inches, i.e. as (width, height, "in").

    One of width or height may be None; the respective value is taken from rcParams[“figure.figsize”] (default: [6.4, 4.8]).

  • dpi (float, default: rcParams[“figure.dpi”] (default: 100.0)) – Dots per inch.

  • facecolor (default: rcParams[“figure.facecolor”] (default: 'white')) – The figure patch facecolor.

  • edgecolor (default: rcParams[“figure.edgecolor”] (default: 'white')) – The figure patch edge color.

  • linewidth (float) – The linewidth of the frame (i.e. the edge linewidth of the figure patch).

  • frameon (bool, default: rcParams[“figure.frameon”] (default: True)) – If False, suppress drawing the figure background patch.

  • subplotpars (~matplotlib.gridspec.SubplotParams) – Subplot parameters. If not given, the default subplot parameters rcParams[“figure.subplot.*”] are used.

  • tight_layout (bool or dict, default: rcParams[“figure.autolayout”] (default: False)) –

    Whether to use the tight layout mechanism. See .set_tight_layout.

    Discouraged

    The use of this parameter is discouraged. Please use layout='tight' instead for the common case of tight_layout=True and use .set_tight_layout otherwise.

  • constrained_layout (bool, default: rcParams[“figure.constrained_layout.use”] (default: False)) –

    This is equal to layout='constrained'.

    Discouraged

    The use of this parameter is discouraged. Please use layout='constrained' instead.

  • layout ({‘constrained’, ‘compressed’, ‘tight’, ‘none’, .LayoutEngine, None}, default: None) –

    The layout mechanism for positioning of plot elements to avoid overlapping Axes decorations (labels, ticks, etc). Note that layout managers can have significant performance penalties.

    • ’constrained’: The constrained layout solver adjusts Axes sizes to avoid overlapping Axes decorations. Can handle complex plot layouts and colorbars, and is thus recommended.

      See Constrained layout guide for examples.

    • ’compressed’: uses the same algorithm as ‘constrained’, but removes extra space between fixed-aspect-ratio Axes. Best for simple grids of Axes.

    • ’tight’: Use the tight layout mechanism. This is a relatively simple algorithm that adjusts the subplot parameters so that decorations do not overlap.

      See Tight layout guide for examples.

    • ’none’: Do not use a layout engine.

    • A .LayoutEngine instance. Builtin layout classes are .ConstrainedLayoutEngine and .TightLayoutEngine, more easily accessible by ‘constrained’ and ‘tight’. Passing an instance allows third parties to provide their own layout engine.

    If not given, fall back to using the parameters tight_layout and constrained_layout, including their config defaults rcParams[“figure.autolayout”] (default: False) and rcParams[“figure.constrained_layout.use”] (default: False).

  • **kwargs (.Figure properties, optional) – Properties: 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: float or None animated: bool canvas: FigureCanvas clip_box: ~matplotlib.transforms.BboxBase or None clip_on: bool clip_path: Patch or (Path, Transform) or None constrained_layout: unknown constrained_layout_pads: unknown dpi: float edgecolor: color facecolor: color figheight: float figure: unknown figwidth: float frameon: bool gid: str in_layout: bool label: object layout_engine: {‘constrained’, ‘compressed’, ‘tight’, ‘none’, .LayoutEngine, None} linewidth: number mouseover: bool path_effects: list of .AbstractPathEffect picker: None or bool or float or callable rasterized: bool size_inches: (float, float) or float sketch_params: (scale: float, length: float, randomness: float) snap: bool or None tight_layout: unknown transform: ~matplotlib.transforms.Transform url: str visible: bool zorder: float

plot_observations(energy, x, y, **kwargs)

Create all plots for the observations provided.

Parameters:
  • energy (ArrayLike) – Observation array energies. Shape matches x and y

  • x (ArrayLike) – Observation array x-coordinate.

  • y (ArrayLike) – Observation array y-coordinate.

  • **kwargs – All other valid kwargs for a matplotlib Figure.

set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, canvas=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, constrained_layout=<UNSET>, constrained_layout_pads=<UNSET>, dpi=<UNSET>, edgecolor=<UNSET>, facecolor=<UNSET>, figheight=<UNSET>, figwidth=<UNSET>, frameon=<UNSET>, gid=<UNSET>, in_layout=<UNSET>, label=<UNSET>, layout_engine=<UNSET>, linewidth=<UNSET>, mouseover=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, rasterized=<UNSET>, size_inches=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, tight_layout=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, zorder=<UNSET>)

Set multiple properties at once.

a.set(a=A, b=B, c=C)

is equivalent to

a.set_a(A)
a.set_b(B)
a.set_c(C)

In addition to the full property names, aliases are also supported, e.g. set(lw=2) is equivalent to set(linewidth=2), but it is an error to pass both simultaneously.

The order of the individual setter calls matches the order of parameters in set(). However, most properties do not depend on each other so that order is rarely relevant.

Supported properties are

Properties:

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: float or None animated: bool canvas: FigureCanvas clip_box: ~matplotlib.transforms.BboxBase or None clip_on: bool clip_path: Patch or (Path, Transform) or None constrained_layout: unknown constrained_layout_pads: unknown dpi: float edgecolor: color facecolor: color figheight: float figure: unknown figwidth: float frameon: bool gid: str in_layout: bool label: object layout_engine: {‘constrained’, ‘compressed’, ‘tight’, ‘none’, .LayoutEngine, None} linewidth: number mouseover: bool path_effects: list of .AbstractPathEffect picker: None or bool or float or callable rasterized: bool size_inches: (float, float) or float sketch_params: (scale: float, length: float, randomness: float) snap: bool or None tight_layout: unknown transform: ~matplotlib.transforms.Transform url: str visible: bool zorder: float

class x_ray_imager_bagriff.position_estimation.plot.SpectrumFigure

Figure with only the energy spectrum plot.

__init__(*args, spectrum_max=None, **kwargs)

Initialize the energy spectrum figure.

Parameters:
  • *args – Passed to the base ImagerFigure class.

  • spectrum_max (float | None) – Maximum on y-axis for the energy spectrum. If not provided, matplotlib automatic limits are used.

  • **kwargs – Passed to the base ImagerFigure class.

plot_observations(energy, x, y, duration=None, d_energy=None, d_x=None, d_y=None, **kwargs)

Plot the energy spectrum.

Parameters:
  • energy (ArrayLike) – Observation array energies. Shape matches x and y

  • x (ArrayLike) – Observation array x-coordinate.

  • y (ArrayLike) – Observation array y-coordinate.

  • duration (float | None) – Total time for collecting these measurements. See ImagerAxes.energy_spectrum() for usage.

  • d_energy (ArrayLike | None)

  • d_x (ArrayLike | None)

  • d_y (ArrayLike | None)

set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, canvas=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, constrained_layout=<UNSET>, constrained_layout_pads=<UNSET>, dpi=<UNSET>, edgecolor=<UNSET>, facecolor=<UNSET>, figheight=<UNSET>, figwidth=<UNSET>, frameon=<UNSET>, gid=<UNSET>, in_layout=<UNSET>, label=<UNSET>, layout_engine=<UNSET>, linewidth=<UNSET>, mouseover=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, rasterized=<UNSET>, size_inches=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, tight_layout=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, zorder=<UNSET>)

Set multiple properties at once.

a.set(a=A, b=B, c=C)

is equivalent to

a.set_a(A)
a.set_b(B)
a.set_c(C)

In addition to the full property names, aliases are also supported, e.g. set(lw=2) is equivalent to set(linewidth=2), but it is an error to pass both simultaneously.

The order of the individual setter calls matches the order of parameters in set(). However, most properties do not depend on each other so that order is rarely relevant.

Supported properties are

Properties:

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: float or None animated: bool canvas: FigureCanvas clip_box: ~matplotlib.transforms.BboxBase or None clip_on: bool clip_path: Patch or (Path, Transform) or None constrained_layout: unknown constrained_layout_pads: unknown dpi: float edgecolor: color facecolor: color figheight: float figure: unknown figwidth: float frameon: bool gid: str in_layout: bool label: object layout_engine: {‘constrained’, ‘compressed’, ‘tight’, ‘none’, .LayoutEngine, None} linewidth: number mouseover: bool path_effects: list of .AbstractPathEffect picker: None or bool or float or callable rasterized: bool size_inches: (float, float) or float sketch_params: (scale: float, length: float, randomness: float) snap: bool or None tight_layout: unknown transform: ~matplotlib.transforms.Transform url: str visible: bool zorder: float

class x_ray_imager_bagriff.position_estimation.plot.ImageHistFigure

Figure with only the position histogram image.

ax_image

The position histogram Axes.

max_imager

The maximum value for the position colormap.

ax_colorbar

The colorbar Axes.

__init__(*args, image_max=None, **kwargs)

Initialize the energy spectrum figure.

Parameters:
  • *args – Passed to the base ImagerFigure class.

  • image_max (float | None) – Maximum for the image colormap in units x-rays/bin. If not provided, matplotlib selects the range automatically.

  • **kwargs – Passed to the base ImagerFigure class.

plot_observations(energy, x, y, energy_range=None, d_energy=None, d_x=None, d_y=None, **kwargs)

Plot the position historgram.

Parameters:
  • energy (ArrayLike) – Observation array energies. Shape matches x and y

  • x (ArrayLike) – Observation array x-coordinate.

  • y (ArrayLike) – Observation array y-coordinate.

  • energy_range (tuple[float, float] | None) – Tuple with the lower and upper limit to be used for the position histogram. Others are ignored.

  • dx – Uncertainty for x. Should have the same shape.

  • dy – Uncertainty for y. Should have the same shape.

  • d_energy (ArrayLike | None)

  • d_x (ArrayLike | None)

  • d_y (ArrayLike | None)

set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, canvas=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, constrained_layout=<UNSET>, constrained_layout_pads=<UNSET>, dpi=<UNSET>, edgecolor=<UNSET>, facecolor=<UNSET>, figheight=<UNSET>, figwidth=<UNSET>, frameon=<UNSET>, gid=<UNSET>, in_layout=<UNSET>, label=<UNSET>, layout_engine=<UNSET>, linewidth=<UNSET>, mouseover=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, rasterized=<UNSET>, size_inches=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, tight_layout=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, zorder=<UNSET>)

Set multiple properties at once.

a.set(a=A, b=B, c=C)

is equivalent to

a.set_a(A)
a.set_b(B)
a.set_c(C)

In addition to the full property names, aliases are also supported, e.g. set(lw=2) is equivalent to set(linewidth=2), but it is an error to pass both simultaneously.

The order of the individual setter calls matches the order of parameters in set(). However, most properties do not depend on each other so that order is rarely relevant.

Supported properties are

Properties:

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: float or None animated: bool canvas: FigureCanvas clip_box: ~matplotlib.transforms.BboxBase or None clip_on: bool clip_path: Patch or (Path, Transform) or None constrained_layout: unknown constrained_layout_pads: unknown dpi: float edgecolor: color facecolor: color figheight: float figure: unknown figwidth: float frameon: bool gid: str in_layout: bool label: object layout_engine: {‘constrained’, ‘compressed’, ‘tight’, ‘none’, .LayoutEngine, None} linewidth: number mouseover: bool path_effects: list of .AbstractPathEffect picker: None or bool or float or callable rasterized: bool size_inches: (float, float) or float sketch_params: (scale: float, length: float, randomness: float) snap: bool or None tight_layout: unknown transform: ~matplotlib.transforms.Transform url: str visible: bool zorder: float

class x_ray_imager_bagriff.position_estimation.plot.ImageSpectrumFigure

Figure with an energy spectrum on top of a position historgram.

ax_spectrum

The energy spectrum Axes.

spectrum_max

The y-axis for the energy spectrum. None will use auto.

ax_image

The position histogram Axes.

max_imager

The maximum value for the position colormap.

ax_colorbar

The colorbar Axes.

__init__(*args, **kwargs)

Initialize the energy spectrum figure.

Parameters:
  • *args – Passed to the base ImagerFigure class.

  • spectrum_max – Maximum on y-axis for the energy spectrum. If not provided, matplotlib automatic limits are used.

  • **kwargs – Passed to the base ImagerFigure class.

plot_observations(*args, energy_range=None, **kwargs)

Plot both energy spectrum and position histogram.

Parameters:

energy_range (tuple[float, float] | None)

set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, canvas=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, constrained_layout=<UNSET>, constrained_layout_pads=<UNSET>, dpi=<UNSET>, edgecolor=<UNSET>, facecolor=<UNSET>, figheight=<UNSET>, figwidth=<UNSET>, frameon=<UNSET>, gid=<UNSET>, in_layout=<UNSET>, label=<UNSET>, layout_engine=<UNSET>, linewidth=<UNSET>, mouseover=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, rasterized=<UNSET>, size_inches=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, tight_layout=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, zorder=<UNSET>)

Set multiple properties at once.

a.set(a=A, b=B, c=C)

is equivalent to

a.set_a(A)
a.set_b(B)
a.set_c(C)

In addition to the full property names, aliases are also supported, e.g. set(lw=2) is equivalent to set(linewidth=2), but it is an error to pass both simultaneously.

The order of the individual setter calls matches the order of parameters in set(). However, most properties do not depend on each other so that order is rarely relevant.

Supported properties are

Properties:

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: float or None animated: bool canvas: FigureCanvas clip_box: ~matplotlib.transforms.BboxBase or None clip_on: bool clip_path: Patch or (Path, Transform) or None constrained_layout: unknown constrained_layout_pads: unknown dpi: float edgecolor: color facecolor: color figheight: float figure: unknown figwidth: float frameon: bool gid: str in_layout: bool label: object layout_engine: {‘constrained’, ‘compressed’, ‘tight’, ‘none’, .LayoutEngine, None} linewidth: number mouseover: bool path_effects: list of .AbstractPathEffect picker: None or bool or float or callable rasterized: bool size_inches: (float, float) or float sketch_params: (scale: float, length: float, randomness: float) snap: bool or None tight_layout: unknown transform: ~matplotlib.transforms.Transform url: str visible: bool zorder: float

class x_ray_imager_bagriff.position_estimation.plot.ImagerAnimation

Animation for a time series of x-ray observations.

__init__(fig, df, step_duration, energy_range=None, use_error=False, **kwargs)

Initialize the x-ray imager animation.

Parameters:
  • fig (ImagerFigure) – The figure used to plot each time step. Should have a plot_observations() function.

  • df (DataFrame) – DataFrame with the observations. It should have columns ‘x’, ‘y’, ‘energy’ plus the time in seconds under ‘t’.

  • step_duration (float) – Duration of each frame in seconds.

  • energy_range (tuple[float, float] | None) – Energy limits to be used. For details, see ImageHistFigure.plot_observations().

  • use_error (bool | None)