Exemplo n.º 1
0
 def test_readJSONMetadata(self):
     """readJSONMetadata should read in the file"""
     dat = dm.readJSONMetadata(self.filename)
     keys = ['PerigeePosGeod', 'S_sc_to_pfn', 'S_pfs_to_Bmin', 'Pfs_gsm',
             'Pfn_ED_MLAT', 'ED_R', 'Dst', 'DateTime', 'DOY', 'ED_MLON',
             'IntModel', 'ApogeePosGeod', 'CD_MLON', 'S_sc_to_pfs',
             'GpsTime', 'JulianDate', 'M_ref', 'ED_MLT', 'Pfs_ED_MLAT',
             'Bfs_geo', 'Bm', 'Pfn_CD_MLON', 'CD_MLAT', 'Pfs_geo',
             'Rsm', 'Pmin_gsm', 'Rgei', 'Rgsm', 'Pfs_CD_MLAT', 'S_total',
             'Rgeod_Height', 'Date', 'Alpha', 'M_igrf', 'Pfs_CD_MLT',
             'ED_MLAT', 'CD_R', 'PerigeeTimes', 'UTC', 'Pfn_ED_MLT',
             'BoverBeq', 'Lsimple', 'Lstar', 'I', 'DipoleTiltAngle',
             'K', 'Bmin_gsm', 'S_Bmin_to_sc', 'Bfs_gsm', 'L',
             'ApogeeTimes', 'ExtModel', 'Kp', 'Pfs_geod_LatLon',
             'MlatFromBoverBeq', 'Pfn_gsm', 'Loss_Cone_Alpha_n', 'Bfn_geo',
             'Pfn_CD_MLAT', 'Rgeod_LatLon', 'Pfs_ED_MLT', 'Pfs_CD_MLON',
             'Bsc_gsm', 'Pfn_geod_Height', 'Lm_eq', 'Rgse',
             'Pfn_geod_LatLon', 'CD_MLT', 'FieldLineType', 'Pfn_CD_MLT',
             'Pfs_geod_Height', 'Rgeo', 'InvLat_eq', 'M_used',
             'Loss_Cone_Alpha_s', 'Bfn_gsm', 'Pfn_ED_MLON', 'Pfn_geo',
             'InvLat', 'Pfs_ED_MLON']
     if str is bytes:
         keys = [unicode(k) for k in keys]
     # make sure data has all the keys and no more or less
     for k in dat:
         self.assertTrue(k in keys)
         ind = keys.index(k)
         del keys[ind]
     self.assertEqual(len(keys), 0)
Exemplo n.º 2
0
 def test_writeJSONMetadata(self):
     """reading metadata should give same keys as original datamodel"""
     dat = dm.readJSONMetadata(self.filename)
     # make sure data has all te keys and no more or less
     t_file = tempfile.NamedTemporaryFile(delete=False)
     t_file.close()
     dm.writeJSONMetadata(t_file.name, dat)
     dat2 = dm.readJSONheadedASCII(t_file.name)
     os.remove(t_file.name)
     keylist1 = sorted(dat.keys())
     keylist2 = sorted(dat2.keys())
     self.assertTrue(keylist1==keylist2)
     #now test that values in some metadata are identical
     self.assertTrue((dat['PerigeePosGeod'] == dat2['PerigeePosGeod']).all())
Exemplo n.º 3
0
 def test_toJSONmetadata_globals(self):
     """Test for handling of int, float, bool, list & dict in global attrs"""
     a = dm.SpaceData()
     a.attrs['Global1'] = 'A global string attribute'
     a.attrs['Global2'] = 2
     a.attrs['Global3'] = 3.0
     a.attrs['Global4'] = [1,2,3,4]
     a.attrs['Global5'] = True
     a['Var1'] = dm.dmarray([1,2,3,4,5], attrs={'Local1': 'A local attribute'})
     a['Var2'] = dm.dmarray([[8,9],[9,1],[3,4],[8,9],[7,8]])
     a['MVar'] = dm.dmarray([7.8], attrs={'Note': 'Metadata'})
     t_file = tempfile.NamedTemporaryFile(delete=False)
     t_file.close()
     dm.writeJSONMetadata(t_file.name, a)
     dat2 = dm.readJSONMetadata(t_file.name)
     #test global attr
     self.assertTrue(a.attrs==dat2.attrs)
     #test that metadata is back and all original keys are present
     for key in a['MVar'].attrs:
         self.assertTrue(key in dat2['MVar'].attrs)
     np.testing.assert_array_equal(a['MVar'], dat2['MVar'])
     os.remove(t_file.name)