FieldVariable#
- class fridom.framework.field_variable.FieldVariable(mset: ModelSettingsBase, name: str, position: Position | None = None, arr: ndarray | None = None, long_name: str = 'Unnamed', units: str = 'n/a', nc_attrs: dict | None = None, is_spectral: bool = False, topo: list[bool] | None = None, flags: dict | list | None = None, bc_types: tuple[BCType] | None = None)[source]#
Bases:
objectClass for field variables in the framework.
Description#
TODO
Parameters#
- msetModelSettings
ModelSettings object
- namestr
Name of the FieldVariable
- positionfr.grid.Position (default cell_center)
Position of the FieldVariable on the grid
- is_spectralbool
True if the FieldVariable should be initialized in spectral space
- topolist[bool] (default None)
Topology of the FieldVariable. If None, the FieldVariable is assumed to be fully extended in all directions. If a list of booleans is given, the FieldVariable has no extend in the directions where the corresponding entry is False.
- bc_typestuple[BCType] (default None)
Tuple of BCType objects that specify the type of boundary condition in each direction. If None, the default boundary conditions is Neumann.
- arrndarray (default None)
The array to be wrapped
- __init__(mset: ModelSettingsBase, name: str, position: Position | None = None, arr: ndarray | None = None, long_name: str = 'Unnamed', units: str = 'n/a', nc_attrs: dict | None = None, is_spectral: bool = False, topo: list[bool] | None = None, flags: dict | list | None = None, bc_types: tuple[BCType] | None = None) None[source]#
Methods
__init__(mset, name[, position, arr, ...])abs()Absolute values of the FieldVariable.
Apply boundary conditions to the FieldVariable.
diff(axis[, order])Compute the partial derivative along an axis.
fft([padding])Fourier transform of the FieldVariable.
get_kw()Return keyword arguments for the FieldVariable constructor.
get_mesh()Get the meshgrid of the FieldVariable.
grad([axes])Compute the gradient.
has_nan()Check if the FieldVariable contains NaN values.
ifft([padding])Inverse Fourier transform of the FieldVariable.
Global integral of the FieldVariable.
interpolate(destination)Interpolate the field to the destination position.
laplacian([axes])Compute the Laplacian.
max([axes])Maximum value of the FieldVariable over the whole domain.
min([axes])Minimum value of the FieldVariable over the whole domain.
norm_l2()Compute the numpy.linalg.norm of the FieldVariable.
sum([axes])Sum of the FieldVariable over the whole domain in the specified axes.
sync()Synchronize the FieldVariable (exchange boundary values).
unpad()Remove padding from the FieldVariable.
Attributes
The underlying array.
The boundary condition types for the FieldVariable.
Dictionary with flag options for the FieldVariable.
The grid object.
Dictionary with information about the field.
True if the FieldVariable is in spectral space.
The long name of the FieldVariable.
The model settings object.
The name of the FieldVariable.
Dictionary with additional attributes for the NetCDF file or xarray.
The position of the FieldVariable on the staggered grid.
Topology of the FieldVariable.
The unit of the FieldVariable.
Convert to xarray DataArray.
Convert a slice of the FieldVariable to xarray DataArray.
- fft(padding: FFTPadding = FFTPadding.NOPADDING) FieldVariable[source]#
Fourier transform of the FieldVariable.
If the FieldVariable is already in spectral space, the inverse Fourier transform is returned.
- Returns:
FieldVariable: Fourier transform of the FieldVariable
- ifft(padding: FFTPadding = FFTPadding.NOPADDING) FieldVariable[source]#
Inverse Fourier transform of the FieldVariable.
- sync() FieldVariable[source]#
Synchronize the FieldVariable (exchange boundary values).
- apply_water_mask() FieldVariable[source]#
Apply boundary conditions to the FieldVariable.
- diff(axis: int, order: int = 1) FieldVariable[source]#
Compute the partial derivative along an axis.
\[\partial_i^n f\]with axis \(i\) and order \(n\).
Parameters#
- axisint
The axis along which to differentiate.
- orderint
The order of the derivative. Default is 1.
Returns#
- FieldVariable
The derivative of the field along the specified axis.
- grad(axes: list[int] | None = None) tuple[FieldVariable | None][source]#
Compute the gradient.
\[\begin{split}\nabla f = \begin{pmatrix} \partial_1 f \\ \dots \\ \partial_n f \end{pmatrix}\end{split}\]Parameters#
- axeslist[int] | None (default is None)
The axes along which to compute the gradient. If None, the gradient is computed along all axes.
Returns#
- tuple[FieldVariable | None]
The gradient of the field along the specified axes. The list contains the gradient components along each axis. Axis which are not included in axes will have a value of None. E.g. for a 3D grid, diff.grad(f, axes=[0, 2]) will return `[df/dx, None, df/dz].
- laplacian(axes: tuple[int] | None = None) FieldVariable[source]#
Compute the Laplacian.
\[\nabla^2 f = \sum_{i=1}^n \partial_i^2 f\]Parameters#
- axestuple[int] | None (default is None)
The axes along which to compute the Laplacian. If None, the Laplacian is computed along all axes.
Returns#
- FieldVariable
The Laplacian of the field.
- interpolate(destination: Position) FieldVariable[source]#
Interpolate the field to the destination position.
Parameters#
- destinationfr.grid.Position
The position to interpolate to.
Returns#
- FieldVariable
The interpolated field.
- property info: dict#
Dictionary with information about the field.
- property xr: xr.DataArray#
Convert to xarray DataArray.
- property xrs: SliceableAttribute#
Convert a slice of the FieldVariable to xarray DataArray.
Example:#
Let f be a large 3D FieldVariable and we want to convert the top of the field to an xarray DataArray. To avoid loading the whole field into memory, we can use slicing:
data_array = f.xrs[:,:,-1] # Only the top of the field
- property arr: ndarray#
The underlying array.
- property name: str#
The name of the FieldVariable.
- property long_name: str#
The long name of the FieldVariable.
- property units: str#
The unit of the FieldVariable.
- property nc_attrs: dict#
Dictionary with additional attributes for the NetCDF file or xarray.
- property is_spectral: bool#
True if the FieldVariable is in spectral space.
- property topo: list[bool]#
Topology of the FieldVariable.
Description#
Field Variables do not have to be extended in all directions. For example, one might want to create a 2D forcing field for a 3D simulation, that only depends on x and y. In this case, the topo of the FieldVariable would be [True, True, False].
- property flags: dict#
Dictionary with flag options for the FieldVariable.
- property mset: ModelSettingsBase#
The model settings object.
- abs() FieldVariable[source]#
Absolute values of the FieldVariable.
- sum(axes: tuple[int] | None = None) float[source]#
Sum of the FieldVariable over the whole domain in the specified axes.
- max(axes: tuple[int] | None = None) float[source]#
Maximum value of the FieldVariable over the whole domain.