mirror of https://github.com/ecmwf/eccodes.git
Examples: Run flake8 checks
This commit is contained in:
parent
2db15a68fc
commit
6198f46ba2
|
@ -23,29 +23,30 @@ from eccodes import *
|
|||
|
||||
VERBOSE = 1 # verbose error reporting
|
||||
|
||||
|
||||
def example(input_filename, output_filename):
|
||||
f = open(input_filename, 'rb')
|
||||
ibufrin = codes_bufr_new_from_file(f)
|
||||
f.close()
|
||||
|
||||
# Need to unpack to get delayed replications and reference values from input
|
||||
codes_set(ibufrin,'unpack',1)
|
||||
references=codes_get_array(ibufrin,'inputOverriddenReferenceValues')
|
||||
replication=codes_get_array(ibufrin,'delayedDescriptorReplicationFactor')
|
||||
codes_set(ibufrin, 'unpack', 1)
|
||||
references = codes_get_array(ibufrin, 'inputOverriddenReferenceValues')
|
||||
replication = codes_get_array(ibufrin, 'delayedDescriptorReplicationFactor')
|
||||
|
||||
ibufrout=codes_clone(ibufrin)
|
||||
ibufrout = codes_clone(ibufrin)
|
||||
|
||||
# Copy over to output
|
||||
codes_set_array(ibufrout,'inputOverriddenReferenceValues',references)
|
||||
codes_set_array(ibufrout,'inputDelayedDescriptorReplicationFactor',replication)
|
||||
codes_set_array(ibufrout, 'inputOverriddenReferenceValues', references)
|
||||
codes_set_array(ibufrout, 'inputDelayedDescriptorReplicationFactor', replication)
|
||||
# Keep all original descriptors and add 'meanWindDirectionForSurfaceTo1500M' (011044)
|
||||
ivalues=( 203014, 7030, 7031, 203255, 307080, 11044, )
|
||||
codes_set_array(ibufrout,'unexpandedDescriptors',ivalues)
|
||||
ivalues = (203014, 7030, 7031, 203255, 307080, 11044,)
|
||||
codes_set_array(ibufrout, 'unexpandedDescriptors', ivalues)
|
||||
|
||||
codes_bufr_copy_data ( ibufrin,ibufrout)
|
||||
codes_bufr_copy_data(ibufrin, ibufrout)
|
||||
|
||||
outfile=open(output_filename, 'wb')
|
||||
codes_write(ibufrout,outfile)
|
||||
outfile = open(output_filename, 'wb')
|
||||
codes_write(ibufrout, outfile)
|
||||
outfile.close()
|
||||
|
||||
codes_release(ibufrin)
|
||||
|
|
|
@ -11,13 +11,16 @@ from eccodes import *
|
|||
|
||||
OUTPUT_FILENAME = 'outfile_ecc_869_test.bufr'
|
||||
|
||||
VERBOSE = 1 # verbose error reporting
|
||||
|
||||
|
||||
def bufr_encode():
|
||||
ibufr = codes_bufr_new_from_samples('BUFR3_local')
|
||||
ivalues = (0, 0, 0, 0 ,)
|
||||
ivalues = (0, 0, 0, 0,)
|
||||
codes_set_array(ibufr, 'inputShortDelayedDescriptorReplicationFactor', ivalues)
|
||||
|
||||
SIZE_OF_BMP = 41
|
||||
bitMask = [1]*SIZE_OF_BMP
|
||||
bitMask = [1] * SIZE_OF_BMP
|
||||
bitMask[0] = 0 # marineObservingPlatformIdentifier
|
||||
bitMask[37] = 0 # pressureReducedToMeanSeaLevel
|
||||
codes_set_array(ibufr, 'inputDataPresentIndicator', bitMask)
|
||||
|
@ -44,7 +47,7 @@ def bufr_encode():
|
|||
codes_set(ibufr, 'localHour', 21)
|
||||
codes_set(ibufr, 'localMinute', 4)
|
||||
codes_set(ibufr, 'localSecond', 0)
|
||||
codes_set(ibufr, 'ident',' 3101544')
|
||||
codes_set(ibufr, 'ident', ' 3101544')
|
||||
codes_set(ibufr, 'rdbtimeDay', 21)
|
||||
codes_set(ibufr, 'rdbtimeHour', 21)
|
||||
codes_set(ibufr, 'rdbtimeMinute', 26)
|
||||
|
@ -71,15 +74,12 @@ def bufr_encode():
|
|||
|
||||
# Create the structure of the data section
|
||||
codes_set_array(ibufr, 'unexpandedDescriptors',
|
||||
(315009,
|
||||
222000, 236000,
|
||||
101000 + SIZE_OF_BMP, 31031,
|
||||
33007, 33007)
|
||||
(315009, 222000, 236000, 101000 + SIZE_OF_BMP, 31031, 33007, 33007)
|
||||
)
|
||||
|
||||
codes_set(ibufr, 'marineObservingPlatformIdentifier', 3101544)
|
||||
codes_set(ibufr, 'marineObservingPlatformIdentifier->percentConfidence', 44)
|
||||
codes_set(ibufr, 'longStationName','SIO Lagrangian Drifter Lab')
|
||||
codes_set(ibufr, 'longStationName', 'SIO Lagrangian Drifter Lab')
|
||||
codes_set(ibufr, 'dataBuoyType', 1)
|
||||
codes_set(ibufr, '#1#timeSignificance', 26)
|
||||
codes_set(ibufr, '#1#year', 2018)
|
||||
|
@ -89,7 +89,7 @@ def bufr_encode():
|
|||
codes_set(ibufr, '#1#minute', 4)
|
||||
codes_set(ibufr, 'latitude', -3.598198000000000008e+01)
|
||||
codes_set(ibufr, 'longitude', -4.484317000000000064e+01)
|
||||
codes_set(ibufr, 'platformTransmitterIdNumber',' 300234065315740')
|
||||
codes_set(ibufr, 'platformTransmitterIdNumber', ' 300234065315740')
|
||||
codes_set(ibufr, 'dataCollectionLocationSystem', 8)
|
||||
codes_set(ibufr, 'directionOfMotionOfMovingObservingPlatform', CODES_MISSING_LONG)
|
||||
codes_set(ibufr, 'platformDriftSpeed', CODES_MISSING_DOUBLE)
|
||||
|
@ -122,7 +122,7 @@ def bufr_encode():
|
|||
|
||||
outfile = open(OUTPUT_FILENAME, 'wb')
|
||||
codes_write(ibufr, outfile)
|
||||
print ("Created output BUFR file ",OUTPUT_FILENAME)
|
||||
print("Created output BUFR file ", OUTPUT_FILENAME)
|
||||
codes_release(ibufr)
|
||||
|
||||
|
||||
|
@ -130,7 +130,11 @@ def main():
|
|||
try:
|
||||
bufr_encode()
|
||||
except CodesInternalError as err:
|
||||
traceback.print_exc(file=sys.stderr)
|
||||
if VERBOSE:
|
||||
traceback.print_exc(file=sys.stderr)
|
||||
else:
|
||||
sys.stderr.write(err.msg + '\n')
|
||||
|
||||
return 1
|
||||
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ from eccodes import *
|
|||
|
||||
VERBOSE = 1 # verbose error reporting
|
||||
|
||||
|
||||
def parse_date(x):
|
||||
return datetime.strptime(x.decode('ascii'), '%Y%m%d')
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ from eccodes import *
|
|||
|
||||
VERBOSE = 1 # verbose error reporting
|
||||
|
||||
|
||||
def get_key_value(msgid, key):
|
||||
v = codes_get(msgid, key)
|
||||
if v == CODES_MISSING_DOUBLE or v == CODES_MISSING_LONG:
|
||||
|
|
|
@ -173,9 +173,7 @@ def example():
|
|||
for k in range(len(memberNumber)):
|
||||
data[k][i] = [lat[k], lon[k], press[k], latWind[k], lonWind[k], wind10m[k]]
|
||||
|
||||
|
||||
# ---------------------------------------- Print the values -------------
|
||||
|
||||
# ---------------------------------------- Print the values -------------
|
||||
for m in range(len(memberNumber)):
|
||||
print("== Member %d" % memberNumber[m])
|
||||
print("step latitude longitude pressure latitude longitude wind")
|
||||
|
|
|
@ -26,8 +26,8 @@ def example():
|
|||
|
||||
gid = codes_grib_new_from_file(fin)
|
||||
|
||||
assert codes_is_missing(gid, 'Ni') == False
|
||||
assert codes_is_missing(gid, 'Nj') == False
|
||||
assert not codes_is_missing(gid, 'Ni')
|
||||
assert not codes_is_missing(gid, 'Nj')
|
||||
nx = codes_get(gid, 'Ni')
|
||||
ny = codes_get(gid, 'Nj')
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ def example():
|
|||
|
||||
# Example of accessing specific elements from data values
|
||||
# Get first, middle and last elements
|
||||
indexes = [0, int(num_vals/2), num_vals-1]
|
||||
indexes = [0, int(num_vals / 2), num_vals - 1]
|
||||
elems = codes_get_double_elements(gid, 'values', indexes)
|
||||
|
||||
codes_release(gid)
|
||||
|
|
|
@ -24,6 +24,7 @@ from eccodes import *
|
|||
INPUT = '../../data/metar/metar.txt'
|
||||
VERBOSE = 1 # verbose error reporting
|
||||
|
||||
|
||||
def print_keys(msg_id):
|
||||
keys = ['CCCC', 'latitude', 'longitude', 'dateTime',
|
||||
'elevation', 'temperature', 'dewPointTemperature', 'qnh']
|
||||
|
|
Loading…
Reference in New Issue