PlasmaCalcs.dimensions.behavior.Behavior
- class PlasmaCalcs.dimensions.behavior.Behavior(arg0=UNSET, dims=None, **kw)
Bases:
dictdict with ‘compatible’ method.__getitem__ altered to include values from self.dims, and ‘dims’ itself.e.g. self[‘dims’] == self.dims; self[‘fluid’] –> self.dims[‘fluid’], if possible.__contains__ altered to include values from self.dims.e.g. ‘fluid’ in self –> fluid in self.keys() or fluid in self.dims- arg0: object
- first argument to pass to dict() constructor.
- dims: None or dict
- dict of dimension values for this behavior.if None, use empty dict.
remaining **kw are passd to dict() constructor- __init__(arg0=UNSET, dims=None, **kw)
- initialize Behavior.
Methods
__init__([arg0, dims])assign_attrs(array)assign_nondefault_attrs(array[, ql, include_xr])clear()compatible(other, *[, lenient, subdims])copy(*[, keys])default_keys([ql])fromkeys([value])get(key[, default])items()keys()label_array(array, *[, skip])nondefault([ql, include_xr])nondefault_keys([ql, include_xr])pop(k[,d])popitem()setdefault(key[, default])update([E, ]**F)values()- assign_attrs(array)
- return copy of array with self keys & vals (but not dims) assigned as attrs.if any were already attrs of array, crash if value mismatch.See also: assign_nondefault_attrs
- assign_nondefault_attrs(array, ql=None, *, include_xr=True)
- return copy of array with self.nondefault() keys & vals (but not dims) assigned as attrs.if any were already attrs of array, crash if value mismatch.
- ql: None or BehaviorHaver
- if provided, used to evaluate some defaults (anything defined with getdefault)e.g. for stat_dims, getdefault = lambda ql: getattr(ql, ‘maindims’, []).
- include_xr: bool
- whether to include keys whose values are xarray objects (DataArray or Dataset).
See also: assign_attrs
- clear() None. Remove all items from D.
- compatible(other, *, lenient=False, subdims=False)
- return whether self and other are compatible.‘compatible’ when self[key] == other[key] for all keys in self (and self.dims).only tests keys in self; other can have more keys than those in self.
- lenient: bool
- whether to only test keys which are in both self and other.if False, and other is missing any keys in self, return False.
- subdims: bool
- whether to be compatible if dim from self is a value within dim from other.when True, if only compatible due to subdims, return list of dims which are subdims.E.g., self = dict(fluid=1, snap=0), other = dict(fluid=[0,1,2,3], snap=0) –>subdims=True –> compatible; result will be [‘fluid’]subdims=False –> not compatible.To check whether other dim is a “list” of values, use is_iterable_dim(other_val)
- copy(*, keys=None)
- return a copy of self, including a copy of self.dims.
- keys: None or iterable
- if provided, the copy will include keys only from this list.(either way, the copy will include a full copy of self.dims.)
- default_keys(ql=None)
- return list of keys in self with key.is_default(value, ql=ql)Does not consider self.dims.
- ql: None or BehaviorHaver
- if provided, used to evaluate some defaults (anything defined with getdefault)e.g. for stat_dims, getdefault = lambda ql: getattr(ql, ‘maindims’, []).
- fromkeys(value=None, /)
- Create a new dictionary with keys from iterable and values set to value.
- get(key, default=None, /)
- Return the value for key if key is in the dictionary, else default.
- items() a set-like object providing a view on D's items
- keys() a set-like object providing a view on D's keys
- label_array(array, *, skip=UNSET)
- label array with coords from self.dims, attrs from self.items().Requires that values of self.dims are all non-iterable, according to is_iterable_dim().
- skip: None, UNSET, or list of strs
- skip these attrs, if provided.UNSET –> skip DEFAULTS.SKIP_BEHAVIOR_ARRAY_LABELS(default [])None –> don’t skip anything.
- nondefault(ql=None, *, include_xr=True)
- returns Behavior like self but dropping all keys with key.is_default(value, ql=ql).
- Note: these are the keys which MIGHT not have default values;
- result includes keys where default was unknown and unchecked.
- ql: None or BehaviorHaver
- if provided, used to evaluate some defaults (anything defined with getdefault)e.g. for stat_dims, getdefault = lambda ql: getattr(ql, ‘maindims’, []).
- include_xr: bool
- whether to include keys whose values are xarray objects (DataArray or Dataset).‘only’ –> instead return a dict of only keys whose values are xarray objects (& not default).
- nondefault_keys(ql=None, *, include_xr=True)
- return list of keys in self with NOT key.is_default(value, ql=ql).Does not consider self.dims.
- ql: None or BehaviorHaver
- if provided, used to evaluate some defaults (anything defined with getdefault)e.g. for stat_dims, getdefault = lambda ql: getattr(ql, ‘maindims’, []).
- include_xr: bool or ‘only’
- whether to include keys whose values are xarray objects (DataArray or Dataset).‘only’ –> instead return only keys whose values are xarray objects (& not default).
- pop(k[, d]) v, remove specified key and return the corresponding value.
- If key is not found, default is returned if given, otherwise KeyError is raised
- popitem()
- Remove and return a (key, value) pair as a 2-tuple.Pairs are returned in LIFO (last-in, first-out) order.Raises KeyError if the dict is empty.
- setdefault(key, default=None, /)
- Insert key with a value of default if key is not in the dictionary.Return the value for key if key is in the dictionary, else default.
- update([E, ]**F) None. Update D from dict/iterable E and F.
- If E is present and has a .keys() method, then does: for k in E: D[k] = E[k]If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = vIn either case, this is followed by: for k in F: D[k] = F[k]
- values() an object providing a view on D's values