def testDiag_withref8_3d(self): ATM_MODEL_DFILES = os.getenv('ATM_MODEL_DFILES').strip() fileName = os.path.join(ATM_MODEL_DFILES,'bcmk_toctoc','2009042700_000') fileId = rmn.fstopenall(fileName, rmn.FST_RO) vgd0ptr = vgd.c_vgd_construct() ok = vgd.c_vgd_new_read(vgd0ptr,fileId,-1,-1,-1,-1) rfld_name = C_MKSTR(' '*vgd.VGD_MAXSTR_NOMVAR) quiet = ct.c_int(0) ok = vgd.c_vgd_get_char(vgd0ptr, _C_WCHAR2CHAR('RFLD'), rfld_name, quiet) rfld = rmn.fstlir(fileId, nomvar=_C_CHAR2WCHAR(rfld_name.value).strip())['d'] MB2PA = 100. rfld = rfld * MB2PA rmn.fstcloseall(fileId) ip1list = ct.POINTER(ct.c_int)() nip1 = ct.c_int(0) quiet = ct.c_int(0) ok = vgd.c_vgd_get_int_1d(vgd0ptr, _C_WCHAR2CHAR('VIPM'), ct.byref(ip1list), ct.byref(nip1), quiet) ni = rfld.shape[0] ; nj = rfld.shape[1] ; in_log = 0 levels8 = np.empty((ni, nj, nip1.value), dtype=np.float64, order='FORTRAN') rfld8 = np.empty((ni, nj), dtype=np.float64, order='FORTRAN') rfld8[:,:] = rfld[:,:] ok = vgd.c_vgd_diag_withref_8(vgd0ptr, ni, nj, nip1, ip1list, levels8, rfld8, in_log, vgd.VGD_DIAG_DPIS) self.assertEqual(ok,vgd.VGD_OK) self.assertEqual([int(x) for x in levels8[ni//2,nj//2,0:5]*10000.], [100000, 138425, 176878, 241408, 305980])
def newdate_options_set(option): """ Set option for newdate, incdatr, difdatr Args: option : 'option=value' to set (str) possible values: 'year=gregorian' 'year=365_day' 'year=360_day' Returns: None Raises: TypeError if option not a string Examples: >>> import rpnpy.librmn.all as rmn >>> rmn.newdate_options_set('year=gregorian') See also: newdate_options_get ignore_leapyear accept_leapyear newdate """ cmd = 'set' _rp.f_newdate_options(_C_WCHAR2CHAR(option), _C_WCHAR2CHAR(cmd), len(option), len(cmd))
def testNewGen2(self): hyb = (30968., 24944., 20493., 16765., 13525., 10814., 8026., 5477., 3488., 1842., 880., 0.) nhyb = len(hyb) chyb = np.asarray(hyb, dtype=np.float32) (rcoef1, rcoef2, rcoef3, rcoef4) = (ct.c_float(0.), ct.c_float(5.), ct.c_float(0.), ct.c_float(100.)) p_ptop = ct.POINTER(ct.c_double)() p_pref = ct.POINTER(ct.c_double)() p_ptop_out = ct.POINTER(ct.c_double)() (kind, version) = (vgd.VGD_HYBHLS_KIND, vgd.VGD_HYBHLS_VER) (ip1, ip2, avg) = (0, 0, 0) dhm = ct.c_float(10.) dht = ct.c_float(2.) dhw = ct.c_float(10.) vgd0ptr = vgd.c_vgd_construct() ok = vgd.c_vgd_new_gen2(vgd0ptr, kind, version, chyb, nhyb, ct.byref(rcoef1), ct.byref(rcoef2), ct.byref(rcoef3), ct.byref(rcoef4), p_ptop, p_pref, p_ptop_out, ip1, ip2, ct.byref(dhm), ct.byref(dht), ct.byref(dhw), avg) self.assertEqual(ok, vgd.VGD_OK) vkind = ct.c_int(0) vvers = ct.c_int(0) quiet = ct.c_int(0) ok = vgd.c_vgd_get_int(vgd0ptr, _C_WCHAR2CHAR('KIND'), ct.byref(vkind), quiet) ok = vgd.c_vgd_get_int(vgd0ptr, _C_WCHAR2CHAR('VERS'), ct.byref(vvers), quiet) self.assertEqual(ok, vgd.VGD_OK) self.assertEqual(vkind.value, vgd.VGD_HYBHLS_KIND) self.assertEqual(vvers.value, vgd.VGD_HYBHLS_VER)
def fnom(filename, filemode=_rc.FST_RW, iunit=0): """ Open a file and make the connection with a unit number. Args: filename : path/name of the file to open filemode : a string with the desired filemode (see librmn doc) or one of these constants: FST_RW, FST_RW_OLD, FST_RO iunit : forced unit number to conect to if zero, will select a free unit Returns: int, Associated file unit number Raises: TypeError on wrong input arg types ValueError on invalid input arg value RMNBaseError on any other error Examples: >>> import os, sys >>> import rpnpy.librmn.all as rmn >>> filename = 'myfstfile.fst' >>> try: ... iunit = rmn.fnom(filename, rmn.FST_RW) ... except rmn.RMNBaseError: ... sys.stderr.write("There was a problem opening the file: {0}".format(filename)) >>> istat = rmn.fclos(iunit) >>> os.unlink(filename) # Remove test file See also: fclos rpnpy.librmn.fstd98.isFST rpnpy.librmn.fstd98.fstopenall rpnpy.librmn.fstd98.fstcloseall rpnpy.librmn.const """ if not isinstance(iunit, _integer_types): raise TypeError("fnom: Expecting arg of type int, Got {0}"\ .format(type(iunit))) ciunit = _ct.c_int(max(0, iunit)) if not isinstance(iunit, _integer_types): raise TypeError("fnom: Expecting arg of type int, Got {0}"\ .format(type(iunit))) if not isinstance(filename, str): raise TypeError("fnom: Expecting filename arg of type str, Got {0}"\ .format(type(filename))) if filename.strip() == '': raise ValueError("fnom: must provide a valid filename") if not isinstance(filemode, str): raise TypeError("fnom: Expecting arg filemode of type str, Got {0}"\ .format(type(filemode))) istat = _rp.c_fnom(_ct.byref(ciunit), _C_WCHAR2CHAR(filename), _C_WCHAR2CHAR(filemode), 0) istat = _C_TOINT(istat) if istat < 0: raise RMNBaseError() return ciunit.value
def testNewReadPutChar(self): vgd0ptr = self._newReadBcmk() v1 = C_MKSTR('PRES') quiet = ct.c_int(0) ok = vgd.c_vgd_put_char(vgd0ptr, _C_WCHAR2CHAR('ETIK'), v1) self.assertEqual(ok, vgd.VGD_OK) v2 = C_MKSTR(' ' * vgd.VGD_MAXSTR_NOMVAR) ok = vgd.c_vgd_get_char(vgd0ptr, _C_WCHAR2CHAR('ETIK'), v2, quiet) self.assertEqual(ok, vgd.VGD_OK) self.assertEqual(_C_CHAR2WCHAR(v2.value).strip(), 'PRES')
def testNewReadPutInt(self): vgd0ptr = self._newReadBcmk() v1 = ct.c_int(6) quiet = ct.c_int(0) ok = vgd.c_vgd_put_int(vgd0ptr, _C_WCHAR2CHAR('IG_1'), v1) self.assertEqual(ok, vgd.VGD_OK) v2 = ct.c_int(0) ok = vgd.c_vgd_get_int(vgd0ptr, _C_WCHAR2CHAR('IG_1'), v2, quiet) self.assertEqual(ok, vgd.VGD_OK) self.assertEqual(v1.value, v2.value)
def testNewReadGetDouble(self): vgd0ptr = self._newReadBcmk() #print vgd0ptr[0].pref_8,vgd0ptr[0].ptop_8 v1 = ct.c_double(0) v2 = ct.c_double(0) quiet = ct.c_int(0) ok = vgd.c_vgd_get_double(vgd0ptr, _C_WCHAR2CHAR('PREF'), ct.byref(v1), quiet) ok = vgd.c_vgd_get_double(vgd0ptr, _C_WCHAR2CHAR('PTOP'), ct.byref(v2), quiet) self.assertEqual(ok,vgd.VGD_OK) self.assertEqual(int(v1.value*100.),8000000) self.assertEqual(int(v2.value*100.),1000)
def testNewReadGetFloat(self): vgd0ptr = self._newReadBcmk() #print vgd0ptr[0].rcoef1,vgd0ptr[0].rcoef2 v1 = ct.c_float(0) v2 = ct.c_float(0) quiet = ct.c_int(0) ok = vgd.c_vgd_get_float(vgd0ptr, _C_WCHAR2CHAR('RC_2'), ct.byref(v2), quiet) ok = vgd.c_vgd_get_float(vgd0ptr, _C_WCHAR2CHAR('RC_1'), ct.byref(v1), quiet) self.assertEqual(ok,vgd.VGD_OK) self.assertEqual(int(v1.value*100),160) self.assertEqual(int(v2.value),vgd.VGD_MISSING)
def testGetPutOptInt(self): quiet = ct.c_int(0) v1 = ct.c_int(0) ok = vgd.c_vgd_getopt_int(_C_WCHAR2CHAR('ALLOW_SIGMA'), ct.byref(v1), quiet) self.assertEqual(ok,vgd.VGD_OK) self.assertEqual(v1.value,vgd.VGD_DISALLOW_SIGMA) ok = vgd.c_vgd_putopt_int(_C_WCHAR2CHAR('ALLOW_SIGMA'), vgd.VGD_ALLOW_SIGMA) self.assertEqual(ok,vgd.VGD_OK) ok = vgd.c_vgd_getopt_int(_C_WCHAR2CHAR('ALLOW_SIGMA'), ct.byref(v1), quiet) self.assertEqual(ok,vgd.VGD_OK) self.assertEqual(v1.value,vgd.VGD_ALLOW_SIGMA)
def testNewReadGetInt(self): vgd0ptr = self._newReadBcmk() vkind = ct.c_int(0) vvers = ct.c_int(0) quiet = ct.c_int(0) ok = vgd.c_vgd_get_int(vgd0ptr, _C_WCHAR2CHAR('KIND'), ct.byref(vkind), quiet) ok = vgd.c_vgd_get_int(vgd0ptr, _C_WCHAR2CHAR('VERS'), ct.byref(vvers), quiet) self.assertEqual(ok,vgd.VGD_OK) self.assertEqual(vkind.value,vgd.VGD_HYB_KIND) self.assertEqual(vvers.value,vgd.VGD_HYB_VER) ok = vgd.c_vgd_get_int(vgd0ptr, _C_WCHAR2CHAR('SCRAP'), ct.byref(vkind), quiet) self.assertEqual(ok,vgd.VGD_ERROR)
def testNewBuildVert(self): vgd0ptr = vgd.c_vgd_construct() (kind, version) = (vgd.VGD_HYBS_KIND, vgd.VGD_HYBS_VER) (ip1, ip2) = (0, 0) ptop = ct.c_double(805.) pref = ct.c_double(100000.) (rcoef1, rcoef2) = (ct.c_float(1.), ct.c_float(10.)) ip1_m =(97618238, 96758972, 95798406, 94560550, 94831790, 95102940, 95299540, 93423264, 75597472) nk = len(ip1_m) - 2 #why -2!!! cip1_m = np.asarray(ip1_m, dtype=np.int32) a_m_8 = (2.30926271551059, 5.66981194184163, 8.23745285281583, 9.84538165280926, 10.7362879740149, 11.1997204664634, 11.4378785724517, 11.51293, 11.5116748020711) ca_m_8 = np.asarray(a_m_8, dtype=np.float64) b_m_8 = (0., 1.154429569962798E-003, 0.157422392639441, 0.591052504380263, 0.856321652104870, 0.955780377300956, 0.991250207889939, 1., 1.) cb_m_8 = np.asarray(b_m_8, dtype=np.float64) ip1_t = (97698159, 96939212, 95939513, 94597899, 94877531, 95139482, 95323042, 93423264, 76746048) cip1_t = np.asarray(ip1_t, dtype=np.int32) a_t_8 = (2.89364884405945, 6.15320066567627, 8.55467550398551, 10.0259661797048, 10.8310952652232, 11.2484934057893, 11.4628969443959, 11.51293, 11.5126753323904) ca_t_8 = np.asarray(a_t_8, dtype=np.float64) b_t_8 = (5.767296480554498E-009, 7.010292926951782E-003, 0.227561997481228, 0.648350006620964, 0.878891216792279, 0.963738779730914, 0.994233214440677, 1. ,1.) cb_t_8 = np.asarray(b_t_8, dtype=np.float64) (nl_m, nl_t) = (len(a_m_8), len(a_t_8)) ok = vgd.c_vgd_new_build_vert(vgd0ptr, kind, version, nk, ip1, ip2, ct.byref(ptop), ct.byref(pref), ct.byref(rcoef1), ct.byref(rcoef2), ca_m_8, cb_m_8, ca_t_8, cb_t_8, cip1_m, cip1_t, nl_m, nl_t) self.assertEqual(ok,vgd.VGD_OK) vkind = ct.c_int(0) vvers = ct.c_int(0) quiet = ct.c_int(0) ok = vgd.c_vgd_get_int(vgd0ptr, _C_WCHAR2CHAR('KIND'), ct.byref(vkind), quiet) ok = vgd.c_vgd_get_int(vgd0ptr, _C_WCHAR2CHAR('VERS'), ct.byref(vvers), quiet) self.assertEqual(ok,vgd.VGD_OK) self.assertEqual(vkind.value,vgd.VGD_HYBS_KIND) self.assertEqual(vvers.value,vgd.VGD_HYBS_VER)
def newdate_options_get(option): """ Get option for newdate, incdatr, difdatr Args: option : option name (str) possible values: 'year' Returns: option value (str) Raises: TypeError if option not a string Examples: >>> import rpnpy.librmn.all as rmn >>> value = rmn.newdate_options_get('year') See also: newdate_options_set ignore_leapyear accept_leapyear newdate """ cmd = 'get ' optionv = _C_MKSTR(option.strip()+' '*32) loptionv = len(optionv.value) _rp.f_newdate_options(optionv, _C_WCHAR2CHAR(cmd), loptionv, len(cmd)) if isinstance(optionv.value, bytes): return _C_CHAR2WCHAR(optionv.value).strip() else: return optionv.value.strip()
def testFree(self): vgd0ptr = self._newReadBcmk() vgd.c_vgd_free(vgd0ptr) v1 = C_MKSTR(' ' * vgd.VGD_MAXSTR_NOMVAR) quiet = ct.c_int(0) ok = vgd.c_vgd_get_char(vgd0ptr, _C_WCHAR2CHAR('RFLD'), v1, quiet) self.assertEqual(ok, vgd.VGD_ERROR)
def testLevels8_prof(self): ATM_MODEL_DFILES = os.getenv('ATM_MODEL_DFILES').strip() fileName = os.path.join(ATM_MODEL_DFILES, 'bcmk_toctoc', '2009042700_000') fileId = rmn.fstopenall(fileName, rmn.FST_RO) vgd0ptr = vgd.c_vgd_construct() ok = vgd.c_vgd_new_read(vgd0ptr, fileId, -1, -1, -1, -1) rmn.fstcloseall(fileId) ip1list = ct.POINTER(ct.c_int)() nip1 = ct.c_int(0) quiet = ct.c_int(0) ok = vgd.c_vgd_get_int_1d(vgd0ptr, _C_WCHAR2CHAR('VIPM'), ct.byref(ip1list), ct.byref(nip1), quiet) MB2PA = 100. p0_stn_mb = 1013. p0_stn = np.empty((1, ), dtype=np.float64, order='FORTRAN') p0_stn[0] = p0_stn_mb * MB2PA prof8 = np.empty((nip1.value, ), dtype=np.float64, order='FORTRAN') ni = 1 nj = 1 in_log = 0 ok = vgd.c_vgd_levels_8(vgd0ptr, ni, nj, nip1, ip1list, prof8, p0_stn, in_log) self.assertEqual(ok, vgd.VGD_OK) self.assertEqual([int(x) for x in prof8[0:5] * 10000.], [100000, 138426, 176879, 241410, 305984])
def testNewReadGetChar(self): vgd0ptr = self._newReadBcmk() #print vgd0ptr[0].ref_name v1 = C_MKSTR(' ' * vgd.VGD_MAXSTR_NOMVAR) quiet = ct.c_int(0) ok = vgd.c_vgd_get_char(vgd0ptr, _C_WCHAR2CHAR('RFLD'), v1, quiet) self.assertEqual(ok, vgd.VGD_OK) self.assertEqual(_C_CHAR2WCHAR(v1.value).strip(), 'P0')
def testStda76_temp(self): vgd0ptr = self._newReadBcmk() ip1list = ct.POINTER(ct.c_int)() nip1 = ct.c_int(0) quiet = ct.c_int(0) ok = vgd.c_vgd_get_int_1d(vgd0ptr, _C_WCHAR2CHAR('VIPM'), ct.byref(ip1list), ct.byref(nip1), quiet) temp = np.empty(nip1.value, dtype=np.float32, order='FORTRAN') ok = vgd.c_vgd_stda76_temp(vgd0ptr, ip1list, nip1, temp) self.assertEqual(ok, vgd.VGD_OK)
def cigaxg(grtyp, ig1, ig2=0, ig3=0, ig4=0): """ Decode ig1, ig2, ig3, ig4 into real grid descriptors (xg1, xg2, xg3, xg4) = cigaxg(grtyp, ig1, ig2, ig3, ig4) (xg1, xg2, xg3, xg4) = cigaxg(grtyp, ig1234) Args: grtyp : type of geographical projection (str) ig1..4 : 4 grid descriptors encoded values (4x int) ig1234 : 4 grid descriptors encoded values (tuple or list of 4x int) Returns: (float, float, float, float), Decoded grid parameters Meaning of xg1..4 values depends on the grid type, please refer to Librmn doc on grids for more details Raises: TypeError on wrong input arg types ValueError on invalid input arg value Examples: >>> import sys >>> import rpnpy.librmn.all as rmn >>> try: ... xg1234 = rmn.cigaxg('E', 0, 0, 0, 0) ... except rmn.RMNBaseError: ... sys.stderr.write("There was a problem getting decoded grid values.") See also: cxgaig rpnpy.librmn.interp.ezgprm rpnpy.librmn.interp.ezgxprm rpnpy.librmn.grids.decodeIG2dict rpnpy.librmn.grids.decodeXG2dict rpnpy.librmn.grids.decodeGrid rpnpy.librmn.grids.encodeGrid """ if not isinstance(grtyp, str): raise TypeError("cigaxg: Expecting grtyp arg of type str, Got {0}"\ .format(type(grtyp))) if grtyp.strip() == '': raise ValueError("cigaxg: must provide a valid grtyp") if _IS_LIST(ig1): (cig1, cig2, cig3, cig4) = (_ct.c_int(ig1[0]), _ct.c_int(ig1[1]), _ct.c_int(ig1[2]), _ct.c_int(ig1[3])) else: (cig1, cig2, cig3, cig4) = (_ct.c_int(ig1), _ct.c_int(ig2), _ct.c_int(ig3), _ct.c_int(ig4)) (cxg1, cxg2, cxg3, cxg4) = (_ct.c_float(0.), _ct.c_float(0.), _ct.c_float(0.), _ct.c_float(0.)) _rp.f_cigaxg(_C_WCHAR2CHAR(grtyp), _ct.byref(cxg1),_ct.byref(cxg2), _ct.byref(cxg3),_ct.byref(cxg4), _ct.byref(cig1),_ct.byref(cig2), _ct.byref(cig3),_ct.byref(cig4)) return (cxg1.value, cxg2.value, cxg3.value, cxg4.value)
def testNewGen(self): hyb = (0.0134575, 0.0203980, 0.0333528, 0.0472815, 0.0605295, 0.0720790, 0.0815451, 0.0889716, 0.0946203, 0.0990605, 0.1033873, 0.1081924, 0.1135445, 0.1195212, 0.1262188, 0.1337473, 0.1422414, 0.1518590, 0.1627942, 0.1752782, 0.1895965, 0.2058610, 0.2229843, 0.2409671, 0.2598105, 0.2795097, 0.3000605, 0.3214531, 0.3436766, 0.3667171, 0.3905587, 0.4151826, 0.4405679, 0.4666930, 0.4935319, 0.5210579, 0.5492443, 0.5780612, 0.6074771, 0.6374610, 0.6679783, 0.6989974, 0.7299818, 0.7591944, 0.7866292, 0.8123021, 0.8362498, 0.8585219, 0.8791828, 0.8983018, 0.9159565, 0.9322280, 0.9471967, 0.9609448, 0.9735557, 0.9851275, 0.9950425) nhyb = len(hyb) chyb = np.asarray(hyb, dtype=np.float32) (rcoef1, rcoef2) = (ct.c_float(0.), ct.c_float(1.)) ptop = ct.c_double(805.) pref = ct.c_double(100000.) p_ptop_out = ct.POINTER(ct.c_double)() (kind, version) = (vgd.VGD_HYBS_KIND, vgd.VGD_HYBS_VER) (ip1, ip2) = (0, 0) dhm = ct.c_float(10.) dht = ct.c_float(2.) (p_dhm, p_dht) = (None, None) #(ct.pointer(dhm), ct.pointer(dht)) #TODO: why: (Cvgd) ERROR: dhm,dht is not a required constructor entry vgd0ptr = vgd.c_vgd_construct() ok = vgd.c_vgd_new_gen(vgd0ptr, kind, version, chyb, nhyb, ct.byref(rcoef1), ct.byref(rcoef2), ct.byref(ptop), ct.byref(pref), p_ptop_out, ip1, ip2, p_dhm, p_dht) self.assertEqual(ok, vgd.VGD_OK) vkind = ct.c_int(0) vvers = ct.c_int(0) quiet = ct.c_int(0) ok = vgd.c_vgd_get_int(vgd0ptr, _C_WCHAR2CHAR('KIND'), ct.byref(vkind), quiet) ok = vgd.c_vgd_get_int(vgd0ptr, _C_WCHAR2CHAR('VERS'), ct.byref(vvers), quiet) self.assertEqual(ok, vgd.VGD_OK) self.assertEqual(vkind.value, vgd.VGD_HYBS_KIND) self.assertEqual(vvers.value, vgd.VGD_HYBS_VER)
def testNewReadGetInt1D(self): vgd0ptr = self._newReadBcmk() ## print vgd0ptr[0].nl_m, vgd0ptr[0].nl_t ## print vgd0ptr[0].ip1_m[0] v1 = ct.POINTER(ct.c_int)() nv = ct.c_int(0) quiet = ct.c_int(0) ok = vgd.c_vgd_get_int_1d(vgd0ptr, _C_WCHAR2CHAR('VIPM'), ct.byref(v1), ct.byref(nv), quiet) self.assertEqual(ok,vgd.VGD_OK) self.assertEqual(nv.value,158) self.assertEqual(v1[0:3],[97642568, 97690568, 97738568])
def testNewReadGetFloat1D(self): vgd0ptr = self._newReadBcmk() ## print vgd0ptr[0].nl_m, vgd0ptr[0].nl_t ## print vgd0ptr[0].ip1_m[0] v1 = ct.POINTER(ct.c_float)() nv = ct.c_int(0) quiet = ct.c_int(0) ok = vgd.c_vgd_get_float_1d(vgd0ptr, _C_WCHAR2CHAR('VCDM'), ct.byref(v1), ct.byref(nv), quiet) self.assertEqual(ok,vgd.VGD_OK) self.assertEqual(nv.value,158) self.assertEqual([int(x*10000000) for x in v1[0:3]],[1250, 1729, 2209])
def testNewReadGetDouble1D(self): vgd0ptr = self._newReadBcmk() ## print vgd0ptr[0].nl_m, vgd0ptr[0].nl_t ## print vgd0ptr[0].a_m_8[0] v1 = ct.POINTER(ct.c_double)() nv = ct.c_int(0) quiet = ct.c_int(0) ok = vgd.c_vgd_get_double_1d(vgd0ptr, _C_WCHAR2CHAR('CA_M'), ct.byref(v1), ct.byref(nv), quiet) self.assertEqual(ok,vgd.VGD_OK) self.assertEqual(nv.value,158) self.assertEqual(int(v1[0]*100.),1000) self.assertEqual(int(v1[1]*100.),1383) self.assertEqual(int(v1[2]*100.),1765)
def testNewReadGetDouble3D(self): vgd0ptr = self._newReadBcmk() ## print vgd0ptr[0].nl_m, vgd0ptr[0].nl_t ## print vgd0ptr[0].a_m_8[0] v1 = ct.POINTER(ct.c_double)() ni = ct.c_int(0) nj = ct.c_int(0) nk = ct.c_int(0) quiet = ct.c_int(0) ok = vgd.c_vgd_get_double_3d(vgd0ptr, _C_WCHAR2CHAR('VTBL'), ct.byref(v1), ct.byref(ni), ct.byref(nj), ct.byref(nk), quiet) self.assertEqual(ok,vgd.VGD_OK) self.assertEqual([int(x*100.) for x in v1[0:9]], [500, 100, 300, 1000, 8000000, 160, 0, 0, 0])
def testNewFromTable(self): vgd0ptr = self._newReadBcmk() v1 = ct.POINTER(ct.c_double)() ni = ct.c_int(0) nj = ct.c_int(0) nk = ct.c_int(0) quiet = ct.c_int(0) ok = vgd.c_vgd_get_double_3d(vgd0ptr, _C_WCHAR2CHAR('VTBL'), ct.byref(v1), ct.byref(ni), ct.byref(nj), ct.byref(nk), quiet) vgd1ptr = vgd.c_vgd_construct() ok = vgd.c_vgd_new_from_table(vgd1ptr, v1, ni, nj, nk) self.assertEqual(ok,vgd.VGD_OK) ok = vgd.c_vgd_vgdcmp(vgd0ptr,vgd1ptr) self.assertEqual(ok,vgd.VGD_OK)
def testStda76_pres(self): vgd0ptr = self._newReadBcmk(vcode_name="21002_SLEVE") ip1list = ct.POINTER(ct.c_int)() nip1 = ct.c_int(0) quiet = ct.c_int(0) ok = vgd.c_vgd_get_int_1d(vgd0ptr, _C_WCHAR2CHAR('VIPM'), ct.byref(ip1list), ct.byref(nip1), quiet) pres = np.empty(nip1.value, dtype=np.float32, order='FORTRAN') (p_sfc_temp, p_sfc_pres) = (None, None) ok = vgd.c_vgd_stda76_pres(vgd0ptr, ip1list, nip1, pres, p_sfc_temp, p_sfc_pres) self.assertEqual(ok, vgd.VGD_OK) #TODO: assert pres values sfc_temp = ct.c_float(273.15) ok = vgd.c_vgd_stda76_pres(vgd0ptr, ip1list, nip1, pres, sfc_temp, p_sfc_pres) self.assertEqual(ok, vgd.VGD_OK) sfc_pres = ct.c_float(100000.) ok = vgd.c_vgd_stda76_pres(vgd0ptr, ip1list, nip1, pres, p_sfc_temp, sfc_pres) self.assertEqual(ok, vgd.VGD_OK)
def wkoffit(filename): """ Return code type of file (int) Args: filename : path/name of the file to examine Returns: int, file type code as follow: -3 FICHIER INEXISTANT -2 FICHIER VIDE -1 FICHIER INCONNU 1 FICHIER STANDARD RANDOM 89 2 FICHIER STANDARD SEQUENTIEL 89 3 FICHIER STANDARD SEQUENTIEL FORTRAN 89 4 FICHIER CCRN 5 FICHIER CCRN-RPN 6 FICHIER BURP 7 FICHIER GRIB 8 FICHIER BUFR 9 FICHIER BLOK 10 FICHIER FORTRAN 11 FICHIER COMPRESS 12 FICHIER GIF89 13 FICHIER GIF87 14 FICHIER IRIS 15 FICHIER JPG 16 FICHIER KMW 17 FICHIER PBM 18 FICHIER PCL 19 FICHIER PCX 20 FICHIER PDSVICAR 21 FICHIER PM 22 FICHIER PPM 23 FICHIER PS 24 FICHIER KMW_ 25 FICHIER RRBX 26 FICHIER SUNRAS 27 FICHIER TIFF 28 FICHIER UTAHRLE 29 FICHIER XBM 30 FICHIER XWD 31 FICHIER ASCII 32 FICHIER BMP 33 FICHIER STANDARD RANDOM 98 34 FICHIER STANDARD SEQUENTIEL 98 35 FICHIER NETCDF Raises: TypeError on wrong input arg types ValueError on invalid input arg value Examples: >>> import os, os.path, sys >>> import rpnpy.librmn.all as rmn >>> ATM_MODEL_DFILES = os.getenv('ATM_MODEL_DFILES').strip() >>> filename = os.path.join(ATM_MODEL_DFILES,'bcmk_toctoc','2009042700_000') >>> itype = rmn.wkoffit(filename) >>> if itype in rmn.WKOFFIT_TYPE_LIST_INV.keys(): ... print('# '+rmn.WKOFFIT_TYPE_LIST_INV[itype]) # STANDARD RANDOM 98 See also: rpnpy.librmn.fstd98.isFST rpnpy.librmn.const """ if not isinstance(filename, str): raise TypeError("wkoffit: Expecting filename arg of type str, " + "Got {0}".format(type(filename))) if filename.strip() == '': raise ValueError("wkoffit: must provide a valid filename") return _rp.c_wkoffit(_C_WCHAR2CHAR(filename), len(filename))
def testNewBuildVert2(self): vgd0ptr = vgd.c_vgd_construct() (kind, version) = (vgd.VGD_HYBHLS_KIND, vgd.VGD_HYBHLS_VER) (ip1, ip2) = (0, 0) p_ptop = ct.POINTER(ct.c_double)() p_pref = ct.POINTER(ct.c_double)() p_ptop_out = ct.POINTER(ct.c_double)() (rcoef1, rcoef2) = (ct.c_float(0.), ct.c_float(1.)) (rcoef3, rcoef4) = (ct.c_float(0.), ct.c_float(5.)) ip1_m = (85095624, 85065817, 86890841, 86530977, 86332098, 86167510, 87911659, 93423364, 75597472) nk = len(ip1_m) - 2 # why -2!!! cip1_m = np.asarray(ip1_m, dtype=np.int32) a_m_8 = (16096.822266, 13116.121094, 9076.089844, 5477.454102, 3488.660400, 1842.784424, 879.851318, 0.000000, 10.000000) ca_m_8 = np.asarray(a_m_8, dtype=np.float64) b_m_8 = (0.000000, 0.001038, 0.096399, 0.492782, 0.767428, 0.932772, 0.984755, 1.000000, 1.000000) cb_m_8 = np.asarray(b_m_8, dtype=np.float64) c_m_8 = (0.000000, 0.252011, 0.529947, 0.375240, 0.181007, 0.053405, 0.012177, 0.000000, 0.000000) cc_m_8 = np.asarray(c_m_8, dtype=np.float64) ip1_t = (85095624, 85065817, 86890841, 86530977, 86332098, 86167510, 87911659, 93423364, 76696048) cip1_t = np.asarray(ip1_t, dtype=np.int32) a_t_8 = (16096.822266, 13116.121094, 9076.089844, 5477.454102, 3488.660400, 1842.784424, 879.851318, 0.000000, 1.500000) ca_t_8 = np.asarray(a_t_8, dtype=np.float64) b_t_8 = (0.000000, 0.001038, 0.096399, 0.492782, 0.767428, 0.932772, 0.984755, 1.000000, 1.000000) cb_t_8 = np.asarray(b_t_8, dtype=np.float64) c_t_8 = (0.000000, 0.252011, 0.529947, 0.375240, 0.181007, 0.053405, 0.012177, 0.000000, 0.000000) cc_t_8 = np.asarray(c_t_8, dtype=np.float64) ip1_w = (85080721, 85045617, 86710909, 86431538, 86249804, 86119364, 93423364, 93423364, 82837504) cip1_w = np.asarray(ip1_w, dtype=np.int32) a_w_8 = (14606.471680, 11096.105469, 7276.771973, 4483.057251, 2665.722412, 1361.317871, 0.000000, 0.000000, 0.000000) ca_w_8 = np.asarray(a_w_8, dtype=np.float64) b_w_8 = (0.000519, 0.048718, 0.294591, 0.630105, 0.850100, 0.958764, 1.000000, 1.000000, 1.000000) cb_w_8 = np.asarray(b_w_8, dtype=np.float64) c_w_8 = (0.126005, 0.390979, 0.452594, 0.278124, 0.117206, 0.032791, 0.000000, 0.000000, 0.000000) cc_w_8 = np.asarray(c_w_8, dtype=np.float64) (nl_m, nl_t, nl_w) = (len(a_m_8), len(a_t_8), len(a_w_8)) ok = vgd.c_vgd_new_build_vert2(vgd0ptr, kind, version, nk, ip1, ip2, p_ptop, p_pref, ct.byref(rcoef1), ct.byref(rcoef2), ct.byref(rcoef3), ct.byref(rcoef4), ca_m_8, cb_m_8, cc_m_8, ca_t_8, cb_t_8, cc_t_8, ca_w_8, cb_w_8, cc_w_8, cip1_m, cip1_t, cip1_w, nl_m, nl_t, nl_w) self.assertEqual(ok, vgd.VGD_OK) vkind = ct.c_int(0) vvers = ct.c_int(0) quiet = ct.c_int(0) ok = vgd.c_vgd_get_int(vgd0ptr, _C_WCHAR2CHAR('KIND'), ct.byref(vkind), quiet) ok = vgd.c_vgd_get_int(vgd0ptr, _C_WCHAR2CHAR('VERS'), ct.byref(vvers), quiet) self.assertEqual(ok, vgd.VGD_OK) self.assertEqual(vkind.value, vgd.VGD_HYBHLS_KIND) self.assertEqual(vvers.value, vgd.VGD_HYBHLS_VER)