Пример #1
0
    def testmrbdclcovKnownValues(self):
        """mrbdcl/cov should give known result with known input"""
        for mypath, itype, iunit in self.knownValues:
            rmn.mrfopt(rmn.FSTOP_MSGLVL, rmn.BURPOP_MSG_FATAL)
            funit = rmn.burp_open(self.getFN(mypath))
            nbrp = rmn.mrfnbr(funit)
            maxlen = max(64, rmn.mrfmxl(funit)) + 10

            buf = None
            handle = 0
            handle = rmn.mrfloc(funit, handle)
            buf = rmn.mrfget(handle, buf, funit)
            params = rmn.mrbhdr(buf)
            for iblk in range(params['nblk']):
                blkparams = rmn.mrbprm(buf, iblk + 1)
                blkdata = rmn.mrbxtr(buf, iblk + 1)
                lstelebufr = rmn.mrbdcl(blkdata['cmcids'])
            rmn.burp_close(funit)
            lstelebufr0 = _np.array([
                7004, 11001, 11002, 12001, 12192, 10194, 8001, 11003, 11004,
                13210
            ],
                                    dtype=_np.int32)
            self.assertFalse(_np.any(lstelebufr0 - lstelebufr != 0))
            lstelecmc = rmn.mrbcol(lstelebufr)
            self.assertFalse(_np.any(lstelecmc - blkdata['cmcids'] != 0))
            v1 = rmn.mrbdcl(blkdata['cmcids'][0])
            v2 = rmn.mrbcol(v1)
            self.assertEqual(lstelebufr0[0], v1)
            self.assertEqual(blkdata['cmcids'][0], v2)
Пример #2
0
    def testmrbhdrKnownValues(self):
        """mrbhdr should give known result with known input"""
        for mypath, itype, iunit in self.knownValues:
            rmn.mrfopt(rmn.FSTOP_MSGLVL, rmn.FSTOPS_MSG_FATAL)
            funit  = rmn.burp_open(self.getFN(mypath))
            nbrp   = rmn.mrfnbr(funit)
            maxlen = max(64, rmn.mrfmxl(funit))+10

            buf = None
            handle = 0
            handle = rmn.mrfloc(funit, handle)
            buf    = rmn.mrfget(handle, buf, funit)
            params = rmn.mrbhdr(buf)
            ## for k,v in rmn.BURP_FLAGS_IDX_NAME.items():
            ##     print k, params['flgsl'][k], v
            params0 = {'flgs': 72706, 'xaux': None, 'nxaux': 0, 'elev': 457,
                       'nblk': 12, 'dy': 0, 'lat': 15420, 'lon': 27663,
                       'nsup': 0, 'time': 0, 'idtyp': 138, 'oars': 518,
                       'dx': 0, 'stnid': '71915    ', 'date': 20070219,
                       'drnd': 0, 'sup': None, 'runn': 8,
                       'flgsl': [False, True, False, False, False, False,
                                 False, False, False, False, True, True,
                                 True, False, False, False, True, False,
                                 False, False, False, False, False, False]}
            for k in params.keys():
                self.assertEqual(params0[k], params[k],
                                 'For {0}, expected {1}, got {2}'
                                 .format(k, params0[k], params[k]))
            rmn.burp_close(funit)
Пример #3
0
 def testmrfnbrKnownValues(self):
     """mrfnbr mrfmxl mrfbfl should give known result with known input"""
     for mypath, itype, iunit in self.knownValues:
         funit   = rmn.fnom(self.getFN(mypath), rmn.FST_RO)
         nbrp    = rmn.mrfnbr(funit)
         maxlen  = rmn.mrfmxl(funit)
         maxlen2 = rmn.mrfbfl(funit)
         ## https://wiki.cmc.ec.gc.ca/wiki/Probl%C3%A8me_avec_les_fonctions_de_manipulation_de_fichiers_BURP_dans_RMNLIB
         maxlen = max(64, maxlen)+10
         rmn.fclos(funit)
         self.assertEqual(nbrp, 47544)
         self.assertEqual(maxlen,  6208+10)
         self.assertEqual(maxlen2, 6208+10)
