Пример #1
0
 def testLgm_B_OP77_1(self):
     """This is a regression functional test for LstarVersusPA (regression)"""
     ans = Lstar.get_Lstar(
         [-4.2, 1, 1], self.date, alpha=90, Kp=4, coord_system="SM", Bfield="Lgm_B_OP77", LstarQuality=1
     )
     self.assertAlmostEqual(4.8619543166, ans[90]["LHilton"], places=4)
     self.assertAlmostEqual(4.86203516, ans[90]["LMcIlwain"], places=4)
     self.assertAlmostEqual(4.571340083084, ans[90]["Lstar"][0], places=4)
     self.assertAlmostEqual(6.29150825380, ans[90]["Lsimple"][0], places=4)
Пример #2
0
 def testLgm_B_T89_2(self):
     """This is a regression functional test for LstarVersusPA (regression)"""
     ans = Lstar.get_Lstar(
         [-4.2, 1, 1], self.date, alpha=90, Kp=5, coord_system="SM", Bfield="Lgm_B_T89", LstarQuality=1
     )
     self.assertAlmostEqual(5.179958506, ans[90]["LHilton"], places=4)
     self.assertAlmostEqual(5.180130107, ans[90]["LMcIlwain"], places=4)
     self.assertAlmostEqual(4.35824001343, ans[90]["Lstar"][0], places=4)
     self.assertAlmostEqual(5.46286608758, ans[90]["Lsimple"][0], places=4)
Пример #3
0
 def testLgm_B_T89_1(self):
     """This is a regression functional test for LstarVersusPA (regression)"""
     ans = Lstar.get_Lstar(
         [-4.2, 1, 1], self.date, alpha=90, Kp=4, coord_system="SM", Bfield="Lgm_B_T89", LstarQuality=1
     )
     self.assertAlmostEqual(5.02934060, ans[90]["LHilton"], places=4)
     self.assertAlmostEqual(5.029461969276, ans[90]["LMcIlwain"], places=4)
     self.assertAlmostEqual(4.4572240898083, ans[90]["Lstar"][0], places=4)
     self.assertAlmostEqual(5.81634438101, ans[90]["Lsimple"][0], places=4)
Пример #4
0
 def testL_B_T89_(self):
     """Test that Lvalue code returns same value of L returned by Lstar"""
     ans = Lstar.get_Lstar(
         [-4.2, 1, 1], self.date, alpha=90, Kp=4, coord_system="GSM", Bfield="Lgm_B_T89", LstarQuality=3
     )
     ans2 = magcoords.Lvalue([-4.2, 1, 1], self.date, alpha=90, Kp=4, Bfield="Lgm_B_T89", method="Hilton")
     ans3 = magcoords.Lvalue([-4.2, 1, 1], self.date, alpha=90, Kp=4, Bfield="Lgm_B_T89", method="McIlwain")
     self.assertAlmostEqual(ans2["L"], ans[90]["LHilton"], places=2)
     self.assertAlmostEqual(ans3["L"], ans[90]["LMcIlwain"], places=2)
Пример #5
0
 def testCentredDipole75(self):
     """Unit test for centred dipole - should give known result"""
     for rdist, qlevel in itertools.product([3, 3.5, 4, 5, 6], range(2, 5)):
         ans = Lstar.get_Lstar(
             [-rdist, 0, 0], self.date, alpha=75, coord_system="SM", Bfield="Lgm_B_cdip", LstarQuality=qlevel
         )
         try:
             self.assertAlmostEqual(rdist, ans[75]["Lstar"][0], places=qlevel - 1)
         except:
             pass  # print('FAILURE L=%f, Qual=%d, date=%s' % (rdist, qlevel, self.date))
Пример #6
0
 def testCentredDipole90(self):
     """Unit test for centred dipole - should give known result"""
     for rdist, qlevel in itertools.product([3, 3.5, 4, 5, 6], range(1, 5)):
         ans = Lstar.get_Lstar(
             [-rdist, 0, 0], self.date, alpha=90, coord_system="SM", Bfield="Lgm_B_cdip", LstarQuality=qlevel
         )
         try:
             self.assertAlmostEqual(rdist, ans[90]["Lstar"][0], places=qlevel)
         except:
             # print('Failed Lstar:CentredDipole90:: L=%f, Qual=%d -- dropped to %d places'
             #    % (rdist, qlevel, qlevel-1))
             self.assertAlmostEqual(rdist, ans[90]["Lstar"][0], places=qlevel - 2)
