|
1 | | -# V2DL3 - VERITAS (VEGAS and Eventdisplay) to DL3 Converter. |
| 1 | +# V2DL3 - VERITAS (VEGAS and Eventdisplay) to DL3 Converter |
2 | 2 |
|
3 | | -V2DL3 is a tool to convert VERITAS data products to DL3 FITS format, allowing to use e.g. the [Gammapy science tools](https://gammapy.org/) for analysis. |
| 3 | +[](https://github.com/VERITAS-Observatory/V2DL3/blob/main/LICENSE) |
| 4 | +[](https://zenodo.org/badge/latestdoi/138582622) |
4 | 5 |
|
5 | | -The converter can be used to convert point-like and full-enclosure IRFs. |
| 6 | +V2DL3 is a tool to convert [VERITAS](https://veritas.sao.arizona.edu/) data products to DL3 FITS format, allowing to use e.g. the [gammapy science tools](https://gammapy.org/) for the high-level analysis. |
| 7 | + |
| 8 | +DL3 files include event lists, instrument response functions (IRFs) and observation index tables. |
| 9 | +The V2DL3 converter can be used to convert point-like and full-enclosure IRFs. |
6 | 10 | The FITS output follows the data formats for gamma-ray astronomy as defined in open [gamma-astro-data-formats](https://github.com/open-gamma-ray-astro/gamma-astro-data-formats) (GADF) repository. |
7 | 11 |
|
8 | | -The projects tries to share as many tools as possible between VEGAS and Eventdisplay, especially those used for writing the FITS files. |
| 12 | +The V2DL3 project tries to share as many tools as possible between VEGAS and [Eventdisplay](https://github.com/VERITAS-Observatory/EventDisplay_v4), especially those used for writing the FITS files. |
9 | 13 |
|
10 | | -The two main tools required to convert VERITAS data products to DL3 FITS format and use them with gammapy are: |
11 | | -- converter to DL3 (`v2dl3-vegas` for VEGAS, `v2dl3_for_Eventdisplay.py` for Eventdisplay) |
12 | | -- tool to generate observation index tables |
| 14 | +Two main steps are required to convert VERITAS data products to DL3 FITS format and use them with gammapy. |
| 15 | +Each of these steps are covered by one of the following tools: |
13 | 16 |
|
14 | | -For contributors: please note the section for developers below. |
| 17 | +- converter of event lists and instrument response functions to DL3 (`v2dl3-vegas` for VEGAS, `v2dl3-for-eventdisplay` for Eventdisplay) |
| 18 | +- `v2dl3-generate-index-file` tool to generate observation index tables |
15 | 19 |
|
16 | | ---- |
17 | | -# V2DL3 for VEGAS |
| 20 | +## V2DL3 for VEGAS |
18 | 21 |
|
19 | | -* VEGAS version >= 2.5.7 |
20 | | -* Requirements are listed in the ```environment-vegas.yml``` file. |
21 | | -* Alternatively, a script which builds a Docker image with the latest V2DL3 and the prerequesite software for v2dl3-vegas is available. See *utils/v2dl3-vegas-docker/README.md* |
| 22 | +- VEGAS version >= 2.5.7 |
| 23 | +- Requirements are listed in the ```environment-vegas.yml``` file. |
| 24 | +- Alternatively, a script which builds a Docker image with the latest V2DL3 and the prerequisite software for v2dl3-vegas is available. See *utils/v2dl3-vegas-docker/README.md* |
22 | 25 |
|
23 | | -## Installation |
| 26 | +### Installation |
24 | 27 |
|
25 | | -Use the [conda package manager](https://docs.conda.io/projects/conda/en/latest/user-guide/install/index.html) to install the dependenies: |
26 | | -``` |
| 28 | +Use the [conda package manager](https://docs.conda.io/projects/conda/en/latest/user-guide/install/index.html) to install the dependencies: |
| 29 | + |
| 30 | +```bash |
27 | 31 | conda env create -f environment-vegas.yml |
28 | 32 | ``` |
| 33 | + |
29 | 34 | The environment ```v2dl3-vegas``` will be created and can be activated with: |
30 | 35 |
|
31 | | -``` |
| 36 | +```bash |
32 | 37 | conda activate v2dl3-vegas |
33 | 38 | ``` |
34 | 39 |
|
35 | 40 | Install now pyV2DL3: |
36 | | -``` |
| 41 | + |
| 42 | +```bash |
37 | 43 | pip install . |
38 | 44 | ``` |
39 | 45 |
|
40 | 46 | ### Docker recipe |
| 47 | + |
41 | 48 | To use a Docker image with v2dl3-vegas pre-installed, see *utils/v2dl3-vegas-docker/README.md* |
42 | 49 |
|
43 | | -## The commandline tool v2dl3 with VEGAS |
| 50 | +### The command line tool v2dl3 with VEGAS |
44 | 51 |
|
45 | 52 | Run `v2dl3-vegas --help` to see all options. |
46 | 53 |
|
47 | 54 | See *README_vegas.md* for more information on newer v2dl3-vegas features such as ITM reconstruction, full-enclosure, and event classes. |
48 | 55 |
|
49 | 56 | Make sure you have ROOT with pyROOT enabled and VEGAS(>=v2.5.7) installed to proceed. |
50 | | -Now, lets create the DL3 fits files from the stage 5 files in the ```./VEGAS/``` folder. |
| 57 | +Now, lets create the DL3 fits files from the stage 5 files in the ```./VEGAS/``` folder. |
51 | 58 |
|
52 | | -### One file at a time |
| 59 | +#### One file at a time |
53 | 60 |
|
54 | | -To convert a single stage 5 file to DL3 fits you need to provide the path to the stage 5 file as well as the corresponding effective area file using the flag ```-f```. The last argument is the name of the ouput DL3 file. |
| 61 | +To convert a single stage 5 file to DL3 fits you need to provide the path to the stage 5 file as well as the corresponding effective area file using the flag ```-f```. The last argument is the name of the output DL3 file. |
55 | 62 |
|
56 | | -``` |
| 63 | +```bash |
57 | 64 | v2dl3-vegas -f ./VEGAS/54809.med.ED.050.St5_Stereo.root ./VEGAS/EA_na21stan_medPoint_050_ED_GRISU.root ./test.fits |
58 | 65 | ``` |
59 | 66 |
|
60 | | -### Generate from a VEGAS stage6 runlist |
| 67 | +#### Generate from a VEGAS stage6 run list |
61 | 68 |
|
62 | | -You can also provide a stage6 runlist to the command line tool. In this case the last argument is the folder where all the output DL3 files will be saved. Beware that the file names for the outputs are inferred from the root file name (xxx.root -> xxx.fits) |
| 69 | +You can also provide a stage6 run list to the command line tool. In this case the last argument is the folder where all the output DL3 files will be saved. Beware that the file names for the outputs are inferred from the root file name (xxx.root -> xxx.fits) |
63 | 70 |
|
64 | | -``` |
| 71 | +```bash |
65 | 72 | v2dl3-vegas -l ./runlist.txt ./test |
66 | 73 | ``` |
67 | 74 |
|
68 | | -Runlists may be generated via a utility script. |
| 75 | +Run lists may be generated via a utility script. |
69 | 76 |
|
70 | | -``` |
| 77 | +```bash |
71 | 78 | python utils/vegas_runlister.py --help |
72 | 79 | ``` |
73 | 80 |
|
74 | | ---- |
| 81 | +## V2DL3 for EventDisplay |
75 | 82 |
|
76 | | -# V2DL3 for EventDisplay |
| 83 | +Requires data products generated with Eventdisplay version >= 490. |
77 | 84 |
|
78 | | -- use Eventdisplay version >= 487 |
79 | | -- recipes for Docker containers are available from the [V2DL3-Docker-recipes](https://github.com/Eventdisplay/V2DL3-Docker-recipes) repository. |
| 85 | +### Developer Installation |
80 | 86 |
|
81 | | -## Installation |
| 87 | +Install dependencies and activate the environment using the [conda package manager](https://docs.conda.io/projects/conda/en/latest/user-guide/install/index.html): |
82 | 88 |
|
83 | | -Use the [conda package manager](https://docs.conda.io/projects/conda/en/latest/user-guide/install/index.html) to install the dependenies: |
84 | | -``` |
| 89 | +```bash |
85 | 90 | conda env create -f environment-eventdisplay.yml |
86 | | -``` |
87 | | - |
88 | | -Activate the environment ```v2dl3Eventdisplay``` and set `PYTHONPATH`: |
89 | | - |
90 | | -``` |
91 | 91 | conda activate v2dl3Eventdisplay |
92 | 92 | export PYTHONPATH=$PYTHONPATH:"${PWD}" |
93 | 93 | ``` |
94 | 94 |
|
95 | | -Note that no pip is required for using the v2dl3 tool with Eventdisplay. |
| 95 | +Note that no pip is required for using the v2dl3 tool with Eventdisplay |
| 96 | +(this will change in future). |
96 | 97 |
|
97 | | -## Usage of commandline tool v2dl3 |
| 98 | +### Converting Eventdisplay data products to DL3 |
98 | 99 |
|
99 | 100 | Run `python pyV2DL3/script/v2dl3_for_Eventdisplay.py --help` to see all options. |
100 | 101 |
|
101 | 102 | Convert an anasum output file to DL3. |
102 | 103 | The following input is required: |
| 104 | + |
103 | 105 | - anasum file for a given run |
104 | 106 | - effective area file for the corresponding cut applied during the preparation of the anasum file (DL3 version) |
105 | 107 |
|
106 | 108 | Example for point-like analysis: |
107 | | -``` |
| 109 | + |
| 110 | +```bash |
108 | 111 | python pyV2DL3/script/v2dl3_for_Eventdisplay.py -f 54809.anasum.root [Effective Area File] ./outputdir/54809.anasum.fits |
109 | 112 | ``` |
| 113 | + |
110 | 114 | Example for full-enclosure analysis: |
111 | | -``` |
| 115 | + |
| 116 | +```bash |
112 | 117 | python pyV2DL3/script/v2dl3_for_Eventdisplay.py --full-enclosure -f 64080.anasum.root [Effective Area File] ./outputdir/64080.anasum.fits |
113 | 118 | ``` |
114 | 119 |
|
115 | | -The run having their observational parameters (zenith, night sky background) outside but close to corresponding IRF axes range can be run with the one of the following two commandline parameters: |
| 120 | +The run having their observational parameters (e.g., zenith, night sky background) outside but close to corresponding IRF axes range can be converted with the one of the following two command line parameters: |
116 | 121 |
|
117 | | -- `--force_extrapolation`: This option extrapolates linearly the IRF at the run parameter value. Use this option with a caution since the exptrapolation happens even for run parameter values very far from the corresponding IRF axes range. |
| 122 | +- `--force_extrapolation`: This option extrapolates linearly the IRF at the run parameter value. Use this option with a caution since the extrapolation is applied even for run parameter values very far from the corresponding IRF axes range. |
118 | 123 |
|
119 | | -- `--fuzzy_boundary tolerance`: This option interpolates the IRF at the boundary value if the run parameter value is within the given tolerance. The tolerance is define as the ratio of absolute difference between boundary and run parameter value to boundary. Tolerances are given per IRF axes, with allowed axes are `zenith` and `pedvar` This option is preferable over `--force_extrapolation`. Example: `--fuzzy_boundary pedvar 0.10 --fuzzy_boundary zenith 0.05`. |
| 124 | +- `--fuzzy_boundary tolerance`: This option interpolates the IRF at the boundary value if the run parameter value is within the given tolerance. The tolerance is define as the ratio of absolute difference between boundary and run parameter value to boundary. This option is preferable over `--force_extrapolation`. |
120 | 125 |
|
121 | | ---- |
122 | | -# Data storage and generating index files |
| 126 | +## Data storage and generating index files |
123 | 127 |
|
124 | | -Two index files are required for DL3-type analysis and can be generated with the tool `generate_index_file.py`. |
| 128 | +Generate observation index and HDU tables for DL3 data storage are required to use with *gammapy* in for reading and analysis of the generated DL3 data. |
| 129 | +This steps is independent of VEGAS or Eventdisplay. |
| 130 | +The two index files are generated with the tool `generate_index_file.py`. |
| 131 | + |
| 132 | +The tables are described on the [GADF website](https://gamma-astro-data-formats.readthedocs.io/en/v0.2/data_storage/index.html): |
125 | 133 |
|
126 | | -The tables are descriped on the [GADF website](https://gamma-astro-data-formats.readthedocs.io/en/v0.2/data_storage/index.html): |
127 | 134 | - [Observation index table](https://gamma-astro-data-formats.readthedocs.io/en/v0.2/data_storage/obs_index/index.html) |
128 | 135 | - [HDU index table](https://gamma-astro-data-formats.readthedocs.io/en/v0.2/data_storage/hdu_index/index.html) |
129 | 136 |
|
130 | 137 | To use `generate_index_file.py`, run: |
| 138 | + |
131 | 139 | - `generate_index_file --help` when using VEGAS |
132 | | -- `python pyV2DL3/script/generate_index_file.py --help` when using Eventdisplay |
| 140 | +- `python pyV2DL3/script/generate_index_file.py --help` when using Eventdisplay |
133 | 141 |
|
134 | | ---- |
| 142 | +## Contributing and Developing Code |
135 | 143 |
|
136 | | -# Contributing and Developing Code |
| 144 | +Your contribution is welcome! |
137 | 145 |
|
138 | 146 | A few remarks when contributing code: |
| 147 | + |
139 | 148 | - goal is to keep as much common code for converting from VEGAS or Eventdisplay data products |
140 | 149 | - put package specific code into the [pyV2DL3/vegas](pyV2DL3/vegas) and [pyV2DL3/eventdisplay](pyV2DL3/eventdisplay) directories. As different environments are used for both packages, do not put any imports to vegas/eventdisplay in modules in pyV2DL3 |
141 | 150 |
|
142 | | -To ensure readability, we try follow the Python [PEP8](https://www.python.org/dev/peps/pep-0008/) style guide. |
| 151 | +To ensure readability, we try follow the Python [PEP8](https://www.python.org/dev/peps/pep-0008/) style guide. |
143 | 152 |
|
144 | 153 | Functions and classes should contain a docstring with a short description. |
145 | 154 |
|
146 | | -Unit tests are encouraged and are available for few cases at this point. Unit tests are in the tests directory and can be called using [pytest](http://docs.pytest.org/). |
| 155 | +Unit tests are encouraged and are available for few cases at this point. Unit tests are in the tests directory and can be called using [pytest](http://docs.pytest.org/). |
147 | 156 |
|
148 | 157 | Use the [python logging system](https://docs.python.org/3/howto/logging.html) instead of the ‘print()’ function to output text. This allows to pipe all output into a log file and for different logging levels (INFO, DEBUG, …). |
149 | | - |
150 | | ---- |
151 | | - |
152 | | -##### Multi file processing |
153 | | - |
154 | | -To convert many runs at once with different Effective Area files there is a anasum script [ANALYSIS.anasum_parallel_from_runlist.sh](https://github.com/VERITAS-Observatory/Eventdisplay_AnalysisScripts_VTS/blob/main/scripts/ANALYSIS.anasum_parallel_from_runlist.sh), that can be used to create a ``` v2dl3_for_runlist_from_EDxxxx-anasum.sh ``` script. This script then contains one line for each processed file in the formatting as shown above in the point-like case. Here, xxxx is the Eventdisplay version (for eg. v487). |
155 | | - |
156 | | -Then in your bash run |
157 | | -``` |
158 | | -./v2dl3_for_runlist_from_EDxxxx-anasum.sh |
159 | | -``` |
160 | | -to create the fits files one after another. |
161 | | - |
162 | | -Alternatively, you can submit one job for each entry of this script using |
163 | | -```bash |
164 | | -v2dl3_qsub --v2dl3_script <script> |
165 | | -``` |
166 | | -where `<script>` is the script that was written out by `ANALYSIS.anasum_parallel_from_runlist_v2dl3.sh`. |
167 | | -`v2dl3_qsub` has the following options: |
168 | | - - `--conda_env` name of the conda environment. Default is `v2dl3` |
169 | | - - `--conda_exe` path to the conda executable. Only needed if `$CONDA_EXE` is not set. |
170 | | - - `--rootsys` path to rootsys. Only needed if `$ROOTSYS` is not set |
171 | | - - `--add_option` allows to add further options to v2dl3. (e.g. `--add_option '--evt_filter /path/to/file.yaml'`) |
172 | | - |
173 | | ---- |
174 | | -**TEXT BELOW REQUIRES REVIEW** |
175 | | - |
176 | | -#### Filter events |
177 | | -Using --evt_filter option, you can filter which events are written to the fits file. The argument takes the path of a |
178 | | -yaml file that stores conditions. E.g. to select only events between 0.5 and 1.0 TeV: |
179 | | -```yaml |
180 | | -Energy: [0.5, 1.0] |
181 | | -``` |
182 | | -
|
183 | | ---- |
184 | | -### Git pushing |
185 | | -If two people have used the same notebook at the same time it gets a bit nasty with a merge due to differences in outputs and cell run counts. To overcome this I have followed the instructions in http://timstaley.co.uk/posts/making-git-and-jupyter-notebooks-play-nice/ |
186 | | -
|
187 | | -Specifically, this requires that you have jq (https://stedolan.github.io/jq/) which should be easy enough to install, I get it through brew on my mac (I'm not sure what happens if you don't have jq installed - maybe you will find out!). |
188 | | -
|
189 | | -The following files have been edited to allow for this (in this repository directory, if you want you can set some of this up globally). |
190 | | -
|
191 | | -.git/config |
192 | | -``` |
193 | | -[core] |
194 | | -attributesfile = .gitattributes |
195 | | - |
196 | | -[filter "nbstrip_full"] |
197 | | -clean = "jq --indent 1 \ |
198 | | - '(.cells[] | select(has(\"outputs\")) | .outputs) = [] \ |
199 | | - | (.cells[] | select(has(\"execution_count\")) | .execution_count) = null \ |
200 | | - | .metadata = {\"language_info\": {\"name\": \"python\", \"pygments_lexer\": \"ipython3\"}} \ |
201 | | - | .cells[].metadata = {} \ |
202 | | - '" |
203 | | -smudge = cat |
204 | | -required = true |
205 | | -``` |
206 | | -
|
207 | | -.gitattributes |
208 | | -``` |
209 | | -*.ipynb filter=nbstrip_full |
210 | | -``` |
0 commit comments