fosanalysis
A framework to evaluate distributed fiber optic sensor data
Loading...
Searching...
No Matches
fosanalysis.utils.misc Namespace Reference

Contains miscellaneous standalone functions. More...

Functions

np.array datetime_to_timestamp (np.array datetime_array)
 Converts an array of datetime entries to an array of Unix timestamps.
 
tuple find_closest_value (np.array arr, float v)
 Returns index and value in arr, that is closest to the given v.
 
np.array last_finite_index (np.array arr, int axis=-1)
 Returns an array with the indices of the most recent finite entry when traversing the arr along the specified axis.
 
np.array nan_diff (np.array arr, int axis=-1)
 Calculate the difference to the previous finite entry.
 
np.array nan_diff_1d (np.array arr)
 Calculate the difference to the previous finite entry.
 
tuple next_finite_neighbor (np.array array, int index, bool to_left, int recurse=0)
 Find the next finite neighbor of the entry array[index].
 
 np_to_python (data)
 Convert the given data to a Python built-in type.
 
np.array timestamp_to_datetime (np.array timestamp_array)
 Converts an array of Unix timestamps to an array of datetime entries.
 

Detailed Description

Contains miscellaneous standalone functions.

Author
Bertram Richter
Date
2023

Function Documentation

◆ datetime_to_timestamp()

np.array fosanalysis.utils.misc.datetime_to_timestamp ( np.array datetime_array)

Converts an array of datetime entries to an array of Unix timestamps.

Parameters
datetime_arrayArray of datetime objects.
Returns
Returns an array of Unix timestamps.

Definition at line 163 of file misc.py.

◆ find_closest_value()

tuple fosanalysis.utils.misc.find_closest_value ( np.array arr,
float v )

Returns index and value in arr, that is closest to the given v.

In case of equal distance of v to both neighbors, the smaller one is chosen.

Parameters
arrArray like (1D) of values in ascending order.
vThe target value, to which the distance should be minimized.
Returns
(<index>, <entry>)

Definition at line 11 of file misc.py.

◆ last_finite_index()

np.array fosanalysis.utils.misc.last_finite_index ( np.array arr,
int axis = -1 )

Returns an array with the indices of the most recent finite entry when traversing the arr along the specified axis.

The returned array has the same shape as arr.

Example:

>>> arr = np.array([1.,2.,"nan", "inf", 5], dtype=float)
array([1., 2., nan, inf, 5.])
>>> last_finite_index(arr)
array([0, 1, 1, 1, 4])

The first element is assumed to be a finite value. All indices before the first finite entry will be 0.

>>> arr = np.array(["nan","nan", "inf", 5], dtype=float)
array([nan, nan, inf, 5.])
>>> last_finite_index(arr)
array([0, 0, 0, 3])
Parameters
arrArray like.
axisAxis along which to apply the indexing. Defaults to the last axis.

Definition at line 34 of file misc.py.

Here is the caller graph for this function:

◆ nan_diff()

np.array fosanalysis.utils.misc.nan_diff ( np.array arr,
int axis = -1 )

Calculate the difference to the previous finite entry.

This is similar to np.diff(), but skipping NaN or inf entries. This function is a wrapper around nan_diff_1d().

Example:

>>> arr = np.array([1.,2.,"nan", "inf", 5], dtype=float)
array([1., 2., nan, inf, 5.])
>>> nan_diff(arr)
array([1., nan, -inf, 3.])
Parameters
arrArray like.
axisAxis along which to calculate the incremental difference. Defaults to the last axis.

Definition at line 93 of file misc.py.

◆ nan_diff_1d()

np.array fosanalysis.utils.misc.nan_diff_1d ( np.array arr)

Calculate the difference to the previous finite entry.

This is similar to np.diff(), but skipping NaN or inf entries.

Example:

>>> arr = np.array([1.,2.,"nan", "inf", 5], dtype=float)
array([1., 2., nan, inf, 5.])
>>> nan_diff_1d(arr)
array([1., nan, -inf, 3.])
Parameters
arrArray like, needs to be 1D.

Definition at line 71 of file misc.py.

Here is the call graph for this function:

◆ next_finite_neighbor()

tuple fosanalysis.utils.misc.next_finite_neighbor ( np.array array,
int index,
bool to_left,
int recurse = 0 )

Find the next finite neighbor of the entry array[index].

An entry <entry> is finite, if np.isfinite(<entry>) == True.

Parameters
arrayArray, on which the search is carried out.
indexPosition in the array, where the search is started.
to_leftTrue, if a neighbor to the left of the starting index should be found, False for a neighbor to the right.
recurseNumber of recursions, that are done. Examples:
  • 0: direct neighbors of the starting index
  • 1: neighbors of the neighbors
  • 2: neighbors of the neighbors' neighbors
  • and so on.
Returns
Tuple like (<index>, <entry>). If no finite value could be found before reaching the end of array (None, None) is returned.

Definition at line 114 of file misc.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ np_to_python()

fosanalysis.utils.misc.np_to_python ( data)

Convert the given data to a Python built-in type.

This function should be used, when type-checking. Iterables are recursively converted into list and instances of np.scalar are converted into standard data types using the method np.item().

Definition at line 150 of file misc.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timestamp_to_datetime()

np.array fosanalysis.utils.misc.timestamp_to_datetime ( np.array timestamp_array)

Converts an array of Unix timestamps to an array of datetime entries.

Parameters
timestamp_arrayArray of floats, representing Unix timestamps.
Returns
Returns an array of datetime.datetime objects.

Definition at line 171 of file misc.py.