Corrections
LiberTEM includes correction facilities to substract a dark frame, multiply with a gain map and patch out defect pixels (dead/hot). These corrections are applied on-the-fly when running a UDF, both in the GUI and via the Python API.
The following data set formats ship with some of this correction data:
FRMS6: dark frame is loaded from the first part of the data set
SEQ: dark frame and gain map are loaded from MRC sidecar files
<basename>.dark.mrc
and<basename>.gain.mrc
, and bad pixels are loaded from<basename>.Config.Metadata.xml
.
In the GUI, all corrections that are supplied by the data set will be applied. In the Python API,
the user can decide to pass their own corrections to apply, via the corrections
parameter
of Context.run()
and Context.run_udf()
. It expects a CorrectionSet
object,
for example:
from libertem.io.corrections import CorrectionSet
import sparse
# excluded pixels are passed as a sparse COO matrix, which can be built
# in different ways, here is one way:
excluded = np.zeros((32, 32), dtype=bool)
excluded[5, 16] = 1
excluded = sparse.COO(excluded)
ctx.run_udf(udf=SumUDF(), dataset=dataset, corrections=CorrectionSet(
dark=np.zeros((32, 32)),
gain=np.ones((32, 32)),
excluded_pixels=excluded,
))
It can also be empty to disable corrections:
ctx.run_udf(udf=SumUDF(), dataset=dataset, corrections=CorrectionSet())
- class libertem.io.corrections.CorrectionSet(dark: ndarray | None = None, gain: ndarray | None = None, excluded_pixels: COO | None = None, allow_empty: bool = False)[source]
A set of corrections to apply.
New in version 0.6.0.
- Parameters:
dark (np.ndarray) – An array containing a dark frame to substract from all frames, its shape needs to match the signal shape of the dataset.
gain (np.ndarray) – An array containing a gain map to multiply with each frame, its shape needs to match the signal shape of the dataset.
excluded_pixels (sparse.COO) – A “sparse pydata” COO array containing only entries for pixels that should be excluded. The shape needs to match the signal shape of the dataset. Can also be anything that is directly compatible with the
sparse.COO
constructor, for example a “roi-like” NumPy array. Asparse.COO
array can be directly constructed from a coordinate array, usingsparse.COO(coords=coords, data=1, shape=ds.shape.sig)
allow_empty (bool) – Do not throw an exception if a repair environment for an excluded pixel is empty. The pixel is left uncorrected in that case.