Utilities¶
Data¶
-
tsipy.utils.data.
closest_binary_search
(array, value)¶ Finds and returns the index of the closest element to
value
.- Args:
array: Sorted 1D array.
value: Value to be searched.
- Return type
int
-
tsipy.utils.data.
create_dir
(results_dir_path, dir_name='results')¶ Creates a directory with added timestamp of creation.
- Return type
str
-
tsipy.utils.data.
denormalize
(y, mean, scale)¶ Denormalize array in the first dimension as given by x = y * scale + mean.
- Return type
ndarray
-
tsipy.utils.data.
downsample_signal
(x, k=1)¶ Downsamples a signal uniformly with a rate of
k
.- Return type
ndarray
-
tsipy.utils.data.
downsampling_indices_by_max_points
(x, max_points=100000)¶ Computes indices of a uniformly downsampled signal of length
max_points
.- Return type
ndarray
-
tsipy.utils.data.
get_time_output
(t_nns, n_per_unit, min_time=None, max_time=None)¶ Creates a time array with n_per_unit` elements per unit.
- Return type
ndarray
-
tsipy.utils.data.
get_window_indices
(x, x_start, x_end)¶ Obtain the start and end indices in x that are in window [x_start, x_end].
- Args:
x: Sorted 1-D array. x_start: Window start. x_end: Window end.
- Returns: A tuple of a start and end index of x, such that
x_start <= x[x_start_id:x_end_id + 1] <= x_end.
- Return type
Tuple
[int
,int
]
-
tsipy.utils.data.
is_integer
(num)¶ Checks if the input has an integer type.
- Return type
bool
-
tsipy.utils.data.
is_sorted
(array)¶ Check if array is sorted.
- Args:
array: 1-D array.
- Returns:
True if array is sorted and False otherwise.
- Return type
bool
-
tsipy.utils.data.
make_dir
(directory)¶ Creates a directory if it does not exist.
- Return type
str
-
tsipy.utils.data.
nonclipped_indices
(x, n_scale=5.0)¶ Return non-clipped indices that are close to array mean.
- Non-clipped index i satisfies:
x_mean + n_std * x_std >= x[i] >= x_mean - n_std * x_std.
- Return type
ndarray
-
tsipy.utils.data.
normalize
(x, mean, scale)¶ Normalize array in the first dimension as given by y = (x - mean) / scale.
- Return type
ndarray
-
tsipy.utils.data.
transform_time_to_unit
(t, t_label='year', start=datetime.datetime(1996, 1, 1, 0, 0))¶ Transforms time unit to t_label starting at start.
- Examples:
>>> import numpy as np >>> t = np.arange(0, 366, 365.25 / 4) # Time in days >>> transform_time_to_unit(t) # Transformed to years array([1996. , 1996.25, 1996.5 , 1996.75, 1997. ])
- Return type
ndarray
Print¶
Pretty print utilities with indents, print blocks and colors.
-
tsipy.utils.print.
cformat
(string, color=None)¶ Colors the input string.
- Return type
str
-
tsipy.utils.print.
pformat
(*args, shift=50, level=0, color=None)¶ Pretty string formatting utility function into two columns.
- It formats arguments passed in two columns:
keyword (left aligned),
values (right aligned and separated by spaces).
- Return type
str
-
tsipy.utils.print.
pprint
(*args, shift=50, level=0, color=None)¶ Pretty print utility function of arguments into two columns.
Formatting is described
pformat()
.- Return type
None
-
tsipy.utils.print.
pprint_block
(*args, width=None, level=0, color=None)¶ Pretty print utility function for code sections.
- Return type
None
Plot¶
Plot utilities for visualizing signals, correction history and signals with confidence intervals.
-
tsipy.utils.plot.
plot_signals
(signal_fourplets, results_dir=None, title=None, tight_layout=True, show=False, **kwargs)¶ Helper function for plotting signals.
- Return type
Tuple
[Figure
,Axes
]
-
tsipy.utils.plot.
plot_signals_and_confidence
(signal_fourplets, results_dir=None, title=None, confidence=0.95, alpha=0.5, tight_layout=False, show=False, **kwargs)¶ Helper function for plotting signal mean and confidence interval.
- Return type
Tuple
[Figure
,Axes
]
-
tsipy.utils.plot.
plot_signals_history
(x, signals_history, results_dir=None, title=None, n_rows=2, n_cols=2, fig_size=(12, 6), tight_layout=False, show=False, **kwargs)¶ Helper function for plotting degradation correction history.
- Return type
Tuple
[Figure
,Axes
]