InputUnitsMap
- class PlasmaCalcs.units.input_units.InputUnitsMap(mapping=None, *, maps_to='si')
Bases:
objectdirectly map “input units” conversion factors to particular variables.
Especially useful if “input units” is not a self-consistent unit system.Call instance to get conversion factor, like:self(var, u) –> conversion factor from “input units” to u.units for var.where u is a UnitsManager object.mapping: None or dict of {var: (ustr, var_to_si)}tells how to map each var into the self-consistent units systemmaps_toNone –> no conversion factor (equivalent to all factors == 1);this is the “trivial” mapping.dict –> ustr is string to pass to a UnitsManager;var_to_si is conversion factor from “input units” to SI units,where original units is the original unit system being converted from.Example mapping:{‘B’: (‘b_field’, 1e-9), # for ‘B’ with input_units [nT]‘n’: (‘number_density’, 1e6), # for ‘n’ with input_units [1/cm^3]‘P’: (‘pressure’, 1e-9), # for ‘P’ with input_units [nPa]‘J’: (‘current_density’, 1e-9), # for ‘J’ with input_units [nA/m^2]‘u’: (‘velocity’, 1e-3)} # for ‘u’ with input_units [km/s]maps_to: ‘si’, ‘raw’, or other strthe self-consistent unit system mapped to by self.mapping.must be in u.known_systems during self.__call__.Example:for mapping above, which provides factors to go from input units to ‘si’,it makes sense to use maps_to=’si’.Example:if “input units” is just ‘raw’ units from self.u, use maps_to=’raw’.(In this case, the InputUnitsMap machinery isn’t really necessary…but it is convenient to be able reproduce this case just bychanging the args here, rather than many if/else checks in other places.)Methods
__call__(var, u)return conversion factor from "input_units" to u.units for var.
- __call__(var, u)
return conversion factor from “input_units” to u.units for var.