Пример #4
0
 def testmrfnbrKnownValues(self):
     """mrfnbr mrfmxl mrfbfl should give known result with known input"""
     for mypath, itype, iunit in self.knownValues:
         funit = rmn.fnom(self.getFN(mypath), rmn.FST_RO)
         nbrp = rmn.mrfnbr(funit)
         maxlen = rmn.mrfmxl(funit)
         maxlen2 = rmn.mrfbfl(funit)
         ## https://wiki.cmc.ec.gc.ca/wiki/Probl%C3%A8me_avec_les_fonctions_de_manipulation_de_fichiers_BURP_dans_RMNLIB
         maxlen = max(64, maxlen) + 10
         rmn.fclos(funit)
         self.assertEqual(nbrp, 47544)
         self.assertEqual(maxlen, 6208 + 10)
         self.assertEqual(maxlen2, 6208 + 10)
Пример #5
0
    def testmrbcvtencodeKnownValues(self):
        """mrbprm should give known result with known input"""
        for mypath, itype, iunit in self.knownValues:
            rmn.mrfopt(rmn.FSTOP_MSGLVL, rmn.BURPOP_MSG_FATAL)
            funit = rmn.burp_open(self.getFN(mypath))
            nbrp = rmn.mrfnbr(funit)
            maxlen = max(64, rmn.mrfmxl(funit)) + 10

            buf = None
            handle = 0
            handle = rmn.mrfloc(funit, handle)
            buf = rmn.mrfget(handle, buf, funit)
            params = rmn.mrbhdr(buf)
            for iblk in range(params['nblk']):
                blkparams = rmn.mrbprm(buf, iblk + 1)
                blkdata = rmn.mrbxtr(buf, iblk + 1)
                rval = rmn.mrbcvt_decode(blkdata['cmcids'], blkdata['tblval'],
                                         blkparams['datyp'])
                tblval = rmn.mrbcvt_encode(blkdata['cmcids'], rval)
                for iele in range(blkdata['cmcids'].size):
                    e_cmcids = blkdata['cmcids'][iele]
                    e_cmcids = rmn.mrbcvt_dict_bufr(
                        e_cmcids, raise_error=False)['e_bufrid']
                    e_rval = rval[iele, :, :]
                    e_tblval0 = blkdata['tblval'][iele, :, :]
                    e_tblval1 = tblval[iele, :, :]
                    if not _np.all(e_tblval0 == e_tblval1):
                        ## print 'b1',repr(blkparams)
                        print('b2', repr(blkdata))
                        print('b3', repr(rmn.mrbcvt_dict(e_cmcids)))
                        print(
                            'b4',
                            repr(
                                rmn.mrbcvt_dict_bufr(e_cmcids,
                                                     raise_error=False)))
                        print('rf', repr(e_rval.ravel()), blkparams['datyp'])
                        print(
                            'rv',
                            repr(_np.round(e_rval).astype(_np.int32).ravel()),
                            blkparams['datyp'])
                        print('t0', repr(e_tblval0.ravel()))
                        print('t1', repr(e_tblval1.ravel()))
                    #TODO: problem w/ values < 0: decode int as is... but encode shift values by -1
                    self.assertTrue(
                        _np.all(e_tblval0 == e_tblval1),
                        "{}, {}: id={}, \nrval:{}, \nexp:{}, \ngot:{}".format(
                            iblk, iele, e_cmcids, e_rval.ravel(),
                            e_tblval0.ravel(), e_tblval1.ravel()))
            rmn.burp_close(funit)
Пример #6
0
    def testmrbxtrdclcvtKnownValues(self):
        """mrbxtrdclcvt should give known result with known input"""
        for mypath, itype, iunit in self.knownValues:
            rmn.mrfopt(rmn.FSTOP_MSGLVL, rmn.BURPOP_MSG_FATAL)
            funit = rmn.burp_open(self.getFN(mypath))
            nbrp = rmn.mrfnbr(funit)
            maxlen = max(64, rmn.mrfmxl(funit)) + 10

            buf = None
            handle = 0
            handle = rmn.mrfloc(funit, handle)
            buf = rmn.mrfget(handle, buf, funit)
            params = rmn.mrbhdr(buf)
            for iblk in range(params['nblk']):
                blkdata = rmn.mrb_prm_xtr_dcl_cvt(buf, iblk + 1)
                #TODO: check results
            rmn.burp_close(funit)
