physical_data
Base class for all calculators that deal with physical data.
- class PhysicalData(parameters)[source]
Bases:
ABC
Base class for physical data.
Implements general framework to read and write such data to and from files.
- 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.
- 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.
- 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.
- 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.
- 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) – Dict 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.
- 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.