4.1.1 pde.fields.base module
Defines base class of fields or collections, which are discretized on grids.
- class FieldBase(grid, data, *, label=None)[source]
Bases:
object
Abstract base class for describing (discretized) fields.
- Parameters:
- apply(func, out=None, *, label=None, evaluate_args=None)[source]
Applies a function/expression to the data and returns it as a field.
- Parameters:
func (callable or str) – The (vectorized) function being applied to the data or an expression that can be parsed using sympy (
evaluate()
is used in this case). The local field values can be accessed using the field labels for a field collection and via the variable c otherwise.out (FieldBase, optional) – Optional field into which the data is written
label (str, optional) – Name of the returned field
evaluate_args (dict) – Additional arguments passed to
evaluate()
. Only used when func is a string.self (TField)
- Returns:
Field with new data. Identical to out if given.
- Return type:
- assert_field_compatible(other, accept_scalar=False)[source]
Checks whether other is compatible with the current field.
- conjugate()[source]
Returns complex conjugate of the field.
- Returns:
the complex conjugated field
- Return type:
- Parameters:
self (TField)
- abstract copy(*, label=None, dtype=None)[source]
Return a new field with the data (but not the grid) copied.
- Parameters:
label (str, optional) – Name of the returned field
dtype (numpy dtype) – The data type of the field. If omitted, it will be determined from data automatically or the dtype of the current field is used.
self (TField)
- Returns:
A copy of the current field
- Return type:
DataFieldBase
- property dtype: dtype[Any] | None | type[Any] | _SupportsDType[dtype[Any]] | str | tuple[Any, int] | tuple[Any, SupportsIndex | Sequence[SupportsIndex]] | list[Any] | _DTypeDict | tuple[Any, Any]
the numpy dtype of the underlying data.
- Type:
DTypeLike
- classmethod from_file(filename)[source]
Create field from data stored in a file.
Field can be written to a file using
FieldBase.to_file()
.Example
Write a field to a file and then read it back:
field = pde.ScalarField(...) field.write_to("test.hdf5") field_copy = pde.FieldBase.from_file("test.hdf5")
- abstract get_image_data()[source]
Return data for plotting an image of the field.
- Parameters:
- Returns:
Information useful for plotting an image of the field
- Return type:
- abstract get_line_data(scalar='auto', extract='auto')[source]
Return data for a line plot of the field.
- Parameters:
- Returns:
Information useful for performing a line plot of the field
- Return type:
- plot_interactive(viewer_args=None, **kwargs)[source]
Create an interactive plot of the field using
napari
For a detailed description of the launched program, see the napari webpage.
- Parameters:
viewer_args (dict) – Arguments passed to
napari.viewer.Viewer
to affect the viewer.**kwargs – Extra arguments passed to the plotting function
- Return type:
None
- split_mpi(decomposition='auto')[source]
Splits the field onto subgrids in an MPI run.
In a normal serial simulation, the method simply returns the field itself. In contrast, in an MPI simulation, the field provided on the main node is split onto all nodes using the given decomposition. The field data provided on all other nodes is not used.
- Parameters:
decomposition (list of ints) – Number of subdivision in each direction. Should be a list of length grid.num_axes specifying the number of nodes for this axis. If one value is -1, its value will be determined from the number of available nodes. The default value auto tries to determine an optimal decomposition by minimizing communication between nodes.
self (TField)
- Returns:
The part of the field that corresponds to the subgrid associated with the current MPI node.
- Return type:
- to_file(filename, **kwargs)[source]
Store field in a file.
The extension of the filename determines what format is being used. If it ends in .h5 or .hdf, the Hierarchical Data Format is used. The other supported format are images, where only the most typical formats are supported.
To load the field back from the file, you may use
FieldBase.from_file()
.Example
Write a field to a file and then read it back:
field = pde.ScalarField(...) field.write_to("test.hdf5") field_copy = pde.FieldBase.from_file("test.hdf5")
- Parameters:
filename (str) – Path where the data is stored
**kwargs – Additional parameters may be supported for some formats
- Return type:
None