Пример #1
0
 def test_readFile(self):
     """Can read a file in and get the same answer"""
     ans = ae9ap9.readFile(self.datafiles[0])
     self.assertEqual((21, ), ans['Energy'].shape)
     self.assertEqual((121, ), ans['Epoch'].shape)
     self.assertEqual((121, 21 ), ans['Fluence'].shape)
     self.assertEqual((121, 3), ans['Coords'].shape)
     self.assertEqual((121, ), ans['MJD'].shape)
     self.assertEqual((3, ), ans['posComp'].shape)
Пример #2
0
 def test_setUnits_convert(self):
     """Conversion correctly changes flux/fluence values, energy values and units"""
     ans = ae9ap9.readFile(self.datafiles[0])
     curr = ans['Energy'].attrs['UNITS']
     self.assertEqual(curr, 'MeV') #test files should have MeV units
     E0 = ans['Energy'][0]
     F0 = ans['Fluence'][0,0]
     ans.setUnits('keV')
     self.assertEqual(ans['Energy'].attrs['UNITS'], 'keV')
     self.assertEqual(E0*1000.0, ans['Energy'][0])
     self.assertTrue('/keV' in ans['Fluence'].attrs['UNITS'])
     self.assertEqual(F0/1000.0, ans['Fluence'][0,0])
Пример #3
0
 def test_setUnits_convert(self):
     """Conversion correctly changes flux/fluence values, energy values and units"""
     ans = ae9ap9.readFile(self.datafiles[0])
     curr = ans['Energy'].attrs['UNITS']
     self.assertEqual(curr, 'MeV') #test files should have MeV units
     E0 = ans['Energy'][0]
     F0 = ans['Fluence'][0,0]
     ans.setUnits('keV')
     self.assertEqual(ans['Energy'].attrs['UNITS'], 'keV')
     self.assertEqual(E0*1000.0, ans['Energy'][0])
     self.assertTrue('/keV' in ans['Fluence'].attrs['UNITS'])
     self.assertEqual(F0/1000.0, ans['Fluence'][0,0])
Пример #4
0
 def test_readFileGzip(self):
     """can read a gziped file as well"""
     # take the input file and gzip it to a temp file
     tmpf = tempfile.NamedTemporaryFile(suffix='.gz')
     tmpf.close()
     tmpname = tmpf.name
     try:
         with open(self.datafiles[0], 'rb') as f_in, gzip.open(tmpname, 'wb') as f_out:
             shutil.copyfileobj(f_in, f_out)
         ans = ae9ap9.readFile(tmpname)
         self.assertEqual((21, ), ans['Energy'].shape)
         self.assertEqual((121, ), ans['Epoch'].shape)
         self.assertEqual((121, 21 ), ans['Fluence'].shape)
         self.assertEqual((121, 3), ans['GSE'].shape)
         self.assertEqual((121, ), ans['MJD'].shape)
         self.assertEqual((3, ), ans['posComp'].shape)
     finally:
         os.remove(tmpname)
Пример #5
0
 def test_readFileGzip(self):
     """can read a gzipped file as well"""
     # take the input file and gzip it to a temp file
     tmpf = tempfile.NamedTemporaryFile(suffix='.gz')
     tmpf.close()
     tmpname = tmpf.name
     try:
         with open(self.datafiles[0], 'rb') as f_in:
             with gzip.open(tmpname, 'wb') as f_out:
                 shutil.copyfileobj(f_in, f_out)
         ans = ae9ap9.readFile(tmpname)
         self.assertEqual((21, ), ans['Energy'].shape)
         self.assertEqual((121, ), ans['Epoch'].shape)
         self.assertEqual((121, 21 ), ans['Fluence'].shape)
         self.assertEqual((121, 3), ans['Coords'].shape)
         self.assertEqual((121, ), ans['MJD'].shape)
         self.assertEqual((3, ), ans['posComp'].shape)
     finally:
         os.remove(tmpname)
Пример #6
0
 def test_setUnits_error(self):
     """Invalid units raise the correct error and message"""
     ans = ae9ap9.readFile(self.datafiles[0])
     self.assertRaisesRegexp(ValueError, '^(Units of FeV)', ans.setUnits, 'FeV')
Пример #7
0
 def test_setUnits_error(self):
     """Invalid units raise the correct error and message"""
     ans = ae9ap9.readFile(self.datafiles[0])
     self.assertRaisesRegexp(ValueError, '^(Units of FeV)', ans.setUnits,
                             'FeV')