Пример #7
0
 def testCentredDipole9(self):
     """Unit test for centred dipole - should give known result
     
     Quality level only tested up to 5 (max 7) as 6 and 7 may not
     converge to a solution on all machines"""
     for rdist, qlevel in itertools.product([3], range(1, 5)):
         ans = Lstar.get_Lstar(
             [-rdist, 0, 0], self.date, alpha=9, coord_system="SM", Bfield="Lgm_B_cdip", LstarQuality=qlevel
         )
         numpy.testing.assert_allclose(
             ans[9]["Lstar"][...], rdist, atol=10 ** (-1 * (qlevel - 2)), rtol=10 ** (-1 * (qlevel))
         )
Пример #8
0
 def testLgm_B_OP77_1(self):
     """This is a regression functional test for LstarVersusPA (regression)"""
     ans = Lstar.get_Lstar([-4.2, 1, 1],
                           self.date,
                           alpha=90,
                           Kp=4,
                           coord_system='SM',
                           Bfield='Lgm_B_OP77',
                           LstarQuality=1)
     self.assertAlmostEqual(4.8619543166, ans[90]['LHilton'], places=4)
     self.assertAlmostEqual(4.86203516, ans[90]['LMcIlwain'], places=4)
     self.assertAlmostEqual(4.571340083084, ans[90]['Lstar'][0], places=4)
     self.assertAlmostEqual(6.29150825380, ans[90]['Lsimple'][0], places=4)
Пример #9
0
 def testLgm_B_T89_2(self):
     """This is a regression functional test for LstarVersusPA (regression)"""
     ans = Lstar.get_Lstar([-4.2, 1, 1],
                           self.date,
                           alpha=90,
                           Kp=5,
                           coord_system='SM',
                           Bfield='Lgm_B_T89',
                           LstarQuality=1)
     self.assertAlmostEqual(5.179958506, ans[90]['LHilton'], places=4)
     self.assertAlmostEqual(5.180130107, ans[90]['LMcIlwain'], places=4)
     self.assertAlmostEqual(4.35824001343, ans[90]['Lstar'][0], places=4)
     self.assertAlmostEqual(5.46286608758, ans[90]['Lsimple'][0], places=4)
Пример #10
0
 def testLgm_B_T89_1(self):
     """This is a regression functional test for LstarVersusPA (regression)"""
     ans = Lstar.get_Lstar([-4.2, 1, 1],
                           self.date,
                           alpha=90,
                           Kp=4,
                           coord_system='SM',
                           Bfield='Lgm_B_T89',
                           LstarQuality=1)
     self.assertAlmostEqual(5.02934060, ans[90]['LHilton'], places=4)
     self.assertAlmostEqual(5.029461969276, ans[90]['LMcIlwain'], places=4)
     self.assertAlmostEqual(4.4572240898083, ans[90]['Lstar'][0], places=4)
     self.assertAlmostEqual(5.81634438101, ans[90]['Lsimple'][0], places=4)
Пример #11
0
 def testCentredDipole75(self):
     """Unit test for centred dipole - should give known result"""
     for rdist, qlevel in itertools.product([3, 3.5, 4, 5, 6], range(2, 5)):
         ans = Lstar.get_Lstar([-rdist, 0, 0],
                               self.date,
                               alpha=75,
                               coord_system='SM',
                               Bfield='Lgm_B_cdip',
                               LstarQuality=qlevel)
         try:
             self.assertAlmostEqual(rdist,
                                    ans[75]['Lstar'][0],
                                    places=qlevel - 1)
         except:
             pass  #print('FAILURE L=%f, Qual=%d, date=%s' % (rdist, qlevel, self.date))
Пример #12
0
 def testCentredDipole9(self):
     """Unit test for centred dipole - should give known result
     
     Quality level only tested up to 5 (max 7) as 6 and 7 may not
     converge to a solution on all machines"""
     for rdist, qlevel in itertools.product([3], range(1, 5)):
         ans = Lstar.get_Lstar([-rdist, 0, 0],
                               self.date,
                               alpha=9,
                               coord_system='SM',
                               Bfield='Lgm_B_cdip',
                               LstarQuality=qlevel)
         numpy.testing.assert_allclose(ans[9]['Lstar'][...],
                                       rdist,
                                       atol=10**(-1 * (qlevel - 2)),
                                       rtol=10**(-1 * (qlevel)))
