PsiData#
- PsiData(ifile, /, model='mas', **kwargs)[source]#
Open a PSI MAS or POT3D HDF file and return the appropriate data reader.
Inspects the file extension and model argument, selects the correct concrete reader (HDF5 or HDF4 backend), and returns it. No data are read from disk at construction time — metadata is resolved from the filename and HDF file attributes, and data transfer happens only inside
read()orvslice(). Full-array reads are cached automatically; partial reads are not.The returned reader exposes the following attributes:
quantity— canonical lower-case quantity identifier (e.g.'br').sequence— integer time-step sequence number.unit—Unitfor code → physical conversion; normalization constants are defined inpsi_io._units.mesh— per-axis Yee-grid stagger as a tuple ofMeshmembers; seepsi_io._mesh.props— fullPropsdescriptor (name, description, unit, mesh code); seepsi_io._models.description— human-readable quantity description.scales—Scales(r, t, p)named tuple of coordinate scale readers, each supporting the sameread()interface as the main reader.shape,ndim,size,nbytes,dtype,attrs— array metadata; shape is in HDF storage order(Nφ, Nθ, Nr).is_cached—Trueafter a full-array read has been cached.
Use
read()to load a slice by index andvslice()to slice by physical coordinate value with linear interpolation. Both return data asQuantityobjects in physical(r, θ, φ)order. The object also supports the context-manager protocol.Warning
POT3D unit convention
POT3D applies no normalization to its output. The stored values are in whatever physical unit the input photospheric magnetogram used — most commonly Gauss, but this is not encoded in the file. The default
unitfor POT3D isdimensionless_unscaled(scale factor 1), soread(unit='physical')will not perform a meaningful conversion unless the correct unit is supplied at construction:reader = PsiData('br001.h5', model='pot3d', unit='Gauss') data, r, t, p = reader.read()
- Parameters:
- ifile
PathLike Path to the HDF4 (
.hdf) or HDF5 (.h5) file.- model{‘mas’, ‘pot3d’}, optional
PSI model type. Defaults to
'mas'.- dataset_id
str, optional Dataset name within the HDF file. Defaults to the PSI standard identifier for the given format.
- quantity
str, optional Override the quantity name inferred from the filename or file attributes.
- sequence
int, optional Override the time-step sequence number.
- unit
stroru.Unit, optional Override the code-to-physical unit from the quantity’s
Propsentry. Accepts any string parseable byUnitor aUnitinstance.- mesh
MeshCodeType, optional Override the mesh stagger from the quantity’s
Propsentry.
- ifile
- Returns:
- out
H5DataorH4Data Open reader implementing the full
_HdfInterfaceAPI. Concrete type depends on the file extension.
- out
- Raises:
ValueErrorIf the file extension / model combination is unsupported or required metadata cannot be resolved.
FileNotFoundErrorIf ifile does not exist.
See also
astropy.units.UnitUnit constructor — accepts strings, compound expressions, and
Unitinstances.astropy.units.Quantity.toUnit conversion used internally when a
unitstring is supplied toread().
Examples
Read a MAS radial field — full array with coordinate scales, then convert:
>>> from psi_io.mhd_io import PsiData >>> reader = PsiData('br001001.h5') >>> data, r, t, p = reader.read() # code units (MAS_b) >>> data, r, t, p = reader.read(unit='Gauss') # convert to Gauss
Use as a context manager:
>>> with PsiData('vr001001.h5') as reader: ... data, r, t, p = reader.read(unit='km/s')
Inspect metadata without loading data:
>>> reader = PsiData('rho001001.h5') >>> reader.quantity # 'rho' >>> reader.unit # MAS_n >>> reader.mesh # (Mesh.HALF, Mesh.HALF, Mesh.HALF) >>> reader.is_cached # False