erTable

class PlasmaCalcs.mhd.mhd_er_tables.erTable(xtable=UNSET, quantity=None, *, ln_quant=False, original=True, **kw__None)

Bases: object

lookup table from eperm and r to quantity. Units are always ‘raw’ units.

Call self(r=r, eperm=eperm) to get value of quantity at eperm and r.
(equivalent: self.interp(r=r, eperm=eperm). See help(self.interp) for more details.)
xtable: UNSET or xarray.DataArray, probably 2D
must have dims & coords for ‘eperm’ and ‘r’.
eperm = internal energy per unit mass; r = mass density.
UNSET –> will call self.load_xtable() to load it.
quantity: None or str
name of quantity, if known.
ln_quant: bool
whether this quantity’s values are in ln-space. E.g. ln(P) instead of P.
original: bool
tells whether this erTable is original (e.g., didn’t come from slicing another table).

Methods

can_assume_sorted()

return whether eperm and r coords are sorted (in non-decreasing order).

coarsen([step, dim])

return self, isel'd with slice(None, None, step) along dim(s).

from_array(array, *, epermcoords, rcoords[, ...])

create reTable from unlabeled array, and coords.

interp(*, r[, eperm, e, ln, keep_er_coords])

return values of quantity at eperm and r.

interp_inverse(quantity, *[, r, eperm, ln])

return values of r or eperm, given quantity values and other coord's values.

isel([indexers])

return new erTable like self but with self.xtable.isel(...).

labeled_xtable(xtable, *[, quantity, units])

return copy of xarray.DataArray, labeled with name=quantity and attrs['units']='raw'

load_xtable()

load xtable.

xtable_from_array(array, *, epermcoords, rcoords)

create xtable from unlabeled array and coords.

_new(**kw_overrides)

return new erTable like self but with some attributes overridden by kw_overrides.

Attributes

coords_are_sorted

whether eperm and r coords (of self.xtable) are sorted (in non-decreasing order).

extrapolate_kind

None or str specifying how to handle extrapolation when interp() is called.

xtable

xarray.DataArray, probably 2D; must have dims for eperm and r.

_new(**kw_overrides)

return new erTable like self but with some attributes overridden by kw_overrides.

can_assume_sorted()

return whether eperm and r coords are sorted (in non-decreasing order).

If True, can assume sorted for xarray interp calls, which improves efficiency signficantly.
coarsen(step=2, dim=None)

return self, isel’d with slice(None, None, step) along dim(s).

dim: None, ‘eperm’, or ‘r’.
dim to coarsen along.
None –> coarsen along both ‘eperm’ and ‘r’.
property coords_are_sorted

whether eperm and r coords (of self.xtable) are sorted (in non-decreasing order).

Cache result for efficiency, assumes coords are not changed later.
property extrapolate_kind

None or str specifying how to handle extrapolation when interp() is called.

None –> use xarray’s default (makes crash or NaNs if extrapolation needed).
‘constant’ –> use nearest neighbor value when extrapolating.
classmethod from_array(array, *, epermcoords, rcoords, quantity=None, extra_dims=None, ln_quant=False, **kw_init)

create reTable from unlabeled array, and coords.

array: array, at least 2D

first two dims must correspond to r (dim0), and eperm (dim1)
additional dims will be unlabeled, E.g. dim_2, dim_3, dim_4, …
epermcoords, rcoords: 1D array
coords for eperm (energy per unit mass) and r (mass density).
Units should be ‘raw’ units.
quantity: None or str
name of quantity, if known.
ln_quant: bool
whether this quantity’s values are in ln-space. E.g. ln(P) instead of P.
extra_dims: extra_dims: None, list of str, or dict
if provided, will be used as names for additional xarray dims.
if dict, will be used as names and coords for additional dims.
interp(*, r, eperm=UNSET, e=UNSET, ln=False, keep_er_coords=False, **kw_xarray_interp)

return values of quantity at eperm and r.

r: number or array

evaluate table at these value(s) of r (mass density).
eperm: UNSET, number, or array
evaluate table at these value(s) of eperm (internal energy per unit mass).
must provide eperm or e, but not both.
e: UNSET, number, or array
evaluate table at these value(s) of e (internal energy density).
since table uses eperm and r, internally convert e to eperm via eperm = e / r.
must provide eperm or e, but not both.
ln: bool
whether to report result in ln-space, e.g. ln(P) instead of P.
keep_er_coords: bool
whether to keep eperm and r as coords in result.
interp_inverse(quantity, *, r=UNSET, eperm=UNSET, ln=False, **kw_interp_inverse)

return values of r or eperm, given quantity values and other coord’s values.

quantity: number or array

values of quantity.
r, eperm: UNSET, number, or array
values of r, eperm. (r=mass density; eperm=internal energy per unit mass==e/r)
must provide exactly one of these.
ln: bool
whether the values of quantity input to this function are in ln-space.
any additional kwargs are passed to xarray_interp_inverse.
isel(indexers=None, **kw_isel)

return new erTable like self but with self.xtable.isel(…).

See help(self.xtable.isel) for more details.
Can provide indexers as dict or as kwargs.
static labeled_xtable(xtable, *, quantity=None, units='raw')

return copy of xarray.DataArray, labeled with name=quantity and attrs[‘units’]=’raw’

Does not make copy if xtable is already labeled appropriately.
load_xtable()

load xtable. Here, raises NotImplementedError.

Subclasses which do not implement this should provide xtable during initialization.
property xtable

xarray.DataArray, probably 2D; must have dims for eperm and r.

if self.xtable was UNSET, self.load_xtable() first. Units are always ‘raw’ units.
static xtable_from_array(array, *, epermcoords, rcoords, quantity=None, extra_dims=None)

create xtable from unlabeled array and coords.

no unit conversions are performed here; provide inputs in the desired unit system.
array: array, at least 2D
first two dims must correspond to r (dim0), and eperm (dim1)
additional dims will be unlabeled, E.g. dim_2, dim_3, dim_4, …
epermcoords, rcoords: 1D array
coords for eperm (energy per unit mass) and r (mass density).
Units should be ‘raw’ units.
quantity: None or str
name of quantity, if known.
extra_dims: extra_dims: None, list of str, or dict
if provided, will be used as names for additional xarray dims.
if dict, will be used as names and coords for additional dims.