galaximview.classeshists module¶
- class galaximview.classeshists.CicHist2DOfXY(xcoords, ycoords, xrange, yrange, nbx=128, nby=128)[source]¶
Bases:
galaximview.classeshists.Hist2DOfXY
Class for two-dimensional cloud-in-cell histograms with nbx,y+1 linear bins edges from x,ymin to x,ymax.
- class galaximview.classeshists.CicHistOfX(rad, xrange, nbins=128)[source]¶
Bases:
galaximview.classeshists.HistOfX
Class for one-dimensional cloud-in-cell histograms with nb+1 linear bins edges from rmin to rmax.
- binned_dispersion_of_y_of_f_of_x(tobin, weights=None)[source]¶
Returns middle-points of bins and mass-weighted dispersion of tobin array in rad bins.
- Parameters
weights (ndarray) – (N,) masses.
tobin –
- class galaximview.classeshists.Hist2DOfXY(xcoords, ycoords, xrange, yrange, nbx=128, nby=128, funcofx=<function identity_function>, funcofy=<function identity_function>, yedges=None, xedges=None)[source]¶
Bases:
object
Class for one-dimensional histograms with nbins+1 linear bins edges in funcofx of array xarr computed in initialization, except if edges are given.
- Parameters
xcoords (ndarray) – (N,) array to bin.
ycoords (ndarray) – (M,) array to bin.
xrange ((float, float) or (None, None)) – Range on which to bin xcoords. If (None, None), chosen by function xrange_from_xarr. Not used if xedges and yedges are not None.
yrange ((float, float) or (None, None)) – Range on which to bin ycoords. If (None, None), chosen by function xrange_from_xarr. Not used if xedges and yedges are not None.
xedges (ndarray or None, optional) – Edges of histogram. Used if given. If None, xedges set with xrange and nbx by function func:~galaximview.classeshists.linearly_spaced_edges_in_function_from_bin_size, so that they are linearly spaced in funcofx.
yedges (ndarray or None, optional) – Edges of histogram. Used if given. If None, yedges set with yrange and nby by function func:~galaximview.classeshists.linearly_spaced_edges_in_function_from_bin_size, so that they are linearly spaced in funcofy.
- binned_in_2d_array(tobin, weights=None)[source]¶
Returns average of tobin array in 2d bins, weighted if weights is not None, middle-points of y bins and of x bins.
- Parameters
tobin (ndarray) – (N,) array to bin.
weights (ndarray, optional) – (N,) weights.
- Returns
(nby, nbx) histogram, (nby,) y bins middle-points and (nbx,) x bins middle-points.
- Return type
(ndarray, ndarray, ndarray)
- binned_in_2d_dispersion_of_array(tobin, weights=None)[source]¶
Returns dispersion of tobin array in 2d bins, weighted if weights is not None, y edges and x edges. :param tobin: (N,) array to bin. :type tobin: ndarray :param weights: (N,) weights. :type weights: ndarray, optional
- Returns
(nby, nbx) histogram, (nby,) y bins middle-points and (nbx,) x bins middle-points.
- Return type
(ndarray, ndarray, ndarray)
- get_x_binswidth()[source]¶
Returns width of bins of (nbx+1) edges computed in self.__init__. :returns: (nbx,) widths. :rtype: ndarray
- get_x_midbins()[source]¶
Returns middle-points of (nbins+1) x edges computed in self.__init__.
- Returns
(nbins,) middle points.
- Return type
ndarray
- get_y_binswidth()[source]¶
Returns width of bins of (nby+1) edges computed in self.__init__. :returns: (nby,) widths. :rtype: ndarray
- get_y_midbins()[source]¶
Returns middle-points of (nbins+1) y edges computed in self.__init__.
- Returns
(nbins,) middle points.
- Return type
ndarray
- hist2d(weights=None)[source]¶
Returns histogram and middle-points of nby bins of (nby+1,) yedges and of nbx bins of (nbx+1,) xedges, and number of points of funcofx(xcoords) and funcofy(ycoords) in 2D bins if weights is None, or else sum of weights of points.
- Parameters
weights (ndarray, optional) – (N,) weights.
- Returns
(nby, nbx) histogram, (nby,) y bins middle-points and (nbx,) x bins middle-points.
- Return type
(ndarray, ndarray, ndarray)
- volumes_of_bins(volstrx, volstry)[source]¶
Attributes a “volume” to 2D bins from their edges: ‘width’ for the normal width, (left edge) - (right edge) of x or y dimension ‘annulus_surface’ for pi * (right edge) ** 2 - (left edge) ** 2 of x or y dimension ‘spherical_shell’ for 4/3 * pi * (right edge) ** 3 - (left edge) ** 3 of x or y dimension
- Parameters
volstrx ({'width', 'annulus_surface', 'spherical_shell'}) – Type of cell volume.
volstry ({'width', 'annulus_surface', 'spherical_shell'}) – Type of cell volume.
- Returns
(nby,nbx) array of bins ‘volume’.
- Return type
ndarray
- volumic_hist2d(weights=None, volstrx='width', volstry='width')[source]¶
Computes a histogram (weighted if weights is not None) divided by the “volume” of bins.
- Parameters
weights (ndarray, optional) – (N,) weights.
volstrx ({'width', 'annulus_surface', 'spherical_shell'}) – Type of bin volume. See ~galaximview.classeshists.Hist2DOfXY.volumes_of_bin.
volstry ({'width', 'annulus_surface', 'spherical_shell'}) – Type of bin volume. See ~galaximview.classeshists.Hist2DOfXY.volumes_of_bin.
- Returns
(nby, nbx) histogram divided by cells ‘volumes’, (nby,) y bins middle-points and (nbx,) x bins middle-points.
- Return type
(ndarray, ndarray, ndarray)
- class galaximview.classeshists.HistOfX(xarr, xrange, nbins=128, funcofx=<function identity_function>, edges=None, fill_range=False)[source]¶
Bases:
object
Class for one-dimensional histograms with nbins+1 linear bins edges in funcofx of array xarr computed in initialization, except if edges are given.
- Parameters
xarr (ndarray) – (N,) array to bin.
xrange ((float, float) or (None, None)) – Range on which to bin xarr. If (None, None), chosen by function xrange_from_xarr. Not used if edges is not None.
nbins (int, default = 128) – Number of bins. Not used if edges is not None.
funcofx (weights: ndarray, optionaldefault =
identity_function()
) – Function such that funcofx(xarr) is binned.edges (ndarray or None, default = None) – Edges of histogram. Used if given. If None, edges set with xrange and nbins by function
linearly_spaced_edges_in_function_from_bin_size()
, so that they are linearly spaced in funcofx.fill_range (bool, default = ` False`) – If True and edges is not None, bins are added to cover full range of xarr. Used to keep a constant bin width.
- binned_dispersion_of_y_of_f_of_x(tobin, weights=None)[source]¶
Returns middle-points of bins and dispersion of tobin array in bins, weighted if weights is not None. :param tobin: (N,) array to bin. :type tobin: ndarray :param weights: (N,) weights. :type weights: ndarray, optional
- Returns
(nbins,) bins middle-points and weighted dispersion of tobin array in bins.
- Return type
(ndarray, ndarray)
- binned_y_of_f_of_x(tobin, weights=None)[source]¶
Returns middle-points of nbins bins of (nbins+1,) edges computed in self.__init__ and average of tobin array in bins, weighted if weights is not None. :param tobin: (N,) array to bin. :type tobin: ndarray :param weights: (N,) weights. :type weights: ndarray, optional
- Returns
(nbins,) bins middle-points and mass-weighted average of tobin array in bins.
- Return type
(ndarray, ndarray)
- get_bins_widths()[source]¶
Returns width of bins of (nbins+1) edges computed in self.__init__.
- Returns
(nbins,) widths.
- Return type
ndarray
- get_midbins()[source]¶
Returns middle-points of (nbins+1) edges computed in self.__init__.
- Returns
(nbins,) middle points.
- Return type
ndarray
- hist_of_f_of_x(weights=None)[source]¶
Returns middle-points of nbins bins of (nbins+1,) edges computed in self.__init__ and number of array members of funcofx(xarr) in bins if weights is None, or else sum of weights of array members of funcofx(xarr) in bins. :param weights: (N,) weights. :type weights: ndarray, optional
- Returns
(nbins,) bins middle-points and histogram of funcofx(xarr).
- Return type
(ndarray, ndarray)
- volumes_of_bin(volstr)[source]¶
Attributes a “volume” to bins from their edges: ‘width’ for the normal width, (left edge) - (right edge) ‘annulus_surface’ for pi * (right edge) ** 2 - (left edge) ** 2 ‘spherical_shell’ for 4/3 * pi * (right edge) ** 3 - (left edge) ** 3
- Parameters
volstr ({'width', 'annulus_surface', 'spherical_shell'}) – Type of cell volume.
- Returns
(nbins,) array of cells ‘volume’.
- Return type
ndarray
- volumic_hist_of_f_of_x(weights=None, volstr='width')[source]¶
Computes a histogram (weighted if weights is not None) of func(xarr) divided by the “volume” of bins.
- Parameters
weights (ndarray, optional) – (N,) weights.
volstr ({'width', 'annulus_surface', 'spherical_shell'}) – Type of bin volume. See ~galaximview.classeshists.HistOfX.volumes_of_bin.
- Returns
(nbins,) bins middle-points and histogram of funcofx(xarr) divided by cells ‘volume’.
- Return type
(ndarray, ndarray)
- galaximview.classeshists.fill_range_around_edges(arr, func, edges)[source]¶
Fills range of func(arr) with additional bins if edges do not cover the whole range. :param arr: (N,) array. :type arr: ndarray :param func: Function such that bins in func(arr) are computed. :type func: ufunc :param edges: Edges. :type edges: ndarray
- Returns
Edges covering the whole range of func(arr), linearly space in func(arr).
- Return type
ndarray
- galaximview.classeshists.linearly_spaced_edges_in_function_from_bin_size(xrange, function, bin_size)[source]¶
Returns edges linearly spaced in function, i.e. function(xmin) + np.arange(nb + 1) * (function(xmax) - function(xmin)) / (nb)”
- Parameters
xrange ((float, float)) – (xmin, xmax)
bin_size (float) – Width of bins.
function (ufunc) – Function such that unction(xmin) + np.arange(nb + 1) * (function(xmax) - function(xmin)) / (nb) is returned.
- Returns
(nb+1,) edges linearly spaced in function.
- Return type
ndarray
- galaximview.classeshists.linearly_spaced_edges_in_function_from_nb(xrange, function, nb)[source]¶
Returns edges linearly spaced in function, i.e. function(xmin) + np.arange(nb + 1) * (function(xmax) - function(xmin)) / (nb)”
- Parameters
xrange ((float, float)) – (xmin, xmax)
nb (int) – Number of bins.
function (ufunc) – Function such that unction(xmin) + np.arange(nb + 1) * (function(xmax) - function(xmin)) / (nb) is returned.
- Returns
(nb+1,) edges linearly spaced in function.
- Return type
ndarray
- galaximview.classeshists.xrange_from_xarr(xarr, xrange, funcofx)[source]¶
Returns xrange if not (None, None) or else chooses reasonable range according to chosen function of x.
- Parameters
xarr (ndarray) – (N,) array.
xrange ((float, float) or (None, None)) – (xmin,xmax) returned as such if not (None, None).
funcofx (ufunc) – Function such that the histogram will be of funcofx(xarr).
- Returns
Rangeon which the histogram of funcofx(xarr) will be computed.
- Return type
(float, float)