Skip to content

Commit

Permalink
Index ndarrays with tuples, not lists
Browse files Browse the repository at this point in the history
This used to be a warning,

```
FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
```

but turned into a hard error some time after numpy 1.21
  • Loading branch information
jvansanten committed May 22, 2024
1 parent e31cb01 commit aa831ae
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions toise/diffuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def point_source_background(
if n_sources is not None:
expand = [None] * bin_areas.ndim
expand[0] = slice(None)
bin_areas = bin_areas * n_sources[expand]
bin_areas = bin_areas * n_sources[tuple(expand)]

# dimensions of the keys in expectations are now energy, radial bin
if is_zenith_weight(zenith_index, self._aeff):
Expand Down Expand Up @@ -475,7 +475,7 @@ def point_source_background(
psi_bins = self._aeff.bin_edges[-1][:-1]
expand = [None] * 5
expand[-1] = slice(None)
bin_areas = (np.pi * np.diff(psi_bins**2))[expand]
bin_areas = (np.pi * np.diff(psi_bins**2))[tuple(expand)]
# observation time shorter for triggered transient searches
if livetime is not None:
background._livetime = livetime / constants.annum
Expand All @@ -494,7 +494,7 @@ def point_source_background(
if n_sources is not None:
expand = [None] * bin_areas.ndim
expand[2] = slice(None)
bin_areas = bin_areas * n_sources[expand]
bin_areas = bin_areas * n_sources[tuple(expand)]

# dimensions of flux are now 1/m^2 sr
if isinstance(sel, slice):
Expand Down
2 changes: 1 addition & 1 deletion toise/fictive.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def get_aeff(angular_resolution=0.5, energy_threshold=1e3):
edges = (e_nu, cos_theta, e_mu[idx:], psi_bins)

return effective_areas.effective_area(
edges, base.values[..., idx:, None] * smear[expand], "cos_theta"
edges, base.values[..., idx:, None] * smear[tuple(expand)], "cos_theta"
)


Expand Down
4 changes: 2 additions & 2 deletions toise/pointsource.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, effective_area, fluence, zenith_selection, with_energy=True):
expand = [None] * effective_area.values.ndim
expand[zenith_dim] = slice(None)
effective_area = (
effective_area.values[..., :-1] * zenith_selection[expand]
effective_area.values[..., :-1] * zenith_selection[tuple(expand)]
).sum(axis=zenith_dim)
else:
effective_area = effective_area.values[..., zenith_selection, :, :-1]
Expand Down Expand Up @@ -82,7 +82,7 @@ def expectations(self, **kwargs):
expand[1] = slice(None)

# FIXME: this still neglects the opening angle between neutrino and muon
total = (self._rate * (specweight[expand])).sum(axis=(0, 1))
total = (self._rate * (specweight[tuple(expand)])).sum(axis=(0, 1))
# assert total.ndim == 2

if not self._use_energies:
Expand Down
2 changes: 1 addition & 1 deletion toise/radio_aeff_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ def point_source_background(
if n_sources is not None:
expand = [None] * bin_areas.ndim
expand[0] = slice(None)
bin_areas = bin_areas * n_sources[expand]
bin_areas = bin_areas * n_sources[tuple(expand)]

# dimensions of the keys in expectations are now energy, radial bin
if is_zenith_weight(zenith_index, self._aeff):
Expand Down
2 changes: 1 addition & 1 deletion toise/surface_veto.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ def point_source_background(
if n_sources is not None:
expand = [None] * bin_areas.ndim
expand[0] = slice(None)
bin_areas = bin_areas * n_sources[expand]
bin_areas = bin_areas * n_sources[tuple(expand)]

# dimensions of the keys in expectations are now energy, radial bin
if is_zenith_weight(zenith_index, self._aeff):
Expand Down

0 comments on commit aa831ae

Please sign in to comment.