Commit b40cfd2f authored by Pierre Paleo's avatar Pierre Paleo
Browse files

Histogram: use silx by default

parent 8fd980fa
from math import log2, ceil
import numpy as np
from silx.math import Histogramnd
from import HDF5File
from ..utils import check_supported
from ..resources.logger import LoggerOrPrint
......@@ -13,17 +14,11 @@ class PartialHistogram:
data are readily available in-memory.
histogram_methods = [
histogram_methods = ["fixed_bins_width", "fixed_bins_number"]
bin_width_policies = ["uint16"]
backends = ["numpy", "silx"]
bin_width_policies = [
def __init__(self, method="fixed_bins_width", bin_width="uint16", num_bins=None, min_bins=None):
def __init__(self, method="fixed_bins_width", bin_width="uint16", num_bins=None, min_bins=None, backend="silx"):
Initialize a PartialHistogram class.
......@@ -49,9 +44,14 @@ class PartialHistogram:
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".
check_supported(method, self.histogram_methods, "histogram computing method")
self.method = method
check_supported(backend, self.backends, "histogram backend")
self.backend = backend
self.min_bins = min_bins
......@@ -114,7 +114,13 @@ class PartialHistogram:
if data.ndim > 1:
data = data.ravel()
dmin, dmax = data.min(), data.max() if data_range is None else data_range
res = np.histogram(data, bins=self.num_bins)
if self.backend == "numpy":
res = np.histogram(data, bins=self.num_bins)
elif self.backend == "silx":
histogrammer = Histogramnd(
data, n_bins=self.num_bins, histo_range=(dmin, dmax), last_bin_closed=True
res = histogrammer.histo, histogrammer.edges[0]
return res
......@@ -232,8 +238,8 @@ class VolumeHistogram:
except KeyError:
msg = str(
"Could not access HDF5 path %s in file %s. Please check that this file \
actually contains a reconstruction and that the HDF5 entry %s is correct"
% (self.data_path, self.fname, self.entry)
actually contains a reconstruction and that the HDF5 path is correct"
% (self.data_path, self.fname)
raise ValueError(msg)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment