nenupy.io.tf_utils.rebin_along_dimension
- nenupy.io.tf_utils.rebin_along_dimension(data, axis_array, axis, dx, new_dx)[source]
Rebin
dataalong itsaxisdimension. The correspondingaxis_arrayis also rebinned. To compute the rebin factor, this function takes as input the inital resolutiondxand the final resolutionnew_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 withindata.dx (
float) – Inital resolution ofaxis_array.new_dx (
float) – Target resolution after rebinning. As the rebin factor is taken as an integer value, the ‘effectivenew_dx’ of thedataafter rebinning is the floor division btewwendxand the targetnew_dx.
- Returns:
Rebinned axis and data.
- Return type:
- Raises:
ValueError – Raised if
axis_arrayis not 1D, or if thedata[axis]’s size does not matchaxis_array, or ifdxis greater thannew_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
See also