signals module

This package defines all sort of classes to handle data for inpystem.

The Scan class

class inpystem.signals.Scan(shape, path, ratio=None)

Scan pattern class.

This class stores the data spatial shape and two copies of the scan pattern. One of these copies is the initial scan pattern which is given to the class. At the same time, a ratio argument can be given to keep only a portion of the available samples. See Notes for more details.

Variables
  • shape (2-length tuple) – The spatial shape (m, n) where m is the number of rows and n is the number of columns.

  • path (numpy array) – The sampling path to be used in the study.

  • path_0 (numpy array) – The initial sampling path to be kept in case the ratio is changed.

  • ratio (float) – The current ratio value such that path`has size :code:`ratio*m*n. Changing this attribute automaticaly updates path.

Note

Consider only r*m*n pixels hve been sampled, then the path_0 attribute has shape (r*m*n, ) and its elements lay between 0 and m*n-1.

Meanwhile, if the user wants to consider only ratio percent of the samples, the ratio argument should be given. The path attribute would then have shape (ratio*m*n, ). In such case, path_0[:ratio*m*n] will be equal to path. Be aware that ratio should be lower than r.

Each element of these arrays is the pixel index in row major order. To recover the row and column index array, type the following commands.

::code:

i = path // n j = path % n

__init__(shape, path, ratio=None)

Scan pattern constructor.

Parameters
  • shape ((m, n) tuple) – The spatial shape where m is the number of rows and n is the number of columns.

  • path (tuple, numpy array) – The sampling path. See class Notes for more detail.

  • ratio (optional, float) – The ratio of sampled pixels. This should lay between 0 (excl.) and 1. Default is None for full sampling.

property ratio

Ratio getter.

Returns

The ratio property value.

Return type

float

classmethod from_file(data_file, ratio=None)

Creates a scan pattern object from a data file (such as .dm3, .dm4 or npz).

In the case of a .npz file, this one should contain the :code:̀’m`, :code:̀’n` and :code:̀’path` variables which are resp. the number of rows and columns and the path array.

Concerning the .dm3/.dm4 files, the data storage is specific to the LPS Lab (Orsay, France) implementation.

An aditional argument :code:̀’ratio` allows you to select only a given ratio of the sampled pixels. This should lay between 0 (excl.) and 1.

Parameters
  • data_file (str) – The data file path.

  • ratio (optional, float) – The ratio of sampled pixels. This should lay between 0 (excl.) and 1. Default is None for full sampling.

Returns

The scan pattern.

Return type

Scan object

classmethod random(shape, ratio=None, seed=None)

Creates a random scan pattern object.

Parameters
  • shape ((m, n) tuple) – The data spatial shape.

  • ratio (optional, float) – The ratio of sampled pixels. It should lay between 0 (excluded) and 1. Default is None for full sampling.

  • seed (optional, int) – Seed for random sampling. Default is None for random seed.

Returns

The scan pattern.

Return type

Scan object

get_mask()

Returns the sampling mask.

The sampling mask is boolean and True is for sampled pixels.

Returns

mask – The sampling mask.

Return type

(m, n) numpy array

plot()

Plots the sampling mask.

White (resp. black) pixels are sampled (resp. non-sampled).

The Stem classes

class inpystem.signals.AbstractStem(hsdata, scan=None, verbose=True)

Abstract STEM acquisition class.

This is an abstract class, which mean you can not instantiate such object.

It defines the structure for a STEM acquisition object.

Variables
  • hsdata (hs BaseSignal) – The acquired STEM data hyperspy object.

  • scan (Scan object) – The sampling scan object associated with the data.

  • verbose (bool) – If True, information is sent to standard output. Default is True.

__init__(hsdata, scan=None, verbose=True)

AbstractStem constructor.

Parameters
  • hsdata (hs BaseSignal) – The acquired STEM data hyperspy object.

  • scan (optional, Scan object) – The sampling scan object associated with the data. Default is None for full sampling.

  • verbose (bool) – If True, information is sent to standard output. Default is True.

correct(rows=slice(None, None, None), cols=slice(None, None, None), bands=slice(None, None, None), dpixels=None)

Correct deffective data.

Deffective data correspond to:

  1. Rows to remove at the begging or at the end of the image.

  2. Columns to remove at the begging or at the end of the image.

  3. Bands to remove at the begging or at the end of the image.

  4. Located dead pixels at the center of the image.

In the cases 1, 2 or 3, the rows and columns are purely removed. The dead pixels are filled with the mean over a neighbourhood.

A :code`slice` object for an object A of length L defines a continuous portion of A such as A[n_1], A[n_1+1], ..., A[n_2-1] with n_1 < n_2. In such case, a slice object definition is slice(n_1, n_2). If n_1 is 0, then use slice(None, n_2). If n_2 is L use slice(n_1, None). Last, if all the elements of A should be kept, use slice(None).

Parameters
  • rows (slice object) – The range of rows to keep.

  • cols (slice object) – The range of columns to keep.

  • cols – The range of bands to keep.

  • dpixels (list) – The positions of the dead pixels.

correct_fromfile(file, force_ndim=None)

force_ndim aims at forcing dimension. Default is None for data dimension.

abstract restore()

Restores corrupted data.

plot()

Plots the masked data.

class inpystem.signals.Stem2D(hsdata, scan=None, verbose=True)

2D image STEM acquisition.

This defines a 2D STEM image with its associated sampling scan.

Variables
  • hsdata (hs BaseSignal) – The acquired STEM data hyperspy object.

  • scan (Path object) – The sampling scan object associated with the data.

restore(method='interpolation', parameters={})

Restores the acquisition.

It performs denoising in the case of full scan and performs recontruction in case of partial sampling.

class inpystem.signals.Stem3D(hsdata, scan=None, verbose=True)

3D image STEM acquisition.

This defines a 3D STEM image with its associated sampling scan.

Variables
  • hsdata (hs BaseSignal) – The acquired STEM data hyperspy object.

  • scan (Path object) – The sampling scan object associated with the data.

restore(method='interpolation', parameters={}, PCA_transform=True, PCA_th='auto')

Restores the acquisition.

It performs denoising in the case of full scan and performs recontruction in case of partial sampling.

Parameters
  • PCA_transform (optional, bool) – Enables the PCA transformation if True, otherwise, no PCA transformation is processed. Default is True.

  • PCA_th (optional, int, str) – The desired data dimension after dimension reduction. Possible values are ‘auto’ for automatic choice, ‘max’ for maximum value and an int value for user value. Default is ‘auto’.

plot_sum()

Shows the sum of the data along the last axis.

plot_as2D()

Implements the HypersSpy tool to visualize the image for a given band.

plot_as1D()

Implements the HypersSpy tool to visualize the spectrum for a given pixel.

plot_roi()

Implements the Hyperspy tool to analyse regions of interest.