Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix unit issue with CTA effective area perf and req #174

Merged
merged 2 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions ctaplot/ana/ana.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def __init__(self):
self.energy = logbin_mean(self.energy_bins)

# Area of CTA sites in meters
self.ParanalArea_prod3 = 19.63e6 * u.m ** 2
self.LaPalmaArea_prod3 = 11341149 * u.m ** 2 # 6.61e6
self.ParanalArea_prod3 = 19.63e6 * u.m**2
self.LaPalmaArea_prod3 = 11341149 * u.m**2 # 6.61e6

@u.quantity_input(energy_bins=u.TeV)
def set_ebin(self, energy_bins):
Expand All @@ -78,7 +78,7 @@ def __init__(self, site):
self.site = site
self.energy = np.empty(0) * u.TeV
self.energy_bins = np.empty(0) * u.TeV
self.effective_area = np.empty(0) * u.m
self.effective_area = np.empty(0) * u.m**2
self.angular_resolution = np.empty(0) * u.deg
self.energy_resolution = np.empty(0)
self.sensitivity = np.empty(0) * u.erg / (u.cm ** 2 * u.s)
Expand All @@ -103,13 +103,13 @@ def get_effective_area(self, observation_time=50 * u.h):
ds.get('CTA-Performance-prod3b-v2-South-20deg-50h-EffArea.txt'),
skiprows=11, unpack=True)
self.energy = energy * u.TeV
self.effective_area = effective_area * u.m
self.effective_area = effective_area * u.m**2
elif observation_time == 0.5 * u.h:
energy, effective_area = np.loadtxt(
ds.get('CTA-Performance-prod3b-v2-North-20deg-30m-EffArea.txt'),
skiprows=11, unpack=True)
self.energy = energy * u.TeV
self.effective_area = effective_area * u.m
self.effective_area = effective_area * u.m**2
else:
raise ValueError("no effective area for this observation time")

Expand All @@ -119,13 +119,13 @@ def get_effective_area(self, observation_time=50 * u.h):
ds.get('CTA-Performance-prod3b-v2-North-20deg-50h-EffArea.txt'),
skiprows=11, unpack=True)
self.energy = energy * u.TeV
self.effective_area = effective_area * u.m
self.effective_area = effective_area * u.m**2
elif observation_time == 0.5 * u.h:
energy, effective_area = np.loadtxt(
ds.get('CTA-Performance-prod3b-v2-North-20deg-30m-EffArea.txt'),
skiprows=11, unpack=True)
self.energy = energy * u.TeV
self.effective_area = effective_area * u.m
self.effective_area = effective_area * u.m**2
else:
raise ValueError("no effective area for this observation time")

Expand Down Expand Up @@ -203,7 +203,7 @@ class cta_requirement:
def __init__(self, site):
self.site = site
self.energy = np.empty(0) * u.TeV
self.effective_area = np.empty(0) * u.m
self.effective_area = np.empty(0) * u.m**2
self.angular_resolution = np.empty(0) * u.deg
self.energy_resolution = np.empty(0)
self.sensitivity = np.empty(0) * u.erg / (u.cm ** 2 * u.s)
Expand Down Expand Up @@ -235,7 +235,7 @@ def get_effective_area(self, observation_time=50 * u.h):
raise ValueError(
f'incorrect site specified, accepted values are {_north_site_names} or {_south_site_names}')
self.energy = energy * u.TeV
self.effective_area = effective_area * u.m
self.effective_area = effective_area * u.m**2
return self.energy, self.effective_area

def get_angular_resolution(self):
Expand Down
13 changes: 13 additions & 0 deletions ctaplot/plots/tests/test_plots.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ctaplot
from ctaplot.plots import plots
import matplotlib.pyplot as plt
import numpy as np
Expand Down Expand Up @@ -32,31 +33,43 @@ def test_plot_energy_resolution():
def test_plot_energy_resolution_cta_requirement():
plt.close('all')
plots.plot_energy_resolution_cta_requirement('north', color='green')
plots.plot_energy_resolution(np.random.rand(2)*u.erg, np.random.rand(2)*u.J)


def test_plot_energy_resolution_cta_performance():
plt.close('all')
plots.plot_energy_resolution_cta_performance('north', color='green')
plots.plot_energy_resolution(np.random.rand(2) * u.erg, np.random.rand(2) * u.J)


def test_plot_angular_resolution_cta_performance():
plt.close('all')
plots.plot_angular_resolution_cta_performance('north', color='green')
a = np.random.rand(3) * u.rad
e = np.random.rand(3) * u.erg
plots.plot_angular_resolution_per_energy(a, a, a, a, e)


def test_plot_angular_resolution_cta_requirement():
plt.close('all')
plots.plot_angular_resolution_cta_requirement('north', color='green')
a = np.random.rand(3) * u.rad
e = np.random.rand(3) * u.erg
plots.plot_angular_resolution_per_energy(a, a, a, a, e)


def test_plot_effective_area_cta_performance():
plt.close('all')
plots.plot_effective_area_cta_performance('north', color='green')
e = np.random.rand(3)*u.erg
ctaplot.plot_effective_area_per_energy(e, e, 10*u.m**2)


def test_plot_effective_area_cta_requirement():
plt.close('all')
plots.plot_effective_area_cta_requirement('north', color='green')
e = np.random.rand(3) * u.erg
ctaplot.plot_effective_area_per_energy(e, e, 10 * u.m ** 2)


def test_plot_sensitivity_cta_performance():
Expand Down