Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
print(' %s: %s' %
(keyname, eccodes.codes_get(self._bufr, keyname)))
# get unexpanded descriptors
key = 'unexpandedDescriptors'
num = eccodes.codes_get_size(self._bufr, key)
print(' size of %s is: %s' % (key, num))
values = eccodes.codes_get_array(self._bufr, key)
for i in xrange(len(values)):
print(" %d %06d" % (i + 1, values[i]))
# get the expanded descriptors
key = 'bufrdcExpandedDescriptors'
num = eccodes.codes_get_size(self._bufr, key)
print(' size of %s is: %s' % (key, num))
values = eccodes.codes_get_array(self._bufr, key)
for i in xrange(len(values)):
print(" %d %06d" % (i + 1, values[i]))
for field in field_names:
if field[0] in string.digits:
print('cannot get data for field: ',field)
continue
# print('trying field name: ', field)
# key = '/subsetNumber={0:d}/{1:s}'.format(subset_nr, field)
key = field
# print('trying key: ', key)
s = eccodes.codes_get_size(self._bufr, key)
# print('s=', s)
if s==1:
value = eccodes.codes_get(self._bufr, key)
data.append(value)
else:
values = eccodes.codes_get_array(self._bufr, key)
# print('DEBUG: values: ', values)
data.append(values)
# finally convert to a numpy array of type object
# for user convenience
values = numpy.array(data, dtype='object')
return values
# #]
def _get_abbr_names(self, subset=1):
# #[ request abbr. name of each descriptor for the given subset
'''
internal method to get the key name needed to extract the data
'''
if (self.msg_index == -1):
raise NoMsgLoadedError
# remove entries that are not expanded and numeric.
# these typically are replication codes and not part
# of the field list
abbr_names = [n for n in
eccodes.codes_get_array(self._bufr,
'expandedAbbreviations')
if not n[0] in string.digits]
return abbr_names
# #]
'scale',
'reference',
'width'
]
iterid = eccodes.codes_keys_iterator_new(self._bufr, 'ls')
while eccodes.codes_keys_iterator_next(iterid):
keyname = eccodes.codes_keys_iterator_get_name(iterid)
print(' %s: %s' %
(keyname, eccodes.codes_get(self._bufr, keyname)))
# get unexpanded descriptors
key = 'unexpandedDescriptors'
num = eccodes.codes_get_size(self._bufr, key)
print(' size of %s is: %s' % (key, num))
values = eccodes.codes_get_array(self._bufr, key)
for i in xrange(len(values)):
print(" %d %06d" % (i + 1, values[i]))
# get the expanded descriptors
key = 'bufrdcExpandedDescriptors'
num = eccodes.codes_get_size(self._bufr, key)
print(' size of %s is: %s' % (key, num))
values = eccodes.codes_get_array(self._bufr, key)
for i in xrange(len(values)):
print(" %d %06d" % (i + 1, values[i]))
def get_units(self, subset=1):
# #[ request unit of each descriptor for the given subset
if (self.msg_index == -1):
raise NoMsgLoadedError
return eccodes.codes_get_array(self._bufr, 'expandedUnits')
# #]
def get_num_elements(self):
# #[
"""
request the number of elements (descriptors) in the current subset
"""
if (self.msg_index == -1):
raise NoMsgLoadedError
fieldnames = eccodes.codes_get_array(self._bufr, 'expandedNames')
# other possibilities are:
# 'expandedAbbreviations'
# 'expandedNames'
# 'expandedUnits'
# 'expandedOriginalScales'
# 'expandedOriginalReferences'
# 'expandedOriginalWidths'
return len(fieldnames)
# #]
def get_array(self, key):
"""Get all data from file for the given BUFR key."""
with open(self.filename, "rb") as fh:
msgCount = 0
while True:
bufr = ec.codes_bufr_new_from_file(fh)
if bufr is None:
break
ec.codes_set(bufr, 'unpack', 1)
# if is the first message initialise our final array
if (msgCount == 0):
arr = da.from_array(ec.codes_get_array(
bufr, key, float), chunks=CHUNK_SIZE)
else:
tmpArr = da.from_array(ec.codes_get_array(
bufr, key, float), chunks=CHUNK_SIZE)
arr = da.concatenate((arr, tmpArr))
msgCount = msgCount+1
ec.codes_release(bufr)
if arr.size == 1:
arr = arr[0]
return arr
"""
if (self.msg_index == -1):
raise NoMsgLoadedError
list_of_names = self._get_abbr_names()
keyname = list_of_names[descr_nr]
print('keyname: ', keyname)
s = eccodes.codes_get_size(self._bufr, keyname)
t = eccodes.codes_get_native_type(self._bufr, keyname)
print('key:', keyname, 'size = ', s, 'type = ', t)
if s==1: # or t==str:
# values = eccodes.codes_get_string(_bufr, keyname)
values = [eccodes.codes_get(self._bufr, keyname),]
else:
values = eccodes.codes_get_array(self._bufr, keyname)
return values
# #]