orbithunter.core.Orbit.__getitem__

Orbit.__getitem__(key)[source]

Slicing of Orbit state and corresponding dimensions

Parameters
keyslice, tuple, np.ndarray

Any type compatible with np.ndarray.__getitem__

Returns
Orbit :

New instance whose state equals self.state[key].

Notes

Because each axis typically represents a continuous dimension, the slicing operation needs to reflect the reduction in the dimension of the domain (tile) of the Orbit. Use OrbitKS as an example. This has ‘t’, ‘x’ as its dimensions time and 1-d space, respectively. If a single row (i.e. single time ‘t’) was sliced then one would expect self.t == 0. after slicing. Taking this type of effect into account becomes quite complicated considering key can be combinations of int, Ellipsis, slice, np.ndarray, tuple, np.newaxis, None. Therefore, in order to ensure that the dimensionality reduction is well defined, only basic indexing which preserves the number of array dimensions should be used. The dimension of any axis whose size is reduced to 1 is equated to setting dimension = 0, as it has no longer has a notion of length in that dimension

If the dimension is discrete, then the size along that new axis is simply set as the new dimension; discrete dimensions may take a value of 1 but 0 is still disallowed.

Examples

If we initialize and Orbit instance with a state of shape=(8, 8, 8, 8) and parameters=(10, 10, 10, 10) (assumed to all be dimensional lengths in this case)

>>> orbit_instance = Orbit(state=np.ones([8, 8, 8, 8], basis='physical', parameters=(16, 16, 16, 16))

Then any sliced instance whose state has shape (2, 2, 2, 2) will have dimensions equal to 4.

>>> sliced_instance = orbit_instance[:2, 2:4, -2:, (0, 1)]
>>> print(sliced_instance.parameters)
(4, 4, 4, 4)

To get a sliced state which maintains len(self.shape) == self.ndim, a slice can be used instead of an integer

>>> sliced_instance = orbit_instance[:2, :2, :2, :1]
>>> print(sliced_instance.shape)
(2, 2, 2, 1)
>>> sliced_instance = orbit_instance[:2, :2, :2, 0]
ValueError: <bound method Orbit.__getitem__ of Orbit({"shape": [32, 32], "basis": "physical",
"parameters": [16, 16, 16, 16]})> does not currently support arguments which squeeze, flatten, or otherwise
reduce the dimension of the state array corresponding to type <class 'orbithunter.core.Orbit'>