axeap.core package

axeap.core.conventions module

Conventions. Shorthands and enums used throughout axeap.

class axeap.core.conventions.PathType(value)[source]

Bases: enum.Enum

An enumeration.

DIR = 3
FILE = 1
FILES = 2

axeap.core.emap module

Energy Map

Energy maps are 2D arrays the same size as a XES image where each pixel in value in the energymap corresponds to an energy. Thus when a pixel is excited in an image, the corresponding energy is added to the spectra with an intensity corresponding to the energy of the pixel.

class axeap.core.emap.EnergyMap(values, name=None, eres=None)[source]

Bases: axeap.core.item.DataItem, axeap.core.item.Saveable, axeap.core.item.Loadable

Class representing a mapping of pixels onto energies.

LOAD_FILE_EXTENTIONS = ['npy']
LOAD_PATH_TYPE = 1
SAVE_FILE_EXTENTIONS = ['npy']
SAVE_PATH_TYPE = 1
TYPE_NAME = 'EnergyMap'
__init__(values, name=None, eres=None)[source]
Parameters
  • values (numpy.ndarray) – 2D array containing energy corresponding to each pixel

  • eres (float) – Energy resolution corresponding to mapping, units of eV/pixel

calcSpectra(scan)[source]

Calculate spectra from scan.

Parameters

scan (scan.Scan) – Scan to calculate spectra from.

Returns

Spectra object.

Return type

Spectra

property dims

Get dimensions of energy map.

Returns

Shape of energy map as (x, y).

Return type

tuple

property eres

Get the energy resolution (eV/pixel) for the energy map.

Returns

Stored value if set in constructor, else estimates resolution from map values.

Return type

float

loadFromPath()[source]

Load energy map from file.

Parameters

fpath (Path) – Path of file from which to load energy map.

Returns

Energy map loaded from file.

Return type

EnergyMap

saveToPath(fpath)[source]

Save energy map to file.

Energy resolution is not saved. This will be added in the future.

Parameters

fpath (Path) – Path of file to which to save energy map

axeap.core.emap.calcEMap(scanset, hrois)[source]

Function that calculates an pixel-to-energy mapping (an energy map) from a set of scans and the horizontal pixel ranges (the groups) that have been determined to correspond to different crystals in the scans.

Parameters
Returns

2D array same size as scans of energy values corresponding to each pixel.

Return type

np.ndarray

axeap.core.item module

class axeap.core.item.DataItem(name=None, meta=None)[source]

Bases: object

Superclass for all data-containing objects.

This is the superclass for objects such as core.scan.Scan or core.spectra.Spectra.

TYPE_NAME

The name of the data item type, for example “Scan”. Same across all instances.

Type

str

name

The name of the data item, not necessarily unique.

Type

str

uuid

UUID of the data item. Unique.

Type

uuid.UUID

meta

Dictionary of metadata describing instance of DataItem.

Type

dict

TYPE_NAME = 'DataItem'
__init__(name=None, meta=None)[source]
Parameters
  • name (str, optional) – Name to assign to item. Should be human-readable, not necessarily unique.

  • meta (dict, optional) – Metadata concerning the item. Keys should be strings.

class axeap.core.item.DataItemSet(items=None, selection_default=True, *args, **kwargs)[source]

Bases: object

Set of DataItem objects.

This is essentially just a list of DataItem objects but with the additional features of allowing items to be “selected” or not and emitting signals when the membership of the DataItemSet changes or the selection status of one of the DataItem’s changes. This is the superclass for core.scan.ScanSet, core.roi.ROISet, and core.spectra.SpectraSet.

Note

Though this uses a list to store the underlying data, users should not depend on the order of the items in the set.

itemadded

When item is added, signal is emitted with item as argument.

Type

core.signal.Signal

itemremoved

When item is removed, signal emitted with item as argument.

Type

core.signal.Signal

selectionchanged

When item selection is changed, signal emitted with signature (item, selection).

Type

core.signal.Signal

__init__(items=None, selection_default=True, *args, **kwargs)[source]
Parameters
  • items (list, optional) – List of DataItem objects to initially populate the DataItemSet.

  • selection_default (bool, optional) – Default selection value for items after being added to set. Default default value is True.

add(item)[source]

Add DataItem to set.

getSelected()[source]

Get list of selected items.

getSelection(item)[source]

Get selection status of item.

remove(item)[source]

Remove DataItem from set.

setSelection(item, sel)[source]

Change selection status of DataItem

Parameters
  • item (DataItem) – Item whose selection status to change.

  • sel (bool) – New selection status.

class axeap.core.item.Loadable[source]

Bases: object

Superclass for any object that can be loaded from a file.

LOAD_FILE_EXTENTIONS

List of strings containing file extensions that the object can be loaded from. Extensions are lowercase and do not include dots (example “txt” instead of “.TXT”). Should be overwritten by subclass definition.

