ComponentList
- class PlasmaCalcs.dimensions.components.ComponentList(*args_list, istart=None, **kw_list)
Bases:
DimensionValueListlist of vector component coordinates.
Methods
__getitem__(ii, **kw_new)return self[ii], giving element from self if int(ii) possible, else new instance of type(self).
append(object, /)Append object to the end of the list.
clear()Remove all items from list.
copy()Return a shallow copy of the list.
count(value, /)Return number of occurrences of value.
extend(iterable, /)Extend list by appending elements from the iterable.
from_array(array)return ComponentList from 0D or 1D array.
from_dict(int_to_element)return DimensionValueList from dict of {i: element}.
from_dicts(dicts, *[, istart])return cls instance from iterable of dicts
from_strings(strings)return ComponentList from iterable of strings.
get(key)return element(s) corresponding to key.
index(value[, start, stop])Return first index of value.
indices(key, *[, return_get, to_list])return indices of element(s) corresponding to key, during self.get(key).
insert(index, object, /)Insert object before index.
inserted(i, element, **kw_new)return copy of self but with element inserted at i.
lookup(key, *[, unique_missing_ok, ...])return element given int, str, or element in self.
return dict for looking up elements given int or str (or element) in self.
pop([index])Remove and return item at index (default last).
popped(key, *[, return_indices])return (self.get(key), self.without_i(indices corresponding to key)).
remove(value, /)Remove first occurrence of value.
reverse()Reverse *IN PLACE*.
return serialization of self, into a list of dictionaries.
sort(*[, key, reverse])Sort the list in ascending order and return None.
to_dict()returns a list of dictionaries,
unique(*[, istart])return DimensionValueList of unique elements from self.
unique_from(elements, *elements_as_args[, ...])return DimensionValueList of unique elements from elements.
with_istart([istart])return new DimensionValueList with elements reindexed, starting from istart.
without_i(i, **kw_init)return a copy of self but dropping elements currently at these indices.
_display_contents(f, *[, nmax])return str to display self's contents, using f(element) for each element.
_new(*args, **kw)return new instance of type(self), with these args and kw.
return simple repr for self; includes type, len, and a repr_simple for a few elements.
return a shorter repr of self; just includes type & len.
Attributes
ndimalias to with_istart
ssize- __getitem__(ii, **kw_new)
return self[ii], giving element from self if int(ii) possible, else new instance of type(self).
- _dimension_key_error
alias of
ComponentKeyError
- _display_contents(f, *, nmax=3)
return str to display self’s contents, using f(element) for each element.
if len(self) > nmax, instead include len(self), self[0], and self[-1], only.
- _new(*args, **kw)
return new instance of type(self), with these args and kw.
- _repr_simple()
return simple repr for self; includes type, len, and a repr_simple for a few elements.
if less than 4 elements, just uses repr_simple for the elements (doesn’t include len).
- _short_repr()
return a shorter repr of self; just includes type & len.
- append(object, /)
Append object to the end of the list.
- clear()
Remove all items from list.
- copy()
Return a shallow copy of the list.
- count(value, /)
Return number of occurrences of value.
- extend(iterable, /)
Extend list by appending elements from the iterable.
- classmethod from_array(array)
return ComponentList from 0D or 1D array.
array values should be Component objects, strings, or ints.Component objects –> use as-isstrings –> if ‘x’, ‘y’, or ‘z’, use XYZ.get(string).Else, use Component(s, i=i) for i in range(len(array))ints –> if 0, 1, or 2, use XYZ.get(int).Else, use Component(i=i) for i in array
- classmethod from_dict(int_to_element)
return DimensionValueList from dict of {i: element}.
See also: cls.from_dicts()
- classmethod from_dicts(dicts, *, istart=UNSET, **kw_value_init)
return cls instance from iterable of dicts
values will all be DimensionValue objects, with type == cls.value_type.
- dicts: iterable of dicts
- each one corresponds to one (cls.value_type) object in result.
- istart: UNSET, None, or int
- mode for inferring i values if needed.UNSET –> dicts[k] uses i=dicts[k][‘i’] if it exists, else i=k.None –> use i from dict if it exists, else None.int –> dicts[k] uses i=istart+k, ignoring any ‘i’ provided in dict.
additional kwargs will be passed to cls.value_type.__init__(in case of conflict with any dicts values, use dicts values).
- classmethod from_strings(strings)
return ComponentList from iterable of strings. (i will be determined automatically.)
- get(key)
return element(s) corresponding to key.
- key: None, int, str, element, DimensionSpecialValueSpecifier, range, slice, or tuple/list
- Some keys will look up and return corresponding element(s):nonnegative int, str, or element –> return corresponding element.DimensionSpecialValueSpecifier spec –> return spec.getter(self).tuple –> return tuple(self.get(k) for k in key)list –> return list(self.get(k) for k in key)range –> return type(self)(self.get(k) for k in key).Other keys will index self using the usual list-like indexing rules:None –> return self, unchanged.negative int –> return self[key], i.e. the key’th element, counting from end.slice –> return self[key], i.e. apply this slice to self.Note that the result will have the same type as self.Note that this supports interprets_fractional_indexing,e.g. slice(0.3, 0.7) will slice(len(self) * 0.3, len(self) * 0.7).if any element in a tuple or list is not in self,keep it unchanged if it is a UniqueDimensionValue,else raise DimensionKeyError.
Note that the result will always be single element, a tuple, a list, or a DimensionValueList.
- index(value, start=0, stop=9223372036854775807, /)
Return first index of value.
Raises ValueError if the value is not present.
- indices(key, *, return_get=False, to_list=False)
return indices of element(s) corresponding to key, during self.get(key).
- to_list: bool.
- True –> return [index] instead of index, if self.get(key) is a single DimensionValue.
return_get: boolTrue –> return (indices, self.get(key)) instead of just indices.result will have same length as self.get(key); self[result[i]] is self.get(key)[i].
- insert(index, object, /)
Insert object before index.
- inserted(i, element, **kw_new)
return copy of self but with element inserted at i. kwargs passed to new self.__init__.
- lookup(key, *, unique_missing_ok=False, handle_special=True)
return element given int, str, or element in self. raise DimensionKeyError if key not in self.
- unique_missing_ok: bool
- whether it is okay for self to be missing key if key is a UniqueDimensionValue.if True and key is a UniqueDimensionValue, return key instead of raising error.
- handle_special: bool
- whether to handle DimensionSpecialValueSpecifier in special way,i.e. if key is a DimensionSpecialValueSpecifier, return key.getter(self).
- lookup_dict()
return dict for looking up elements given int or str (or element) in self.
uses caching; assumes int(element) & str(element) never changes for any element.
- pop(index=-1, /)
Remove and return item at index (default last).
Raises IndexError if list is empty or index is out of range.
- popped(key, *, return_indices=False, **kw_init)
return (self.get(key), self.without_i(indices corresponding to key)).
see help(self.get) for details on allowed keys.return_indices: boolif True, also return the indices (as a list) of the popped element(s),i.e. return (indices, popped element(s), self.without_i(…), self with elements removed).index will be None if no elements were removed.kw_init are used when making the copy of self. E.g. use istart=0 to make the copy start at 0.
- property reindexed
alias to with_istart
- remove(value, /)
Remove first occurrence of value.
Raises ValueError if the value is not present.
- reverse()
Reverse *IN PLACE*.
- serialize()
return serialization of self, into a list of dictionaries.
- sort(*, key=None, reverse=False)
Sort the list in ascending order and return None.
The sort is in-place (i.e. the list itself is modified) and stable (i.e. the
order of two equal elements is maintained).If a key function is given, apply it once to each list item and sort them,ascending or descending, according to their function values.The reverse flag can be set to sort in descending order.
- to_dict()
returns a list of dictionaries,
each dictionary corresponds to each DimensionValue in the DimensionValueList.
- unique(*, istart=None)
return DimensionValueList of unique elements from self.
equality checked via element.equal_except_i, i.e. ignore index.(if all elements are unique, return self, else return new DimensionValueList.)istart: None or int. int –> use result[k].with_i(istart + k) for all k.
- classmethod unique_from(elements, *elements_as_args, istart=None)
return DimensionValueList of unique elements from elements.
equality checked via element.equal_except_i, i.e. ignore index.- elements: iterable of DimensionValue of cls.value_type.
- or, single DimensionValue, in which case treat it as first arg,and can provide more elements as additional args.
istart: None or int. int –> use result[k].with_i(istart + k) for all k.
- with_istart(istart=0)
return new DimensionValueList with elements reindexed, starting from istart.
elements with incorrect i will be replaced with copies.if istart is None, just return self, unchanged.
- without_i(i, **kw_init)
return a copy of self but dropping elements currently at these indices.
i: int or iterable of int. indices to remove.
kw_init are passed to __init__ when making the copy of self.