erTableFromMemmap
- class PlasmaCalcs.mhd.mhd_er_tables.erTableFromMemmap(filename, quantity=None, *, epermcoords, rcoords, index_in_file, ln_quant=False, scale_quant=1, extra_dims=None, data_shape=None, data_dtype=<class 'numpy.float32'>, data_order='F', **kw_super)
Bases:
erTablelookup table from eperm and r to quantity. Table loaded from a memmap file.
Internally, all values should be in ‘raw’ units (see scale_quant kwarg for more details).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.)filename: strname of file. Internally stored as abspath.quantity: None or strname of quantity, if known.epermcoords, rcoords: 1D arraycoords for eperm (energy per unit mass) and r (mass density).Units should be ‘raw’ units.index_in_file: intn such that this table is the nth table in the memmap file.ln_quant: boolwhether this quantity’s values are in ln-space. E.g. ln(P) instead of P.scale_quant: number, default 1.scale quantity by this value immediately after reading from memmap.(always corresponds to the not-ln’d quant, even if ln_quant=True).extra_dims: extra_dims: None, list of str, or dictif provided, will be used as names for additional xarray dims.if dict, will be used as names and coords for additional dims.use this when memmap arrays have more dims than just eperm and r.data_shape: None or tupleshape of a single array in the memmap file.None –> infer shape = (len(epermcoords), len(rcoords))if extra_dims provided with coords, include those in inferred shape too.data_dtype: data_dtype: np.dtype or something which implies np.dtypedtype of the data in memmap filedata_order: ‘C’ or ‘F’order of the data in memmap file. ‘F’ is Fortran order.[EFF] loading is “lazy”; wait to load until first time the table is actually accessed.Methods
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.
infer data_shape from self.data_shape and self.extra_dims;
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 with data from self, but using self.xtable.isel(...).
labeled_xtable(xtable, *[, quantity, units])return copy of xarray.DataArray, labeled with name=quantity and attrs['units']='raw'
load table xarray from memmap file.
xtable_from_array(array, *, epermcoords, rcoords)create xtable from unlabeled array and coords.
load table array from memmap file.
_new(**kw_overrides)return new erTable like self but with some attributes overridden by kw_overrides.
Attributes
whether eperm and r coords (of self.xtable) are sorted (in non-decreasing order).
None or str specifying how to handle extrapolation when interp() is called.
xarray.DataArray, probably 2D; must have dims for eperm and r.
- _load_table_array()
load table array from memmap file.
- _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 arraycoords for eperm (energy per unit mass) and r (mass density).Units should be ‘raw’ units.quantity: None or strname of quantity, if known.ln_quant: boolwhether this quantity’s values are in ln-space. E.g. ln(P) instead of P.extra_dims: extra_dims: None, list of str, or dictif provided, will be used as names for additional xarray dims.if dict, will be used as names and coords for additional dims.
- init_infer_data_shape()
infer data_shape from self.data_shape and self.extra_dims;
set self.data_shape to the inferred value.
- 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 arrayevaluate table at these value(s) of eperm (internal energy per unit mass).must provide eperm or e, but not both.e: UNSET, number, or arrayevaluate 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: boolwhether to report result in ln-space, e.g. ln(P) instead of P.keep_er_coords: boolwhether 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 arrayvalues of r, eperm. (r=mass density; eperm=internal energy per unit mass==e/r)must provide exactly one of these.ln: boolwhether 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 with data from self, but using 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 table xarray from memmap file. scale quant by self.scale_quant if not 1.
save result to self.xtable, also return it.
- 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 2Dfirst 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 arraycoords for eperm (energy per unit mass) and r (mass density).Units should be ‘raw’ units.quantity: None or strname of quantity, if known.extra_dims: extra_dims: None, list of str, or dictif provided, will be used as names for additional xarray dims.if dict, will be used as names and coords for additional dims.