numpyXtns package

Submodules

numpyXtns.numpyXtns module

numpyXtns.numpyXtns.RMSE(d1, d2, ax=None)

Compute root-mean-square difference.

Parameters:
  • d1 (array) – first data set.
  • d2 (array) – second data set (should be of same length and shape).
Returns:

Root-mean-square difference of the two input arrays (float).

numpyXtns.numpyXtns.arrayMax(a)

Finds position of data array minimum.

Parameters:a (float) – data array.
Returns:Integer tuple with maximum position.
numpyXtns.numpyXtns.arrayMin(a)

Finds position of data array minimum.

Parameters:a (float) – data array.
Returns:Integer tuple with minimum position.
numpyXtns.numpyXtns.daysPerMonth(y, m)

Computes days of a month and its center as datetime object.

Parameters:
  • y (int) – Year.
  • m (int) – Month.
Returns:

Tuple of days per month (int) and centre of the month (datetime).

class numpyXtns.numpyXtns.deflatableArray(data, *args, **opts)

Bases: numpy.ma.core.MaskedArray

Class of deflatable arrays, i.e. masked arrays that can be deflated (removing shape and masked elements), manipulated and reinflated to original shape.

Variables:
  • idx (integer list tuple) – tuple with integer lists of non-masked elements.
  • fullShape (integer tuple) – shape of inflated array.
  • fillval (float, integer) – fill value of masked array.
  • compressedShape (integer) – size of deflated array.
  • deflated – array data in compressed shape.
__init__(data, *args, **opts)

Initialises the deflatable array as masked array.

Inherits:
MaskedArray
Parameters:
  • data (array) – data array to be deflated.
  • *args, **opts – positional and optional arguments passed to MaskedArray initialisation function.
__module__ = 'numpyXtns.numpyXtns'
deflate()

Deflates array removing shape and masked elements.

inflate()

Inflates array by reinserting masked elements and reshaping into original structure.

numpyXtns.numpyXtns.iqr(a)

Compute inter-quartile range of data.

Parameters:a (float or int array) – data array.
Returns:inter-quartile range (float).
numpyXtns.numpyXtns.loadASCIIlist(fname, separator=None, fillValue=None, dtype=None)

Reads an ascii data file into a nested list with outer elements being lines, inner elements separated by an arbitrary separating character. The default separator None corresponds to any whitespace character. fillValue (if defined) replaces empty elements (‘’).

Parameters:
  • fname (str) – input file path.
  • separator (str) – str used as element separator in input file.
  • fillValue () – object that will be used as fill value for empty elements.
  • dtype (function) – conversion function to be applied on input element strings.
Returns:

Nested list (1 level) with data from file.

numpyXtns.numpyXtns.midDate(do1, do2)

Compute the centre of two date time object.

Parameters:
  • do1 (datetime) – First date.
  • do2 (datetime) – Second date.
Returns:

datetime object in the middle of the two input dates.

numpyXtns.numpyXtns.midMonth(y, m)

Computes centre of a month as datetime object.

Parameters:
  • y (int) – Year.
  • m (int) – Month.
Returns:

datetime object in the middle of the month.

numpyXtns.numpyXtns.midYear(y)

Computes centre of a year as datetime object.

Parameters:y (int) – Year.
Returns:datetime object in the middle of the year.
numpyXtns.numpyXtns.point_inside_polygon(x, y, poly)

Check if point (x,y) is in polygon poly. Polygon poly is of shape N,2.

Parameters:
  • x (float) – x-coordinate of point to check.
  • y (float) – y-coordinate of point to check.
  • poly (seqeunce of float tuples) – polygon.
Returns:

True if inside, False if not.

numpyXtns.numpyXtns.polygonArea(corners)

Compute polygon area.

Parameters:corners (seqeunce of float tuples) – polygon corner points.
Returns:Polygon area (float).
numpyXtns.numpyXtns.quantiles(data, prob=[0.25, 0.5, 0.75], alphap=0.4, betap=0.4, axis=None)

