nenupy.io.tf_utils.rebin_along_dimension

nenupy.io.tf_utils.rebin_along_dimension(data, axis_array, axis, dx, new_dx)[source]

Rebin data along its axis dimension. The corresponding axis_array is also rebinned. To compute the rebin factor, this function takes as input the inital resolution dx and the final resolution new_dx. If this process results in a new dimension that is not a multiple of the rebin factor, the last samples are leftover and not averaged.

Parameters:
  • data (ndarray) – Data array to be rebinned.

  • axis_array (ndarray) – 1D array, corresponding to the axis tp rebin.

  • axis (int) – Index of the axis to rebin within data.

  • dx (float) – Inital resolution of axis_array.

  • new_dx (float) – Target resolution after rebinning. As the rebin factor is taken as an integer value, the ‘effective new_dx’ of the data after rebinning is the floor division btewwen dx and the target new_dx.

Returns:

Rebinned axis and data.

Return type:

Tuple[ndarray, ndarray]

Raises:

ValueError – Raised if axis_array is not 1D, or if the data[axis]’s size does not match axis_array, or if dx is greater than new_dx.

Examples

>>> from nenupy.io.tf_utils import rebin_along_dimension
>>> new_axis, data_rebinned = rebin_along_dimension(
        data=np.arange(11),
        axis_array=np.arange(11),
        axis=0,
        dx=1,
        new_dx=2.5 # this would result in a rebin-factor of 2.5//1.=2
    )
>>> print(data_rebinned)
[0.5 2.5 4.5 6.5 8.5] # the last sample of data (i.e. 10) has not been considered