maad.util.into_bins
- maad.util.into_bins(x, an, bin_step, axis=0, bin_min=None, bin_max=None, display=False)[source]
Divide a vector (1D) or a matrix (2D) into multiple bins according to a bin_step with respect of the energy
- Parameters:
- xarray-like
1D or 2D array to bin
- an :1d ndarray of floats
Vector containing the positions of each value. In case of 2D matrix, this vector corresponds to the horizontal (row) or vertical (columns) units
- bin_stepscalar
Determine the width of each bin.
- axisinteger, optional, default is 0
Determine along which axis the transformation is done. In case of matrix : axis = 0 => transformation is done on column axis = 1 => transformation is done on row
- bin_minscalar, optional, default is None
This minimum value corresponds to the start of the first bin. By default, the minimum value is the first value of an.
- bin_maxscalar, optional, default is None
This maximum value corresponds to end of the last bin. By default, the maximum value is the last value of an.
- displayboolean, optional, defualt is False
Display the result of the tranformation : an histogram In case of matrix, the mean histogram is shown.
- Returns:
- xbinsarray-like
1D or 2D array which correspond to the data after being transformed into bins
- bin1d ndarray of floats
Vector containing the positions of each bin
Examples
>>> import numpy as np >>> frequency = np.arange(0,20000,100) >>> delta = np.random.uniform(-10,10, size=(len(frequency),)) >>> amplitude = 0.001 * frequency + 3 + delta >>> fig_kwargs = {'figtitle':'', 'xlabel':'Frequency [Hz]', 'ylabel':'AU', 'linewidth': 0.5, 'legend' : 'before binning' } >>> ax,fig = maad.util.plot1d(frequency,amplitude,**fig_kwargs) >>> amplitude_bin,frequency_bin = maad.util.into_bins(amplitude,frequency,bin_step=1000) >>> fig_kwargs = {'figtitle':'', 'xlabel':'Frequency [Hz]', 'ylabel':'AU', 'linewidth': 0.5, 'color' :'red', 'legend' : 'after binning' } >>> ax,fig = maad.util.plot1d(frequency_bin, amplitude_bin, ax, **fig_kwargs)