pypret.lib module

Miscellaneous helper functions

These functions fulfill small numerical tasks used in several places in the package.

pypret.lib.abs2(x)[source]

Calculates the squared magnitude of a complex array.

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.best_scale(E, E0)[source]

Scales rho so that:

sum (rho * |E| - |E0|)^2

is minimal.

pypret.lib.build_coords(*axes)[source]

Builds a coordinate array from the axes.

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 deviation sigma.

pypret.lib.jit(pyfunc=None, **kwargs)[source]
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.mask_phase(x, amp, phase, threshold=0.001)[source]
pypret.lib.mean(x, y)[source]

Calculates the mean of the distribution described by (x, y).

pypret.lib.norm(x)[source]

Calculates the L2 or Euclidian norm of array x.

pypret.lib.norm2(x)[source]

Calculates the squared L2 or Euclidian norm of array x.

pypret.lib.nrms(x, y)[source]

Calculates the normalized rms error between x and y.

The convention for normalization varies. Here we use:

max |y|

as normalization.

pypret.lib.phase(x)[source]

The phase of a complex array.

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.

pypret.lib.rms(x, y)[source]

Calculates the root mean square (rms) error between x and y.

pypret.lib.standard_deviation(x, y)[source]

Calculates the standard deviation of the distribution described by (x, y).

pypret.lib.variance(x, y)[source]

Calculates the variance of the distribution described by (x, y).