How to use the eccodes.codes_set function in eccodes

To help you get started, we’ve selected a few eccodes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jdkloe / pybufr-ecmwf / pybufr_ecmwf / bufr.py View on Github external
def __init__(self, bufr, msg_index):
#                 section_sizes, section_start_locations,
#                 expand_flags, verbose,
#                 table_b_to_use, table_c_to_use,
#                 table_d_to_use, tables_dir,
#                 expand_strings):
        #  #[ initialise and decode
        ''' delegate the actual work to BUFRInterfaceECMWF '''
        self._bufr = bufr
        self.msg_index = msg_index
        
        # unpack this bufr message
        print('unpacking msg with index ', self.msg_index)
        eccodes.codes_set(self._bufr,'unpack',1)
        print('done with unpacking')

        self.num_subsets = eccodes.codes_get(self._bufr, "numberOfSubsets")
        print('num_subsets = ', self.num_subsets)
        
        # define the attributes to be printed (see BUFR code table B)
        attrs = [
            'code',
            'units',
            'scale',
            'reference',
            'width'
            ]
        
        iterid = eccodes.codes_keys_iterator_new(self._bufr, 'ls')
        while eccodes.codes_keys_iterator_next(iterid):
github pytroll / satpy / satpy / readers / seviri_l2_bufr.py View on Github external
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]