Skip to content

Commit 18e9f07

Browse files
committed
added example to module docs
1 parent 8b67c78 commit 18e9f07

2 files changed

Lines changed: 58 additions & 3 deletions

File tree

docs/api-reference/irf/irfs.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
.. _irfs:
22

33
**************
4-
IRF components
4+
IRF generation
55
**************
66

77

88
Reference/ API
99
==============
1010

11-
.. automodapi:: ctapipe.irf.irfs
11+
.. automodapi:: ctapipe.irf
12+
:no-inheritance-diagram:
13+
14+
.. automodapi:: ctapipe.irf.event_weighter
1215
:no-inheritance-diagram:

src/ctapipe/irf/event_weighter.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,58 @@
11
#!/usr/bin/env python3
22

3-
"""Components for computing event weights."""
3+
"""
4+
Components for computing event weights.
5+
6+
`~ctapipe.irf.EventWeighter` is a base Component with implementations of spectral event weighting:
7+
8+
* `~ctapipe.irf.SimpleEventWeighter`: spectral weighting for the full FOV
9+
* `~ctapipe.irf.RadialEventWeighter`: spectral weighing in radial bins in the FOV
10+
11+
They operate on a pre-processed table of DL2 information, where you specify the
12+
energy and FOV coordinate columns to use. The interface is as follows:
13+
14+
.. code-block:: python
15+
16+
from astropy.table import QTable
17+
18+
from ctapipe.irf import RadialEventWeighter spectrum_from_name
19+
20+
table = QTable(
21+
dict(
22+
true_energy=[1.0, 2.0, 0.5, 0.2] * u.TeV,
23+
true_fov_offset=[0.1, 1.2, 2.2, 3.2] * u.deg,
24+
)
25+
)
26+
27+
# the source spectrum can be anything, but is usually loaded
28+
# with ctapipe.irf.spectrum_from_simulation_config() to
29+
# weight simulations. Here we will just use the electron
30+
# spectrum as a demo:
31+
source_spectrum = spectrum_from_name("IRFDOC_ELECTRON_SPECTRUM")
32+
33+
weighter = RadialEventWeighter(
34+
source_spectrum=source_spectrum
35+
target_spectrum_name="CRAB_HEGRA",
36+
fov_offset_max=5.0*u.deg,
37+
fov_offset_n_bins=5,
38+
)
39+
40+
table_with_weights = weighter(table)
41+
print(table_with_weights)
42+
43+
44+
::
45+
46+
true_energy true_fov_offset weight fov_offset_bin
47+
TeV deg
48+
----------- --------------- ------------------ --------------
49+
1.0 0.1 12.399508446433442 1
50+
2.0 1.2 7.247055871572714 2
51+
0.5 2.2 1.4149219056909543 3
52+
0.2 3.2 0.4812883464910382 4
53+
54+
55+
"""
456

557
from abc import abstractmethod
658
from collections.abc import Callable

0 commit comments

Comments
 (0)