Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions baccmod/base_acceptance_map_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

from .bkg_collection import BackgroundCollectionZenith, BackgroundCollection, BackgroundCollectionZenithSplitAzimuth
from .exception import BackgroundModelFormatException
from .logging import MOREINFO
from .toolbox import (compute_rotation_speed_fov,
get_unique_wobble_pointings,
get_time_mini_irf,
Expand Down Expand Up @@ -608,6 +609,7 @@ def _compute_dynamic_energy_axis(self, base_energy_axis: MapAxis, data: np.ndarr
indexes_edges = [len(edges_energy_axis)-1]

# Evaluate bin edges fulfilling the dynamic criteria
maximum_wideness_hit = 0
while i > min_i:
# Index for the mean count criteria
j_counts = np.sum(rev_cumsumdata >= self.dynamic_energy_axis_target_statistics)-1
Expand All @@ -625,8 +627,7 @@ def _compute_dynamic_energy_axis(self, base_energy_axis: MapAxis, data: np.ndarr
j = j_counts
else:
j = j_maxw
logger.warning(
'Dynamic energy binning is unable to reach target statistics due to bin maximum bin wideness')
maximum_wideness_hit += 1
indexes_edges.append(j)
rev_cumsumdata -= rev_cumsumdata[j]
i = j
Expand All @@ -636,7 +637,13 @@ def _compute_dynamic_energy_axis(self, base_energy_axis: MapAxis, data: np.ndarr
if self.dynamic_energy_axis_merge_zeros_high_energy and len(zeros_highE)>0:
zeros_highE = np.array([i0], dtype=int)
indexes_edges=np.sort(np.concatenate([zeros_highE, indexes_edges, zeros_lowE], dtype=int))
return MapAxis.from_energy_edges(edges_energy_axis[np.array(indexes_edges, dtype=int)], name='energy')
energy_axis = MapAxis.from_energy_edges(edges_energy_axis[np.array(indexes_edges, dtype=int)], name='energy')
logger.log(MOREINFO,'Dynamic energy binning : %s', np.array_str(np.round(energy_axis.edges, 3)))
Comment thread
MSCarrasco marked this conversation as resolved.
logger.log(MOREINFO,'Number of bin limited by the maximum bin wideness : %d', maximum_wideness_hit)
logger.debug('Number of counts per spatial bin in each energy bin:\n%s', np.array_str(
Comment thread
MSCarrasco marked this conversation as resolved.
np.abs(np.append(np.diff(rev_cumsumdata[np.array(indexes_edges[:-1], dtype=int)]),
cumsumdata[-1]+rev_cumsumdata[indexes_edges[-2]]-rev_cumsumdata[0]))))
return energy_axis

@staticmethod
def _split_observations_azimuth(observations: Observations) -> Tuple[Observations, Observations, Dict[int, Dict[str, Any]]]:
Expand Down Expand Up @@ -910,6 +917,7 @@ def _create_acceptance_model(self,
"""
models={}
for key in off_observations.keys():
logger.info('Creating model for subset : %s', key)
if zenith_interpolation or zenith_binning:
models[key] = self._create_model_cos_zenith_binned(observations=off_observations[key])
else:
Expand Down
Loading