def testSanity(self): """cigaxg(cxgaig(n))==n for all n""" for name, proj, dims, xg, ig in self.knownValues: xgout = rmn.cigaxg(proj, ig[0], ig[1], ig[2], ig[3]) igout = rmn.cxgaig(proj, xgout[0], xgout[1], xgout[2], xgout[3]) self.assertEqual(igout, ig, name + igout.__repr__() + xgout.__repr__())
def setIG_L(self,gp): ig1234 = rmn.cxgaig(gp['grtyp'],gp['lat0'],gp['lon0'], gp['dlat'],gp['dlon']) gp['ig1'] = ig1234[0] gp['ig2'] = ig1234[1] gp['ig3'] = ig1234[2] gp['ig4'] = ig1234[3] return gp
def cxgaig(grtyp, xg1, xg2, xg3, xg4): """Encode grid descriptors (Interface to cxgaig) (ig1, ig2, ig3, ig4) = Fstdc.cxgaig(grtyp, xg1, xg2, xg3, xg4) @param ...TODO... @return (ig1, ig2, ig3, ig4) @exception TypeError @exception Fstdc.error """ try: return _rmn.cxgaig(grtyp, xg1, xg2, xg3, xg4) except: raise error("")
def test_fstecr_fstluk_order(self): rmn.fstopt(rmn.FSTOP_MSGLVL, rmn.FSTOPI_MSG_CATAST) fname = '__rpnstd__testfile2__.fst' try: os.unlink(fname) except: pass funit = rmn.fstopenall(fname, rmn.FST_RW) (ig1, ig2, ig3, ig4) = rmn.cxgaig(self.grtyp, self.xg14[0], self.xg14[1], self.xg14[2], self.xg14[3]) (ni, nj) = (90, 45) la = rmn.FST_RDE_META_DEFAULT.copy() la.update({ 'nomvar': 'LA', 'typvar': 'C', 'ni': ni, 'nj': nj, 'nk': 1, 'grtyp': self.grtyp, 'ig1': ig1, 'ig2': ig2, 'ig3': ig3, 'ig4': ig4 }) lo = la.copy() lo['nomvar'] = 'LO' #Note: For the order to be ok in the FSTD file, order='FORTRAN' is mandatory la['d'] = np.empty((ni, nj), dtype=np.float32, order='FORTRAN') lo['d'] = np.empty((ni, nj), dtype=np.float32, order='FORTRAN') for j in range(nj): for i in range(ni): lo['d'][i, j] = 100. + float(i) la['d'][i, j] = float(j) rmn.fstecr(funit, la['d'], la) rmn.fstecr(funit, lo) rmn.fstcloseall(funit) funit = rmn.fstopenall(fname, rmn.FST_RW) kla = rmn.fstinf(funit, nomvar='LA')['key'] la2 = rmn.fstluk(kla) #,rank=2) klo = rmn.fstinf(funit, nomvar='LO')['key'] lo2 = rmn.fstluk(klo) #,rank=2) rmn.fstcloseall(funit) try: os.unlink(fname) except: pass self.assertTrue(np.isfortran(la2['d'])) self.assertTrue(np.isfortran(lo2['d'])) self.assertFalse(np.any(np.fabs(la2['d'] - la['d']) > self.epsilon)) self.assertFalse(np.any(np.fabs(lo2['d'] - lo['d']) > self.epsilon))
def test_fstecr_fstluk_order(self): rmn.fstopt(rmn.FSTOP_MSGLVL,rmn.FSTOPI_MSG_CATAST) fname = '__rpnstd__testfile2__.fst' try: os.unlink(fname) except: pass funit = rmn.fstopenall(fname,rmn.FST_RW) (ig1,ig2,ig3,ig4) = rmn.cxgaig(self.grtyp,self.xg14[0],self.xg14[1],self.xg14[2],self.xg14[3]) (ni,nj) = (90,45) la = rmn.FST_RDE_META_DEFAULT.copy() la.update( {'nomvar' : 'LA', 'typvar' : 'C', 'ni' : ni, 'nj' : nj, 'nk' : 1, 'grtyp' : self.grtyp, 'ig1' : ig1, 'ig2' : ig2, 'ig3' : ig3, 'ig4' : ig4 } ) lo = la.copy() lo['nomvar'] = 'LO' #Note: For the order to be ok in the FSTD file, order='FORTRAN' is mandatory la['d'] = np.empty((ni,nj),dtype=np.float32,order='FORTRAN') lo['d'] = np.empty((ni,nj),dtype=np.float32,order='FORTRAN') for j in xrange(nj): for i in xrange(ni): lo['d'][i,j] = 100.+float(i) la['d'][i,j] = float(j) rmn.fstecr(funit,la['d'],la) rmn.fstecr(funit,lo) rmn.fstcloseall(funit) funit = rmn.fstopenall(fname,rmn.FST_RW) kla = rmn.fstinf(funit,nomvar='LA')['key'] la2 = rmn.fstluk(kla)#,rank=2) klo = rmn.fstinf(funit,nomvar='LO')['key'] lo2 = rmn.fstluk(klo)#,rank=2) rmn.fstcloseall(funit) try: os.unlink(fname) except: pass self.assertTrue(np.isfortran(la2['d'])) self.assertTrue(np.isfortran(lo2['d'])) self.assertFalse(np.any(np.fabs(la2['d'] - la['d']) > self.epsilon)) self.assertFalse(np.any(np.fabs(lo2['d'] - lo['d']) > self.epsilon))
def setIG_ZE(self,gp,offx=0): ig1234 = rmn.cxgaig(gp['grref'],gp['xlat1'],gp['xlon1'], gp['xlat2'],gp['xlon2']) gp['ig1ref'] = ig1234[0] gp['ig2ref'] = ig1234[1] gp['ig3ref'] = ig1234[2] gp['ig4ref'] = ig1234[3] gp['ig1'] = ig1234[0] gp['ig2'] = ig1234[1] gp['ig3'] = ig1234[2] gp['ig4'] = ig1234[3] ## if offx: offx=1 ## gp['ig1'] = 123+offx ## gp['ig2'] = 231+offx ## gp['ig3'] = 312+offx ## gp['ig4'] = 0 return gp
def create_basefile(self): """create a basic test file for RPNFile tests""" self.erase_testfile() funit = rmn.fstopenall(self.fname, rmn.FST_RW) (ig1, ig2, ig3, ig4) = rmn.cxgaig(self.grtyp, self.xg14[0], self.xg14[1], self.xg14[2], self.xg14[3]) self.la = rmn.FST_RDE_META_DEFAULT.copy() self.la.update({ 'nomvar': 'LA', 'typvar': 'C', 'ni': self.lad.shape[0], 'nj': self.lad.shape[1], 'nk': 1, 'grtyp': self.grtyp, 'ig1': ig1, 'ig2': ig2, 'ig3': ig3, 'ig4': ig4, 'd': self.lad }) rmn.fstecr(funit, self.la['d'], self.la) self.lo = rmn.FST_RDE_META_DEFAULT.copy() self.lo.update({ 'nomvar': 'LO', 'typvar': 'C', 'ni': self.lod.shape[0], 'nj': self.lod.shape[1], 'nk': 1, 'grtyp': self.grtyp, 'ig1': ig1, 'ig2': ig2, 'ig3': ig3, 'ig4': ig4, 'd': self.lod }) rmn.fstecr(funit, self.lo['d'], self.lo) rmn.fstcloseall(funit) return (self.la, self.lo)
def create_basefile(self): """create a basic test file for RPNFile tests""" self.erase_testfile() funit = rmn.fstopenall(self.fname,rmn.FST_RW) (ig1,ig2,ig3,ig4) = rmn.cxgaig(self.grtyp,self.xg14[0],self.xg14[1],self.xg14[2],self.xg14[3]) self.la = rmn.FST_RDE_META_DEFAULT.copy() self.la.update( {'nomvar' : 'LA', 'typvar' : 'C', 'ni' : self.lad.shape[0], 'nj' : self.lad.shape[1], 'nk' : 1, 'grtyp' : self.grtyp, 'ig1' : ig1, 'ig2' : ig2, 'ig3' : ig3, 'ig4' : ig4, 'd' : self.lad} ) rmn.fstecr(funit,self.la['d'],self.la) self.lo = rmn.FST_RDE_META_DEFAULT.copy() self.lo.update( {'nomvar' : 'LO', 'typvar' : 'C', 'ni' : self.lod.shape[0], 'nj' : self.lod.shape[1], 'nk' : 1, 'grtyp' : self.grtyp, 'ig1' : ig1, 'ig2' : ig2, 'ig3' : ig3, 'ig4' : ig4, 'd' : self.lod} ) rmn.fstecr(funit,self.lo['d'],self.lo) rmn.fstcloseall(funit) return (self.la,self.lo)
def testCxgaigKnownValues(self): """Cxgaig should give known result with known input""" for name, proj, dims, xg, ig in self.knownValues: igout = rmn.cxgaig(proj, xg[0], xg[1], xg[2], xg[3]) self.assertEqual(igout, ig, name + igout.__repr__())