Skip to content

Commit 5de461c

Browse files
authored
Merge pull request #25 from vuillaut/eff_area
refactoring of the cta irf
2 parents 8047fab + cc4b413 commit 5de461c

File tree

8 files changed

+162
-32
lines changed

8 files changed

+162
-32
lines changed

ctaplot/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
from .plotcamera import *
33
from .ana import *
44
from .dataset import *
5+
from .io import *

ctaplot/ana.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def __init__(self):
2020
self.E = logbin_mean(self.E_bin)
2121

2222
# Area of CTA sites in meters
23-
self.ParanalArea = 19.63e6
24-
self.LaPalmaArea = 6.61e6
23+
self.ParanalArea_prod3 = 19.63e6
24+
self.LaPalmaArea_prod3 = 11341149 #6.61e6
2525

2626
def set_E_bin(self, E_bin):
2727
self.E_bin = E_bin
@@ -355,11 +355,11 @@ def energy_bias(SimuE, RecoE):
355355

356356

357357
def get_angles_pipi(angles):
358-
return np.mod(angles+pi, 2*pi) - pi
358+
return np.mod(angles + np.pi, 2 * np.pi) - np.pi
359359

360360

361361
def get_angles_0pi(angles):
362-
return np.mod(angles, pi)
362+
return np.mod(angles, np.pi)
363363

364364

365365
def theta2(RecoAlt, RecoAz, AltSource, AzSource):

ctaplot/io.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import json
2+
import numpy as np
3+
4+
5+
class mc_run_header():
6+
7+
def __init__(self):
8+
pass
9+
10+
def read(self, filename):
11+
"""
12+
Read a json file containing a Monte-Carlo run header.
13+
14+
Parameters
15+
----------
16+
filename: string
17+
path to the json file
18+
19+
Returns
20+
-------
21+
dict
22+
"""
23+
with open(filename) as file:
24+
self.data = json.load(file)
25+
26+
def get_e_range(self):
27+
"""
28+
return simulated energy range
29+
30+
Returns
31+
-------
32+
[e_min, e_max]
33+
"""
34+
return self.data['E_range']
35+
36+
def get_core_range(self):
37+
"""
38+
return core range
39+
40+
Returns
41+
-------
42+
[r_min, r_max]
43+
"""
44+
return self.data['core_range']
45+
46+
def get_core_area(self):
47+
"""
48+
return simulated core area
49+
50+
Returns
51+
-------
52+
area: float
53+
"""
54+
if self.data['core_pos_mode'] == 1:
55+
return np.pi * (self.data['core_range'][1] - self.data['core_range'][0])**2
56+
else:
57+
raise Exception("Sorry I do not know this simulation mode")
58+
59+
def get_number_simulated_events(self):
60+
"""
61+
return the number of simulated events (number of simulated showers times number of use)
62+
63+
Returns
64+
-------
65+
float
66+
"""
67+
return self.data['n_showers'] * self.data['n_use']
68+
69+

ctaplot/plots.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ def plot_effective_area_per_energy(SimuE, RecoE, simuArea, ax=None, **kwargs):
555555
>>> irf = ctaplot.ana.irf_cta()
556556
>>> simue = 10**(-2 + 4*np.random.rand(1000))
557557
>>> recoe = 10**(-2 + 4*np.random.rand(100))
558-
>>> ax = ctaplot.plots.plot_effective_area_per_energy(simue, recoe, irf.LaPalmaArea)
558+
>>> ax = ctaplot.plots.plot_effective_area_per_energy(simue, recoe, irf.LaPalmaArea_prod3)
559559
"""
560560

561561
ax = plt.gca() if ax is None else ax
@@ -576,7 +576,7 @@ def plot_effective_area_per_energy(SimuE, RecoE, simuArea, ax=None, **kwargs):
576576
return ax
577577

578578

579-
def plot_effective_area_requirement(cta_site, ax=None, **kwargs):
579+
def plot_effective_area_cta_requirements(cta_site, ax=None, **kwargs):
580580
"""
581581
Plot the CTA requirement for the effective area
582582
@@ -609,7 +609,7 @@ def plot_effective_area_requirement(cta_site, ax=None, **kwargs):
609609
return ax
610610

611611

612-
def plot_effective_area_performances(cta_site, ax=None, **kwargs):
612+
def plot_effective_area_cta_performances(cta_site, ax=None, **kwargs):
613613
"""
614614
Plot the CTA performances for the effective area
615615
@@ -667,15 +667,15 @@ def saveplot_effective_area_per_energy(SimuE, RecoE, simuArea, ax=None, Outfile=
667667
ax = plot_effective_area_per_energy(SimuE, RecoE, simuArea, ax=ax, **kwargs)
668668

669669
if cta_site:
670-
ax = plot_effective_area_requirement(cta_site, ax=ax, color='black')
670+
ax = plot_effective_area_cta_requirements(cta_site, ax=ax, color='black')
671671

672672
plt.savefig(Outfile + ".png", bbox_inches="tight", format='png', dpi=200)
673673
plt.close()
674674

675675
return ax
676676

677677

678-
def plot_sensitivity_requirement(cta_site, ax=None, **kwargs):
678+
def plot_sensitivity_cta_requirements(cta_site, ax=None, **kwargs):
679679
"""
680680
Plot the CTA requirement for the sensitivity
681681
Parameters
@@ -707,7 +707,7 @@ def plot_sensitivity_requirement(cta_site, ax=None, **kwargs):
707707
return ax
708708