Type

list

SAVE_PATH_TYPE

Specifies whether the object can be loaded from a file, multiple files, or a directory. Should be overwritten by subclass but constant across instances.

Type

core.conventions.PathType

LOAD_FILE_EXTENTIONS = []
LOAD_PATH_TYPE = 1
loadFromFile()[source]

Load data from file and use to instantiate class.

Parameters

path (pathlib.Path, str) – Path of file containing data.

Returns

Instance of object, populated with data from file.

Return type

Loadable

class axeap.core.item.Saveable[source]

Bases: object

Superclass for any object that can be saved to a file.

SAVE_FILE_EXTENTIONS

List of strings containing file extensions that the object can be saved under. Extensions are lowercase and do not include dots (example “txt” instead of “.TXT”). Should be overwritten in subclass definition.

Type

list

SAVE_PATH_TYPE

Specifies whether the object can be saved as a file or a directory. Should be overwritten by subclass definition.

Type

core.conventions.PathType

SAVE_FILE_EXTENTIONS = []
SAVE_PATH_TYPE = 1
saveToPath(path)[source]

Save data stored in object to a given path.

Parameters

path (pathlib.Path, str) – Path to store object data to. Could be file or directory.

axeap.core.roi module

Region of Interest (ROI)

ROIs define regions of an image.

class axeap.core.roi.ComboROI(*rois, **kwargs)[source]

Bases: axeap.core.roi.ROI

ROI composed of a combination of other ROIs.

__init__(*rois, **kwargs)[source]
Parameters

*rois (List of ROI)) – The component ROIs to combine.

class axeap.core.roi.EllipseROI(p, rx, ry, **kwargs)[source]

Bases: axeap.core.roi.ROI

Ellipse-shaped ROI

__init__(p, rx, ry, **kwargs)[source]
Parameters
  • p (array-like) – Coordinates (x,y) for center of ellipse.

  • rx (float) – Radius along x-axis.

  • ry (float) – Radius along y-axis.

class axeap.core.roi.HROI(p1, p2, **kwargs)[source]

Bases: axeap.core.roi.SpanROI

ROI spanning range along x-axis.

class axeap.core.roi.ROI(name=None, meta=None)[source]

Bases: axeap.core.item.DataItem

Region of Interest superclass.

Used as parent of specific ROIs. Do not instantiate directly.

class axeap.core.roi.ROISet(items=None, selection_default=True, *args, **kwargs)[source]

Bases: axeap.core.item.DataItemSet

core.item.DataItemSet for ROI’s

getROIsInside(nroi)[source]

Get ROIs in set contained by given ROI

Parameters

nroi (ROI) – ROI used to choose ROIs from set.

Returns

List of ROIs contained in nroi.

Return type

list

class axeap.core.roi.RectangleROI(p1, p2, **kwargs)[source]

Bases: axeap.core.roi.ROI

Rectangular ROI

__init__(p1, p2, **kwargs)[source]
Parameters
  • p1 (array-like) – Coordinates (x,y) of one corner of rectangular.

  • p2 (array-like) – Coordinates (x,y) of diagonally opposite corner to p1.

fromHVROIs(vroi)[source]

Create Rectangular ROI from horizontal and vertical ROIs.

Parameters
  • hroi (HROI) – Horizontal ROI.

  • vroi (VROI) – Vertical ROI.

Returns

Rectangular ROI spanning vertical and horizontal regions.

Return type

RectangleROI

class axeap.core.roi.SpanROI(p1, p2, **kwargs)[source]

Bases: axeap.core.roi.ROI

Abstract superclass to HROI and VROI. Do not instantiate.

__init__(p1, p2, **kwargs)[source]
Parameters
  • p1 (float) – Lower end of span.

  • p2 (float) – Higher end of span.

class axeap.core.roi.VROI(p1, p2, **kwargs)[source]

Bases: axeap.core.roi.SpanROI

ROI spanning range along y-axis.

axeap.core.roifinding module

Automatic Calculation of Regions of Interest.

axeap.core.roifinding.calcHROIs(scan, min_width, group_buffer=0, return_lines=False)[source]

Static function to separate image into columns based on line segments found in image.

This works by combining line segements that overlap in their horizontal ranges by more than 50% of their length to form groups. These groups are then trimmed so as to not overlap. This is meant to be used with _calcLines to find the horizontal ranges of pixels in the scan image that correspond to each crystal. However, if two crystals are lined up such that they produce a single line segment in the image, this function will create one group spanning both crystals.

Parameters
  • scan (core.scan.Scan) – Scan to calculate horizontal regions of interest for.

  • group_buffer (int) – Minimum number of pixels to separate groups by.

  • return_lines (bool) – Whether or not to return the lines segments detected in the image.

