helpers

Functions:

edges4grid(grid)

Returns the edges for a given grid vector as well as the corresponding width of these bins.

bin_data(y, x, X[, statistic])

This is a wrapper around scipy's binned_statistic.

pyEvalData.helpers.edges4grid(grid)[source]

Returns the edges for a given grid vector as well as the corresponding width of these bins.

The grid is NOT altered - on purpose! So even if the grid is not unique there will be bins of width 0.

Be also aware of the hanling of the first and last bin, as they will contain values which will lay outside of the original grid.

grid x x x x x x x x

edges | | | | | | | | |

binwidth <—> <—> <—> <—> <—> <—> <—> <—>

Attributes

grid (ndarray[float]) – array of grid points.

Returns

(tuple)

  • edges (ndarray[float]) - array of edges.

  • binwidth (ndarray[float]) - array of bin widths.

pyEvalData.helpers.bin_data(y, x, X, statistic='mean')[source]

This is a wrapper around scipy’s binned_statistic. In the first step possbile masked elements from the input arrays x and y are removed. The same applies for the new grid array X which is also sorted and made unique.

In a second step the edges for the new grid are calculated by edges4grid and used to calculate the new binned values Y by using scipy.stats.binned_statistsic.

The type of statistic can be chosen. In case of sum Poisson statistics are applied to calculate the standard derivation of the binned values Y. Also errors due to the horizontal binning are calculated and returned. All return values contain only elements with according non-zero bins.

Parameters
  • y (ndarray[float]) – input y array.

  • x (ndarray[float]) – input x array.

  • X (ndarray[float]) – new grid array.

  • statistic (str, optional) – type of statistics used for scipy’s binned_statistic - default is mean.

Returns

(tuple)

  • Y (ndarray[float]) - binned Y data without zero-bins.

  • X (ndarray[float]) - new X grid array.

  • Yerr (ndarray[float]) - Error for Y, according to statistic.

  • Xerr (ndarray[float]) - Error for Y, according to statistic.

  • Ystd (ndarray[float]) - Std for Y, according to statistic.

  • Xstd (ndarray[float]) - Std for X, according to statistic.

  • edges (ndarray[float]) - Edges of binned data.

  • bins (ndarray[float]) - Indices of the bins.

  • n (ndarray[float]) - Number of values per given bin.