Skip to content

How to add a new field transformation algorithm

Paolo Tormene edited this page Dec 4, 2015 · 1 revision

Adding a new field transformation algorithm to the IRMT plugin is quite straightforward.

Let's call such new algorithm NEW_ALG. It is sufficient to define a new decorated function to svir/calculations/transformation_algs.py, as in the following example:

@TRANSFORMATION_ALGS.add('NEW_ALG')
def new_alg(input_list, variant_name=None, inverse=False):
r"""
Direct:
    :math:`f(x_i) = something`
"""
invalid_input_values = []
output_list = []
if variant_name:
    raise NotImplementedError("%s variant not implemented" % variant_name)
if inverse:
    raise NotImplementedError("Inverse function not implemented")
# implement the direct transformation here
# (and accumulate invalid input values if present)
for x in input_list:
    try:
        output = someoperation(x)
    except:
        output = QPyNullVariant(float)
        invalid_input_values.append(x)
    output_list.append(output)
return output_list, invalid_input_values
Clone this wiki locally