def test_effective_area_interpolation(): ''' This test checks if the interpolated effective area is in a sensible range of values. The data mus have the following structure: # comment # comment # comment # log10(E/TeV), A_eff/cm^2 data, data data, data . . . ''' a_eff_list = get_effective_area_list() for a_eff in a_eff_list: # check that log10(energy/TeV) is > 1 MeV assert a_eff.x.min() > -6 # check that log10(energy/TeV) is < 1000000 TeV assert a_eff.x.max() < 7 # check that effective area/cm^2 is positive assert a_eff.y.min() >= 0 # check that effective area/cm^2 is smaller than earth's surface assert a_eff.y.max() < 5e18
def test_get_useful_e_0(): ''' This tests if the get_useful_e_0 function returns sensible values ''' a_eff_list = get_effective_area_list() for a_eff in a_eff_list: e_0 = gls.get_useful_e_0(a_eff) assert e_0 in [0.1, 1.0, 100000.0]
def test_get_effective_area(): ''' This test checks if the effective area is an interpolated function ''' # build path to test files a_eff_list = get_effective_area_list() for a_eff in a_eff_list: # check that it is interpolation function assert isinstance(a_eff, scipy.interpolate.interpolate.interp1d)
def test_get_energy_range(): ''' Test if the function really returns sensible energy ranges in units of TeV ''' a_eff_list = get_effective_area_list() for a_eff in a_eff_list: e_range = gls.get_energy_range(a_eff) assert e_range[0] > 5e-6 # all supplied effective areas start > 5 MeV assert e_range[1] < 1e7 # all supplied effective areas stop < 1e7 TeV
def test_get_effective_area_figure(): ''' Test to check if the above function really returns a matplotlib figure ''' a_eff_list = get_effective_area_list() a_eff_figures = [ gls.get_effective_area_figure(a_eff_interpol) for a_eff_interpol in a_eff_list ] for plot in a_eff_figures: assert isinstance(plot, matplotlib.figure.Figure)
def test_inverse_sensitive_energy(): ''' Test if the calculation of the inverse sensitive energy (calculation of Gamma) makes sense. ''' gamma_test = -2.6 a_eff = get_effective_area_list()[2] # Veritas V5 lowZd sensitive_e = gls.sensitive_energy(gamma_test, a_eff) gamma_inverse = gls.get_gamma_from_sensitive_energy(sensitive_e, a_eff) assert np.abs(gamma_inverse-gamma_test)/gamma_test < 1e-4
def test_sensitive_energy(): ''' Test if the calculation of the sensitive energy makes sense. ''' gamma_test = -2.6 a_eff = get_effective_area_list()[2] # Veritas V5 lowZd sensitive_e = gls.sensitive_energy(gamma_test, a_eff) assert sensitive_e < 1. assert sensitive_e > 0.1
def test_get_ul_spectrum_figure(): ''' Test to check if the above function really returns a matplotlib figure ''' a_eff_list = get_effective_area_list() __a, __b, __c, lambda_lim = get_random_on_off_experiment_no_source() ul_spectrum_figures, energy_xs, dn_de_ys = zip( *(gls.get_ul_spectrum_figure( 1. * 3600., lambda_lim, a_eff_interpol, e_0=1., n_points_to_plot=2) for a_eff_interpol in a_eff_list)) for plot in ul_spectrum_figures: assert isinstance(plot, matplotlib.figure.Figure)
def test_get_ul_phasespace_figure(): ''' Test to check if the above function really returns a matplotlib figure ''' a_eff_list = get_effective_area_list() __a, __b, __c, lambda_lim = get_random_on_off_experiment_no_source() ul_phasespace_figures = [ gls.get_ul_phasespace_figure(1. * 3600., lambda_lim, a_eff_interpol, pixels_per_line=2) for a_eff_interpol in a_eff_list ] for plot in ul_phasespace_figures: assert isinstance(plot, matplotlib.figure.Figure)
def test_get_sens_spectrum_figure(): ''' Test to check if the above function returns matplotlib figure ''' a_eff_list = get_effective_area_list() sens_phasespace_figures, energy_xs, dn_de_ys = zip( *(gls.get_sens_spectrum_figure(sigma_bg=10. / 3600., alpha=0.2, t_obs=10. * 3600, a_eff_interpol=a_eff_interpol, e_0=1., n_points_to_plot=2) for a_eff_interpol in a_eff_list)) for plot in sens_phasespace_figures: assert isinstance(plot, matplotlib.figure.Figure)
def test_get_sens_phasespace_figure(): ''' Test to check if the above function really returns a matplotlib figure ''' a_eff_list = get_effective_area_list() sens_phasespace_figures = [ gls.get_sens_phasespace_figure(sigma_bg=10. / 3600., alpha=0.2, t_obs=100. * 3600, a_eff_interpol=a_eff_interpol, pixels_per_line=2) for a_eff_interpol in a_eff_list ] for plot in sens_phasespace_figures: assert isinstance(plot, matplotlib.figure.Figure)
def test_get_ul_f_0(): ''' Test if the calculation of f_0 from the implicit condition lambda_s = lambda_limi is correct. This also tests effective_area_averaged_flux() and power_law() ''' gamma_test = -2.6 a_eff = get_effective_area_list()[2] # Veritas V5 lowZd f_0_calc = gls.get_ul_f_0( t_obs=7.*3600., lambda_lim=11.3, a_eff_interpol=a_eff, e_0=1., gamma=gamma_test ) assert f_0_calc < 2e-13 assert f_0_calc > 1e-13
def test_get_predict_phasespace_figure(): ''' A simple test for the get_phasespace_figure() function ''' a_eff_list = get_effective_area_list() chosen_index = 1 predict_phasespace_figure = gls.get_predict_phasespace_figure( sigma_bg=7. / 3600., alpha=0.2, f_0=1e-12, df_0=1e-13, gamma=-2.6, dgamma=0.1, e_0=1., a_eff_interpol=a_eff_list[chosen_index], pixels_per_line=2) assert isinstance(predict_phasespace_figure, matplotlib.figure.Figure)
def test_get_predict_spectrum_figure(): ''' A simple test for the get_spectrum_figure() function ''' a_eff_list = get_effective_area_list() chosen_index = 0 predict_spectrum_figure, __a, __b = gls.get_predict_spectrum_figure( sigma_bg=7. / 3600., alpha=0.2, t_obs_est=[1. * 3600., 2. * 3600., 3. * 3600.], f_0=1e-12, df_0=1e-13, gamma=-2.6, dgamma=0.1, e_0=1., a_eff_interpol=a_eff_list[chosen_index], n_points_to_plot=2) assert isinstance(predict_spectrum_figure, matplotlib.figure.Figure)
def test_integral_spectral_exclusion_zone(): ''' Test the function for calculating the integral spectral exclusion zone ''' energy_test = 1.2 # TeV lambda_lim_test = 11.3 t_obs_test = 7.*3600. # in s a_eff = get_effective_area_list()[2] # Veritas V5 lowZd f_0_result, gamma_result = gls.integral_spectral_exclusion_zone_parameters( energy_test, lambda_lim_test, a_eff, t_obs_test) # test results assert f_0_result > 1e-14 assert f_0_result < 1e-10 assert gamma_result > -10 assert gamma_result < 0.5 # cross check that the sensitive energy for inferred gamma is actually # equal (to one permil) to the one calculated with the Lagrangian result sensitive_e = gls.sensitive_energy(gamma_result, a_eff) assert np.abs(sensitive_e-energy_test)/energy_test < 1e-4
def test_get_t_obs_samples(): ''' Test if this function retruns a sensible array of t_obs_est ''' a_eff_list = get_effective_area_list() chosen_index = 2 a_eff = a_eff_list[chosen_index] t_obs_samples = gls.get_t_obs_samples( sigma_bg=7./3600., alpha=0.2, f_0=1e-12, df_0=1e-13, gamma=-2.6, dgamma=0.1, e_0=1., a_eff_interpol=a_eff, n_samples=5, ) for t_obs_est in t_obs_samples: assert t_obs_est > 0.