Threshold

Description

Keep grid points or cells that respect the given threshold values.

threshold1 ==> threshold2

Initial grid shown on the left. Grid after threshold on the right.

Construction

import antares
myt = antares.Treatment('threshold')

Parameters

  • base: antares.Base

    The input base

  • variables: list(str)

    The name of variables on which the threshold is applied.

  • threshold: list(tuple)

    List of tuples of values (min, max) for each threshold variable. If a value is None, it will not be taken into account. So, variables must be greater or equal than min, type operator variables must be lesser or equal than max.

    example: if \(4 < x < 5\), then threshold = [(3.0, 3.5)] will test

    • if \(3.0 < x\)

    • if \(x < 3.5\)

    • the type operator will be applied between the two previous conditions

  • type: str, default= and

    Have all conditions simultaneously fulfilled (and) or at least one condition (or).

  • invert: bool, default= False

    Keep points or cells that are located outside the given threshold range. In other words, the bitwise_not operator is applied after each threshold have been applied on all variables. The bitwise_not operator is not applied on each tuple.

  • memory_mode: bool, default= False

    If True, the initial base is deleted on the fly to limit memory usage

  • with_families: bool, default= False

    If True, the output of the treatment contains rebuilt families based on the input base. All the families and all the levels of sub-families are rebuilt, but only attributes and Zone are transfered (not yet implemented for Boundary and Window).

Preconditions

With data located at nodes, the threshold variable must be continuous in the given domain of definition (i.e. the base)

e.g.: You can not go from one point with a value \(\pi\) to its neighbour that has a value \(-\pi\).

If the threshold variables are not shared, the threshold is based on the values of the threshold variables from the first Instant for each Zone. Indeed, the threshold could give different numbers of nodes per Instant, but as all the Instants of one Zone should have the same shape, it would lead to a shape AssertionError.

Postconditions

The output base is always unstructured. It does not contain any boundary condition.

The input base is made unstructured.

If with_families is enabled, the output base contains the reconstructed families of base.

Example

import antares
myt = antares.Treatment('threshold')
myt['base'] = base
myt['variables'] = ['x', 'ro']
myt['threshold'] = [(50., 70.), (None, 0.9)]
thres = myt.execute()

Main functions

class antares.treatment.TreatmentThreshold.TreatmentThreshold
execute()

Execute the threshold treatment.

Returns

The unstructured Base obtained after applying the threshold.

Return type

antares.Base

Example

"""
This example shows how to apply a threshold on a base.

Note that even if the input base is structured, the output of the
threshold treatment will be unstructured.
"""
import os
if not os.path.isdir('OUTPUT'):
    os.makedirs('OUTPUT')

from antares import Reader, Treatment, Writer

# ------------------
# Reading the files
# ------------------
reader = Reader('bin_tp')
reader['filename'] = os.path.join('..', 'data', 'ROTOR37', 'GENERIC', 'flow_<zone>_<instant>.dat')
ini_base = reader.read()

# ------------------------
# Threshold
# ------------------------
# Only the cells which respect the given threshold condition are kept
# in the result base. Note that the output dataset present a crinkly
# interface at the threshold position
treatment = Treatment('threshold')
treatment['base'] = ini_base
treatment['variables'] = ['x', 'ro']
treatment['threshold'] = [(None, 70.), (None, 0.9)]
result = treatment.execute()

# -------------------
# Writing the result
# -------------------
writer = Writer('bin_tp')
writer['filename'] = os.path.join('OUTPUT', 'ex_threshold.plt')
writer['base'] = result
writer.dump()