axeap.core package
axeap.core.conventions module
Conventions. Shorthands and enums used throughout axeap.
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 pixeleres (float) – Energy resolution corresponding to mapping, units of eV/pixel
- property dims
Get dimensions of energy map.
- Returns
Shape of energy map as (x, y).
- Return type
- 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
- 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
scanset (ScanSet) – Set of calibration scans.
hrois (list) – List of
core.roi.HROI
corresponding to each crystal.
- 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
orcore.spectra.Spectra
.- TYPE_NAME = 'DataItem'
- 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 theDataItemSet
changes or the selection status of one of theDataItem
’s changes. This is the superclass forcore.scan.ScanSet
,core.roi.ROISet
, andcore.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
- itemremoved
When item is removed, signal emitted with item as argument.
- Type
- selectionchanged
When item selection is changed, signal emitted with signature (item, selection).
- Type
- 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
- 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.
- 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
- 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
- SAVE_PATH_TYPE
Specifies whether the object can be saved as a file or a directory. Should be overwritten by subclass definition.
- 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.
- class axeap.core.roi.EllipseROI(p, rx, ry, **kwargs)[source]
Bases:
axeap.core.roi.ROI
Ellipse-shaped ROI
- 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
forROI
’s
- 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.
- class axeap.core.roi.SpanROI(p1, p2, **kwargs)[source]
Bases:
axeap.core.roi.ROI
- 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
- axeap.core.roifinding.calcHorizontalLineSegments(scan, min_line_length, anglerange=None)[source]
Function that calculates line segments from scan.
- Parameters
- Returns
Array of line segments encoded as [[x1,y1],[x2,y2]]
- Return type
- 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.
- __init__(fpath)[source]
- Parameters
fpath (
pathlib.Path
,str
) – Path of file containing information.
- property energies
Get list of energies used to take scans
- 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
- NOCUTS = -1
- NOROI = -1
- NOSCALE = -1
- __init__(basespec=None, cuts=None, scale=None, blur=None, roi=None)[source]
- 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.
- 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 valuesname (
str
) – Name for the scan.cache (
bool
,dict
) – PassFalse
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
- 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
- getImgFromSpecs(imgspec)[source]
Get image after applying imagespec.
- Parameters
imgspec (
ImageSpec
)) – Specifications for image.- Returns
2D array representing image.
- Return type
- 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).Returns – numpy.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
- 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
forScan
objects.- DEFAULT_IMGDIMS = (100, 100)
- LOAD_PATH_TYPE = 3
- TYPE_NAME = 'Scan Set'
- addCalibRunInfo(runinfo)[source]
- Populate metadata of scans with calibration run information (incident
energy, intensity, etc).
- Parameters
runinfo (
CalibRunInfo
) – Calibration run information.
- property dims
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 theemit()
call.- connect(f)[source]
Connects a listener callable.
- Parameters
f (
callable
) – The listener to connect to the signal.
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.
- class axeap.core.spectra.SpectraSet(spectra=None, selection_default=True)[source]
Bases:
axeap.core.item.DataItemSet
- 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