Repository navigation
Fix np.digitize mapping values at the upper bin edge to an out-of-range index - #346
Conversation
| log_true_e_idxs = np.clip( | ||
| np.digitize(log_true_e, bins=sm.true_e_bin_edges) - 1, | ||
| 0, | ||
| sm.n_log10_true_e_bins - 1, | ||
| ) |
There was a problem hiding this comment.
I'm not 100% sure if we need to clip here as that should not happen, but it's probably better to be safe.
There was a problem hiding this comment.
But then we also need to make sure that the correct energy is stored in the log_true_energy key of the events record array maybe, no?
There was a problem hiding this comment.
okay, I've replaced the clip with 4f1badd because sometime later there is a check for isvalid events and in case log_true_e happened to be outside the valid range it wouldn't be injected 😅
Claude is complaining a bit but it's our fault that we didn't match aeff and sm binnings....
A separate issue I noticed: in about 5–11 declination bins for IC40, IC59 and IC79, the spline can return energies slightly below the lower end of the valid range. That's because an effective-area
bin whose centre is inside the range can have its lower edge outside it. Those energies are still inside the smearing matrix, but in a true-energy bin with no reconstructed-energy PDF, so those
events come out as isvalid=False. This was already happening before the PR, so I'd leave it for a separate issue.
| """ | ||
| return self._aeff_decnu_log10enu | ||
|
|
||
| def get_decnu_idx(self, decnu: float) -> int: |
There was a problem hiding this comment.
This change is here so that it merges with #342 with less conflicts
09acf22 to
c89fc14
Compare
There was a problem hiding this comment.
I think that, as it is written now, the last bin always includes the upper edge, right? Maybe update the docstring to reflect this?
| log_true_e_idxs = np.clip( | ||
| np.digitize(log_true_e, bins=sm.true_e_bin_edges) - 1, | ||
| 0, | ||
| sm.n_log10_true_e_bins - 1, | ||
| ) |
There was a problem hiding this comment.
But then we also need to make sure that the correct energy is stored in the log_true_energy key of the events record array maybe, no?
There was a problem hiding this comment.
Let's use the new get_bin_indices_from_binedges method here too!
c89fc14 to
52419b3
Compare
…sampled true energies
4f1badd to
40ae2e6
Compare
No description provided.