Line-by-line Lasers

Laser

Class for data collected line-by-line. Line-by-line data is collected in multiple lines, with each line performed as a continuous ablation in one direction. The lines are then stacked to form an image.

class pewlib.laser.Laser(data, calibration=None, config=None, info=None)

Class for line-by-line laser data.

Parameters:
  • data (ndarray) – structured array of elemental data

  • calibration (dict[str, Calibration] | None) – dict mapping elements to calibrations, optional

  • config (Config | None) – laser parameters

  • info (dict[str, str] | None) – dict (str, str) of additional info

add(element, data, calibration=None)

Adds a new element.

Parameters:
  • element (str) – element name

  • data (ndarray) – array

  • calibration (Calibration | None) – calibration for data, optional

Return type:

None

property elements: tuple[str, ...]

Elements stored.

property extent: tuple[float, float, float, float]

Image extent in μm

classmethod from_list(elements, datas, config=None, info={})

Creates class from a list of names and unstructured arrays.

Return type:

Laser

get(element=None, calibrate=False, extent=None, **kwargs)

Get elemental data.

If element is None then all elements are returned in a structured array.

Parameters:
  • element (str | None) – element name, optional

  • calibrate (bool | None) – apply calibration

  • extent (tuple[float, float, float, float] | None) – trim to extent, μm

Return type:

ndarray

Returns:

structured if element is None else unstructured

remove(names)

Remove element(s).

Return type:

None

rename(names)

Change the name of element(s).

Parameters:

names (dict[str, str]) – dict mapping old to new names

Return type:

None

Config

class pewlib.config.Config(spotsize=35.0, speed=140.0, scantime=0.25)

Class for the rastered parameters of image.

Parameters:
  • spotsize (float) – laser-spot diameter, μm

  • speed (float) – laser movement speed, μm/s

  • scantime (float) – MS acquisition time, s

data_extent(shape)

Extent of data in μm.

Return type:

tuple[float, float, float, float]

get_pixel_height()

Pixel height in μm.

Return type:

float

get_pixel_width()

Pixel width in μm.

Return type:

float

class pewlib.config.SpotConfig(spotsize=100.0, spotsize_y=None)

Class for the spotwise parameters of image.

Parameters:

spotsize (float) – x, y distance between laser-spots, μm

get_pixel_height()

Pixel height in μm.

Return type:

float

get_pixel_width()

Pixel width in μm.

Return type:

float

Calibration

class pewlib.calibration.Calibration(intercept=0.0, gradient=1.0, unit='', rsq=None, error=None, points=None, weights='Equal')

Class for calibration storage and calculations.

Weights can be automatically generated by passing weighting string to weights.

Parameters:
  • intercept (float) – of line-of-best-fit

  • gradient (float) – of line-of-best-fit

  • unit (str) – calibration units, eg. ‘ppm’

  • rsq (float | None) – r² of line-of-best-fit

  • error (float | None) – error in line-of-best-fit

  • points (ndarray | None) – array of (x, y)

  • weights (str | tuple[str, ndarray]) – weighting {‘Equal’, ‘x’, ‘1/x’, ‘1/(x^2)’, ‘y’, ‘1/y’, ‘1/(y^2)’} or (name, array) of weights for linear-regression, same length as points

classmethod from_points(points, unit='', weights='Equal')

Create a Calibration from points.

Calulates linear-regression params from points.

Return type:

Calibration

to_array(size=None)

Convert to a Numpy array. Points and weights are trimmed or padded with nan to ‘size’ if passed.

Return type:

ndarray

pewlib.calibration.weighted_linreg(x, y, w=None)

Weighted linear regression.

Uses polyfit with sqrt(weights) for intercept and gradient.

Parameters:
  • x (ndarray) – 1d-array

  • y (ndarray) – array, same size as x

  • w (ndarray | None) – weights, same size as x

Return type:

tuple[float, float, float, float]

Returns:

gradient intercept r² error, S(y,x) the (unweighted) residual standard deviation

pewlib.calibration.weighted_rsq(x, y, w=None)

Calculate r² for weighted linear regression.

Parameters:
  • x (ndarray) – 1d-array

  • y (ndarray) – array, same size as x

  • w (ndarray | None) – weights, same size as x

Return type:

float

pewlib.calibration.weights_from_weighting(x, weighting, safe=True)

Get weighting for x.

Conveience function for calculating simple weightings. If safe then any zeros in x are replace with the minimum non-zero value.

Parameters:
  • x (ndarray) – 1d-array

  • weighting (str) – weighting string {‘Equal’, ‘x’, ‘1/x’, ‘1/(x^2)’}

  • safe (bool) – replace zeros with minimum

Return type:

ndarray

Returns:

weights, same size as x