Пример #7
0
    def testmrbprmKnownValues(self):
        """mrbprm should give known result with known input"""
        for mypath, itype, iunit in self.knownValues:
            rmn.mrfopt(rmn.FSTOP_MSGLVL, rmn.BURPOP_MSG_FATAL)
            funit = rmn.burp_open(self.getFN(mypath))
            nbrp = rmn.mrfnbr(funit)
            maxlen = max(64, rmn.mrfmxl(funit)) + 10

            buf = None
            handle = 0
            handle = rmn.mrfloc(funit, handle)
            buf = rmn.mrfget(handle, buf, funit)
            params = rmn.mrbhdr(buf)
            for iblk in range(params['nblk']):
                blkparams = rmn.mrbprm(buf, iblk + 1)
            blkparams0 = {
                'datypd': 'uint',
                'nele': 10,
                'nbit': 20,
                'datyp': 2,
                'nval': 17,
                'bdesc': 0,
                'btyp': 9326,
                'bfam': 10,
                'nt': 1,
                'bit0': 288,
                'bktyp': 70,
                'bkstp': 14,
                'bknat': 4,
                'bknat_multi': 1,
                'bknat_kind': 0,
                'bknat_kindd': 'data',
                'bktyp_alt': 1,
                'bktyp_kind': 6,
                'bkno': iblk + 1,
                'bktyp_kindd': 'data seen by OA at altitude, global model',
                'bkstpd': "statistiques d'erreur d'observation"
            }
            ## print 1,blkparams
            for k in blkparams.keys():
                self.assertEqual(
                    blkparams0[k], blkparams[k],
                    'For {0}, expected {1}, got {2}'.format(
                        k, blkparams0[k], blkparams[k]))
            rmn.burp_close(funit)
Пример #8
0
    def testmrfgetKnownValues(self):
        """mrfget should give known result with known input"""
        for mypath, itype, iunit in self.knownValues:
            rmn.mrfopt(rmn.FSTOP_MSGLVL, rmn.FSTOPS_MSG_FATAL)
            funit = rmn.burp_open(self.getFN(mypath))
            nbrp  = rmn.mrfnbr(funit)
            maxlen = max(64, rmn.mrfmxl(funit))+10

            buf = None
            handle = 0
            handle = rmn.mrfloc(funit, handle)
            buf = rmn.mrfget(handle, buf, funit)
            self.assertEqual(buf.size, 12416)
            #TODO: self.assertEqual(buf, ???)
            ## sys.stderr.write(repr(handle)+"("+repr(maxlen)+') rmn.mrfget None size='+repr(buf.size)+'\n')

            buf = maxlen
            handle = 0
            handle = rmn.mrfloc(funit, handle)
            buf = rmn.mrfget(handle, buf, funit)
            self.assertEqual(buf.size, 12436)
            #TODO: self.assertEqual(buf, ???)
            ## sys.stderr.write(repr(handle)+"("+repr(maxlen)+') rmn.mrfget maxlen size='+repr(buf.size)+'\n')

            buf = _np.empty((maxlen, ), dtype=_np.int32)
            buf[0] = maxlen
            handle = 0
            handle = rmn.mrfloc(funit, handle)
            buf = rmn.mrfget(handle, buf, funit)
            self.assertEqual(buf.size, 6218)
            #TODO: self.assertEqual(buf, ???)
            ## sys.stderr.write(repr(handle)+"("+repr(maxlen)+') rmn.mrfget empty size='+repr(buf.size)+'\n')

            handle = 0
            for irep in xrange(nbrp):
                handle = rmn.mrfloc(funit, handle)
                buf = rmn.mrfget(handle, buf, funit)
                ## print handle, buf.shape, buf[0:10]
                self.assertEqual(buf.size, 6218)
            
            rmn.burp_close(funit)
