pyrfu.pyrf.histogram2d#
- pyrfu.pyrf.histogram2d(inp1, inp2, bins=100, y_range=None, weights=None, density=True, scale='linlin')[source]#
Computes 2d histogram of inp2 vs inp1 with nbins number of bins.
- Parameters:
inp1 (xarray.DataArray) – Time series of the x coordinates of the points to be histogrammed.
inp2 (xarray.DataArray) – Time series of the y coordinates of the points to be histogrammed.
bins (int or array_like or [int, int] or [array, array], Optional) – Number of bins along both dimensions, number of bins along each dimension, or explicit bin edges. Default is
bins=100.y_range (array_like, shape(2,2), Optional) – The leftmost and rightmost edges of the bins along each dimension (if not specified explicitly in the bins parameters):
[[xmin, xmax], [ymin, ymax]]. All values outside of this range will be considered outliers and not tallied in the histogram.weights (array_like, shape(N,), Optional) – An array of values
w_iweighing each sample(x_i, y_i). Weights are normalized to 1 if density is True. If density is False, the values of the returned histogram are equal to the sum of the weights belonging to the samples falling into each bin.density (bool, Optional) – If False, returns the number of samples in each bin. If True, the default, returns the probability density function at the bin,
bin_count / sample_count / bin_area.scale ({"linlin", "loglin", "linlog", "loglog"}, Optional) – Spacing of the bins along the x and y dimensions, in this order. Default is
scale="linlin"(linear bins along both dimensions). A logarithmically spaced dimension only bins strictly positive values, the others are discarded.
- Returns:
out – 2D map of the density of
inp2vsinp1. The bin edges, the scale and the normalization are stored in the attributes.- Return type:
- Raises:
ValueError – If no sample is left to compute the range of the bins, or if a range along a logarithmic dimension is not strictly positive.
Notes
Samples for which either coordinate is not finite (or is not strictly positive along a logarithmic dimension) are discarded, as is the corresponding weight.
When the data along a dimension are constant (and no range or edges are given), the bins span one unit around the value (one decade along a logarithmic dimension), as in numpy.histogram.
The bin centers are the arithmetic means of the bin edges along a linear dimension and their geometric means along a logarithmic one, so that they are at the center of the bins as they are displayed.
The first dimension of the output (
x_bins) is the one ofinp1.xarrayplots the last dimension along the x axis, so useout.plot(x="x_bins")(orout.T.plot()) to getinp2vsinp1.Examples
>>> import numpy as np >>> from pyrfu import mms, pyrf
Time interval
>>> tint = ["2019-09-14T07:54:00.000", "2019-09-14T08:11:00.000"]
Spacecraft indices
>>> mms_id = np.arange(1, 5)
Load magnetic field and electric field
>>> r_mms = [mms.get_data("r_gse", tint, i) for i in mms_id] >>> b_mms = [mms.get_data("b_gse_fgm_srvy_l2", tint, i) for i in mms_id]
Compute current density, etc
>>> j_xyz, _, b_xyz, _, _, _ = pyrf.c_4_j(r_mms, b_mms)
Compute magnitude of B and J
>>> b_mag = pyrf.norm(b_xyz) >>> j_mag = pyrf.norm(j_xyz)
Histogram of J vs B
>>> h2d_b_j = pyrf.histogram2d(b_mag, j_mag)
Same histogram with logarithmically spaced bins along both dimensions
>>> h2d_b_j = pyrf.histogram2d(b_mag, j_mag, scale="loglog")