gwexpy.interop.meep_ο
Interoperate with Meep FDTD simulation output files.
Interoperability with Meep FDTD simulation output files.
Meepβs output_field_function writes HDF5 files where each field component
is stored as a pair of real/imaginary datasets named <field>.r / <field>.i
(complex fields) or as a single dataset named <field> (real-only fields).
This module reads those HDF5 files and reconstructs GWexpy ScalarField or
VectorField objects without requiring the Meep Python library itself β only
h5py is needed.
References
https://meep.readthedocs.io/en/latest/Python_User_Interface/#output-functions
Functions
|
Read a Meep HDF5 field output into a ScalarField or VectorField. |
- gwexpy.interop.meep_.from_meep_hdf5(cls: type, filepath: str | Path, *, field_name: str | None = None, component: str | None = None, resolution: float | None = None, origin: tuple[float, ...] | None = None, axis0_domain: Literal['time', 'frequency'] = 'frequency', unit: Any | None = None) Any[source]
Read a Meep HDF5 field output into a ScalarField or VectorField.
Meep writes electromagnetic field data as HDF5 files with dataset naming conventions:
Complex fields:
<name>.r(real part) and<name>.i(imaginary part).Real-only fields:
<name>(no suffix).
Common field names are
ex,ey,ez,hx,hy,hz.- Parameters:
cls (type) β
ScalarFieldorVectorFieldclass to instantiate.filepath (str or Path) β Path to the HDF5 file produced by Meep.
field_name (str, optional) β
Base name of the field dataset(s) to read. If None, all datasets are auto-detected:
ScalarFieldcls β first dataset found.VectorFieldcls β all recognised vector components.
component (str, optional) β Specific component to extract (e.g.,
"ex"). When given, a singleScalarFieldis always returned, regardless of cls.resolution (float, optional) β Meep resolution (grid points per unit length). Used to build spatial coordinate axes. Defaults to
1.0when not set.origin (tuple of float, optional) β Grid origin coordinates (x, y, z) in Meep length units. Defaults to
(0.0, 0.0, 0.0).axis0_domain ({"time", "frequency"}, default "frequency") β Physical domain of axis 0 in the resulting field. Meep frequency-domain outputs should use
"frequency"; time snapshots should use"time".unit (str or astropy.units.Unit, optional) β Physical unit to assign to the field data.
- Returns:
ScalarField β When
componentis given, or only one component is found, or cls isScalarField.VectorField β When multiple vector components are found and cls is
VectorField.
- Raises:
ValueError β If no matching datasets are found in the file, or if real/imaginary dataset shapes do not match.
ImportError β If
h5pyis not installed.
Examples
Read the Ez component from a frequency-domain output:
>>> from gwexpy.fields import ScalarField >>> sf = ScalarField.from_meep_hdf5("ez.h5")
Read all E-field components as a VectorField:
>>> from gwexpy.fields import VectorField >>> vf = VectorField.from_meep_hdf5("fields.h5")