DimensionAttrSpecifier
- class PlasmaCalcs.dimensions.dimension_tools.dimension_value.DimensionAttrSpecifier(attr, name=None, *, single=False, value=ATTR_UNSET, values=ATTR_UNSET, min=ATTR_UNSET, max=ATTR_UNSET, morethan=ATTR_UNSET, lessthan=ATTR_UNSET)
Bases:
DimensionSpecialValueSpecifierDimensionSpecialValueSpecifier which specifies elements where this attribute equals a provided value.
Example:
MYPARAM_SPECIFIER = DimensionAttrSpecifier(‘myparam’)dlist.get(MYPARAM_SPECIFIER(7)) –> get value(s) from dlist with val.myparam == 7.name: None or display nameif provided, display will use this name instead of showing type of self,and it is assumed the name makes it obvious which attr is being specified.E.g., in example above, might provide name=’MYPARAM_SPECIFIER’,then will have repr(MYPARAM_SPECIFIER) == ‘MYPARAM_SPECIFIER’,and also repr(MYPARAM_SPECIFIER(7)) == ‘MYPARAM_SPECIFIER(7)’.single: boolwhether this specifier is expected to specify a single value from dlist.True –> getter and iseler will ensure only 1 value is returned,and results will be DimensionValue / like using isel(dim=v).False –> getter and iseler will not check for number of values returned,and results will be DimensionValueList / like using isel(dim=[list of values]).value: ATTR_UNSET or any objectvalue to specify for the attribute.ATTR_UNSET –> value is missing; cannot use instance in get() or xarray_isel() yet.value can be set any time by calling an instance of this class,as in example above, where it is set to 7.values: ATTR_UNSET or any objectlike value, but specify multiple allowed values instead of only one.Cannot provide at the same time as value.min, morethan, max, lessthan: ATTR_UNSET or any objectcan provide any of these, instead of value or values, to specify based on inequality instead.(Makes InputConflictError if any of these are provided while value is also provided.)Can provide min or morethan to set a lower bound:val >= min (if min provided); val > morethan (if morethan provided).Can provide max or lessthan to set an upper bound:val <= max (if max provided); val < lessthan (if lessthan provided).More Examples:Continuing example above, there are other input options:MYPARAM_SPECIFIER(morethan=5) –> gets values from dlist with val.myparam > 5.MYPARAM_SPECIFIER(min=7, lessthan=100) –> gets values from dlist with 7 <= val.myparam < 100.MYPARAM_SPECIFIER(7, 8, 9, 10) –> get values from dlist with val.myparam in [7, 8, 9, 10].MYPARAM_SPECIFIER(max=3, single=True) –> get the single value from dlist with val.myparam <= 3.Methods
__call__([value, values, single, min, max, ...])return a new DimensionByAttrSpecifier like self, but with value or values defined.
getter(dlist)get the value(s) from dlist specified by val.(self.attr) == self.value.
iseler(dvals)get the index(es) from dvals specified by val.(self.attr) == self.value.
return whether value or any bound is defined
returns str representation of self.getter.
_getter_from_str(dlist)get the value from dlist specified by str self.getter.
_include(val)tells whether to inclue val by comparing it to value/values/min/max/morethan/lessthan.
returns str representation of self.iseler.
_iseler_from_str(dvals)get the indexes from dlist specified by str self.iseler.
_iseler_when_none(dvals)crash, because self was passed to xarray_isel or xarray_sel but self.iseler is None.
_new(**kw_init)make a new DimensionByAttrSpecifier like self, possibly changing some kws.
contents for repr; used by __repr__.
return str suitable for "meaning" kwarg of _assert_single.
- __call__(value=ATTR_UNSET, *more_values, values=ATTR_UNSET, single=None, min=ATTR_UNSET, max=ATTR_UNSET, morethan=ATTR_UNSET, lessthan=ATTR_UNSET)
return a new DimensionByAttrSpecifier like self, but with value or values defined.
Alternatively, can set bounds (min or morethan / max or lessthan) instead of value/values.To provide multiple values, either do self(values=[v1, v2, …]) or self(v1, v2, …).See help(self) for more details.
- _any_bound_defined()
return whether value or any bound is defined
- _getter_as_str()
returns str representation of self.getter.
Use self.init_getter if it exists, else self.getter if it exists, else ‘UNKNOWN_GETTER’.
- _getter_from_str(dlist)
get the value from dlist specified by str self.getter.
- _include(val)
tells whether to inclue val by comparing it to value/values/min/max/morethan/lessthan.
- _iseler_as_str()
returns str representation of self.iseler.
Use self.init_iseler if it exists, else self.iseler if it exists, else ‘UNKNOWN_ISELER’.
- _iseler_from_str(dvals)
get the indexes from dlist specified by str self.iseler.
- _iseler_when_none(dvals)
crash, because self was passed to xarray_isel or xarray_sel but self.iseler is None.
- _new(**kw_init)
make a new DimensionByAttrSpecifier like self, possibly changing some kws.
- _repr_contents()
contents for repr; used by __repr__.
- _single_meaning()
return str suitable for “meaning” kwarg of _assert_single.
- getter(dlist)
get the value(s) from dlist specified by val.(self.attr) == self.value.
- iseler(dvals)
get the index(es) from dvals specified by val.(self.attr) == self.value.