709709

710-
def plot_sensitivity_performances(cta_site, ax=None, **kwargs):
710+
def plot_sensitivity_cta_performances(cta_site, ax=None, **kwargs):
711711
"""
712712
Plot the CTA performances for the sensitivity
713713
Parameters
@@ -900,15 +900,15 @@ def saveplot_angular_res_per_energy(RecoAlt, RecoAz, AltSource, AzSource, SimuE,
900900
ax = plot_angular_res_per_energy(RecoAlt, RecoAz, AltSource, AzSource, SimuE, ax=ax, **kwargs)
901901

902902
if cta_site:
903-
ax = plot_angular_res_requirement(cta_site, ax=ax)
903+
ax = plot_angular_res_requirements(cta_site, ax=ax)
904904

905905
plt.savefig(Outfile + ".png", bbox_inches="tight", format='png', dpi=200);
906906
plt.close()
907907

908908
return ax
909909

910910

911-
def plot_angular_res_requirement(cta_site, ax=None, **kwargs):
911+
def plot_angular_res_cta_requirements(cta_site, ax=None, **kwargs):
912912
"""
913913
Plot the CTA requirement for the angular resolution
914914
Parameters
@@ -1244,7 +1244,7 @@ def plot_energy_resolution(SimuE, RecoE, ax=None, bias_correction=False, **kwarg
12441244
return ax
12451245

12461246

1247-
def plot_energy_resolution_requirements(cta_site, ax=None, **kwargs):
1247+
def plot_energy_resolution_cta_requirements(cta_site, ax=None, **kwargs):
12481248
"""
12491249
Plot the cta requirement for the energy resolution
12501250
@@ -1321,7 +1321,7 @@ def saveplot_energy_resolution(SimuE, RecoE, Outfile="EnergyResolution.png", cta
13211321
ax = plot_energy_resolution(SimuE, RecoE)
13221322

13231323
if cta_site != None:
1324-
ax = plot_energy_resolution_requirements(cta_site, ax=ax)
1324+
ax = plot_energy_resolution_cta_requirements(cta_site, ax=ax)
13251325

13261326
plt.savefig(Outfile, bbox_inches="tight", format='png', dpi=200)
13271327
plt.close()
@@ -1600,11 +1600,11 @@ def set_site(self, site):
16001600
if site == 'north' or site == 'lapalma':
16011601
self.site = site
16021602
irf = ana.irf_cta()
1603-
self.SimuArea = irf.LaPalmaArea
1603+
self.SimuArea = irf.LaPalmaArea_prod3
16041604
if site == 'south' or site == 'paranal':
16051605
self.site = site
16061606
irf = ana.irf_cta()
1607-
self.SimuArea = irf.ParanalArea
1607+
self.SimuArea = irf.ParanalArea_prod3
16081608

16091609
def plot_all(self, MultiplicityMin=[2, 4]):
16101610
self.multiplicity_hist()
@@ -1700,7 +1700,7 @@ def angular_res_per_energy(self, MultiplicityMin=[2], cta_goal=True, ax=None, **
17001700
ax = plt.gca() if ax is None else ax
17011701

17021702
if cta_goal:
1703-
ax = plot_angular_res_requirement(self.site, ax=ax, color='black')
1703+
ax = plot_angular_res_cta_requirements(self.site, ax=ax, color='black')
17041704

17051705
if len(MultiplicityMin) > 1 and not 'alpha' in kwargs:
17061706
kwargs['alpha'] = 0.8
@@ -1767,7 +1767,7 @@ def effective_area_per_energy(self, MultiplicityMin=[2], cta_goal=True, ax=None,
17671767
ax = plt.gca() if ax is None else ax
17681768

17691769
if cta_goal:
1770-
ax = plot_effective_area_requirement(self.site, ax=ax, color='black')
1770+
ax = plot_effective_area_cta_requirements(self.site, ax=ax, color='black')
17711771

17721772
if len(MultiplicityMin) > 1 and not 'alpha' in kwargs:
17731773
kwargs['alpha'] = 0.8
@@ -1868,7 +1868,7 @@ def energy_resolution(self, cta_goal=True, MultiplicityMin=[2], bias_correction=
18681868
ax = plt.gca()
18691869

18701870
if cta_goal:
1871-
ax = plot_energy_resolution_requirements(self.site, ax=ax, color='black')
1871+
ax = plot_energy_resolution_cta_requirements(self.site, ax=ax, color='black')
18721872

18731873
alpha = 1.0
18741874
if len(MultiplicityMin) > 1:

ctaplot/tests/test_plots.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ def test_plot_energy_resolution():
1717
plots.plot_energy_resolution(E, E**2, color='red')
1818

1919

20-
def test_plot_energy_resolution_requirements():
20+
def test_plot_energy_resolution_cta_requirements():
2121
plt.close('all')
22-
plots.plot_energy_resolution_requirements('north', color='green')
22+
plots.plot_energy_resolution_cta_requirements('north', color='green')
2323

2424

2525
def test_saveplot_energy_resolution():
@@ -39,24 +39,24 @@ def test_plot_angular_resolution_cta_performances():
3939
plots.plot_angular_res_cta_performance('north', color='green')
4040

4141

42-
def test_plot_angular_resolution_requirements():
43-
plots.plot_angular_res_requirement('north', color='green')
42+
def test_plot_angular_resolution_cta_requirements():
43+
plots.plot_angular_res_cta_requirements('north', color='green')
4444

4545

46-
def test_plot_effective_area_performances():
47-
plots.plot_effective_area_performances('north', color='green')
46+
def test_plot_effective_area_cta_performances():
47+
plots.plot_effective_area_cta_performances('north', color='green')
4848

4949

50-
def test_plot_effective_area_requirement():
51-
plots.plot_effective_area_requirement('north', color='green')
50+
def test_plot_effective_area_cta_requirements():
51+
plots.plot_effective_area_cta_requirements('north', color='green')
5252

5353

54-
def test_plot_sensitivity_performances():
55-
plots.plot_sensitivity_performances('north', color='green')
54+
def test_plot_sensitivity_cta_performances():
55+
plots.plot_sensitivity_cta_performances('north', color='green')
5656

5757

58-
def test_plot_sensitivity_requirement():
59-
plots.plot_sensitivity_requirement('north', color='green')
58+
def test_plot_sensitivity_cta_requirements():
59+
plots.plot_sensitivity_cta_requirements('north', color='green')
6060

6161
def test_plot_theta2():
6262
n = 10

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def package_files(directory):
1818
print("dataset {}".format(dataset))
1919

2020
setup(name='ctaplot',
21-
version=0.1,
21+
version=0.2,
2222
description="DESCRIPTION",
2323
# these should be minimum list of what is needed to run (note
2424
# don't need to list the sub-dependencies like numpy, since
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{"shower_prog_id": 1,
2+
"shower_prog_vers": 6990,
3+
"shower_prog_start": 1482580800,
4+
"detector_prog_id": 1,
5+
"detector_prog_vers": 1481293431,
6+
"detector_prog_start": 1482579523,
7+
"obsheight": 2147.0,
8+
"n_showers": 25000,
9+
"n_use": 20,
10+
"core_pos_mode": 1,
11+
"core_range": [0.0, 1900.0],
12+
"alt_range": [1.2217305, 1.2217305],
13+
"az_range": [0.0, 0.0],
14+
"diffuse": 1,
15+
"viewcone": [ 0.0, 10.0],
16+
"E_range": [3.0e-03, 3.3e+02],
17+
"spectral_index": -2.0,
18+
"B_total": 38.7280158996582,
19+
"B_inclination": 0.662263810634613,
20+
"B_declination": 0.0,
21+
"injection_height": -1.0,
22+
"atmosphere": 36,
23+
"corsika_iact_options": 187,
24+
"corsika_low_E_model": 2,
25+
"corsika_high_E_model": 3,
26+
"corsika_bunchsize": 5.0,
27+
"corsika_wlen_min": 240.0,
28+
"corsika_wlen_max": 700.0,
29+
"corsika_low_E_detail": 0,
30+
"corsika_high_E_detail": 101}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{ "shower_prog_vers": 6990,
2+
"shower_prog_start": 1467288000,
3+
"detector_prog_id": 1,
4+
"detector_prog_vers": 1462392225,
5+
"detector_prog_start": 1467287384,
6+
"obsheight": 2150.0,
7+
"n_showers": 20000,
8+
"n_use": 10,
9+
"core_pos_mode": 1,
10+
"core_range": [ 0.0, 2500.0],
11+
"alt_range": [1.2217305, 1.2217305],
12+
"az_range": [0.0, 0.0],
13+
"diffuse": 0,
14+
"viewcone": [0.0, 0.0],
15+
"E_range": [3.0e-03, 3.3e+02],
16+
"spectral_index": -2.0,
17+
"B_total": 23.11772346496582,
18+
"B_inclination": -0.39641156792640686,
19+
"B_declination": 0.0,
20+
"injection_height": -1.0,
21+
"atmosphere": 26,
22+
"corsika_iact_options": 187,
23+
"corsika_low_E_model": 2,
24+
"corsika_high_E_model": 3,
25+
"corsika_bunchsize": 5.0,
26+
"corsika_wlen_min": 240.0,
27+
"corsika_wlen_max": 700.0,
28+
"corsika_low_E_detail": 0,
29+
"corsika_high_E_detail": 303
30+
}

0 commit comments

Comments
 (0)