artemis.externals.physt.histogram1d¶
One-dimensional histograms.
Module Contents¶
-
class
artemis.externals.physt.histogram1d.Histogram1D(binning, frequencies=None, errors2=None, *, stats=None, **kwargs)¶ Bases:
artemis.externals.physt.histogram_base.HistogramBaseOne-dimensional histogram data.
The bins can be of different widths.
The bins need not be consecutive. However, some functionality may not be available for non-consecutive bins (like keeping information about underflow and overflow).
-
_stats¶ - Type
dict
These are the basic attributes that can be used in the constructor (see there) Other attributes are dynamic.
-
EMPTY_STATS¶
-
property
axis_name(self)¶
-
select(self, axis, index, force_copy: bool = False)¶ Alias for [] to be compatible with HistogramND.
-
__getitem__(self, i)¶ Select sub-histogram or get one bin.
- Parameters
i (int or slice or bool masked array or array with indices) – In most cases, this has same semantics as for numpy.ndarray.__getitem__
- Returns
Depending on the parameters, a sub-histogram or content of one bin are returned.
- Return type
Histogram1D or tuple
-
property
_binning(self)¶ Adapter property for HistogramBase interface
-
property
binning(self)¶ The binning.
Note: Please, do not try to update the object itself.
-
property
bins(self)¶ Array of all bin edges.
- Returns
- Return type
Wide-format [[leftedge1, rightedge1], .. [leftedgeN, rightedgeN]]
-
property
numpy_bins(self)¶ Bins in the format of numpy.
-
property
edges(self)¶
-
property
numpy_like(self)¶ Same result as would the numpy.histogram function return.
-
property
cumulative_frequencies(self)¶ Cumulative frequencies.
Note: underflow values are not considered
-
property
underflow(self)¶
-
property
overflow(self)¶
-
property
inner_missed(self)¶
-
mean(self)¶ Statistical mean of all values entered into histogram.
This number is precise, because we keep the necessary data separate from bin contents.
-
std(self)¶ Standard deviation of all values entered into histogram.
This number is precise, because we keep the necessary data separate from bin contents.
- Returns
- Return type
float
-
variance(self)¶ Statistical variance of all values entered into histogram.
This number is precise, because we keep the necessary data separate from bin contents.
- Returns
- Return type
float
-
property
bin_left_edges(self)¶ Left edges of all bins.
- Returns
- Return type
numpy.ndarray
-
property
bin_right_edges(self)¶ Right edges of all bins.
- Returns
- Return type
numpy.ndarray
-
property
min_edge(self)¶ Left edge of the first bin.
- Returns
- Return type
float
-
property
max_edge(self)¶ Right edge of the last bin.
- Returns
- Return type
float
-
property
bin_centers(self)¶ Centers of all bins.
- Returns
- Return type
numpy.ndarray
-
property
bin_widths(self)¶ Widths of all bins.
- Returns
- Return type
numpy.ndarray
-
property
total_width(self)¶ Total width of all bins.
In inconsecutive histograms, the missing intervals are not counted in.
- Returns
- Return type
float
-
property
bin_sizes(self)¶
-
find_bin(self, value)¶ Index of bin corresponding to a value.
- Parameters
value (float) – Value to be searched for.
- Returns
index of bin to which value belongs (-1=underflow, N=overflow, None=not found - inconsecutive)
- Return type
int
-
fill(self, value, weight=1)¶ Update histogram with a new value.
- Parameters
value (float) – Value to be added.
weight (float, optional) – Weight assigned to the value.
- Returns
int – index of bin which was incremented (-1=underflow, N=overflow, None=not found)
Note (If a gap in unconsecutive bins is matched,)
underflow & overflow are not valid anymore.
Note (Name was selected because of the eponymous method in ROOT)
-
fill_n(self, values, weights=None, dropna: bool = True)¶ Update histograms with a set of values.
- Parameters
values (array_like) –
weights (Optional[array_like]) –
drop_na (Optional[bool]) – If true (default), all nan’s are skipped.
-
__eq__(self, other)¶
-
to_dataframe(self)¶ Convert to pandas DataFrame.
This is not a lossless conversion - (under/over)flow info is lost.
-
classmethod
_kwargs_from_dict(cls, a_dict: dict)¶
-
-
artemis.externals.physt.histogram1d.calculate_frequencies(data, binning, weights=None, validate_bins=True, already_sorted=False, dtype=None)¶ Get frequencies and bin errors from the data.
- Parameters
data (array_like) – Data items to work on.
binning (physt.binnings.BinningBase) – A set of bins.
weights (array_like, optional) – Weights of the items.
validate_bins (bool, optional) – If True (default), bins are validated to be in ascending order.
already_sorted (bool, optional) – If True, the data being entered are already sorted, no need to sort them once more.
dtype (Optional[type]) – Underlying type for the histogram. (If weights are specified, default is float. Otherwise long.)
- Returns
frequencies (numpy.ndarray) – Bin contents
errors2 (numpy.ndarray) – Error squares of the bins
underflow (float) – Weight of items smaller than the first bin
overflow (float) – Weight of items larger than the last bin
stats (dict) – { sum: …, sum2: …}
Note
Checks that the bins are in a correct order (not necessarily consecutive). Does not check for numerical overflows in bins.