afterglowpy
Advanced tools
| import unittest | ||
| import numpy as np | ||
| import afterglowpy.flux as flux | ||
| class TestFlux(unittest.TestCase): | ||
| def compareArrayEqualSingle(a1, a2): | ||
| return (a1 == a2).all() | ||
| def compareArrayTuple(self, func, argin, out): | ||
| res = func(*argin) | ||
| self.assertEqual(len(res), len(out)) | ||
| for i, a in enumerate(res): | ||
| self.assertTrue((a == out[i]).all()) | ||
| def test_checkTNu(self): | ||
| a1_5 = np.arange(5) | ||
| a1_4 = np.arange(4) | ||
| a2_45 = np.random.rand(4, 5) | ||
| a2_46 = np.random.rand(4, 6) | ||
| b2_45 = np.random.rand(4, 5) | ||
| s1_1 = np.array([3.0]) | ||
| s1_4 = np.empty(4) | ||
| s1_4[:] = 3.0 | ||
| s2_45 = np.empty((4, 5)) | ||
| s2_45[:] = 3.0 | ||
| # Check singleton args | ||
| self.compareArrayTuple(flux.checkTNu, (s1_1, s1_1), (s1_1, s1_1)) | ||
| self.compareArrayTuple(flux.checkTNu, (3.0, s1_1), (s1_1, s1_1)) | ||
| self.compareArrayTuple(flux.checkTNu, (s1_1, 3.0), (s1_1, s1_1)) | ||
| self.compareArrayTuple(flux.checkTNu, (3.0, 3.0), (s1_1, s1_1)) | ||
| # Check correct 1d array args | ||
| self.compareArrayTuple(flux.checkTNu, (a1_4, a1_4), (a1_4, a1_4)) | ||
| self.compareArrayTuple(flux.checkTNu, (s1_1, a1_4), (s1_4, a1_4)) | ||
| self.compareArrayTuple(flux.checkTNu, (a1_4, s1_1), (a1_4, s1_4)) | ||
| self.compareArrayTuple(flux.checkTNu, (3.0, a1_4), (s1_4, a1_4)) | ||
| self.compareArrayTuple(flux.checkTNu, (a1_4, 3.0), (a1_4, s1_4)) | ||
| # Check correct 2d array args | ||
| self.compareArrayTuple(flux.checkTNu, (a2_45, b2_45), (a2_45, b2_45)) | ||
| self.compareArrayTuple(flux.checkTNu, (s1_1, a2_45), (s2_45, a2_45)) | ||
| self.compareArrayTuple(flux.checkTNu, (a2_45, s1_1), (a2_45, s2_45)) | ||
| self.compareArrayTuple(flux.checkTNu, (3.0, a2_45), (s2_45, a2_45)) | ||
| self.compareArrayTuple(flux.checkTNu, (a2_45, 3.0), (a2_45, s2_45)) | ||
| # Check incorrect args | ||
| self.assertRaises(ValueError, flux.checkTNu, a1_4, a1_5) | ||
| self.assertRaises(ValueError, flux.checkTNu, a1_4, a2_45) | ||
| self.assertRaises(ValueError, flux.checkTNu, a2_45, a2_46) | ||
| def test_checkThetaPhiTNu(self): | ||
| a1_4 = np.arange(4) | ||
| a1_5 = np.arange(5) | ||
| a1_6 = np.arange(6) | ||
| a2_45 = np.random.rand(4, 5) | ||
| a2_46 = np.random.rand(4, 6) | ||
| s1_1 = np.array([3.0]) | ||
| s1_4 = np.empty(4) | ||
| s1_4[:] = 3.0 | ||
| s1_5 = np.empty(5) | ||
| s1_5[:] = 3.0 | ||
| s1_6 = np.empty(6) | ||
| s1_6[:] = 3.0 | ||
| s1_7 = np.empty(7) | ||
| s1_7[:] = 3.0 | ||
| s2_45 = np.empty((4, 5)) | ||
| s2_45[:] = 3.0 | ||
| # Check singleton args | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (s1_1, s1_1, s1_1, s1_1), | ||
| (s1_1, s1_1, s1_1, s1_1)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (3.0, s1_1, s1_1, s1_1), | ||
| (s1_1, s1_1, s1_1, s1_1)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (s1_1, 3.0, s1_1, s1_1), | ||
| (s1_1, s1_1, s1_1, s1_1)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (s1_1, s1_1, 3.0, s1_1), | ||
| (s1_1, s1_1, s1_1, s1_1)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (s1_1, s1_1, s1_1, 3.0), | ||
| (s1_1, s1_1, s1_1, s1_1)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (3.0, 3.0, s1_1, s1_1), | ||
| (s1_1, s1_1, s1_1, s1_1)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (3.0, s1_1, 3.0, s1_1), | ||
| (s1_1, s1_1, s1_1, s1_1)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (3.0, s1_1, s1_1, 3.0), | ||
| (s1_1, s1_1, s1_1, s1_1)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (s1_1, 3.0, 3.0, s1_1), | ||
| (s1_1, s1_1, s1_1, s1_1)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (s1_1, 3.0, s1_1, 3.0), | ||
| (s1_1, s1_1, s1_1, s1_1)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (s1_1, s1_1, 3.0, 3.0), | ||
| (s1_1, s1_1, s1_1, s1_1)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (3.0, 3.0, 3.0, s1_1), | ||
| (s1_1, s1_1, s1_1, s1_1)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (3.0, 3.0, s1_1, 3.0), | ||
| (s1_1, s1_1, s1_1, s1_1)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (3.0, s1_1, 3.0, 3.0), | ||
| (s1_1, s1_1, s1_1, s1_1)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (s1_1, 3.0, 3.0, 3.0), | ||
| (s1_1, s1_1, s1_1, s1_1)) | ||
| # Check correct 1d array args | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (a1_4, a1_4, a1_4, a1_4), | ||
| (a1_4, a1_4, a1_4, a1_4)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (s1_1, a1_4, a1_4, a1_4), | ||
| (s1_4, a1_4, a1_4, a1_4)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (a1_4, s1_4, a1_4, a1_4), | ||
| (a1_4, s1_4, a1_4, a1_4)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (a1_4, a1_4, s1_4, a1_4), | ||
| (a1_4, a1_4, s1_4, a1_4)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (a1_4, a1_4, a1_4, s1_4), | ||
| (a1_4, a1_4, a1_4, s1_4)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (3.0, a1_4, a1_4, a1_4), | ||
| (s1_4, a1_4, a1_4, a1_4)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (a1_4, 3.0, a1_4, a1_4), | ||
| (a1_4, s1_4, a1_4, a1_4)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (a1_4, a1_4, 3.0, a1_4), | ||
| (a1_4, a1_4, s1_4, a1_4)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (a1_4, a1_4, a1_4, 3.0), | ||
| (a1_4, a1_4, a1_4, s1_4)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (a1_4, 3.0, 3.0, 3.0), | ||
| (a1_4, s1_4, s1_4, s1_4)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (3.0, a1_4, 3.0, 3.0), | ||
| (s1_4, a1_4, s1_4, s1_4)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (3.0, 3.0, a1_4, 3.0), | ||
| (s1_4, s1_4, a1_4, s1_4)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (3.0, 3.0, 3.0, a1_4), | ||
| (s1_4, s1_4, s1_4, a1_4)) | ||
| # Check correct 2d array args | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (a2_45, a2_45, a2_45, a2_45), | ||
| (a2_45, a2_45, a2_45, a2_45)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (s1_1, a2_45, a2_45, a2_45), | ||
| (s2_45, a2_45, a2_45, a2_45)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (a2_45, s2_45, a2_45, a2_45), | ||
| (a2_45, s2_45, a2_45, a2_45)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (a2_45, a2_45, s2_45, a2_45), | ||
| (a2_45, a2_45, s2_45, a2_45)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (a2_45, a2_45, a2_45, s2_45), | ||
| (a2_45, a2_45, a2_45, s2_45)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (3.0, 3.0, a2_45, a2_45), | ||
| (s2_45, s2_45, a2_45, a2_45)) | ||
| self.compareArrayTuple(flux.checkThetaPhiTNu, | ||
| (a2_45, a2_45, 3.0, 3.0), | ||
| (a2_45, a2_45, s2_45, s2_45)) | ||
| self.assertRaises(ValueError, flux.checkThetaPhiTNu, | ||
| a1_4, a1_4, a1_4, a1_5) | ||
| self.assertRaises(ValueError, flux.checkThetaPhiTNu, | ||
| a1_4, a1_4, a1_5, a1_4) | ||
| self.assertRaises(ValueError, flux.checkThetaPhiTNu, | ||
| a1_4, a1_5, a1_4, a1_4) | ||
| self.assertRaises(ValueError, flux.checkThetaPhiTNu, | ||
| a1_5, a1_4, a1_4, a1_4) | ||
| self.assertRaises(ValueError, flux.checkThetaPhiTNu, | ||
| a1_6, a1_4, a1_4, a1_5) | ||
| self.assertRaises(ValueError, flux.checkThetaPhiTNu, | ||
| a1_4, a1_6, a1_5, a1_4) | ||
| self.assertRaises(ValueError, flux.checkThetaPhiTNu, | ||
| a1_4, a1_5, a1_6, a1_4) | ||
| self.assertRaises(ValueError, flux.checkThetaPhiTNu, | ||
| a1_5, a1_4, a1_4, a1_6) | ||
| self.assertRaises(ValueError, flux.checkThetaPhiTNu, | ||
| 3.0, a1_4, a1_4, a1_5) | ||
| self.assertRaises(ValueError, flux.checkThetaPhiTNu, | ||
| a1_4, 3.0, a1_5, a1_4) | ||
| self.assertRaises(ValueError, flux.checkThetaPhiTNu, | ||
| a1_4, a1_5, 3.0, a1_4) | ||
| self.assertRaises(ValueError, flux.checkThetaPhiTNu, | ||
| a1_5, a1_4, a1_4, 3.0) | ||
| self.assertRaises(ValueError, flux.checkThetaPhiTNu, | ||
| a2_45, a2_45, a2_45, a2_46) | ||
| self.assertRaises(ValueError, flux.checkThetaPhiTNu, | ||
| a2_45, a2_45, a2_46, a2_45) | ||
| self.assertRaises(ValueError, flux.checkThetaPhiTNu, | ||
| a2_45, a2_46, a2_45, a2_45) | ||
| self.assertRaises(ValueError, flux.checkThetaPhiTNu, | ||
| a2_46, a2_45, a2_45, a2_45) | ||
| self.assertRaises(ValueError, flux.checkThetaPhiTNu, | ||
| 3.0, a2_45, a2_45, a1_4) | ||
| def test_checkJetArgs(self): | ||
| EPS = 1.0e-8 | ||
| Y0 = np.array([0.05, 1.0e53, 0.1, 0.4, 4, 0, 0, 0, 1.0, 2.2, 0.1, | ||
| 0.01, 0.99, 1.0e28]) | ||
| Z0 = {'z': 0.5} | ||
| Y = Y0.copy() | ||
| Z = {} | ||
| for k in Z0: | ||
| Z[k] = Z0[k] | ||
| models = [-2, -1, 0, 1, 2, 4] | ||
| s = 0 | ||
| for m in models: | ||
| self.assertIsNone(flux.checkJetArgs(m, s, *Y0, **Z)) | ||
| # theta_obs | ||
| Y[0] = 0.0 | ||
| self.assertIsNone(flux.checkJetArgs(m, s, *Y, **Z)) | ||
| Y[0] = -0.1 | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[0] = 0.5*np.pi + EPS | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[0] = Y0[0] | ||
| # E0 | ||
| Y[1] = 0.0 | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[1] = -1.0 | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[1] = Y0[1] | ||
| # theta_C | ||
| Y[2] = 0.0 | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[2] = -0.1 | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[2] = 0.5*np.pi + EPS | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[2] = Y0[2] | ||
| # theta_W | ||
| if m != -1: | ||
| Y[3] = 0.0 | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[3] = -0.1 | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[3] = 0.5*np.pi + EPS | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[3] = Y0[3] | ||
| # b | ||
| if m == 4: | ||
| Y[4] = 0.0 | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[4] = -1.0 | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[4] = Y0[4] | ||
| # L0 | ||
| Y[5] = -1.0 | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[5] = Y0[5] | ||
| # t_s | ||
| Y[7] = -1.0 | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[7] = Y0[7] | ||
| # n0 | ||
| Y[8] = 0.0 | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[8] = -1.0 | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[8] = Y0[8] | ||
| # p | ||
| Y[9] = 0.0 | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[9] = 2.0 | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[9] = 1.0 | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[9] = -1.0 | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[9] = Y0[9] | ||
| s = 2 | ||
| Y[9] = 2.0 | ||
| self.assertIsNone(flux.checkJetArgs(m, s, *Y, **Z)) | ||
| Y[9] = 1.0 | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[9] = 0.0 | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[9] = -1.0 | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[9] = Y0[9] | ||
| s = 0 | ||
| # eps_e | ||
| Y[10] = 1.0 | ||
| self.assertIsNone(flux.checkJetArgs(m, s, *Y, **Z)) | ||
| Y[10] = 1.0 + EPS | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[10] = 0.0 | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[10] = -1.0 | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[10] = Y0[10] | ||
| # eps_B | ||
| Y[11] = 1.0 | ||
| self.assertIsNone(flux.checkJetArgs(m, s, *Y, **Z)) | ||
| Y[11] = 1.0 + EPS | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[11] = 0.0 | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[11] = -1.0 | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[11] = Y0[11] | ||
| # xi_N | ||
| Y[12] = 1.0 | ||
| self.assertIsNone(flux.checkJetArgs(m, s, *Y, **Z)) | ||
| Y[12] = 1.0 + EPS | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[12] = 0.0 | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[12] = -1.0 | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[12] = Y0[12] | ||
| # dL | ||
| Y[13] = 0.0 | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[13] = -1.0 | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Y[13] = Y0[13] | ||
| # z | ||
| Z['z'] = -1.0 | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| Z['z'] = Z0['z'] | ||
| # specific for cone | ||
| m = -2 | ||
| Y[3] = 0.5*Y[2] | ||
| self.assertRaises(ValueError, flux.checkJetArgs, m, s, *Y, **Z) | ||
| def test_checkCocoonArgs(self): | ||
| EPS = 1.0e-8 | ||
| Y0 = np.array([10.0, 1.0, 1.0e53, 5, 1.0e-5, 0, 0, 0, 1.0, 2.2, 0.1, | ||
| 0.01, 0.99, 1.0e28]) | ||
| Z0 = {'z': 0.5} | ||
| Y = Y0.copy() | ||
| Z = {} | ||
| for k in Z0: | ||
| Z[k] = Z0[k] | ||
| models = [3] | ||
| s = 0 | ||
| for m in models: | ||
| self.assertIsNone(flux.checkCocoonArgs(m, s, *Y0, **Z)) | ||
| # u_max | ||
| Y[0] = 0.0 | ||
| self.assertRaises(ValueError, flux.checkCocoonArgs, m, s, *Y, **Z) | ||
| Y[0] = -1.0 | ||
| self.assertRaises(ValueError, flux.checkCocoonArgs, m, s, *Y, **Z) | ||
| Y[0] = Y0[0] | ||
| # u_min | ||
| Y[1] = 0.0 | ||
| self.assertRaises(ValueError, flux.checkCocoonArgs, m, s, *Y, **Z) | ||
| Y[1] = -1.0 | ||
| self.assertRaises(ValueError, flux.checkCocoonArgs, m, s, *Y, **Z) | ||
| Y[1] = Y0[1] | ||
| # Ei | ||
| Y[2] = 0.0 | ||
| self.assertRaises(ValueError, flux.checkCocoonArgs, m, s, *Y, **Z) | ||
| Y[2] = -0.1 | ||
| self.assertRaises(ValueError, flux.checkCocoonArgs, m, s, *Y, **Z) | ||
| Y[2] = Y0[2] | ||
| # Mej_solar | ||
| Y[4] = 0.0 | ||
| self.assertRaises(ValueError, flux.checkCocoonArgs, m, s, | ||
| *Y, **Z) | ||
| Y[4] = -1.0 | ||
| self.assertRaises(ValueError, flux.checkCocoonArgs, m, s, | ||
| *Y, **Z) | ||
| Y[4] = Y0[4] | ||
| # L0 | ||
| Y[5] = -1.0 | ||
| self.assertRaises(ValueError, flux.checkCocoonArgs, m, s, *Y, **Z) | ||
| Y[5] = Y0[5] | ||
| # t_s | ||
| Y[7] = -1.0 | ||
| self.assertRaises(ValueError, flux.checkCocoonArgs, m, s, *Y, **Z) | ||
| Y[7] = Y0[7] | ||
| # n0 | ||
| Y[8] = 0.0 | ||
| self.assertRaises(ValueError, flux.checkCocoonArgs, m, s, *Y, **Z) | ||
| Y[8] = -1.0 | ||
| self.assertRaises(ValueError, flux.checkCocoonArgs, m, s, *Y, **Z) | ||
| Y[8] = Y0[8] | ||
| # p | ||
| Y[9] = 0.0 | ||
| self.assertRaises(ValueError, flux.checkCocoonArgs, m, s, *Y, **Z) | ||
| Y[9] = 2.0 | ||
| self.assertRaises(ValueError, flux.checkCocoonArgs, m, s, *Y, **Z) | ||
| Y[9] = 1.0 | ||
| self.assertRaises(ValueError, flux.checkCocoonArgs, m, s, *Y, **Z) | ||
| Y[9] = -1.0 | ||
| self.assertRaises(ValueError, flux.checkCocoonArgs, m, s, *Y, **Z) | ||
| Y[9] = Y0[9] | ||
| # eps_e | ||
| Y[10] = 1.0 | ||
| self.assertIsNone(flux.checkCocoonArgs(m, s, *Y, **Z)) | ||
| Y[10] = 1.0 + EPS | ||
| self.assertRaises(ValueError, flux.checkCocoonArgs, m, s, *Y, **Z) | ||
| Y[10] = 0.0 | ||
| self.assertRaises(ValueError, flux.checkCocoonArgs, m, s, *Y, **Z) | ||
| Y[10] = -1.0 | ||
| self.assertRaises(ValueError, flux.checkCocoonArgs, m, s, *Y, **Z) | ||
| Y[10] = Y0[10] | ||
| # eps_B | ||
| Y[11] = 1.0 | ||
| self.assertIsNone(flux.checkCocoonArgs(m, s, *Y, **Z)) | ||
| Y[11] = 1.0 + EPS | ||
| self.assertRaises(ValueError, flux.checkCocoonArgs, m, s, *Y, **Z) | ||
| Y[11] = 0.0 | ||
| self.assertRaises(ValueError, flux.checkCocoonArgs, m, s, *Y, **Z) | ||
| Y[11] = -1.0 | ||
| self.assertRaises(ValueError, flux.checkCocoonArgs, m, s, *Y, **Z) | ||
| Y[11] = Y0[11] | ||
| # xi_N | ||
| Y[12] = 1.0 | ||
| self.assertIsNone(flux.checkCocoonArgs(m, s, *Y, **Z)) | ||
| Y[12] = 1.0 + EPS | ||
| self.assertRaises(ValueError, flux.checkCocoonArgs, m, s, *Y, **Z) | ||
| Y[12] = 0.0 | ||
| self.assertRaises(ValueError, flux.checkCocoonArgs, m, s, *Y, **Z) | ||
| Y[12] = -1.0 | ||
| self.assertRaises(ValueError, flux.checkCocoonArgs, m, s, *Y, **Z) | ||
| Y[12] = Y0[12] | ||
| # dL | ||
| Y[13] = 0.0 | ||
| self.assertRaises(ValueError, flux.checkCocoonArgs, m, s, *Y, **Z) | ||
| Y[13] = -1.0 | ||
| self.assertRaises(ValueError, flux.checkCocoonArgs, m, s, *Y, **Z) | ||
| Y[13] = Y0[13] | ||
| # z | ||
| Z['z'] = -1.0 | ||
| self.assertRaises(ValueError, flux.checkCocoonArgs, m, s, *Y, **Z) | ||
| Z['z'] = Z0['z'] | ||
| if __name__ == "__main__": | ||
| unittest.main() |
| Metadata-Version: 2.1 | ||
| Name: afterglowpy | ||
| Version: 0.6.3 | ||
| Version: 0.6.4 | ||
| Summary: GRB Afterglow Models | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/geoffryan/afterglowpy |
@@ -20,2 +20,3 @@ MANIFEST.in | ||
| afterglowpy.egg-info/requires.txt | ||
| afterglowpy.egg-info/top_level.txt | ||
| afterglowpy.egg-info/top_level.txt | ||
| test/test_flux.py |
+241
-14
@@ -17,5 +17,5 @@ from . import cocoon | ||
| ---------- | ||
| t: array_like | ||
| t: array_like or scalar | ||
| Time since burst in observer frame, measured in seconds. | ||
| nu: array_like | ||
| nu: array_like or scalar | ||
| Frequency of flux in observer frame, measured in Hz, same size as t. | ||
@@ -85,4 +85,19 @@ jetType: int | ||
| The flux density F_nu in the observer frame, same shape as t and nu. | ||
| Raises | ||
| ------ | ||
| ValueError | ||
| If t, nu are the wrong shape or arguments take illegal values. | ||
| """ | ||
| # Check Arguments, will raise ValueError if args are bad | ||
| t, nu = checkTNu(t, nu) | ||
| if jetType == 3: | ||
| checkCocoonArgs(jetType, specType, *args, **kwargs) | ||
| else: | ||
| checkJetArgs(jetType, specType, *args, **kwargs) | ||
| # arguments are good, full steam ahead! | ||
| if 'z' in kwargs.keys(): | ||
@@ -105,6 +120,11 @@ z = kwargs.pop('z') | ||
| # timeA = time.time() | ||
| Fnu = np.empty(tz.shape) | ||
| if jetType == 3: | ||
| Fnu = cocoon.fluxDensity(tz, nuz, jetType, specType, *args, **kwargs) | ||
| Fnu.flat[:] = cocoon.fluxDensity(tz.flat, nuz.flat, jetType, specType, | ||
| *args, **kwargs) | ||
| else: | ||
| Fnu = jet.fluxDensity(tz, nuz, jetType, specType, *args, **kwargs) | ||
| Fnu.flat[:] = jet.fluxDensity(tz.flat, nuz.flat, jetType, specType, | ||
| *args, **kwargs) | ||
| # timeB = time.time() | ||
@@ -132,13 +152,14 @@ # print("Eval took: {0:f} s".format(timeB - timeA)) | ||
| ---------- | ||
| theta: array_like | ||
| Polar angle from jet axis in radians. | ||
| phi: array_like | ||
| theta: array_like or scalar | ||
| Polar angle from jet axis in radians. Scalar, or array of same shape | ||
| as phi, t, and nu. | ||
| phi: array_like or scalar | ||
| Azimuthal angle around jet axis in radians. Observer is at phi = 0. | ||
| Same size as theta. | ||
| t: array_like | ||
| Time since burst in observer frame, measured in seconds. Same size as | ||
| theta. | ||
| nu: array_like | ||
| Frequency of flux in observer frame, measured in Hz, same size as | ||
| theta. | ||
| Scalar, or array of same shape as theta, t, and nu. | ||
| t: array_like or scalar | ||
| Time since burst in observer frame, measured in seconds. Scalar, or | ||
| array of same shape as theta, phi, and nu. | ||
| nu: array_like or scalar | ||
| Frequency of flux in observer frame, measured in Hz. Scalar, or array | ||
| of same shape as theta, phi, and t. | ||
| jetType: int | ||
@@ -207,4 +228,21 @@ Code for type of jet. Options are: -2 cone, -1 top hat, 0 Gaussian, | ||
| The flux density F_nu in the observer frame, same shape as t and nu. | ||
| Raises | ||
| ------ | ||
| ValueError | ||
| If theta, phi, t, nu are the wrong shape or arguments take illegal | ||
| values. | ||
| """ | ||
| # Check Arguments, will raise ValueError if args are bad | ||
| t, nu = checkThetaPhiTNu(theta, phi, t, nu) | ||
| if jetType == 3: | ||
| checkCocoonArgs(jetType, specType, *args, **kwargs) | ||
| else: | ||
| checkJetArgs(jetType, specType, *args, **kwargs) | ||
| # arguments are good, full steam ahead! | ||
| if 'z' in kwargs.keys(): | ||
@@ -237,1 +275,190 @@ z = kwargs.pop('z') | ||
| return Inu | ||
| def checkTNu(t, nu): | ||
| # Make sure t and nu are array_like or castable to an array. | ||
| t = np.atleast_1d(t) | ||
| nu = np.atleast_1d(nu) | ||
| # Check shapes, if scalars make into right size array | ||
| if t.shape != nu.shape: | ||
| if t.shape == (1, ): | ||
| T = t[0] | ||
| t = np.empty(nu.shape) | ||
| t[:] = T | ||
| elif nu.shape == (1, ): | ||
| NU = nu[0] | ||
| nu = np.empty(t.shape) | ||
| nu[:] = NU | ||
| else: | ||
| raise ValueError("t and nu must be same shape or scalars") | ||
| return t, nu | ||
| def checkThetaPhiTNu(theta, phi, t, nu): | ||
| # Make sure args are array_like or castable to an array. | ||
| theta = np.atleast_1d(theta) | ||
| phi = np.atleast_1d(phi) | ||
| t = np.atleast_1d(t) | ||
| nu = np.atleast_1d(nu) | ||
| shape = (1, ) | ||
| if shape != theta.shape: | ||
| shape = theta.shape | ||
| elif shape != phi.shape: | ||
| shape = phi.shape | ||
| elif shape != t.shape: | ||
| shape = t.shape | ||
| else: | ||
| shape = nu.shape | ||
| if theta.shape != shape: | ||
| if theta.shape == (1, ): | ||
| TH = theta[0] | ||
| theta = np.empty(shape) | ||
| theta[:] = TH | ||
| else: | ||
| msg = "theta must be scalar or same shape as phi, t, nu" | ||
| raise ValueError(msg) | ||
| if phi.shape != shape: | ||
| if phi.shape == (1, ): | ||
| PH = phi[0] | ||
| phi = np.empty(shape) | ||
| phi[:] = PH | ||
| else: | ||
| msg = "phi must be scalar or same shape as theta, t, nu" | ||
| raise ValueError(msg) | ||
| if t.shape != shape: | ||
| if t.shape == (1, ): | ||
| T = t[0] | ||
| t = np.empty(shape) | ||
| t[:] = T | ||
| else: | ||
| msg = "t must be scalar or same shape as theta, phi, nu" | ||
| raise ValueError(msg) | ||
| if nu.shape != shape: | ||
| if nu.shape == (1, ): | ||
| NU = nu[0] | ||
| nu = np.empty(shape) | ||
| nu[:] = NU | ||
| else: | ||
| msg = "nu must be scalar or same shape as theta, phi, t" | ||
| raise ValueError(msg) | ||
| return theta, phi, t, nu | ||
| def checkJetArgs(jetType, specType, *args, **kwargs): | ||
| for x in args: | ||
| if not np.isfinite(x): | ||
| raise ValueError("All parameters must be finite") | ||
| theta_obs = args[0] | ||
| E0 = args[1] | ||
| theta_c = args[2] | ||
| theta_w = args[3] | ||
| b = args[4] | ||
| L0 = args[5] | ||
| t_s = args[7] | ||
| n0 = args[8] | ||
| p = args[9] | ||
| epse = args[10] | ||
| epsB = args[11] | ||
| xiN = args[12] | ||
| dL = args[13] | ||
| # More-or-less universal bounds | ||
| if theta_obs < 0.0 or theta_obs > 0.5*np.pi: | ||
| raise ValueError("theta_obs must be in [0.0, pi/2]") | ||
| if E0 <= 0.0: | ||
| raise ValueError("E0 must be positive") | ||
| if theta_c <= 0.0 or theta_c > 0.5*np.pi: | ||
| raise ValueError("theta_c must be in (0.0, pi/2]") | ||
| if jetType != -1 and (theta_w <= 0.0 or theta_w > 0.5*np.pi): | ||
| raise ValueError("theta_w must be in (0.0, pi/2]") | ||
| if jetType == 4 and b <= 0.0: | ||
| raise ValueError("b must be positive") | ||
| if L0 < 0.0: | ||
| raise ValueError("L0 must be non-negative") | ||
| if t_s < 0.0: | ||
| raise ValueError("t_s must be non-negative") | ||
| if n0 <= 0.0: | ||
| raise ValueError("n0 must be positive") | ||
| if specType != 2 and p <= 2.0: | ||
| raise ValueError("p must be in (2, inf)") | ||
| if specType == 2 and p <= 1.0: | ||
| raise ValueError("p must be in (1, inf)") | ||
| if epse <= 0.0 or epse > 1.0: | ||
| raise ValueError("epsilon_e must be in (0, 1]") | ||
| if epsB <= 0.0 or epsB > 1.0: | ||
| raise ValueError("epsilon_B must be in (0, 1]") | ||
| if xiN <= 0.0 or xiN > 1.0: | ||
| raise ValueError("xi_N must be in (0, 1]") | ||
| if dL <= 0.0: | ||
| raise ValueError("dL must be positive") | ||
| if 'z' in kwargs: | ||
| if kwargs['z'] < 0.0: | ||
| raise ValueError("z must be non-negative") | ||
| # Model Specific bounds | ||
| if jetType == -2 and theta_c > theta_w: | ||
| raise ValueError("theta_w must be larger than theta_c for cone model") | ||
| return | ||
| def checkCocoonArgs(jetType, specType, *args, **kwargs): | ||
| for x in args: | ||
| if not np.isfinite(x): | ||
| raise ValueError("All parameters must be finite") | ||
| u_max = args[0] | ||
| u_min = args[1] | ||
| Ei = args[2] | ||
| Mej_solar = args[4] | ||
| L0 = args[5] | ||
| t_s = args[7] | ||
| n0 = args[8] | ||
| p = args[9] | ||
| epse = args[10] | ||
| epsB = args[11] | ||
| xiN = args[12] | ||
| dL = args[13] | ||
| if u_max <= 0.0: | ||
| raise ValueError("u_max must be positive") | ||
| if u_min <= 0.0: | ||
| raise ValueError("u_min must be positive") | ||
| if Ei <= 0.0: | ||
| raise ValueError("Ei must be positive") | ||
| if Mej_solar <= 0.0: | ||
| raise ValueError("Mej_solar must be positive") | ||
| if L0 < 0.0: | ||
| raise ValueError("L0 must be non-negative") | ||
| if t_s < 0.0: | ||
| raise ValueError("t_s must be non-negative") | ||
| if n0 <= 0.0: | ||
| raise ValueError("n0 must be positive") | ||
| if specType != 2 and p <= 2.0: | ||
| raise ValueError("p must be in (2, inf)") | ||
| if epse <= 0.0 or epse > 1.0: | ||
| raise ValueError("epsilon_e must be in (0, 1]") | ||
| if epsB <= 0.0 or epsB > 1.0: | ||
| raise ValueError("epsilon_B must be in (0, 1]") | ||
| if xiN <= 0.0 or xiN > 1.0: | ||
| raise ValueError("xi_N must be in (0, 1]") | ||
| if dL <= 0.0: | ||
| raise ValueError("dL must be positive") | ||
| if 'z' in kwargs: | ||
| if kwargs['z'] < 0.0: | ||
| raise ValueError("z must be non-negative") | ||
| return |
@@ -5,2 +5,2 @@ #!/usr/bin/env python | ||
| __short_version__ = '0.6' | ||
| __version__ = '0.6.3' | ||
| __version__ = '0.6.4' |
+1
-1
| Metadata-Version: 2.1 | ||
| Name: afterglowpy | ||
| Version: 0.6.3 | ||
| Version: 0.6.4 | ||
| Summary: GRB Afterglow Models | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/geoffryan/afterglowpy |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
189282
16.43%23
4.55%966
184.12%