Пример #9
0
    def testmrfgetKnownValues(self):
        """mrfget should give known result with known input"""
        for mypath, itype, iunit in self.knownValues:
            rmn.mrfopt(rmn.FSTOP_MSGLVL, rmn.BURPOP_MSG_FATAL)
            funit = rmn.burp_open(self.getFN(mypath))
            nbrp = rmn.mrfnbr(funit)
            maxlen = max(64, rmn.mrfmxl(funit)) + 10

            buf = None
            handle = 0
            handle = rmn.mrfloc(funit, handle)
            buf = rmn.mrfget(handle, buf, funit)
            self.assertEqual(buf.size, 12416)
            #TODO: self.assertEqual(buf, ???)
            ## sys.stderr.write(repr(handle)+"("+repr(maxlen)+') rmn.mrfget None size='+repr(buf.size)+'\n')

            buf = maxlen
            handle = 0
            handle = rmn.mrfloc(funit, handle)
            buf = rmn.mrfget(handle, buf, funit)
            self.assertEqual(buf.size, 12436)
            #TODO: self.assertEqual(buf, ???)
            ## sys.stderr.write(repr(handle)+"("+repr(maxlen)+') rmn.mrfget maxlen size='+repr(buf.size)+'\n')

            buf = _np.empty((maxlen, ), dtype=_np.int32)
            buf[0] = maxlen
            handle = 0
            handle = rmn.mrfloc(funit, handle)
            buf = rmn.mrfget(handle, buf, funit)
            self.assertEqual(buf.size, 6218)
            #TODO: self.assertEqual(buf, ???)
            ## sys.stderr.write(repr(handle)+"("+repr(maxlen)+') rmn.mrfget empty size='+repr(buf.size)+'\n')

            handle = 0
            for irep in range(nbrp):
                handle = rmn.mrfloc(funit, handle)
                buf = rmn.mrfget(handle, buf, funit)
                ## print handle, buf.shape, buf[0:10]
                self.assertEqual(buf.size, 6218)

            rmn.burp_close(funit)
Пример #10
0
    def testmrbcvtdecodeKnownValues(self):
        """mrbprm should give known result with known input"""
        for mypath, itype, iunit in self.knownValues:
            rmn.mrfopt(rmn.FSTOP_MSGLVL, rmn.BURPOP_MSG_FATAL)
            funit = rmn.burp_open(self.getFN(mypath))
            nbrp = rmn.mrfnbr(funit)
            maxlen = max(64, rmn.mrfmxl(funit)) + 10

            buf = None
            handle = 0
            handle = rmn.mrfloc(funit, handle)
            buf = rmn.mrfget(handle, buf, funit)
            params = rmn.mrbhdr(buf)
            for iblk in range(params['nblk']):
                blkparams = rmn.mrbprm(buf, iblk + 1)
                blkdata = rmn.mrbxtr(buf, iblk + 1)
                rval = rmn.mrbcvt_decode(blkdata['cmcids'], blkdata['tblval'],
                                         blkparams['datyp'])
                rval = rmn.mrbcvt_decode(blkdata, datyp=blkparams['datyp'])
                #TODO: check results
            rmn.burp_close(funit)
Пример #11
0
    def testmrbxtrKnownValues(self):
        """mrbprm should give known result with known input"""
        for mypath, itype, iunit in self.knownValues:
            rmn.mrfopt(rmn.FSTOP_MSGLVL, rmn.BURPOP_MSG_FATAL)
            funit = rmn.burp_open(self.getFN(mypath))
            nbrp = rmn.mrfnbr(funit)
            maxlen = max(64, rmn.mrfmxl(funit)) + 10

            buf = None
            handle = 0
            handle = rmn.mrfloc(funit, handle)
            buf = rmn.mrfget(handle, buf, funit)
            params = rmn.mrbhdr(buf)
            ## blkdata = {
            ##     'cmcids' : None,
            ##     'tblval' : None
            ##     }
            for iblk in range(params['nblk']):
                blkparams = rmn.mrbprm(buf, iblk + 1)
                ## blkdata   = rmn.mrbxtr(buf, iblk+1, blkdata['cmcids'], blkdata['tblval'])
                blkdata = rmn.mrbxtr(buf, iblk + 1)
                for k in blkparams.keys():
                    self.assertEqual(
                        blkparams[k], blkdata[k],
                        'For {0}, expected {1}, got {2}'.format(
                            k, blkparams[k], blkdata[k]))
            lstele0 = _np.array(
                [1796, 2817, 2818, 3073, 3264, 2754, 2049, 2819, 2820, 3538],
                dtype=_np.int32)
            tblval0 = _np.array(
                [10000, -1, -1, -1, -1, 405, -1, -1, -1, 1029000],
                dtype=_np.int32)
            self.assertFalse(_np.any(lstele0 - blkdata['cmcids'] != 0))
            self.assertEqual(
                (blkparams['nele'], blkparams['nval'], blkparams['nt']),
                blkdata['tblval'].shape)
            self.assertFalse(
                _np.any(
                    tblval0 - blkdata['tblval'][0:blkdata['nele'], 0, 0] != 0))
            rmn.burp_close(funit)
