Skip to content

Commit

Permalink
Set numpy version to less than 1.23.0
Browse files Browse the repository at this point in the history
Because of #70
  • Loading branch information
dachengx committed Jul 31, 2023
1 parent 1f9251b commit 789e3f2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
28 changes: 13 additions & 15 deletions alea/template_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def format_named_parameters(self):
return format_named_parameters

def build_histogram(self):
"""Build the histogram of the source."""
templatename = self.config["templatename"].format(**self.format_named_parameters)
histname = self.config["histname"].format(**self.format_named_parameters)
h = template_to_multihist(templatename, histname)
Expand All @@ -112,7 +113,8 @@ def build_histogram(self):

# Fix the bin sizes
if can_check_binning:
self._check_binning(h, f"{histname:s} in hdf5 file {templatename:s}")
histogram_info = f"{histname:s} in hdf5 file {templatename:s}"
self._check_binning(h, histogram_info)

self.set_dtype()
self.set_pdf_histogram(h)
Expand Down Expand Up @@ -241,6 +243,7 @@ class CombinedSource(TemplateSource, HistogramPdfSource):
"""

def build_histogram(self):
"""Build the histogram of the source."""
if not self.config.get("in_events_per_bin", True):
raise ValueError(
"CombinedSource does not support in_events_per_bin=False")
Expand Down Expand Up @@ -293,21 +296,12 @@ def build_histogram(self):
for i in range(len(weights)):
h_comp = histograms[0].similar_blank_histogram()
h = histograms[i + 1]
# base_part_norm = 0.
# h_centers = h_comp.bin_centers()
# h_inds = [range(len(hc)) for hc in h_centers]
# for inds in product(*h_inds):
# bincs = [h_centers[j][k] for j, k in enumerate(inds)]
# inds_comp = h_comp.get_bin_indices(bincs)
# base_part_norm += histograms[0][inds]
# h_comp[inds] = h[inds_comp]
# h_comp *= base_part_norm
hslices = []
for j, bincs in enumerate(h.bin_centers()):
hsliced = h_comp.get_axis_bin_index(bincs[0], j)
hsliceu = h_comp.get_axis_bin_index(bincs[-1], j) + 1
hslices.append(slice(hsliced, hsliceu))
# TODO: check here what norm I want.
hslices.append(slice(hsliced, hsliceu, 1))
# TODO: check the normalization here.
h_comp[hslices] += h.histogram
histograms[0] += h_comp * weights[i]
h = histograms[0]
Expand All @@ -332,7 +326,8 @@ def build_histogram(self):

# Fix the bin sizes
if can_check_binning:
self._check_binning(h, f"combined template {histnames} in hdf5 file {templatenames}")
histogram_info = f"combined template {histnames} in hdf5 file {templatenames}"
self._check_binning(h, histogram_info)

self.set_dtype()
self.set_pdf_histogram(h)
Expand All @@ -357,7 +352,8 @@ def _get_json_spectrum(filename):
:param filename: Name of the JSON file.
:type filename: str
"""
contents = json.load(open(filename, "r"))
with open(filename, "r") as f:
contents = json.load(f)
logging.debug(contents["description"])
esyst = contents["coordinate_system"][0][1]
ret = interp1d(
Expand All @@ -366,6 +362,7 @@ def _get_json_spectrum(filename):
return ret

def build_histogram(self):
"""Build the histogram of the source."""
templatename = self.config["templatename"].format(**self.format_named_parameters)
histname = self.config["histname"].format(**self.format_named_parameters)
h = template_to_multihist(templatename, histname)
Expand Down Expand Up @@ -394,7 +391,8 @@ def build_histogram(self):

# Fix the bin sizes
if can_check_binning:
self._check_binning(h, f"reweighted {histname:s} in hdf5 file {templatename:s}")
histogram_info = f"reweighted {histname:s} in hdf5 file {templatename:s}"
self._check_binning(h, histogram_info)

self.set_dtype()
self.set_pdf_histogram(h)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ iminuit>=2.21.0
matplotlib
mergedeep
multihist
numpy
numpy<1.23.0
PyYAML
scipy
setuptools
Expand Down

0 comments on commit 789e3f2

Please sign in to comment.