InputOutput (I/O)
IO contains classes and functions to read and write SEM data.
The main modules are:
We have developed wrapper functions that can be used to read and write data in a more user-friendly way. Here we show them:
Wrappers to ease IO
- pysemtools.io.wrappers.partition_read_data(comm, fname: str | None = None, distributed_axis: int = 0)
Generate partition information for hdf5 files. Useful if needing to read or write multiple files with the same partitioning, such that the read/write functions does not need to do the same every time.
- Parameters:
- commMPI.Comm
The MPI communicator
- fnamestr
The name of the file to read
- distributed_axisint, optional
The axis along which the data is distributed, by default 0. This is used to determine how many elements to read from the file in parallel.
- Returns:
- list
A list of slices corresponding to the local data to be read by each process
- pysemtools.io.wrappers.read_data(comm, fname: str, keys: list[str], parallel_io: bool = False, dtype=<class 'numpy.float32'>, distributed_axis: int = 0, slices: list | None = None)
Read data from a file and return a dictionary with the names of the files and keys
- Parameters:
- comm, MPI.Comm
The MPI communicator
- fnamestr
The name of the file to read
- keyslist[str]
The keys to read from the file
- parallel_iobool, optional
If True, read the file in parallel, by default False. This is aimed for hdf5 files, and currently it does not work if True
- dtypenp.dtype, optional
The data type of the data to read, by default np.single
- distributed_axisint, optional
The axis along which the data is distributed, by default 0. This is used to determine how many elements to read from the file in parallel.
- sliceslist, optional
A list of slices to read from the file. If None, the local data will be read based on the distributed_axis and the communicator. If provided, it should match the number of dimensions in the data. Note that if you are reading in parallel, the slices should be provided in such a way that they correspond to the local data on each process, otherwise the data will be replicated. If in doubt, do not provide slices, and the local data will be determined automatically.
- Returns:
- dict
A dictionary with the keys and the data read from the file
- pysemtools.io.wrappers.write_data(comm, fname: str, data_dict: dict[str, ~numpy.ndarray], parallel_io: bool = False, dtype=<class 'numpy.float32'>, msh: ~pysemtools.datatypes.msh.Mesh | list[~numpy.ndarray] | None = None, write_mesh: bool = False, distributed_axis: int = 0, uniform_shape: bool = False)
Write data to a file
- Parameters:
- comm, MPI.Comm
The MPI communicator
- fnamestr
The name of the file to write
- data_dictdict
The data to write to the file
- parallel_iobool, optional
If True, write the file in parallel, by default False. This is aimed for hdf5 files, and currently it does not work if True
- dtypenp.dtype, optional
- mshMesh, optional
The mesh object to write to a fld file, by default None
- write_meshbool, optional
Only valid for writing fld files
- distributed_axisint, optional
The axis along which the data is distributed, by default 0
- uniform_shapebool, optional
If True, the global shape of the data is assumed to be uniform, by default False
Additionally, there exist a class to read probes written in the csv format. Here we show it:
- class pysemtools.io.read_probes.ProbesReader(file_name: str)
A class to read probed fields from a Neko simulation.
- Attributes:
- pointsnp.ndarray of floats
The probe locations.
- timesnp.array of floats
The times at each time step.
- field_nameslist of strings
The names of the fields.
- fieldsdictionary of np.array
The fields at each time step.