def test_ezqkdef_file_ezgprm_ezgfstp(self): rmn.fstopt(rmn.FSTOP_MSGLVL,rmn.FSTOPI_MSG_CATAST) ATM_MODEL_DFILES = os.getenv('ATM_MODEL_DFILES') myfile = os.path.join(ATM_MODEL_DFILES.strip(),'bcmk/geophy.fst') funit = rmn.fstopenall(myfile,rmn.FST_RO) (ni,nj) = (201,100) gp = { 'shape' : (ni,nj), 'ni' : ni, 'nj' : nj, 'grtyp' : 'Z', 'ig1' : 2002, 'ig2' : 1000, 'ig3' : 0, 'ig4' : 0, 'grref' : 'E', 'ig1ref' : 900, 'ig2ref' : 0, 'ig3ref' : 43200, 'ig4ref' : 43200, 'iunit' : funit } gid1 = rmn.ezqkdef(gp) a = rmn.ezgfstp(gid1) rmn.fstcloseall(funit) self.assertTrue(gid1>=0) gp['id'] = gid1 gprm = rmn.ezgxprm(gid1) for k in gprm.keys(): self.assertEqual(gp[k],gprm[k]) self.assertEqual(a['nomvarx'].strip(),'>>') self.assertEqual(a['nomvary'].strip(),'^^') rmn.gdrls(gid1)
def test_ezqkdef_ezgprm(self): gp = self.getGridParams_L() gid1 = rmn.ezqkdef(gp) self.assertTrue(gid1>=0) gp['id'] = gid1 gprm = rmn.ezgprm(gid1) for k in gprm.keys(): self.assertEqual(gp[k],gprm[k]) rmn.gdrls(gid1)
def test_ezqkdef_1subgrid(self): gp = self.getGridParams_L() gid1 = rmn.ezqkdef(gp) self.assertTrue(gid1>=0) ng = rmn.ezget_nsubgrids(gid1) self.assertEqual(ng,1) subgid = rmn.ezget_subgridids(gid1) self.assertEqual(subgid,[gid1]) rmn.gdrls(gid1)
def test_ezqkdef_gdll(self): gp = self.getGridParams_L() gid1 = rmn.ezqkdef(gp) self.assertTrue(gid1>=0) gll = rmn.gdll(gid1) self.assertEqual(gp['shape'],gll['lat'].shape) self.assertEqual(gp['shape'],gll['lon'].shape) self.assertEqual(gp['lat0'],gll['lat'][0,0]) self.assertEqual(gp['lon0'],gll['lon'][0,0]) rmn.gdrls(gid1)
def test_ezgkdef_fmem_ezgxprm(self): gp = self.getGridParams_ZE() gid1 = rmn.ezgdef_fmem(gp['ni'],gp['nj'],gp['grtyp'],gp['grref'], gp['ig1ref'],gp['ig2ref'],gp['ig3ref'],gp['ig4ref'], gp['ax'],gp['ay']) self.assertTrue(gid1>=0) gp['id'] = gid1 gprm = rmn.ezgxprm(gid1) for k in gprm.keys(): self.assertEqual(gp[k],gprm[k],'(%s) Expected: %s, Got: %s :: %s' % (k,repr(gp[k]),repr(gprm[k]),repr(gprm))) rmn.gdrls(gid1)
def test_gdxysval(self): gp1 = self.getGridParams_L() gid1 = rmn.ezqkdef(gp1) self.assertTrue(gid1>=0) zin = np.empty(gp1['shape'],dtype=np.float32,order='FORTRAN') for x in range(gp1['ni']): zin[:,x] = x xx = np.array([1.5],dtype=np.float32,order='FORTRAN') yy = np.array([1.5],dtype=np.float32,order='FORTRAN') zout = rmn.gdxysval(gid1,xx,yy,zin) self.assertEqual(xx.shape,zout.shape) self.assertTrue(abs((zin[0,0]+zin[1,1])/2. - zout[0]) < self.epsilon) rmn.gdrls(gid1)
def test_gdllsval(self): gp1 = self.getGridParams_L() gid1 = rmn.ezqkdef(gp1) self.assertTrue(gid1>=0) zin = np.empty(gp1['shape'],dtype=np.float32,order='FORTRAN') for x in range(gp1['ni']): zin[:,x] = x lat = np.array([gp1['lat0']+gp1['dlat']/2.],dtype=np.float32,order='FORTRAN') lon = np.array([(gp1['lon0']+gp1['dlon'])/2.],dtype=np.float32,order='FORTRAN') zout = rmn.gdllsval(gid1,lat,lon,zin) self.assertEqual(lat.shape,zout.shape) self.assertTrue(abs((zin[0,0]+zin[1,1])/2. - zout[0]) < self.epsilon) rmn.gdrls(gid1)
def test_gdllsval(self): gp1 = self.getGridParams_L() gid1 = rmn.ezqkdef(gp1) self.assertTrue(gid1>=0) zin = np.empty(gp1['shape'],dtype=np.float32,order='FORTRAN') for x in xrange(gp1['ni']): zin[:,x] = x lat = np.array([gp1['lat0']+gp1['dlat']/2.],dtype=np.float32,order='FORTRAN') lon = np.array([(gp1['lon0']+gp1['dlon'])/2.],dtype=np.float32,order='FORTRAN') zout = rmn.gdllsval(gid1,lat,lon,zin) self.assertEqual(lat.shape,zout.shape) self.assertTrue(abs((zin[0,0]+zin[1,1])/2. - zout[0]) < self.epsilon) rmn.gdrls(gid1)
def test_gdxysval(self): gp1 = self.getGridParams_L() gid1 = rmn.ezqkdef(gp1) self.assertTrue(gid1>=0) zin = np.empty(gp1['shape'],dtype=np.float32,order='FORTRAN') for x in xrange(gp1['ni']): zin[:,x] = x xx = np.array([1.5],dtype=np.float32,order='FORTRAN') yy = np.array([1.5],dtype=np.float32,order='FORTRAN') zout = rmn.gdxysval(gid1,xx,yy,zin) self.assertEqual(xx.shape,zout.shape) self.assertTrue(abs((zin[0,0]+zin[1,1])/2. - zout[0]) < self.epsilon) rmn.gdrls(gid1)
def test_ezgkdef_fmem_gdgaxes(self): gp = self.getGridParams_ZE() gid1 = rmn.ezgdef_fmem(gp['ni'],gp['nj'],gp['grtyp'],gp['grref'], gp['ig1ref'],gp['ig2ref'],gp['ig3ref'],gp['ig4ref'], gp['ax'],gp['ay']) self.assertTrue(gid1>=0) gp['id'] = gid1 axes = rmn.gdgaxes(gid1) self.assertEqual(axes['ax'].shape,gp['ax'].shape) self.assertEqual(axes['ay'].shape,gp['ay'].shape) for i in xrange(gp['ni']): self.assertTrue(abs(axes['ax'][i,0]-gp['ax'][i,0])<self.epsilon) for j in xrange(gp['nj']): self.assertTrue(abs(axes['ay'][0,j]-gp['ay'][0,j])<self.epsilon) rmn.gdrls(gid1)
def test_ezqkdef_ezgxprm(self): gp = self.getGridParams_L() gid1 = rmn.ezqkdef(gp['ni'],gp['nj'],gp['grtyp'], gp['ig1'],gp['ig2'],gp['ig3'],gp['ig4']) self.assertTrue(gid1>=0) gp['id'] = gid1 gp['grref'] = '' gp['ig1ref'] = 0 gp['ig2ref'] = 0 gp['ig3ref'] = 0 gp['ig4ref'] = 0 gprm = rmn.ezgxprm(gid1) for k in gprm.keys(): self.assertEqual(gp[k],gprm[k]) rmn.gdrls(gid1)
def test_ezgkdef_fmem_gdgaxes(self): gp = self.getGridParams_ZE() gid1 = rmn.ezgdef_fmem(gp['ni'],gp['nj'],gp['grtyp'],gp['grref'], gp['ig1ref'],gp['ig2ref'],gp['ig3ref'],gp['ig4ref'], gp['ax'],gp['ay']) self.assertTrue(gid1>=0) gp['id'] = gid1 axes = rmn.gdgaxes(gid1) self.assertEqual(axes['ax'].shape,gp['ax'].shape) self.assertEqual(axes['ay'].shape,gp['ay'].shape) for i in range(gp['ni']): self.assertTrue(abs(axes['ax'][i,0]-gp['ax'][i,0])<self.epsilon) for j in range(gp['nj']): self.assertTrue(abs(axes['ay'][0,j]-gp['ay'][0,j])<self.epsilon) rmn.gdrls(gid1)
def test_ezgkdef_fmem_gdxyfll(self): gp = self.getGridParams_ZE() gid1 = rmn.ezgdef_fmem(gp['ni'],gp['nj'],gp['grtyp'],gp['grref'], gp['ig1ref'],gp['ig2ref'],gp['ig3ref'],gp['ig4ref'], gp['ax'],gp['ay']) self.assertTrue(gid1>=0) lat = np.array([gp['ay'][0,0],gp['ay'][0,1]],dtype=np.float32,order='FORTRAN') lon = np.array([gp['ax'][0,0],gp['ax'][1,0]],dtype=np.float32,order='FORTRAN') xypts = rmn.gdxyfll(gid1, lat, lon) self.assertEqual(xypts['x'].shape,lat.shape) self.assertEqual(xypts['y'].shape,lat.shape) self.assertTrue(abs(xypts['x'][0]-1.)<self.epsilon) self.assertTrue(abs(xypts['y'][0]-1.)<self.epsilon) self.assertTrue(abs(xypts['x'][1]-2.)<self.epsilon) self.assertTrue(abs(xypts['y'][1]-2.)<self.epsilon) rmn.gdrls(gid1)
def test_ezgkdef_fmem_gdllfxy(self): gp = self.getGridParams_ZE() gid1 = rmn.ezgdef_fmem(gp['ni'],gp['nj'],gp['grtyp'],gp['grref'], gp['ig1ref'],gp['ig2ref'],gp['ig3ref'],gp['ig4ref'], gp['ax'],gp['ay']) self.assertTrue(gid1>=0) xx = np.array([1.,2.],dtype=np.float32,order='FORTRAN') yy = np.array([1.,3.],dtype=np.float32,order='FORTRAN') llpts = rmn.gdllfxy(gid1, xx, yy) self.assertEqual(llpts['x'].shape,xx.shape) self.assertEqual(llpts['y'].shape,xx.shape) self.assertTrue(abs(llpts['lon'][0]-gp['ax'][0,0])<self.epsilon) self.assertTrue(abs(llpts['lat'][0]-gp['ay'][0,0])<self.epsilon) self.assertTrue(abs(llpts['lon'][1]-gp['ax'][1,0])<self.epsilon) self.assertTrue(abs(llpts['lat'][1]-gp['ay'][0,2])<self.epsilon) rmn.gdrls(gid1)