physical_data
Base class for all calculators that deal with physical data.
- class PhysicalData(parameters)[source]
Bases:
ABC
Base class for volumetric physical data.
Implements general framework to read and write such data to and from files. Volumetric data is assumed to exist on a 3D grid. As such it either has the dimensions [x,y,z,f], where f is the feature dimension. All loading functions within this class assume such a 4D array. Within MALA, occasionally 2D arrays of dimension [x*y*z,f] are used and reshaped accordingly.
- Parameters:
parameters (mala.Parameters) – MALA Parameters object used to create this class.
- parameters
MALA parameters object.
- Type:
mala.Parameters
- grid_dimensions
List of the grid dimensions (x,y,z)
- Type:
list
- class SkipArrayWriting(dataset, feature_size)[source]
Bases:
object
Optional/alternative parameter for write_to_openpmd_file function.
The function write_to_openpmd_file can be used:
either for writing the entire openPMD file, as the name implies
or for preparing and initializing the structure of an openPMD file, without actually having the array data at hand yet. This means writing attributes, creating the hierarchy and specifying the dataset extents and types.
In the latter case, no numpy array is provided at the call site, but two kinds of information are still required for preparing the structure, that would normally be extracted from the numpy array:
The dataset extent and type.
The feature size.
In order to provide this data, the numpy array can be replaced with an instance of the class SkipArrayWriting.
- Parameters:
dataset (openpmd_api.Dataset) – OpenPMD Data set to eventually write to.
feature_size (int) – Size of the feature dimension.
- dataset
OpenPMD Data set to eventually write to.
- Type:
mala.Parameters
- feature_size
Size of the feature dimension.
- Type:
list
- read_dimensions_from_numpy_file(path, read_dtype=False)[source]
Read only the dimensions from a numpy file.
- Parameters:
path (string) – Path to the numpy file.
read_dtype (bool) – If True, the dtype is read alongside the dimensions.
- Returns:
dimension_info – If read_dtype is False, then only a list containing the dimensions of the saved array is returned. If read_dtype is True, a tuple containing this list of dimensions and the dtype of the array will be returned.
- Return type:
list or tuple
- read_dimensions_from_openpmd_file(path, comm=None, read_dtype=False)[source]
Read only the dimensions from a openPMD file.
- Parameters:
path (string) – Path to the openPMD file.
read_dtype (bool) – If True, the dtype is read alongside the dimensions.
comm (MPI.Comm) – An MPI communicator to be used for parallelized I/O
- Returns:
dimension_info – A list containing the dimensions of the saved array.
- Return type:
list
- read_from_numpy_file(path, units=None, array=None, reshape=False)[source]
Read the data from a numpy file.
- Parameters:
path (string) – Path to the numpy file.
units (string) – Units the data is saved in.
array (np.ndarray) – If not None, the array to save the data into. The array has to be 4-dimensional.
reshape (bool) – If True, the loaded 4D array will be reshaped into a 2D array.
- Returns:
data – If array is None, a numpy array containing the data. Elsewise, None, as the data will be saved into the provided array.
- Return type:
numpy.ndarray or None
- read_from_openpmd_file(path, units=None, array=None)[source]
Read the data from a numpy file.
- Parameters:
path (string) – Path to the openPMD file.
units (string) – Units the data is saved in.
array (np.ndarray) – If not None, the array to save the data into. The array has to be 4-dimensional.
- Returns:
data – If array is None, a numpy array containing the data. Elsewise, None, as the data will be saved into the provided array.
- Return type:
numpy.ndarray or None
- write_to_numpy_file(path, array)[source]
Write data to a numpy file.
- Parameters:
path (string) – File to save into.
array (numpy.ndarray) – Array to save.
- write_to_openpmd_file(path, array, additional_attributes={}, internal_iteration_number=0)[source]
Write data to an OpenPMD file.
- Parameters:
path (string) – File to save into. If no file ending is given, .h5 is assumed. Alternatively: A Series, opened already.
array (Either numpy.ndarray or an SkipArrayWriting object) – Either the array to save or the meta information needed to create the openPMD structure.
additional_attributes (dict) – Dictionary containing additional attributes to be saved.
internal_iteration_number (int) – Internal OpenPMD iteration number. Ideally, this number should match any number present in the file name, if this data is part of a larger data set.
- write_to_openpmd_iteration(iteration, array, local_offset=None, local_reach=None, additional_metadata=None, feature_from=0, feature_to=None)[source]
Write a file within an OpenPMD iteration.
- Parameters:
iteration (OpenPMD iteration) – OpenPMD iteration into which to save.
array (numpy.ndarry) – Array to save.
additional_metadata (list) – If not None, and the selected class implements it, additional metadata will be read from this source. This metadata will then, depending on the class, be saved in the OpenPMD file.
local_offset (list) – [x,y,z] value from which to start writing the array.
local_reach (list) – [x,y,z] value until which to read the array.
feature_from (int) – Value from which to start writing in the feature dimension. With this parameter and feature_to, one can parallelize over the feature dimension.
feature_to (int) – Value until which to write in the feature dimension. With this parameter and feature_from, one can parallelize over the feature dimension.
- abstract property data_name
Get a string that describes the data (for e.g. metadata).
- abstract property feature_size
Get the feature dimension of this data.
- abstract property si_dimension
Dictionary containing the SI unit dimensions in OpenPMD format.
Needed for OpenPMD interface.
- abstract property si_unit_conversion
Numeric value of the conversion from MALA (ASE) units to SI.
Needed for OpenPMD interface.