Mercurial > repos > astroteam > cta_astro_tool
annotate model_cube_file.py @ 0:2f3e314c3dfa draft default tip
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
| author | astroteam | 
|---|---|
| date | Fri, 19 Apr 2024 10:06:21 +0000 | 
| parents | |
| children | 
| rev | line source | 
|---|---|
| 
0
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
1 #!/usr/bin/env python | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
2 # coding: utf-8 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
3 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
4 # flake8: noqa | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
5 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
6 import json | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
7 import os | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
8 import shutil | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
9 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
10 from oda_api.json import CustomJSONEncoder | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
11 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
12 get_ipython().run_cell_magic( # noqa: F821 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
13 "bash", | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
14 "", | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
15 'rm -r IRFS | echo "Ok"\nmkdir IRFS\ncd IRFS\nwget https://zenodo.org/records/5499840/files/cta-prod5-zenodo-fitsonly-v0.1.zip\nunzip cta-prod5-zenodo-fitsonly-v0.1.zip\ncd fits\nfor fn in *.gz ; do tar -zxvf $fn; done \n', | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
16 ) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
17 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
18 import sys | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
19 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
20 sys.path.append(".") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
21 from pathlib import Path | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
22 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
23 import astropy.units as u | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
24 import matplotlib.pyplot as plt | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
25 import numpy as np | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
26 from astropy import units as u | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
27 from astropy import wcs | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
28 from astropy.coordinates import SkyCoord | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
29 from astropy.io import fits | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
30 from gammapy.data import ( | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
31 FixedPointingInfo, | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
32 Observation, | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
33 PointingMode, | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
34 observatory_locations, | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
35 ) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
36 from gammapy.datasets import MapDataset, MapDatasetEventSampler | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
37 from gammapy.irf import load_irf_dict_from_file | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
38 from gammapy.makers import MapDatasetMaker | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
39 from gammapy.maps import Map, MapAxis | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
40 from gammapy.modeling.models import ( | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
41 FoVBackgroundModel, | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
42 Models, | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
43 SkyModel, | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
44 TemplateSpatialModel, | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
45 ) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
46 from numpy import cos, pi, sqrt | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
47 from oda_api.api import ProgressReporter | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
48 from oda_api.data_products import BinaryProduct, PictureProduct | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
49 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
50 # not for run on Galaxy | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
51 # %%bash | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
52 # git lfs install | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
53 # git lfs pull | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
54 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
55 data_cube = "3d.fits" # http://odahub.io/ontology#POSIXPath | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
56 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
57 # Source flux normalisaiton F0 in 1/(TeV cm2 s) at reference energy E0 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
58 F0 = 1e-11 # http://odahub.io/ontology#Float | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
59 E0 = 1.0 # http://odahub.io/ontology#Energy_TeV | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
60 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
61 OffAxis_angle = 0.4 # http://odahub.io/ontology#AngleDegrees | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
62 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
63 Radius_spectal_extraction = 0.2 # http://odahub.io/ontology#AngleDegrees | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
64 Radius_sky_image = 2.5 # http://odahub.io/ontology#AngleDegrees | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
65 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
66 Site = "North" # http://odahub.io/ontology#String ; oda:allowed_value "North","South" | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
67 Telescopes_LST = True # http://odahub.io/ontology#Boolean | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
68 Telescopes_MST = True # http://odahub.io/ontology#Boolean | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
69 Telescopes_SST = False # http://odahub.io/ontology#Boolean | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
70 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
71 Texp = 1.0 # http://odahub.io/ontology#TimeIntervalHours | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
72 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
73 _galaxy_wd = os.getcwd() | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
74 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
75 with open("inputs.json", "r") as fd: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
76 inp_dic = json.load(fd) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
77 if "_data_product" in inp_dic.keys(): | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
78 inp_pdic = inp_dic["_data_product"] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
79 else: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
80 inp_pdic = inp_dic | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
81 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
82 for vn, vv in inp_pdic.items(): | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
83 if vn != "_selector": | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
84 globals()[vn] = type(globals()[vn])(vv) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
85 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
86 R_s = Radius_spectal_extraction | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
87 Radius = Radius_sky_image | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
88 LSTs = Telescopes_LST | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
89 MSTs = Telescopes_MST | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
90 SSTs = Telescopes_SST | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
91 file_path = data_cube | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
92 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
93 pr = ProgressReporter() | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
94 pr.report_progress(stage="Progress", progress=10.0) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
95 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
96 print("loading " + file_path) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
97 cube_map = Map.read(file_path) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
98 cube_map.geom | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
99 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
100 print("locating source") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
101 # source = SkyCoord.from_name(src_name, frame='icrs', parse=False, cache=True) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
102 source = cube_map.geom.center_skydir | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
103 DEC = float(source.dec / u.deg) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
104 RA = float(source.ra / u.deg) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
105 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
106 CTA_south_lat = -25.0 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
107 CTA_north_lat = 18.0 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
108 filename = "" | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
109 if Site == "North": | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
110 Zd = abs(DEC - CTA_north_lat) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
111 if Zd < 30.0: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
112 Zd = "20deg-" | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
113 elif Zd < 50: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
114 Zd = "40deg-" | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
115 elif Zd < 70.0: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
116 Zd = "60deg-" | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
117 else: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
118 raise RuntimeError("Source not visible from " + Site) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
119 if DEC > CTA_north_lat: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
120 N_S = "NorthAz-" | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
121 else: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
122 N_S = "SouthAz-" | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
123 if LSTs: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
124 tel = "4LSTs" | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
125 if MSTs: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
126 tel += "09MSTs" | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
127 if SSTs: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
128 raise RuntimeError("No SSTs on the North site") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
129 filename = "IRFS/fits/Prod5-North-" + Zd + N_S + tel | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
130 else: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
131 Zd = abs(DEC - CTA_south_lat) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
132 if Zd < 30.0: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
133 Zd = "20deg-" | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
134 elif Zd < 50: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
135 Zd = "40deg-" | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
136 elif Zd < 70.0: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
137 Zd = "60deg-" | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
138 else: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
139 raise RuntimeError("Source not visible from " + Site) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
140 if DEC > CTA_south_lat: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
141 N_S = "NorthAz-" | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
142 else: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
143 N_S = "SouthAz-" | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
144 if MSTs: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
145 tel = "14MSTs" | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
146 if SSTs: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
147 tel += "37MSTs" | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
148 if LSTs: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
149 raise RuntimeError("No LSTs on the South site") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
150 filename = "IRFS/fits/Prod5-South-" + Zd + N_S + tel | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
151 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
152 if Texp < 1800: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
153 filename += ".1800s-v0.1.fits.gz" | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
154 elif Texp < 18000: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
155 filename += ".18000s-v0.1.fits.gz" | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
156 else: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
157 filename += ".180000s-v0.1.fits.gz" | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
158 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
159 import os | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
160 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
161 print(filename) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
162 if os.path.exists(filename) == False: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
163 raise RuntimeError("No reponse function found") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
164 message = "No reponse function found!" | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
165 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
166 # telescope pointing will be shifted slightly | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
167 cdec = cos(DEC * pi / 180.0) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
168 RA_pnt = RA - OffAxis_angle / cdec | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
169 DEC_pnt = DEC | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
170 pnt = SkyCoord(RA_pnt, DEC_pnt, unit="degree") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
171 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
172 # telescope is pointing at a fixed position in ICRS for the observation | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
173 pointing = FixedPointingInfo(fixed_icrs=pnt, mode=PointingMode.POINTING) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
174 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
175 location = observatory_locations["cta_south"] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
176 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
177 print("loading IRFs") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
178 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
179 # irfs = load_irf_dict_from_file(path / irf_filename) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
180 # filename = "data/Prod5-North-20deg-AverageAz-4LSTs09MSTs.180000s-v0.1.fits.gz" | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
181 irfs_filename = ( | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
182 "IRFS/fits/Prod5-North-20deg-AverageAz-4LSTs09MSTs.180000s-v0.1.fits.gz" | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
183 ) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
184 irfs = load_irf_dict_from_file(irfs_filename) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
185 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
186 print("Creating observation") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
187 livetime = Texp * u.hr | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
188 observation = Observation.create( | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
189 obs_id=1001, | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
190 pointing=pointing, | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
191 livetime=livetime, | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
192 irfs=irfs, | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
193 location=location, | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
194 ) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
195 print(observation) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
196 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
197 def GetBinSpectralModel( | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
198 E, bins_per_decade=20, amplitude=1e-12 * u.Unit("cm-2 s-1") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
199 ): | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
200 # amplitude=1e-12 * u.Unit("cm-2 s-1") * norm | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
201 from gammapy.modeling.models import GaussianSpectralModel | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
202 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
203 sigma = (10 ** (1 / bins_per_decade) - 1) * E | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
204 return GaussianSpectralModel(mean=E, sigma=sigma, amplitude=amplitude) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
205 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
206 print("Calculate energy range") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
207 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
208 # selected_n_bins_per_decade = 20 # n bins per decade | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
209 max_rel_energy_error = 3 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
210 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
211 energy_axis = cube_map.geom.axes["energy"] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
212 EminMap = energy_axis.edges[0] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
213 EmaxMap = energy_axis.edges[-1] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
214 stepE = energy_axis.edges[1] / energy_axis.edges[0] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
215 nbins_per_decade = int(np.round(np.log(10) / np.log(stepE))) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
216 Emin = EminMap / max_rel_energy_error | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
217 Emax = EmaxMap * max_rel_energy_error | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
218 nbins_per_decade, Emin, Emax | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
219 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
220 print("Create empty dataset") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
221 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
222 # energy_axis = MapAxis.from_energy_bounds(max_rel_energy_error*Emin*u.TeV, Emax*u.TeV, nbin=selected_n_bins_per_decade, per_decade=True) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
223 energy_axis_true = MapAxis.from_energy_bounds( | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
224 Emin, Emax, nbin=nbins_per_decade, per_decade=True, name="energy_true" | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
225 ) # TODO: get from geom | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
226 migra_axis = MapAxis.from_bounds( | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
227 1.0 / max_rel_energy_error, | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
228 max_rel_energy_error, | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
229 nbin=150, | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
230 node_type="edges", | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
231 name="migra", | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
232 ) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
233 # TODO: get from geom | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
234 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
235 geom = cube_map.geom | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
236 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
237 empty = MapDataset.create( | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
238 geom, | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
239 energy_axis_true=energy_axis_true, | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
240 migra_axis=migra_axis, | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
241 name="my-dataset", | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
242 ) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
243 maker = MapDatasetMaker(selection=["exposure", "background", "psf", "edisp"]) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
244 dataset = maker.run(empty, observation) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
245 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
246 Path("event_sampling").mkdir(exist_ok=True) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
247 dataset.write("./event_sampling/dataset.fits", overwrite=True) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
248 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
249 print("Plotting GaussianSpectralModel") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
250 from gammapy.modeling.models import GaussianSpectralModel | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
251 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
252 meanE = 1 * u.TeV | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
253 bins_per_decade = 20 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
254 sigma = (10 ** (1 / bins_per_decade) - 1) * meanE | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
255 amplitude = 1 * u.Unit("cm-2 s-1") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
256 gm = GaussianSpectralModel(mean=meanE, sigma=sigma, amplitude=amplitude) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
257 ax = gm.plot(energy_bounds=(0.1, 100) * u.TeV) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
258 ax.set_yscale("linear") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
259 gm.integral(meanE - 3 * sigma, meanE + 3 * sigma) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
260 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
261 print("cube_map.get_spectrum()") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
262 spec = cube_map.get_spectrum() | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
263 spec | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
264 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
265 # print('spec.plot()') | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
266 # spec.plot() # this plot shows dN/dE * E | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
267 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
268 pr.report_progress(stage="Progress", progress=20.0) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
269 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
270 print("Find norm bin") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
271 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
272 energy_bins = cube_map.geom.axes["energy"].center | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
273 len(energy_bins), float(np.max(energy_bins) / u.TeV) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
274 norm_bin = 0 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
275 for i, E in enumerate(energy_bins): | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
276 if E > E0 * u.TeV: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
277 norm_bin = i | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
278 break | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
279 assert norm_bin > 0 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
280 norm_bin | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
281 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
282 print("obtain norm_bin_width") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
283 norm_bin_width = cube_map.geom.axes["energy"].bin_width[norm_bin] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
284 norm_bin_width | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
285 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
286 print("find norm_flux") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
287 # Npart=5000 # TODO update | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
288 # n_events_reduction_factor = 1 # suppress flux factor | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
289 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
290 int_bin_flux = ( | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
291 spec.data.flatten() | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
292 ) # we don't have to multiply by energy_bins /u.TeV since spectrum is already multiplied by E (see above) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
293 norm_flux = int_bin_flux[norm_bin] / norm_bin_width | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
294 norm_flux | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
295 # int_bin_flux /= (Npart/200000 * np.max(int_bin_flux) * n_events_reduction_factor * 20/len(energy_bins)) # roughly 100 events | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
296 # int_bin_flux | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
297 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
298 print("find mult") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
299 mult = F0 * u.Unit("cm-2 s-1 TeV-1") / norm_flux # .decompose() | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
300 mult | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
301 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
302 print("find int_bin_flux") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
303 int_bin_flux = mult * int_bin_flux | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
304 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
305 int_bin_flux | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
306 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
307 pr.report_progress(stage="Progress", progress=30.0) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
308 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
309 print("Creating bin_models") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
310 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
311 bin_models = [] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
312 for i, (flux, E) in enumerate(zip(int_bin_flux, energy_bins)): | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
313 # print(i) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
314 if flux == 0: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
315 print("skipping bin ", i) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
316 continue | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
317 # print(flux) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
318 spectral_model_delta = GetBinSpectralModel( | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
319 E, amplitude=flux | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
320 ) # normalizing here | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
321 spacial_template_model = TemplateSpatialModel( | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
322 cube_map.slice_by_idx({"energy": i}), | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
323 filename=f"cube_bin{i}.fit", | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
324 normalize=True, | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
325 ) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
326 sky_bin_model = SkyModel( | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
327 spectral_model=spectral_model_delta, | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
328 spatial_model=spacial_template_model, | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
329 name=f"bin_{i}", | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
330 ) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
331 bin_models.append(sky_bin_model) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
332 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
333 print("Creating bkg_model") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
334 bkg_model = FoVBackgroundModel(dataset_name="my-dataset") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
335 models = Models(bin_models + [bkg_model]) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
336 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
337 print("dataset.models = models") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
338 dataset.models = models | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
339 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
340 print("Creating sampler") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
341 sampler = MapDatasetEventSampler(random_state=0) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
342 print("Running sampler") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
343 events = sampler.run(dataset, observation) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
344 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
345 hdul = fits.open(filename) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
346 aeff = hdul["EFFECTIVE AREA"].data | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
347 ENERG_LO = aeff["ENERG_LO"][0] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
348 ENERG_HI = aeff["ENERG_HI"][0] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
349 THETA_LO = aeff["THETA_LO"][0] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
350 THETA_HI = aeff["THETA_HI"][0] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
351 EFFAREA = aeff["EFFAREA"][0] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
352 ind_offaxis = len(THETA_LO[THETA_LO < OffAxis_angle] - 1) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
353 EFAREA = EFFAREA[ind_offaxis] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
354 HDU_EFFAREA = hdul["EFFECTIVE AREA"] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
355 HDU_RMF = hdul["ENERGY DISPERSION"] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
356 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
357 pr.report_progress(stage="Progress", progress=80.0) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
358 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
359 print(f"Save events ...") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
360 primary_hdu = fits.PrimaryHDU() | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
361 hdu_evt = fits.BinTableHDU(events.table) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
362 hdu_gti = fits.BinTableHDU(dataset.gti.table, name="GTI") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
363 hdu_all = fits.HDUList([primary_hdu, hdu_evt, hdu_gti, HDU_EFFAREA, HDU_RMF]) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
364 hdu_all.writeto(f"./events.fits", overwrite=True) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
365 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
366 print(f"Reading events ...") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
367 hdul = fits.open("events.fits") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
368 ev = hdul["EVENTS"].data | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
369 ra = ev["RA"] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
370 dec = ev["DEC"] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
371 en = ev["ENERGY"] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
372 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
373 [cube_map.geom.center_coord[i] / cube_map.geom.data_shape[i] for i in (0, 1)] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
374 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
375 ra_bins, dec_bins = (int(2 * x) for x in cube_map.geom.center_pix[:2]) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
376 ra_bins, dec_bins | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
377 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
378 Radius = float(min(cube_map.geom.width / 2 / u.degree).decompose()) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
379 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
380 print(f"Building event image ...") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
381 plt.close() | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
382 pixsize = 0.1 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
383 from matplotlib.colors import LogNorm | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
384 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
385 cube_map.geom.width[0] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
386 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
387 Nbins = 2 * int(Radius / pixsize) + 1 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
388 ra0 = np.mean(ra) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
389 dec0 = np.mean(dec) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
390 from numpy import cos, pi | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
391 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
392 cdec = cos(DEC_pnt * pi / 180.0) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
393 ra_bins = np.linspace(RA - Radius / cdec, RA + Radius / cdec, Nbins + 1) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
394 dec_bins = np.linspace(DEC - Radius, DEC + Radius, Nbins + 1) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
395 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
396 h = plt.hist2d(ra, dec, bins=[ra_bins, dec_bins], norm=LogNorm()) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
397 image = h[0] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
398 plt.colorbar() | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
399 plt.xlabel("RA") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
400 plt.ylabel("Dec") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
401 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
402 print(f"Building event image 2 ...") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
403 plt.figure() | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
404 # Create a new WCS object. The number of axes must be set | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
405 # from the start | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
406 w = wcs.WCS(naxis=2) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
407 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
408 w.wcs.ctype = ["RA---CAR", "DEC--CAR"] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
409 # we need a Plate carrée (CAR) projection since histogram is binned by ra-dec | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
410 # the peculiarity here is that CAR projection produces rectilinear grid only if CRVAL2==0 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
411 # also, we will follow convention of RA increasing from right to left (CDELT1<0, need to flip an input image) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
412 # otherwise, aladin-lite doesn't show it | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
413 w.wcs.crval = [RA_pnt, 0] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
414 w.wcs.crpix = [Nbins / 2.0 + 0.5, 1 - dec_bins[0] / pixsize] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
415 w.wcs.cdelt = np.array([-pixsize / cdec, pixsize]) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
416 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
417 header = w.to_header() | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
418 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
419 hdu = fits.PrimaryHDU(np.flip(image.T, axis=1), header=header) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
420 hdu.writeto("Image.fits", overwrite=True) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
421 hdu = fits.open("Image.fits") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
422 im = hdu[0].data | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
423 wcs1 = wcs.WCS(hdu[0].header) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
424 ax = plt.subplot(projection=wcs1) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
425 lon = ax.coords["ra"] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
426 lon.set_major_formatter("d.dd") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
427 lat = ax.coords["dec"] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
428 lat.set_major_formatter("d.dd") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
429 plt.imshow(im, origin="lower") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
430 plt.colorbar(label="Counts") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
431 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
432 plt.scatter( | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
433 [RA_pnt], | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
434 [DEC_pnt], | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
435 marker="x", | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
436 color="white", | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
437 alpha=0.5, | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
438 transform=ax.get_transform("world"), | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
439 ) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
440 plt.scatter( | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
441 [RA], | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
442 [DEC], | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
443 marker="+", | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
444 color="red", | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
445 alpha=0.5, | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
446 transform=ax.get_transform("world"), | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
447 ) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
448 plt.grid(color="white", ls="solid") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
449 plt.xlabel("RA") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
450 plt.ylabel("Dec") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
451 plt.savefig("Image.png", format="png", bbox_inches="tight") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
452 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
453 print("building event spectrum") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
454 plt.close() | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
455 E = (events.energy / u.TeV).decompose() | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
456 ras = events.radec.ra.deg | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
457 decs = events.radec.dec.deg | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
458 # plt.hist(E,bins=np.logspace(-2,2,41)) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
459 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
460 mask = events.table["MC_ID"] > 0 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
461 plt.hist(E[mask], bins=np.logspace(-2, 2, 41), alpha=0.5, label="source") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
462 mask = events.table["MC_ID"] == 0 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
463 plt.hist(E[mask], bins=np.logspace(-2, 2, 41), alpha=0.5, label="background") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
464 plt.xlabel("E, TeV") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
465 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
466 plt.xscale("log") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
467 plt.yscale("log") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
468 plt.legend(loc="upper right") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
469 plt.savefig("event_spectrum.png", format="png") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
470 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
471 coord_s = SkyCoord(RA, DEC, unit="degree") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
472 RA_bkg = RA_pnt - (RA - RA_pnt) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
473 DEC_bkg = DEC_pnt - (DEC - DEC_pnt) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
474 coord_b = SkyCoord(RA_bkg, DEC_bkg, unit="degree") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
475 coords = SkyCoord(ra, dec, unit="degree") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
476 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
477 plt.figure() | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
478 ev_src = en[coords.separation(coord_s).deg < R_s] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
479 ev_bkg = en[coords.separation(coord_b).deg < R_s] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
480 ENERG_BINS = np.concatenate((ENERG_LO, [ENERG_HI[-1]])) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
481 ENERG = sqrt(ENERG_LO * ENERG_HI) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
482 h1 = np.histogram(ev_src, bins=ENERG_BINS) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
483 h2 = np.histogram(ev_bkg, bins=ENERG_BINS) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
484 cts_s = h1[0] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
485 cts_b = h2[0] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
486 src = cts_s - cts_b | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
487 src_err = sqrt(cts_s + cts_b) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
488 plt.errorbar(ENERG, src, src_err) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
489 plt.axhline(0, linestyle="dashed", color="black") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
490 plt.xscale("log") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
491 plt.xlabel(r"$E$, TeV") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
492 plt.ylabel("Counts") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
493 plt.yscale("log") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
494 plt.ylim(0.1, 2 * max(src)) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
495 plt.savefig("Count_spectrum.png") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
496 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
497 plt.figure() | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
498 sep_s = coords.separation(coord_s).deg | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
499 sep_b = coords.separation(coord_b).deg | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
500 plt.hist(sep_s**2, bins=np.linspace(0, 0.5, 50)) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
501 plt.hist(sep_b**2, bins=np.linspace(0, 0.5, 50)) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
502 plt.axvline(R_s**2, color="black", linestyle="dashed") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
503 plt.xlabel(r"$\theta^2$, degrees") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
504 plt.ylabel("Counts") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
505 plt.savefig("Theta2_plot.png") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
506 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
507 pr.report_progress(stage="Progress", progress=100.0) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
508 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
509 fits_events = BinaryProduct.from_file("events.fits") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
510 bin_image = PictureProduct.from_file("Image.png") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
511 spec_image = PictureProduct.from_file("Count_spectrum.png") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
512 theta2_png = PictureProduct.from_file("Theta2_plot.png") | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
513 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
514 spectrum_png = spec_image # http://odahub.io/ontology#ODAPictureProduct | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
515 theta2_png = theta2_png # http://odahub.io/ontology#ODAPictureProduct | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
516 image_png = bin_image # http://odahub.io/ontology#ODAPictureProduct | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
517 event_list_fits = fits_events # http://odahub.io/ontology#ODABinaryProduct | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
518 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
519 # output gathering | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
520 _galaxy_meta_data = {} | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
521 _oda_outs = [] | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
522 _oda_outs.append( | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
523 ( | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
524 "out_model_cube_file_spectrum_png", | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
525 "spectrum_png_galaxy.output", | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
526 spectrum_png, | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
527 ) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
528 ) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
529 _oda_outs.append( | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
530 ("out_model_cube_file_theta2_png", "theta2_png_galaxy.output", theta2_png) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
531 ) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
532 _oda_outs.append( | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
533 ("out_model_cube_file_image_png", "image_png_galaxy.output", image_png) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
534 ) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
535 _oda_outs.append( | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
536 ( | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
537 "out_model_cube_file_event_list_fits", | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
538 "event_list_fits_galaxy.output", | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
539 event_list_fits, | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
540 ) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
541 ) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
542 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
543 for _outn, _outfn, _outv in _oda_outs: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
544 _galaxy_outfile_name = os.path.join(_galaxy_wd, _outfn) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
545 if isinstance(_outv, str) and os.path.isfile(_outv): | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
546 shutil.move(_outv, _galaxy_outfile_name) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
547 _galaxy_meta_data[_outn] = {"ext": "_sniff_"} | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
548 elif getattr(_outv, "write_fits_file", None): | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
549 _outv.write_fits_file(_galaxy_outfile_name) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
550 _galaxy_meta_data[_outn] = {"ext": "fits"} | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
551 elif getattr(_outv, "write_file", None): | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
552 _outv.write_file(_galaxy_outfile_name) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
553 _galaxy_meta_data[_outn] = {"ext": "_sniff_"} | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
554 else: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
555 with open(_galaxy_outfile_name, "w") as fd: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
556 json.dump(_outv, fd, cls=CustomJSONEncoder) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
557 _galaxy_meta_data[_outn] = {"ext": "json"} | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
558 | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
559 with open(os.path.join(_galaxy_wd, "galaxy.json"), "w") as fd: | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
560 json.dump(_galaxy_meta_data, fd) | 
| 
 
2f3e314c3dfa
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 4543470805fc78f6cf2604b9d55beb6f06359995
 
astroteam 
parents:  
diff
changeset
 | 
561 print("*** Job finished successfully ***") | 
