pyloggrid.Libs.datasci
Libraries for data science
Module Contents
Functions
|
Trims a 1D array from its first and last portions. |
|
Mean of |
|
Replace all zero values with |
|
Fit |
|
Power law fit |
|
Random array of complex numbers, see |
|
Random array of complex numbers, normally distributed in modulus and uniformly in angle |
|
Returns a pseudorandom array of same shape as |
|
Like |
|
Transform an 1D array of 1D array of different sizes into an array of array of same sizes, i.e a classic 2D array. |
|
Logarithmic mean along an axis, ignoring zero and nan values. |
- filter_range(data: ndarray, start: float = 0, end: float = 1) ndarray
Trims a 1D array from its first and last portions.
This is a shortcut to
data[int(size * start) : int(size * end)]- Parameters:
data – the data to filter
start – where to start in the values (ex: 0.2 -> we ommit the 20% first values)
end – where to end in the values (ex: 0.8 -> we ommit the 20% last values)
- Returns:
the new array (if filtered, the shape is altered)
- mean(data: ndarray, ts: ndarray | None = None, log: bool = False, start: float = 0, end: float = 1) tuple[ndarray, ndarray | None]
Mean of
data. Iftsis provided, the mean is weighted by the time intervals. Iflog, the log mean is returned.- Parameters:
data – data to average
ts – times associated with the data. Must be increasing.
log – if True, only the mean avg is returned
exp(mean(log(abs(data_weighted))), and the variance returnsNonestart – where to start in the values (ex: 0.2 -> we ommit the 20% first values)
end – where to end in the values (ex: 0.2 -> we ommit the 20% last values)
- Returns:
the mean and std value
- clamp_zero(data: ndarray, fill: Any = None) ndarray
Replace all zero values with
fill(defaults tomin(data)/10)- Parameters:
data – array to clamp
fill – if specified, all zero values are filled with this
- Returns:
The clamped array
- fit(f: Callable, x: ndarray, y: ndarray, mask: ndarray | tuple[float, float] = None) tuple[float, Ellipsis]
Fit
(x,y)by the functionfwith an optional mask- Parameters:
f – fit function
x –
y –
mask – an array mask, or a tuple (start, end)
- powerlaw_fit(x: ndarray, y: ndarray, mask: ndarray | float = None, a: float = None) tuple[float, float]
Power law fit
Y = b * X ^ a- Parameters:
x – X array
y – Y array
mask – mask to specify the relevant values of X, Y to use (same as
fit())a – optional fixed value for
a. If specified, onlybis fitted
- Returns:
the fit parameters
b, a
- randcomplex_like(data: ndarray) ndarray
Random array of complex numbers, see
randcomplex()- Parameters:
data – array to copy the shape from
- Returns:
random array
- randcomplex(shape: Iterable) ndarray
Random array of complex numbers, normally distributed in modulus and uniformly in angle
- Parameters:
shape – return array shape
- Returns:
random array
- rand_seeded_by_array(source: ndarray, seed: int) ndarray
Returns a pseudorandom array of same shape as
sourcewhere items with the samesourcewill have the same value for a given seed.This is useful when creating pseudorandom arrays based on
kx,ky,kz, of different sizes, e.g. when changing the grid size but keeping the same pseudorandom forcingWarning
This is not optimised for speed, and should probably not be called every step
- randcomplex_seeded_by_array(source: ndarray, seed: int) ndarray
Like
rand_seeded_by_array(), but returns a complex array (uniform in a square)
- ragged_array_to_array(data: ndarray | list, fill=np.nan) ndarray
Transform an 1D array of 1D array of different sizes into an array of array of same sizes, i.e a classic 2D array.
Smaller arrays are padded with
fill.If a classic 2D array is given, it does nothing.
- Parameters:
data – array of array of different sizes
fill – fill value
- Returns:
padded 2D-array