eradiate.data.convert.make_prt_v1#

eradiate.data.convert.make_prt_v1(w, phamat, mu, theta, ext, ssa, phase, state_dims=None, nangles=None, pmom=None, nmom=None, grid_res=3, attrs=None, normalize=False, check=None)#

Create a new dataset in any variant of the Prt v1 format.

All Prt variants share the core dimensions w, phamat, iangle and imom. Variants add state dimensions, inserted after w (see Extensions): e.g. Prt-MS adds reff and veff, Prt-Hum adds hum. These are passed through state_dims; in the shapes below, *state stands for their sizes, in the order of state_dims. Without state dimensions, the output is in the Prt-Core format.

Parameters:
  • w (quantity) – Wavelength, shape (nw,).

  • phamat (list of str) – Phase matrix component list, shape (nphamat,).

  • mu (quantity) – Scattering angle cosine, shape (nw, *state, nangle).

  • theta (quantity) – Scattering angle, shape (nw, *state, nangle).

  • ext (quantity) – Extinction coefficient, shape (nw, *state).

  • ssa (quantity) – Single-scattering albedo, shape (nw, *state).

  • phase (quantity) – Phase matrix values, shape (nphamat, nw, *state, nangle). Integral normalized to 2 (i.e. ∫ p(μ) dμ = 2).

  • state_dims (dict, optional) – Mapping of state dimension names to their coordinate values, each of shape (n,) and strictly increasing (irregular grids are supported). Known dimensions (reff, veff, hum) get CF metadata; unknown ones use their name as standard and long name.

  • nangles (ndarray, optional) – Number of valid angular samples, shape (nw, *state), dtype int. When provided, entries beyond nangles in mu, theta, and phase must be NaN-padded. The nangles dataset variable is always written; if not provided, it is inferred by counting non-NaN entries in the first phase matrix component.

  • pmom (ndarray, optional) – Legendre polynomials for the (1,1) phase matrix element, shape (nw, *state, nimom). If not provided, they are computed automatically from phase and theta using compute_pmom() with coefficients=True.

  • nmom (int or ndarray, optional) – Controls the number of Legendre polynomials. The nmom dataset variable is always written when pmom is present.

    • None (default) — when pmom is not provided, compute 129 coefficients and store their count as a uniform nmom array; when pmom is provided explicitly, infer counts by counting non-NaN entries in the first phase matrix component, consistent with the NaN-padding convention.

    • int — scalar moment count; used as the target for automatic computation and stored as a uniform nmom array.

    • ndarray shape (nw, *state) — count stored as-is. pmom must be provided explicitly when nmom is an ndarray.

  • grid_res (int, default: 3) – Angular grid resolution passed to compute_pmom() when pmom is computed automatically. 3 uses the input grid with the exact BDE method (recommended). See compute_pmom() for all options.

  • attrs (dict) – Dataset attributes.

  • normalize (bool, default: False) – If True, rescale the phase matrix so that p₁₁ integrates to 2 over μ ∈ [-1, 1]. All phase matrix components are multiplied by the same factor (2 / ∫p₁₁ dμ), preserving their relative magnitudes. When False (default), the caller is responsible for providing a pre-normalized phase array.

  • check ({"none", "fast", "full"}, optional) – Controls validation of the mu angular grid sort order.

    • None or "none" — no check (default).

    • "fast" — sampling-based check: validates a random 10 % of entries (at least one). Intended as a cheap guard during bulk production runs.

    • "full" — validates every entry.

    A ValueError is raised if any sampled row is not strictly monotonically increasing in μ. Only the valid (non-NaN) portion of each row is checked (bounded by nangles).

Returns:

Dataset

Raises:
  • ValueError – If a value check fails, if mu does not have one dimension per core and state dimension, or if a state dimension coordinate is not strictly increasing.

  • TypeError – If nmom is an ndarray but pmom is not provided.