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 datacalibration (
dict
[str
,Calibration
] |None
) – dict mapping elements to calibrations, optionalconfig (
Config
|None
) – laser parametersinfo (
dict
[str
,str
] |None
) – dict (str, str) of additional info
- add(element, data, calibration=None)
Adds a new element.
- Parameters:
element (
str
) – element namedata (
ndarray
) – arraycalibration (
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:
- 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, optionalcalibrate (
bool
|None
) – apply calibrationextent (
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, μmspeed (
float
) – laser movement speed, μm/sscantime (
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
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-fitgradient (
float
) – of line-of-best-fitunit (
str
) – calibration units, eg. ‘ppm’rsq (
float
|None
) – r² of line-of-best-fiterror (
float
|None
) – error in line-of-best-fitpoints (
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:
- 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-arrayy (
ndarray
) – array, same size as xw (
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
See also
- pewlib.calibration.weighted_rsq(x, y, w=None)
Calculate r² for weighted linear regression.
- Parameters:
x (
ndarray
) – 1d-arrayy (
ndarray
) – array, same size as xw (
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-arrayweighting (
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