Numpy utilities
utilities for auxiliary numpy array processing
nan_helper_1d
nan_helper_1d (y:numpy.ndarray)
*Helper to handle indices and logical indices of NaNs.
Parameters:
- y, 1d numpy array with possible NaNs
Returns:
- nans, logical indices of NaNs
- index, a function, with signature indices= index(logical_indices),
to convert logical indices of NaNs to 'equivalent' indices
Example: linear interpolation of NaNs
>>> nans, x= nan_helper_1d(y)
>>> y[nans]= np.interp(x(nans), x(~nans), y[~nans])
sources:
https://stackoverflow.com/questions/6518811/interpolate-nan-values-in-a-numpy-array*
Type | Details | |
---|---|---|
y | ndarray | utils for handling indices and logical indices of NaNs |
Returns | Tuple |
nan_interp_1d
nan_interp_1d (y:numpy.ndarray)
*Linear interpolation of NaNs.
Parameter:
- y, 1d numpy array with possible NaNs
Return:
- y, 1d numpy array with NaNs replaced by linear interpolation
Example: linear interpolation of NaNs
>>> y = nan_interp_1d(y)
sources:
https://stackoverflow.com/questions/6518811/interpolate-nan-values-in-a-numpy-array*
Type | Details | |
---|---|---|
y | ndarray | linear interpolation of NaNs |
Returns | ndarray | np array with NaNs replaced by linear interpolation |
ragged_nparray_list_interp
ragged_nparray_list_interp (ragged_list_list:List[List], ob_num:int)
*Linear interpolation of NaNs.
Parameter:
- y, list ragged array
Return:
- y, 2d numpy array with missing elements replaced by linear interpolation
Example: linear interpolation of NaNs
>>> y = nan_interp_1d(y)
sources:
https://stackoverflow.com/questions/6518811/interpolate-nan-values-in-a-numpy-array*
Type | Details | |
---|---|---|
ragged_list_list | List | list to be interpolated with NaNs |
ob_num | int | number of observations |
Returns | ndarray | np array with NaNs replaced by linear interpolation |
timestamps_from_can_strings
timestamps_from_can_strings (can_timestamp_strings:List[str], signal_freq:float, unit_num:int, unit_duration:float)
*Extract timestamps from CAN strings.
Parameters:
- can_timestamp_strings, list of CAN strings
- signal_freq, signal frequency
- unit_num, number of CAN units
- unit_duration, duration in seconds per CAN unit
Return:
- timestamps, 1d numpy array of timestamps
Example: extract timestamps from “CAN” strings
>>> timestamps_arr = timestamps_from_can_strings(can_timestamp_strings)*
Type | Details | |
---|---|---|
can_timestamp_strings | List | list of strings from CAN |
signal_freq | float | signal frequency |
unit_num | int | number of CAN units |
unit_duration | float | duration in seconds per CAN unit |
Returns | ndarray | np array of timestamps |