Пример #13
0
 def testCentredDipole90(self):
     """Unit test for centred dipole - should give known result"""
     for rdist, qlevel in itertools.product([3, 3.5, 4, 5, 6], range(1, 5)):
         ans = Lstar.get_Lstar([-rdist, 0, 0],
                               self.date,
                               alpha=90,
                               coord_system='SM',
                               Bfield='Lgm_B_cdip',
                               LstarQuality=qlevel)
         try:
             self.assertAlmostEqual(rdist,
                                    ans[90]['Lstar'][0],
                                    places=qlevel)
         except:
             #print('Failed Lstar:CentredDipole90:: L=%f, Qual=%d -- dropped to %d places'
             #    % (rdist, qlevel, qlevel-1))
             self.assertAlmostEqual(rdist,
                                    ans[90]['Lstar'][0],
                                    places=qlevel - 2)
Пример #14
0
 def testL_B_T89_(self):
     """Test that Lvalue code returns same value of L returned by Lstar"""
     ans = Lstar.get_Lstar([-4.2, 1, 1],
                           self.date,
                           alpha=90,
                           Kp=4,
                           coord_system='GSM',
                           Bfield='Lgm_B_T89',
                           LstarQuality=3)
     ans2 = magcoords.Lvalue([-4.2, 1, 1],
                             self.date,
                             alpha=90,
                             Kp=4,
                             Bfield='Lgm_B_T89',
                             method='Hilton')
     ans3 = magcoords.Lvalue([-4.2, 1, 1],
                             self.date,
                             alpha=90,
                             Kp=4,
                             Bfield='Lgm_B_T89',
                             method='McIlwain')
     self.assertAlmostEqual(ans2['L'], ans[90]['LHilton'], places=2)
     self.assertAlmostEqual(ans3['L'], ans[90]['LMcIlwain'], places=2)
Пример #15
0
pos = [-4, 0, 0]
date = datetime.datetime(2010, 12, 1)

results = {}

for i in range(9):
    results[i] = {}
    results[i]['Lsimple'] = []
    results[i]['time'] = []
    results[i]['Lstar'] = []

for qual in range(9):
    for n in range(20):
        print qual, n
        t0 = now()
        ans = Lstar.get_Lstar(pos, date, LstarQuality=qual, Bfield='Lgm_B_T89')
        t1 = now()
        results[qual]['time'].append((t1 - t0).seconds +
                                     (t1 - t0).microseconds / 1000000)
        results[qual]['Lsimple'].append(ans[90]['Lsimple'])
        try:
            results[qual]['Lstar'].append(ans[90]['Lstar'])
        except KeyError:
            pass

colors = ('b', 'g', 'r', 'c', 'm', 'y', 'k', 'b', 'g')
data = []
for i in range(9):
    for j, val in enumerate(results[i]['time']):
        plot(j, val, color=colors[i], marker='o', markersize=10)
    data.append(results[i]['time'])
Пример #16
0
 def test_init(self):
     """Lstar_Data can be created"""
     a = Lstar.Lstar_Data()
     self.assertTrue(hasattr(a, 'attrs'))
     self.assertTrue(a['position'] == {})
Пример #17
0

results = {}

for i in range(9):
    results[i] = {}
    results[i]['Lsimple']=[]
    results[i]['time']=[]
    results[i]['Lstar']=[]


for qual in range(9):
    for n in range(20):
        print qual, n
        t0 = now()
        ans = Lstar.get_Lstar(pos, date, LstarQuality=qual, Bfield = 'Lgm_B_T89')
        t1 = now()
        results[qual]['time'].append((t1-t0).seconds + (t1-t0).microseconds/1000000)
        results[qual]['Lsimple'].append(ans[90]['Lsimple'])
        try:
            results[qual]['Lstar'].append(ans[90]['Lstar'])
        except KeyError:
            pass

colors = ('b', 'g', 'r', 'c', 'm', 'y', 'k', 'b', 'g')
data = []
for i in range(9):
    for j, val in enumerate(results[i]['time']):
        plot(j, val, color=colors[i], marker='o', markersize=10)
    data.append(results[i]['time'])