LiberTEM icon indicating copy to clipboard operation
LiberTEM copied to clipboard

Corrections: UDF preferences

Open sk1p opened this issue 4 years ago • 0 comments

To allow UDFs to implement their own corrections support, there needs to be an interface to specify the preferences. See #778 for discussions.

For example, some UDFs may want to fold the correction into the computation in a more efficient way than as a pre-processing step (ApplyMasksUDF etc.)

The corrections are already available on UDFMeta, once #778 is merged.

Here are some strawmen examples for discussion (from #778):

The very explicit way:

def postprocess(self):
    my_own_apply_corrections_fn(self.results.something_sig_shaped, self.meta.corrections)

def get_correction_preferences(self):
    return {"custom_corrections": self.meta.set_of_corrections == {UDF.CORR_DARK_FRAME, UDF.CORR_GAIN_MAP, UDF.CORR_PATCH_PIXELS}}

Something a bit more "automatic", for supporting all kinds of linear corrections:

def postprocess(self):
    my_apply_basic_corrections(self.results.something_sig_shaped, number_of_frames)

def get_correction_preferences(self):
    return {"custom_corrections": self.meta.set_of_corrections == UDF.CORR_SET_BASIC}

Support for patching masks:

def get_task_data(self):
    masks = ...  # possibly need to fold this into the mask container somehow, or the mask factory fn
    self.meta.corrections.patch_masks(masks)
    return {"masks": masks}

def get_correction_preferences(self):
    # we know what can be patched into masks, so we can also provide that as a set of identifiers:
    return {"custom_corrections": self.meta.set_of_corrections == UDF.CORR_SET_MASK_PATCH}

UDF.CORR_SET_BASIC is set into stone, so people can re-implement it in any way they like. The UDF has access to the correction metadata (dark frame, gain map, list of excluded pixels) and helper functions (correct, correct_dot_mask)

sk1p avatar Jun 08 '20 18:06 sk1p