pypret.lib module¶
Miscellaneous helper functions
These functions fulfill small numerical tasks used in several places in the package.
-
pypret.lib.
arglimit
(y, threshold=0.001, padding=0.0, normalize=True)[source]¶ Returns the first and last index where y >= threshold * max(abs(y)).
-
pypret.lib.
as_list
(x)[source]¶ Try to convert argument to list and return it.
Useful to implement function arguments that could be scalar values or lists.
-
pypret.lib.
edges
(x)[source]¶ Calculates the edges of the array elements.
Assuming that the input array contains the midpoints of a supposed data set, the function returns the (N+1) edges of the data set points.
-
pypret.lib.
find
(x, condition, n=1)[source]¶ Return the index of the nth element that fulfills the condition.
-
pypret.lib.
fwhm
(x, y)[source]¶ Calculates the full width at half maximum of the distribution described by (x, y).
-
pypret.lib.
gaussian
(x, x0=0.0, sigma=1.0)[source]¶ Calculates a Gaussian function with center
x0
and standard deviationsigma
.
-
pypret.lib.
limit
(x, y=None, threshold=0.001, padding=0.25, extend=True)[source]¶ Returns the maximum x-range where the y-values are sufficiently large.
Parameters: - x (array_like) – The x values of the graph.
- y (array_like, optional) – The y values of the graph. If None the maximum range of x is used. That is only useful if padding > 0.
- threshold (float) – The threshold relative to the maximum of y of values that should be included in the bracket.
- padding (float) – The relative padding on each side in fractions of the bracket size.
- extend (bool, optional) – Signals if the returned range can be larger than the values in
x
. Default is True.
Returns: xl, xr – Lowest and biggest value of the range.
Return type: float
-
pypret.lib.
marginals
(data, normalize=False, axes=None)[source]¶ Calculates the marginals of the data array.
axes specifies the axes of the marginals, e.g., the axes on which the sum is projected.
If axis is None a list of all marginals is returned.
-
pypret.lib.
nrms
(x, y)[source]¶ Calculates the normalized rms error between
x
andy
.The convention for normalization varies. Here we use:
max |y|
as normalization.
-
pypret.lib.
rescale
(x, window=[0.0, 1.0])[source]¶ Rescales a numpy array to the range specified by
window
.Default is [0, 1].
-
pypret.lib.
retrieval_report
(res)[source]¶ Simple helper that prints out important information from the retrieval result object.