Translation¶
Description¶
Translates zones of a base with respect to translation vector.
Construction¶
import antares
myt = antares.Treatment('translation')
Parameters¶
- base:
Base
The input base to be translated.
- base:
- coordinates: list(str), default= None
The variable names that define the set of coordinates. If None the default coordinate system of the base is used.
- vector:
seq(float)
, default=*[]* The displacement vector (sequence of floats) used to translate the base.
- vector:
- memory_mode: bool, default= False
If True, the modifications are done directly on the input base to limit memory usage. If False, a new base is created.
Preconditions¶
The coordinate system must be the cartesian coordinate system.
The dimension of vector must match the length of the coordinate system
Postconditions¶
If memory_mode = False, the input base remains unchanged and the output base has the same structure as the input base. If memory_mode = True, the input base is modified in-place and the returned base is the same object as the input base.
Example¶
The following example shows a translation of a base by a vector [10., 10., 10.].
import antares
myt = antares.Treatment('translation')
myt['base'] = base
myt['coordinates'] = ['x', 'y', 'z']
myt['vector'] = [10., 10., 10.]
translated_base = myt.execute()
Main functions¶
Example¶
import antares
import numpy as np
import os
output_folder = os.path.join("OUTPUT", "TreatmentTranslation")
os.makedirs(output_folder, exist_ok=True)
X, Y = np.mgrid[0:10, 0:10]
# Create base to translate
base = antares.Base()
base.init()
base[0][0]['x'] = X
base[0][0]['y'] = Y
base[0][0]['myvar'] = X*Y # create a dummy variable
base.coordinate_names = ['x', 'y']
# Dump base to translate
w = antares.Writer('hdf_antares')
w['base'] = base
w['filename'] = os.path.join(output_folder, 'base_to_translate')
w.dump()
# Apply translation treatment
translation = antares.Treatment('translation')
translation['base'] = base
translation['vector'] = [15, 20]
translated_base = translation.execute()
# Dump result
w = antares.Writer('hdf_antares')
w['base'] = translated_base
w['filename'] = os.path.join(output_folder, 'translated_base')
w.dump()