nabu.processing.histogram module

class nabu.processing.histogram.PartialHistogram(method='fixed_bins_width', bin_width='uint16', num_bins=None, min_bins=None, backend='silx')[source]

Bases: object

A class for computing histogram progressively.

In certain cases, it is cumbersome to compute a histogram directly on a big chunk of data (ex. data not fitting in memory, disk access too slow) while some parts of the data are readily available in-memory.

Initialize a PartialHistogram class.

Parameters:
  • method (str, optional) –

    Partial histogram computing method. Available are:
    • fixed_bins_width: all the histograms are computed with the same bin width. The class adapts to the data range and computes the number of bins accordingly.

    • fixed_bins_number: all the histograms are computed with the same number of bins. The class adapts to the data range and computes the bin width accordingly.

    Default is “fixed_bins_width”

  • bin_width (str or float, optional) –

    Policy for histogram bins when method=”fixed_bins_width”. Available are:
    • ”uint16”: The bin width is computed so that floating-point elements f1 and f2 satisfying |f1 - f2| < bin_width implies f1_converted - f2_converted < 1 once cast to uint16.

    • A number: all the bins have this fixed width.

    Default is “uint16”

  • num_bins (int, optional) – Number of bins when method = ‘fixed_bins_number’.

  • min_bins (int, optional) – Minimum number of bins when method = ‘fixed_bins_width’.

  • backend (str, optional) – Which histogram backend to use for computations. Available are “silx”, “numpy”. Fastest is “silx”.

histogram_methods = ['fixed_bins_width', 'fixed_bins_number']
bin_width_policies = ['uint16']
backends = ['numpy', 'silx']
get_bin_width(dmin, dmax)[source]
compute_histogram(data, data_range=None)[source]
merge_histograms(histograms, **kwargs)[source]
class nabu.processing.histogram.VolumeHistogram(data_url, chunk_size_slices=100, chunk_size_GB=None, nbins=1000000.0, logger=None)[source]

Bases: object

A class for computing the histogram of an entire volume. Unless explicitly specified, histogram is computed in several passes so that not all the volume is loaded in memory.

Initialize a VolumeHistogram object.

Parameters:
  • fname (DataUrl) – DataUrl to the HDF5 file.

  • chunk_size_slices (int, optional) – Compute partial histograms of groups of slices. This is the default behavior, where the groups size is 100 slices. This parameter is mutually exclusive with ‘chunk_size_GB’.

  • chunk_size_GB (float, optional) – Maximum memory (in GB) to use when computing the histogram by group of slices. This parameter is mutually exclusive with ‘chunk_size_slices’.

  • nbins (int, optional) – Histogram number of bins. Default is 1e6.

compute_volume_histogram()[source]
nabu.processing.histogram.hist_as_2Darray(hist, center=True, dtype='f')[source]
nabu.processing.histogram.add_last_bin(histo_bins)[source]

Add the last bin (max value) to a list of bin edges.