Closed tristangrad closed 12 months ago
The code for reproducing the error is missing, right? This is not failing for me
ahh the function is in the title...
works for me:
In [24]: fov_offset_bins = u.Quantity(sorted(np.random.rand(100)), 'deg')
In [25]: true_energy_bins = u.Quantity(sorted(np.random.rand(100)), 'TeV')
In [26]:
In [26]: effective_area_per_energy_and_fov(selected_events, simulation_info, true_energy_bins, fov_offset_bins)
Out[26]:
<Quantity [[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]] m2>
Same here, I've rewritten your example as a test, which passes. Maybe some conflicting versions of astropy and numpy?
def test_viewcone_integral_effective_area_per_energy_and_fov():
import astropy.units as u
from astropy.table import QTable
from pyirf.irf import effective_area_per_energy_and_fov
from pyirf.simulations import SimulatedEventsInfo
simulation_info = SimulatedEventsInfo(
energy_min=0.003 * u.TeV,
energy_max=330 * u.TeV,
spectral_index=-2,
n_showers=1000000,
max_impact=500 * u.m,
viewcone_min=0 * u.deg,
viewcone_max=10 * u.deg,
)
fov_bins = [0, 2] * u.deg
energy_bins = [0, 1] * u.TeV
selected_events = QTable(
data=[[0.05 * u.TeV], [1.35 * u.deg]],
names=["true_energy", "true_source_fov_offset"],
)
aeff = effective_area_per_energy_and_fov(
selected_events=selected_events,
simulation_info=simulation_info,
true_energy_bins=energy_bins,
fov_offset_bins=fov_bins,
)
assert aeff >= 0
Tested with the current pyirf main and astropy=5.3.2 numpy=1.25.2 python=3.11.5
Edit: Also works in a fresh python 3.9 env with pyirf v0.10
Test works for me too with: astropy=5.3.3 numpy=1.25.2 python=3.9.18
installed via conda
using this function with below specified (but probably arbitrarily) args creates the error 'AttributeError: 'numpy.ndarray' object has no attribute '_set_unit''
minimal (not) working example: