viscid.sliceutil module¶
Handle slice by index / location (value)
-
viscid.sliceutil.
prune_comp_sel
(sel_list, comp_names)[source]¶ Discover and remove vector component from selection list
-
viscid.sliceutil.
raw_sel2sel_list
(sel)[source]¶ Turn generic selection into something standard we can work with
Parameters: sel (object) – some slice selection
Returns: - items in sel_list are guarenteed to be
of type {slice, int, complex, string, numpy.ndarray}
Return type: (sel_list, input_type)
Raises: TypeError
– slice-by-array invalid dtypeValueError
– slice-by-array not 1D
-
viscid.sliceutil.
fill_nd_sel_list
(sel_list, ax_names)[source]¶ fully determine a sparsely selected sel_list
-
viscid.sliceutil.
standardize_sel_list
(sel_list)[source]¶ turn all selection list elements into fundamental python types
-
viscid.sliceutil.
standardize_sel
(sel)[source]¶ turn selection list element into fundamental python types
-
viscid.sliceutil.
standardize_value
(sel, bool_argwhere=False)[source]¶ Turn a value element to fundamental type or array
Returns: - One of the following::
- None
- np.newaxis
- Ellipsis
- bool
- int
- complex (slice by value)
- numpy.datetime64
- numpy.timedelta64
- ndarray
- numpy.integer
- numpy.bool_
- numpy.timedelta64
- numpy.datetime64
- numpy.complex
-
viscid.sliceutil.
std_sel_list2index
(std_sel_list, crd_arrs, val_endpoint=True, interior=False, tdunit='s', epoch=None, tol=100)[source]¶ turn standardized selection list into index slice
-
viscid.sliceutil.
std_sel2index
(std_sel, crd_arr, val_endpoint=True, interior=False, tdunit='s', epoch=None)[source]¶ Turn single standardized selection into slice (by int or None)
Normally (val_endpoint=True, interior=False), the rules for float lookup val_endpoints are:
- The slice will never include an element whose value in arr is < start (or > if the slice is backward) - The slice will never include an element whose value in arr is > stop (or < if the slice is backward) - !! The slice WILL INCLUDE stop if you don't change val_endpoint. This is different from normal slicing, but it's more natural when specifying a slice as a float.
If interior=True, then the slice is expanded such that start and stop are interior to the sliced array.
Parameters: - std_sel – single standardized selection
- arr (ndarray) – filled with floats to do the lookup
- val_endpoint (bool) – iff True then include stop in the slice when slicing-by-value (DOES NOT EFFECT SLICE-BY-INDEX). Set to False to get python slicing symantics when it comes to excluding stop, but fair warning, python symantics feel awkward here. Consider the case [0.1, 0.2, 0.3][:0.25]. If you think this should include 0.2, then leave keep val_endpoint=True.
- interior (bool) – if True, then extend both ends of the slice such that slice-by-location endpoints are interior to the slice
- epoch (datetime64-like) – Epoch for to go datetime64 <-> float
- tdunit (str) – Presumed time unit for floats
- tol (int) – number of machine epsilons to consider “close enough”
-
viscid.sliceutil.
sel_list2values
(arrs, sel_list, epoch=None, tdunit='s')[source]¶ find the extrema values for a given sel list
-
viscid.sliceutil.
sel2values
(arr, sel, epoch=None, tdunit='s')[source]¶ find the extrema values for a given selection
Parameters: - arr (None, sequence) – array that is being selected, if this is None, then the output will contain np.nan where it can not infer values.
- selection (slice, str) – a single selection that could be given
to
to_slice()
- epoch (datetime64-like) – Epoch for to go datetime64 <-> float
- tdunit (str) – Presumed time unit for floats
Returns: (start_val, stop_val) as floats
- If arr is None and start/stop are None, then they will become +/- inf depending on the sign of step.
- If arr is None and start/stop are slice-by-index, they will become NaN.
-
viscid.sliceutil.
selection2values
(arr, sel, epoch=None, tdunit='s')¶ find the extrema values for a given selection
Parameters: - arr (None, sequence) – array that is being selected, if this is None, then the output will contain np.nan where it can not infer values.
- selection (slice, str) – a single selection that could be given
to
to_slice()
- epoch (datetime64-like) – Epoch for to go datetime64 <-> float
- tdunit (str) – Presumed time unit for floats
Returns: (start_val, stop_val) as floats
- If arr is None and start/stop are None, then they will become +/- inf depending on the sign of step.
- If arr is None and start/stop are slice-by-index, they will become NaN.
-
viscid.sliceutil.
make_fwd_slice
(shape, slices, reverse=None, cull_second=True)[source]¶ Make sure slices go forward
This function returns two slices equivalent to slices such that the first slice always goes forward. This is necessary because h5py can’t deal with reverse slices such as [::-1].
The optional reverse can be used to interpret a dimension as flipped. This is used if the indices in a slice are based on a coordinate array that has already been flipped. For instance, the result is equivalent to arr[::-1][slices], but in a way that can be handled by h5py. This lets us efficiently load small subsets of large arrays on disk, which is most useful when the large array is coming through sshfs.
Note
The only restriction on slices is that neither start nor stop can be outide the range [-L, L].
Parameters: - shape – shape of the array that is to be sliced
- slices – a tuple of slices to work with
- reverse (optional) – list of bools that indicate if the corresponding value in slices should be ineterpreted as flipped
- cull_second (bool, optional) – iff True, remove elements of the second slice for dimensions that don’t exist after the first slice has completed. This is only here for a super-hacky case when slicing fields.
Returns: (first_slice, second_slice)
- first_slice: a forward-only slice that retrieves the desired elements of an array
- second_slice: a slice that does [::1] or [::-1] as needed to make the result equivalent to slices. If keep_all, then this may contain None indicating that this dimension no longer exists after the first slice.
Examples
>> a = np.arange(8) >> first, second = make_fwd_slice(len(a),slice(None, None, -1)) >> (a[::-1] == a[first][second]).all() True
>> a = np.arange(4*5*6).reshape((4, 5, 6)) >> first, second = make_fwd_slice(a.shape, >> [slice(None, -1, 1), >> slice(-1, None, 1), >> slice(-4, -1, 2)], >> [True, True, True]) >> a1 = a[::-1, ::-1, ::-1][:-1, -1:, -4:-1:2] >> a2 = a[first][second] >> a1 == a2 True