Пример #12
0
    def testmrbcvtdecodeKnownValues(self):
        """mrbprm should give known result with known input"""
        for mypath, itype, iunit in self.knownValues:
            rmn.mrfopt(rmn.FSTOP_MSGLVL, rmn.FSTOPS_MSG_FATAL)
            funit  = rmn.burp_open(self.getFN(mypath))
            nbrp   = rmn.mrfnbr(funit)
            maxlen = max(64, rmn.mrfmxl(funit))+10

            buf = None
            handle = 0
            handle = rmn.mrfloc(funit, handle)
            buf    = rmn.mrfget(handle, buf, funit)
            params = rmn.mrbhdr(buf)
            for iblk in xrange(params['nblk']):
                blkparams = rmn.mrbprm(buf, iblk+1)
                blkdata   = rmn.mrbxtr(buf, iblk+1)
                rval      = rmn.mrbcvt_decode(blkdata['lstele'],
                                              blkdata['tblval'],
                                              blkparams['datyp'])
                rval      = rmn.mrbcvt_decode(blkdata,
                                              datyp=blkparams['datyp'])
                #TODO: check results            
            rmn.burp_close(funit)
Пример #13
0
    def testmrbdclKnownValues(self):
        """mrbprm should give known result with known input"""
        for mypath, itype, iunit in self.knownValues:
            rmn.mrfopt(rmn.FSTOP_MSGLVL, rmn.FSTOPS_MSG_FATAL)
            funit  = rmn.burp_open(self.getFN(mypath))
            nbrp   = rmn.mrfnbr(funit)
            maxlen = max(64, rmn.mrfmxl(funit))+10

            buf = None
            handle = 0
            handle = rmn.mrfloc(funit, handle)
            buf    = rmn.mrfget(handle, buf, funit)
            params = rmn.mrbhdr(buf)
            for iblk in xrange(params['nblk']):
                blkparams  = rmn.mrbprm(buf, iblk+1)
                blkdata    = rmn.mrbxtr(buf, iblk+1)
                lstelebufr = rmn.mrbdcl(blkdata['lstele'])
            lstelebufr0 = _np.array([7004, 11001, 11002, 12001, 12192, 10194,
                                     8001, 11003, 11004, 13210],
                                     dtype=_np.int32)
            self.assertFalse(_np.any(lstelebufr0 - lstelebufr != 0))
            
            rmn.burp_close(funit)
Пример #14
0
    def testmrbprmKnownValues(self):
        """mrbprm should give known result with known input"""
        for mypath, itype, iunit in self.knownValues:
            rmn.mrfopt(rmn.FSTOP_MSGLVL, rmn.FSTOPS_MSG_FATAL)
            funit  = rmn.burp_open(self.getFN(mypath))
            nbrp   = rmn.mrfnbr(funit)
            maxlen = max(64, rmn.mrfmxl(funit))+10

            buf = None
            handle = 0
            handle = rmn.mrfloc(funit, handle)
            buf    = rmn.mrfget(handle, buf, funit)
            params = rmn.mrbhdr(buf)
            for iblk in xrange(params['nblk']):
                blkparams = rmn.mrbprm(buf, iblk+1)
            blkparams0 = {'nele': 10, 'nbit': 20, 'datyp': 2, 'nval': 17,
                          'bdesc': 0, 'btyp': 9326, 'bfam': 10, 'nt': 1,
                          'bit0': 288}
            for k in blkparams.keys():
                self.assertEqual(blkparams0[k], blkparams[k],
                                 'For {0}, expected {1}, got {2}'
                                 .format(k, blkparams0[k], blkparams[k]))
            rmn.burp_close(funit)
