from __future__ import absolute_import import bufrpy from bufrpy.template import safnwc from bufrpy.table import libbufr import json import sys import time import codecs bufr_fname = None if len(sys.argv) == 4: # b-table and d-table table = libbufr.read_tables(codecs.open(sys.argv[1], 'rb', 'utf-8'), codecs.open(sys.argv[2], 'rb', 'utf-8')) bufr_fname = sys.argv[3] else: # either just b-table or a template file bufr_fname = sys.argv[2] try: # First try reading as safnwc template table = safnwc.read_template(codecs.open(sys.argv[1], 'rb', 'utf-8')) except Exception as e: # Try reading as libbufr table table = libbufr.read_tables(codecs.open(sys.argv[1], 'rb', 'utf-8')) msg = bufrpy.decode_file(open(bufr_fname, 'rb'), table) out = json.dumps(bufrpy.to_json(msg)) dec = bufrpy.from_json(json.loads(out)) print(out)
def read_file(b_table_file, d_table_file, bufr_file): return _do_read(b_table_file, d_table_file, bufr_file, lambda f, table: bufrpy.decode_file(f, table))
df.loc[(df['lon'] <= -180), 'lon'] = df['lon'] + 360. df.loc[(df['lon'] > 180), 'lon'] = df['lon'] - 360. alldata.append(df) return alldata #//TODO Deal with output file name if __name__ == '__main__': table = libbufr.read_tables(codecs.open(BUFR_TABLES[0], 'rb', 'utf-8'), codecs.open(BUFR_TABLES[1], 'rb', 'utf-8')) bufr_fname = '/ct12/abrammer/graphics/ecmf_tc_data/data/A_JSXX01ECEP141200_C_ECMP_20170714120000_tropical_cyclone_track_FERNANDA_-118p3degW_11degN_bufr4.bin' bufr_out = 'test.dat' #bufr_fname.replace('.bin', '.dat') bufr_fname = sys.argv[1] print(f"Converting {bufr_fname}") msg = bufrpy.decode_file(open(bufr_fname, 'rb'), table) alldata = bufr_to_data(msg) with open(bufr_out, 'a') as fout: for subset in alldata: basin = which_basin(subset) for index, datum in subset.iterrows(): if (pd.notnull(datum.get_value('lon'))): fout.write( atcf.line_out(basin, int(subset['STORM IDENTIFIER'][0][:2]), subset['date'][0], to_tech(subset), datum['tau'], datum['lat'], datum['lon'],