Returns

  • list – List of core.roi.HROI’s representing regions corresponding to each crystal.

  • np.ndarray, optional – Array of line segments detected in image, encoded as [[x1,y1],[x2,y2]]. Returned if return_lines is set True.

axeap.core.roifinding.calcHorizontalLineSegments(scan, min_line_length, anglerange=None)[source]

Function that calculates line segments from scan.

Parameters
  • scan (scan.Scan) – Scan to calculate lines from.

  • min_line_length (float) – Minimum length line segments must be.

  • anglerange (tuple) – Range of angles that line segments must be within. Horizontal is 0, vertical is pi/2. Range encoded as (t1,t2).

Returns

Array of line segments encoded as [[x1,y1],[x2,y2]]

Return type

numpy.ndarray

axeap.core.roifinding.calcVROIs(scan, minheight, maxgap, cutoff_frac=0.1, buffer=0)[source]

Calculate vertical regions of interest (VROIs) for a scan.

Parameters
  • scan (core.scan.Scan) – Scan to calculate VROIs for.

  • minheight (float) – Minimum height of VROI.

  • maxgap (int) – Maximum empty (no non-zero pixels) space allowed within a VROI.

  • cutoff_frac (float) – Fraction of peak intensity to use as low-cut.

  • buffer (int) – Extra space to add around VROI.

axeap.core.scan module

Scan. The Scan class represents an image from a PAD detector. This file contains all code relating to Scans.

class axeap.core.scan.CalibRunInfo(fpath)[source]

Bases: object

Class that represents the settings used during the collection of a set of calibration scans.

energies

List of energies scans were taken at.

Type

list

__init__(fpath)[source]
Parameters

fpath (pathlib.Path, str) – Path of file containing information.

property energies

Get list of energies used to take scans

getEnergy(i)[source]

Get energy used to take scan by scan number.

Parameters
  • i (int) – Index of scan (0 for first scan, 1 for second, etc).

  • Returns

:param float: Energy of scan

getIncidentIntensity(i)[source]

Get incident intensity that a scan was taken with.

Parameters

i (int, float) – Scan number or scan energy.

Returns

Incident x-ray intensity scan was taken with.

Return type

float

axeap.core.scan.IS

Alias for ImageSpec.

class axeap.core.scan.ImageSpec(basespec=None, cuts=None, scale=None, blur=None, roi=None)[source]

Bases: dict

Class representing specifications applied to scan image.

NOBLUR = -1
class property NOCHANGE[source]

An ImageSpec that signifies no change to be made to an image.

NOCUTS = -1
NOROI = -1
NOSCALE = -1
__init__(basespec=None, cuts=None, scale=None, blur=None, roi=None)[source]
Parameters
  • basespec (ImageSpec) – ImageSpec to use as default values.

  • cuts (tuple, optional) – Pair of values (l,h) where any pixel values with intensity <l or >h are set to 0.

  • scale (float, optional) – Number to scale all intensity values in image by.

  • blur (int, optional) – Kernel size of gaussian blur to apply to image.

  • roi (core.ROI, optional) – Region of interest to which to restrict image. The rest of the image will be masked off.

class axeap.core.scan.Scan(img, imgspec=None, name=None, meta=None, cache=True)[source]

Bases: axeap.core.item.DataItem, axeap.core.item.Saveable, axeap.core.item.Loadable

Class representing a scan image taken with a XES detector.

LOAD_FILE_EXTENTIONS = ['tiff', 'tif', 'scan']
SAVE_FILE_EXTENTIONS = ['tif', 'png', 'scan']
SAVE_PATH_TYPE = 1
TYPE_NAME = 'Scan'
__init__(img, imgspec=None, name=None, meta=None, cache=True)[source]
Parameters
  • img (numpy.ndarray) – 2D array of intensity values

  • name (str) – Name for the scan.

  • cache (bool, dict) – Pass False to turn off cacheing of images. An already-prepared cache of images in the form a dictionary of image specs to images can also be passed. Do not use unless you know what you’re doing.

count(roi=None)[source]

Count total intensity within ROI.

Parameters
  • roi (core.roi.ROI, optional) – Region of Interest to restrict count to. If not given, region is considered to be entire scan.

  • Returns

:param int: Total intensity summed over region.

property dims

Dimensions of scan image.

Returns

Dimensions of scan image in form (x,y).

Return type

tuple

getImg(*args, **kwargs)[source]

Get 2D array of intensity values associated with scan, optionally pre-processed.

Parameters
  • cuts (tuple, optional) – Pair of values (l,h) where any pixel values with intensity <l or >h are set to 0.

  • scale (float, optional) – Number to scale all intensity values in image by.

  • blur (int, optional) – Kernel size of gaussian blur to apply to image.

  • roi (core.ROI, optional) – Region of interest to which to restrict image. The rest of the image will be masked off.