Пример #15
0
    def testmrbxtrKnownValues(self):
        """mrbprm should give known result with known input"""
        for mypath, itype, iunit in self.knownValues:
            rmn.mrfopt(rmn.FSTOP_MSGLVL, rmn.FSTOPS_MSG_FATAL)
            funit  = rmn.burp_open(self.getFN(mypath))
            nbrp   = rmn.mrfnbr(funit)
            maxlen = max(64, rmn.mrfmxl(funit))+10

            buf = None
            handle = 0
            handle = rmn.mrfloc(funit, handle)
            buf    = rmn.mrfget(handle, buf, funit)
            params = rmn.mrbhdr(buf)
            ## blkdata = {
            ##     'lstele' : None,
            ##     'tblval' : None
            ##     }
            for iblk in xrange(params['nblk']):
                blkparams = rmn.mrbprm(buf, iblk+1)
                ## blkdata   = rmn.mrbxtr(buf, iblk+1, blkdata['lstele'], blkdata['tblval'])
                blkdata   = rmn.mrbxtr(buf, iblk+1)
                for k in blkparams.keys():
                    self.assertEqual(blkparams[k], blkdata[k],
                                     'For {0}, expected {1}, got {2}'
                                     .format(k, blkparams[k], blkdata[k]))
            lstele0 = _np.array([1796, 2817, 2818, 3073, 3264, 2754, 2049,
                                 2819, 2820, 3538], dtype=_np.int32)
            tblval0 = _np.array([10000, -1, -1, -1, -1, 405, -1, -1, -1,
                                 1029000], dtype=_np.int32)
            self.assertFalse(_np.any(lstele0 - blkdata['lstele'] != 0))
            self.assertEqual((blkparams['nele'], blkparams['nval'],
                              blkparams['nt']), blkdata['tblval'].shape)
            self.assertFalse(_np.any(tblval0 -
                                     blkdata['tblval'][0:blkdata['nele'],0,0]
                                     != 0))
            rmn.burp_close(funit)
Пример #16
0
    def testmrbhdrKnownValues(self):
        """mrbhdr should give known result with known input"""
        for mypath, itype, iunit in self.knownValues:
            rmn.mrfopt(rmn.FSTOP_MSGLVL, rmn.BURPOP_MSG_FATAL)
            funit = rmn.burp_open(self.getFN(mypath))
            nbrp = rmn.mrfnbr(funit)
            maxlen = max(64, rmn.mrfmxl(funit)) + 10

            buf = None
            handle = 0
            handle = rmn.mrfloc(funit, handle)
            buf = rmn.mrfget(handle, buf, funit)
            params = rmn.mrbhdr(buf)
            ## for k,v in rmn.BURP_FLAGS_IDX_NAME.items():
            ##     print k, params['flgsl'][k], v
            params0 = {
                'datemm':
                2,
                'dy':
                0.0,
                'nxaux':
                0,
                'lat':
                64.19999999999999,
                'xaux':
                None,
                'flgsl': [
                    0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0,
                    0, 0, 0, 0
                ],
                'idtypd':
                'TEMP + PILOT + SYNOP',
                'lon':
                276.63,
                'nsup':
                0,
                'datedd':
                19,
                'timemm':
                0,
                'drnd':
                0,
                'flgs':
                72706,
                'flgsd':
                'surface wind used, data observed, data derived, residues, TEMP part B',
                'sup':
                None,
                'nblk':
                12,
                'ilon':
                27663,
                'oars':
                518,
                'dx':
                0.0,
                'stnid':
                '71915    ',
                'date':
                20070219,
                'ilat':
                15420,
                'ielev':
                457,
                'idx':
                0,
                'idy':
                0,
                'idtyp':
                138,
                'elev':
                57.0,
                'time':
                0,
                'dateyy':
                2007,
                'timehh':
                0,
                'runn':
                8
            }
            for k in params.keys():
                self.assertEqual(
                    params0[k], params[k],
                    'For {0}, expected {1}, got {2}'.format(
                        k, params0[k], params[k]))
            rmn.burp_close(funit)