How to use the eccodes.codes_get 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
for a given descriptor number for all subsets
        NOTE: this may not work for templates using delayed replication.
        """
        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
        #  #]
github jdkloe / pybufr-ecmwf / pybufr_ecmwf / bufr.py View on Github external
# print('field_names = ', field_names)
        # print('DEBUG: names = ',self.get_names(subset_nr))
        # print('subset: ', subset_nr)
        
        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
        #  #]
github jdkloe / pybufr-ecmwf / pybufr_ecmwf / bufr.py View on Github external
#                 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):
            keyname = eccodes.codes_keys_iterator_get_name(iterid)
            print('  %s: %s' %
                  (keyname, eccodes.codes_get(self._bufr, keyname)))
github jdkloe / pybufr-ecmwf / pybufr_ecmwf / bufr.py View on Github external
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):
            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]))
github jdkloe / pybufr-ecmwf / pybufr_ecmwf / bufr.py View on Github external
def get_unexp_descr_list(self):
        #  #[ get unexpanded descfriptor list
        '''
        wrapper around  self._bufr_obj.py_unexp_descr_list
        '''
        if (self.msg_index == -1):
            raise NoMsgLoadedError

        n = eccodes.codes_get(self._bufr, 'numberOfUnexpandedDescriptors')
        if n==1:
            list_of_unexp_descr = [eccodes.codes_get(self._bufr,
                                                'unexpandedDescriptors'),]
        else:
            list_of_unexp_descr = eccodes.codes_get_array(self._bufr,
                                                'unexpandedDescriptors')
        
        return list_of_unexp_descr
        #  #]
github jdkloe / pybufr-ecmwf / pybufr_ecmwf / bufr.py View on Github external
def get_unexp_descr_list(self):
        #  #[ get unexpanded descfriptor list
        '''
        wrapper around  self._bufr_obj.py_unexp_descr_list
        '''
        if (self.msg_index == -1):
            raise NoMsgLoadedError

        n = eccodes.codes_get(self._bufr, 'numberOfUnexpandedDescriptors')
        if n==1:
            list_of_unexp_descr = [eccodes.codes_get(self._bufr,
                                                'unexpandedDescriptors'),]
        else:
            list_of_unexp_descr = eccodes.codes_get_array(self._bufr,
                                                'unexpandedDescriptors')
        
        return list_of_unexp_descr
        #  #]