Returns

2D array of intensity values representing image.

Return type

numpy.ndarray

getImgFromSpecs(imgspec)[source]

Get image after applying imagespec.

Parameters

imgspec (ImageSpec)) – Specifications for image.

Returns

2D array representing image.

Return type

numpy.ndarray

loadFromPath()[source]

Load scan data from file.

Parameters
  • fpath (pathlib.Path, str) – Path to file containing image data.

  • Returns

:param Scan: Scan object containing data from file.

loadImageFromFile()[source]

Load an image from a file.

Parameters
  • fpath (pathlib.Path, str) – Path of image file (either TIF or NPY).

  • Returnsnumpy.ndarray: 2D image data array.

mod(*args, **kwargs)[source]

Return scan with a different default imgspec.

Parameters
  • cuts (tuple, optional) – Pair of values (l,h) where any pixel values with intensity <l or >h are set to 0.

  • scale (float, optional) – Number to scale all intensity values in image by.

  • blur (int, optional) – Kernel size of gaussian blur to apply to image.

  • roi (core.ROI, optional) – Region of interest to which to restrict image. The rest of the image will be masked off.

Returns

Scan object with given default imgspec.

Return type

Scan

name = 'Scan'
saveToPath(fpath)[source]

Save scan to file.

Parameters

fpath (pathlib.Path, str) – Path of file to which to save scan.

class axeap.core.scan.ScanSet(scans=None, name=None, imgdims=None, selection_default=True)[source]

Bases: axeap.core.item.DataItemSet, axeap.core.item.Loadable

core.item.DataItemSet for Scan objects.

DEFAULT_IMGDIMS = (100, 100)
LOAD_PATH_TYPE = 3
TYPE_NAME = 'Scan Set'
add(scan)[source]

Add Scan to set.

See core.item.DataItemSet.add.

addCalibRunInfo(runinfo)[source]
Populate metadata of scans with calibration run information (incident

energy, intensity, etc).

Parameters

runinfo (CalibRunInfo) – Calibration run information.

composite(imgkwargs=None)[source]

Create scan by adding images from all selected scans in set.

Parameters
  • imgkwargs (ImageSpec) – Specifications to apply to image extracted from each Scan.

  • Returns

    Scan

    Scan object representing combined image.

property dims
loadFromPath(calibinfopath=None)[source]

axeap.core.signal module

class axeap.core.signal.Signal[source]

Bases: object

Signal that can trigger distribution of data to all connected functions.

This class is used for a barebones event system. Signal objects are owned as visible attributes of objects. Callables, including methods of other objects, can be connected to this signal. These callables are referred to as the “listeners” of the signal. Then when the object that owns the signal emits it, all the connected listeners are called (in the order that they were connected) with arguments specified in the emit() call.

connect(f)[source]

Connects a listener callable.

Parameters

f (callable) – The listener to connect to the signal.

disconnect(f)[source]

Disconnect a listener callable.

Parameters

f (callable) – The listener to disconnect from the signal.

emit(*args, **kwargs)[source]

Emit the signal.

All connected listeners are called with the given arguments.

Parameters
  • *args – Positional arguments to send to listeners.

  • **kwargs – Keyword arguments to send to listeners.

axeap.core.spectra module

class axeap.core.spectra.Spectra(energies, intensities)[source]

Bases: axeap.core.item.Saveable, axeap.core.item.Loadable

Class representing a spectra, indicating intensity over a range of energies.

LOAD_FILE_EXTENTIONS = ['npy']
LOAD_PATH_TYPE = 1
SAVE_PATH_TYPE = ['npy']
TYPE_NAME = 'Spectra'
__init__(energies, intensities)[source]
Parameters
  • energies (numpy.ndarray) – List of energies.

  • intensities (numpy.ndarray) – List of intensities corresponding to each energy.

loadFromFile()[source]

Load spectra from file.

Parameters

fpath (path) – Path of file from which to load spectra.

Returns

Spectra with data loaded from file.

Return type

Spectra

saveToFile(fpath)[source]

Save spectra to file.

Parameters

fpath (path) – Path of file to which to save spectra.

class axeap.core.spectra.SpectraSet(spectra=None, selection_default=True)[source]

Bases: axeap.core.item.DataItemSet

core.item.DataItemSet for Spectra.

axeap.core.spectra.calcSpectra(emap, image, evres=0.5, normalize=False)[source]

Generates spectra from image and energy map.

Parameters
  • emap (numpy.ndarray) – 2D array of energy values.

  • image (numpy.ndarray) – 2D array of intensity values, same size as emap.

  • evres (float) – Resolution of spectra in number of eVs.

  • normalize (bool) – Normalize the spectra so peak has intensity 1.

Returns

2D array structured as list of energy-intensity pairs.

Return type

numpy.ndarray