Computes empirical quantiles for a 1xN data array. Samples quantile are defined by: Q(p) = (1-g).x[i] +g.x[i+1] where x[j] is the jth order statistic, with i = (floor(n*p+m)), m=alpha+p*(1-alpha-beta) and g = n*p + m - i).

Typical values of (alpha,beta) are:

  • (0,1) : p(k) = k/n : linear interpolation of cdf (R, type 4)
  • (.5,.5) : p(k) = (k+1/2.)/n : piecewise linear function (R, type 5)
  • (0,0) : p(k) = k/(n+1) : (R type 6)
  • (1,1) : p(k) = (k-1)/(n-1). In this case, p(k) = mode[F(x[k])]. That’s R default (R type 7)
  • (1/3,1/3): p(k) = (k-1/3)/(n+1/3). Then p(k) ~ median[F(x[k])]. The resulting quantile estimates are approximately median-unbiased regardless of the distribution of x. (R type 8)
  • (3/8,3/8): p(k) = (k-3/8)/(n+1/4). Blom. The resulting quantile estimates are approximately unbiased if x is normally distributed (R type 9)
  • (.4,.4) : approximately quantile unbiased (Cunnane)
  • (.35,.35): APL, used with PWM
Parameters:
  • x (sequence) – Input data, as sequence or array of maximum 2 dimensions.
  • prob (sequence) – List of quantiles to compute.
  • alpha (float) – Plotting positions parameter.
  • beta (float) – Plotting positions parameter.
  • axis (integer) – axis along which to compute quantiles. If None, uses the whole (flattened/compressed) dataset.
Returns:

Array with quantiles at the probabilities requested, returns NaN for points masked in all samples.

numpyXtns.numpyXtns.sd_N(x, N=2)

Convert number to N significant digits.

Parameters:
  • x (float) – float to Convert
  • N (integer) – number of significant digits to keep
Returns:

Converted number (float).

numpyXtns.numpyXtns.secsSince(date, refdate)

Computes the seconds passed since a reference date.

Parameters:
  • date (datetime) – Date.
  • refdate (datetime)
Returns:

Seconds passed (integer).

numpyXtns.numpyXtns.smooth(x, window_len=11, window='hanning', extrapolate='rotation')

Smooth input data using a window with requested size.

This method is based on the convolution of a scaled window with the signal. The signal is prepared by introducing reflected copies of the signal (with the window size) in both ends so that transient parts are minimized in the begining and end part of the output signal.

Parameters:
  • x (array) – the input signal
  • window_len (int) – the dimension of the smoothing window; should be an odd integer
  • window (str) – the type of window from ‘flat’, ‘hanning’, ‘hamming’, ‘bartlett’, ‘blackman’; flat window will produce a moving average smoothing.
Returns:

The smoothed signal.

Example:

t=linspace(-2,2,0.1)
x=sin(t)+randn(len(t))*0.1
y=smooth(x)

see also:

numpy.hanning, numpy.hamming, numpy.bartlett, numpy.blackman, numpy.convolve scipy.signal.lfilter

TODO: the window parameter could be the window itself if an array instead
of a string
numpyXtns.numpyXtns.spread(a)

Print basic statistical information on data.

Parameters:a (float or int array) – data array.
numpyXtns.numpyXtns.wquantiles(data, weights, prob=[0.5], axis=None)

Computes weighted quantiles as the intersect of the probability level with the corresponding cumulative distribution function, where the bin height of each sample on the probability axis is given by its relative weight (i.e. the weights are normalised to add up to 1).

Parameters:
  • data (array of sortable type) – input dataset
  • weights (array of floats) – weight for each sample, same dimension as input dataset
  • prob (sequence of floats) – quantiles to be computed (defaults to median)
Returns:

Array with quantile data for each probability requested in the first dimension.

This function does not deal with mask, if you have masked data, retrieve the pure data and set the weight factors to 0 for the masked elements.

Module contents

numpyXtns package initialisation.