def test_headerStr(self): lv = Level() _set_header_vals(HEADER_VALS[0], lv) lv.valid_fields = 1 header = _Header(lv, lv.valid_fields) expected_str = ' 39.78000 -104.8600072469 DENVER/STAPLETON INT., CO. / U.S.A. FM-35 TEMP GTS (ROHK) UKUS09 KWBC 051200 RRA 1626.00000 1 -888888 -888888 890 -888888 T F F -888888 -888888 20080205120000-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0' self.assertEqual(str(header), expected_str)
def test_LittleRFormatter_add_level_error(self): # Make sure that the formatter fails if a report hasn't been started fmtr = LittleRFormatter() self.assertRaises(IndexError, fmtr.add_level, Level()) fmtr.start_new_report() try: fmtr.add_level(Level()) except IndexError: self.fail('add_level raised an unexpected error.')
def test_header_length(self): max_len = 600 lv = Level() lv.name = 'A' * 100 lv.id = 'I' * 100 lv.source = 'S' * 100 h = _Header(lv, lv.valid_fields) self.assertEqual(len(str(h)), max_len)
def test_LittleRFormatter_add_level(self): testlv1 = Level() testlv1.height = (0.0, 0) testlv2 = Level() testlv2.height = (1.0, 0) out = LittleRFormatter() out.start_new_report() out.add_level(testlv1) out.start_new_report() out.add_level(testlv2) # Make sure that add_level adds the levels to the appropriate reports self.assertNotEqual(out.reports[0].records[0].lv, out.reports[1].records[0].lv) self.assertNotEqual(str(out.reports[0].records[0]), str(out.reports[1].records[0]))
def test_recordStr(self): # Test default rec = _Record(Level()) expected_str = '-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0' self.assertEqual(str(rec), expected_str, "Default Record str must match expected") # Test with specific values lv = Level() lv.pres = (83500.00000, 0) lv.temp = (264.44998, 0) lv.dewpoint = (263.35001, 0) rec = _Record(lv) expected_str = ' 83500.00000 0-888888.00000 0 264.44998 0 263.35001 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0' self.assertEqual(str(rec), expected_str, "Record str must match expected")
def _parse(self, src): try: data = _parse_graw_file(src) except GrawParsingError as e: raise GrawParsingError("Could not parse graw data file: " + e.message) self.count = data.shape[0] for i in range(self.count): level = Level() lv = data.iloc[i] # Header level.lat = lv.loc[_ILAT] level.lon = lv.loc[_ILON] level.id = self._src_id level.name = self._src_name level.source = self._src_source level.platform = 'FM-38 TEMP MOBIL' level.alt = lv.loc[_IALT] # TODO: implement seq num level.is_sounding = True level.bogus = False level.date = _get_date_str(self._start_date, lv.loc[_ITIME]) # TODO: implement SLP, sfc_pres # Fields level.pres = (_convert_pres(lv.loc[_IPRES]), 0) level.height = (lv.loc[_IALT], 0) level.temp = (_convert_temp(lv.loc[_ITEMP]), 0) level.dewpoint = (_convert_temp(lv.loc[_IDEW]), 0) wspd = lv.loc[_IWS] wdir = lv.loc[_IWD] level.windspd = (wspd, 0) level.winddir = (wdir, 0) u, v = uv_from_met(wspd, wdir) level.windu = (u, 0) level.windv = (v, 0) level.rh = (lv.loc[_IRH], 0) level.valid_fields = 9 self.levels.append(level)
def _vals_to_level(hvals, vals): lv = Level() _set_header_vals(hvals, lv) lv.valid_fields = len(vals) - vals.count(DEFAULT_FLOAT) lv.pres = (vals[0], 0) lv.height = (vals[1], 0) lv.temp = (vals[2], 0) lv.dewpoint = (vals[3], 0) lv.windspd = (vals[4], 0) lv.winddir = (vals[5], 0) lv.windu = (vals[6], 0) lv.windv = (vals[7], 0) lv.rh = (vals[8], 0) lv.thickness = (vals[9], 0) return lv
def __init__(self): self.records = [] # Ending sentinel level self.ending_lv = Level() self.ending_lv.pres = (_END_RECORD_VALUE, 0) self.ending_lv.height = (_END_RECORD_VALUE, 0)