...
Code Block | ||||
---|---|---|---|---|
| ||||
"key" : "unexpandedDescriptors", "value" : [ 301150, 307091 ] }, [ [ { "key" : "subsetNumber", "value" : 1 }, { "key" : "wigosIdentifierSeries", "value" : 0, "units" : "Numeric" }, [ { "key" : "wigosIssuerOfIdentifier", "value" : 76, "units" : "Numeric" |
This process can be adapted for other BUFR data as well. For instance, from Brazil we received two different BUFR files
SYNOP-wsi.bfr
climat-wsi-test.bfr
To find the proper encoding function to replace bufr_encode_new in the script, we can use the ecCodes command line tool bufr_dump
bufr_dump -E python SYNOP-wsi.bfr > SYNOP-wsi.bfr.py
bufr_dump -E python climat-wsi-test.bfr >climat-wsi-test.bfr.py
This command generates a python code that contains the code to update the bufr_encode_new function.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
def bufr_encode():
ibufr = codes_bufr_new_from_samples('BUFR4')
ivalues = (
0, 0 ,)
codes_set_array(ibufr, 'inputDelayedDescriptorReplicationFactor', ivalues)
codes_set(ibufr, 'edition', 4)
codes_set(ibufr, 'masterTableNumber', 0)
codes_set(ibufr, 'bufrHeaderCentre', 43)
codes_set(ibufr, 'bufrHeaderSubCentre', 0)
codes_set(ibufr, 'updateSequenceNumber', 0)
codes_set(ibufr, 'dataCategory', 0)
codes_set(ibufr, 'internationalDataSubCategory', 2)
codes_set(ibufr, 'dataSubCategory', 2)
codes_set(ibufr, 'masterTablesVersionNumber', 28)
codes_set(ibufr, 'localTablesVersionNumber', 0)
codes_set(ibufr, 'typicalYear', 2018)
codes_set(ibufr, 'typicalMonth', 10)
codes_set(ibufr, 'typicalDay', 16)
codes_set(ibufr, 'typicalHour', 0)
codes_set(ibufr, 'typicalMinute', 0)
codes_set(ibufr, 'typicalSecond', 0)
codes_set(ibufr, 'numberOfSubsets', 1)
codes_set(ibufr, 'observedData', 1)
codes_set(ibufr, 'compressedData', 0)
ivalues = (
301150, 307080,)
# Create the structure of the data section
codes_set_array(ibufr, 'unexpandedDescriptors', ivalues)
|
As the bufr_encode_new function receives a handle ( ibufr) from the message_encoding function so the first line
ibufr = codes_bufr_new_from_samples('BUFR4')
is not needed
This function message_encoding generates handles to bufr messages using a template BUFR4_local that is part of ecCodes installation ( can be seen by using codes_info)
Code Block | ||||
---|---|---|---|---|
| ||||
def message_encoding(FullInputFileName,fout):
'''
Message encoding function
FullInputFilename : full path of the Ascii file for example /tmp/data/rema_20180918.txt
fout : file Object to write the output bufr file( obtained by a call to open )
Requires ecCodes and the BUFR4_local template on
ECCODES_PATH/share/eccodes/samples
'''
TEMPLATE='BUFR4_local'
# reads the Ascii file into a pandas Dataframe
dfFull=read_ascii(FullInputFileName)
# loops over the rows of the dataFrame dfFull
for _,row in dfFull.iterrows():
bid=codes_bufr_new_from_samples(TEMPLATE)
try:
bufr_encode_new(bid,row)
codes_write(bid,fout)
except CodesInternalError as ec:
print ec
codes_release(bid) |
The last four lines of SYNOP-wsi.bfr.py are not needed either as they are replaced by the try/except block in the message_encoding function
Code Block | ||||
---|---|---|---|---|
| ||||
outfile = open('outfile.bufr', 'w')
codes_write(ibufr, outfile)
print ("Created output BUFR file 'outfile.bufr'")
codes_release(ibufr)
|
DISCLAIMER: This software is intended for testing purposes only. Feedback would be appreciated but technical support can only be given if our workload permits.