# 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)

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, which can also be empty to disable corrections completely. For example:

from libertem.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,
))

class libertem.corrections.corrset.CorrectionSet(dark=None, gain=None, excluded_pixels=None)[source]

A set of corrections to apply.

New in version 0.6.0.

__init__(dark=None, gain=None, excluded_pixels=None)[source]
Parameters
• dark (np.ndarray) – A ND array containing a dark frame to substract from all frames, its shape needs to match the signal shape of the dataset.

• gain (np.ndarray) – A ND 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. A sparse.COO array can be directly constructed from a coordinate array, using sparse.COO(coords=coords, data=1, shape=ds.shape.sig)