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

from_meep_hdf5(cls, filepath, *[, ...])

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) – ScalarField or VectorField class 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:

    • ScalarField cls → first dataset found.

    • VectorField cls → all recognised vector components.

  • component (str, optional) – Specific component to extract (e.g., "ex"). When given, a single ScalarField is always returned, regardless of cls.

  • resolution (float, optional) – Meep resolution (grid points per unit length). Used to build spatial coordinate axes. Defaults to 1.0 when 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 component is given, or only one component is found, or cls is ScalarField.

  • 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 h5py is 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")