Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_next_msg(self):
# #[
"""
step to the next BUFR message in the open file
"""
print('getting next message')
if self.msg_index < self.num_msgs:
self.msg_index += 1
print('self.msg_index = ', self.msg_index)
# get an instance of the eccodes bufr class
self._bufr = eccodes.codes_bufr_new_from_file(self.fd)
print('self._bufr = ', self._bufr)
if self._bufr is None:
raise StopIteration
else:
self.msg_index = -1
self._bufr = -1
raise StopIteration
self.msg = BUFRMessageECCODES_R(self._bufr, self.msg_index)
# expand_flags, msg_index, verbose,
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)