- Timestamp:
- Sep 16, 2015, 6:00:32 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r629 r631 15332 15332 return radiipos, SQradiipos 15333 15333 15334 def hor_weight_int(SWval, SEval, NWval, NEval, xpos, ypos): 15335 """ Function to weighted by distance interpolate a horizontal value from it closest 4 neighbourgs 15336 field= a 4 points representing the environment of a given point 15337 xpos, ypos: position to which one want to interpolate (relative to 0,0 at the corner SW) 15338 >>> hor_weight_int(1., 1., 1., 2., 0.75, 0.75) 15339 1.44888128193 15340 """ 15341 fname = 'hor_weight_int' 15342 15343 vals = np.array([SWval, SEval, NWval, NEval]) 15344 print vals 15345 if xpos > 1.: 15346 print errormsg 15347 print ' ' + fname + ': Wrong position to interpolate! (',xpos,',',ypos, \ 15348 ') must be within (1,1) !!' 15349 quit(-1) 15350 15351 vertexs = np.zeros((4,2), dtype=np.float) 15352 vertexs[0,0] = 0. 15353 vertexs[0,1] = 0. 15354 vertexs[1,0] = 1. 15355 vertexs[1,1] = 0. 15356 vertexs[2,0] = 0. 15357 vertexs[2,1] = 1. 15358 vertexs[3,0] = 1. 15359 vertexs[3,1] = 1. 15360 print vertexs 15361 15362 dist = np.sqrt((vertexs[:,0]-xpos)**2 + (vertexs[:,1]-ypos)**2) 15363 print dist 15364 done = False 15365 for id in range(4): 15366 if dist[id] == 0.: 15367 intval = vals[id] 15368 done = True 15369 15370 if not done: intval = np.sum(vals/dist)/np.sum(1./dist) 15371 15372 return intval 15373 15334 15374 def compute_tevolboxtraj_radialsec(values, ncfile, varn): 15335 15375 """ Function to compute tevolboxtraj_radialsec: temporal evolution at a given point along … … 15338 15378 [trajfile]: ASCII file with the trajectory ('#' not readed) 15339 15379 [time] [xpoint] [ypoint] 15340 [Tbeg]: equivalent first time-step of the tra jectory within the netCDF file15380 [Tbeg]: equivalent first time-step of the traqjectory within the netCDF file 15341 15381 [lonname],[latname],[zname],[timename]: longitude, latitude, z and time variables names 15342 15382 [timekind]: kind of time … … 15433 15473 trjSQradii = {} 15434 15474 15475 TOTradii = [] 15476 15435 15477 iline = 0 15436 15478 it = 0 … … 15458 15500 gtrajvals[it,1] = int(line.split(' ')[1]) 15459 15501 gtrajvals[it,2] = int(line.split(' ')[2]) 15460 #print it,'t:',gtrajvals[it,0],'x y:', gtrajvals[it,1], gtrajvals[it,2]15502 print it,'t:',gtrajvals[it,0],'x y:', gtrajvals[it,1], gtrajvals[it,2] 15461 15503 15462 15504 if timekind == 'wrf': … … 15484 15526 posangle = np.zeros((radii,2), dtype=np.float) 15485 15527 15486 trjradii[it,:,:,:], trjSQradii[it] = radii_points(trajvals[it,0], \ 15487 trajvals[it,1],radii,Nangle,dimx,dimy) 15488 print trjradii[it,:,:,:] 15489 print '-----------' 15490 print trjSQradii[it,:,:,:] 15491 15528 trjradii[it,:,:,:], trjSQradii[it] = radii_points(gtrajvals[it,1], \ 15529 gtrajvals[it,2],radii,Nangle,dimx,dimy) 15530 if it == 0: 15531 TOTradii = list(trjSQradii[it].keys()) 15532 else: 15533 for ir in trjSQradii[it].keys(): 15534 if searchInlist(TOTradii,ir): TOTradii.append(ir) 15492 15535 it = it + 1 15493 15536 iline = iline + 1 15494 15537 15495 quit()15496 15538 15497 15539 trajobj.close() 15498 15540 # Creation of the netCDF file 15499 15541 ## 15542 NtotSQradii = len(TOTradii) 15543 TOTSQradii = sorted(TOTradii) 15544 print ' ' + fname + ':',NtotSQradii,' squared radii:',TOTSQradii 15545 15500 15546 if varn.find(',') != -1: 15501 15547 varnS = 'multi-var' … … 15503 15549 varnS = varn.replace(',','-') 15504 15550 15505 ofile = 'tevol boxtraj_' + varnS + '.nc'15551 ofile = 'tevolradiitraj_' + varnS + '.nc' 15506 15552 objofile = NetCDFFile(ofile, 'w') 15507 15553 15554 boxs = radii*2+1 15508 15555 # Dimensions 15509 15556 newdim = objofile.createDimension('x', boxs) 15510 15557 newdim = objofile.createDimension('y', boxs) 15511 newdim = objofile.createDimension('xr', Nrad*2+1)15512 newdim = objofile.createDimension('yr', Nrad*2+1)15513 15558 newdim = objofile.createDimension('time', None) 15559 newdim = objofile.createDimension('radii', radii) 15560 newdim = objofile.createDimension('SQradii', NtotSQradii) 15514 15561 15515 15562 stsn = ['min', 'max', 'mean', 'mean2', 'stdev', 'ac'] … … 15521 15568 cstatnames = [] 15522 15569 for i in range(Nsts): 15523 statnames.append(stsn[i] + ' box')15524 cstatnames.append(stsn[i] + ' circle')15570 statnames.append(stsn[i] + 'radii') 15571 cstatnames.append(stsn[i] + 'SQradii') 15525 15572 15526 15573 # Getting values 15527 15574 ## 15528 15575 ivar = 0 15576 box2=0 15529 15577 15530 15578 for vn in varns: … … 15581 15629 15582 15630 varvals = np.ones(tuple([Ttraj,dimz,boxs,boxs]), dtype=np.float) 15583 lonvals = np.ones(tuple([Ttraj, dimz,boxs,boxs]), dtype=np.float)15631 lonvals = np.ones(tuple([Ttraj,boxs,boxs]), dtype=np.float) 15584 15632 latvals = np.ones(tuple([Ttraj,boxs,boxs]), dtype=np.float) 15585 rvarvals = np.ones(tuple([Ttraj,dimz,Nrad*2+1,Nrad*2+1]), dtype=np.float) 15586 rlonvals = np.ones(tuple([Ttraj,dimz,Nrad*2+1,Nrad*2+1]), dtype=np.float) 15587 rlatvals = np.ones(tuple([Ttraj,dimz,Nrad*2+1,Nrad*2+1]), dtype=np.float) 15633 radiivarvals = np.ones(tuple([Ttraj,dimz,radii]), dtype=np.float)*fillValueF 15634 SQradiivarvals = np.ones(tuple([Ttraj,dimz,NtotSQradii]), dtype=np.float)*fillValueF 15588 15635 15589 15636 # One dimension plus for the values at the center of the trajectory … … 15593 15640 for it in range(Ttraj): 15594 15641 it0 = Tbeg + it 15642 # Radii values 15643 # trjradii[it,:,:,:], trjSQradii[it] 15644 for ir in range(radii): 15645 for ia in range(Nangle): 15646 xp = trjradii[it,ia,ir,0] 15647 yp = trjradii[it,ia,ir,1] 15648 xpI = int(xp*1.) 15649 ypI = int(yp*1.) 15650 print 'xp yp:',xp,yp,'xpI ypI:',xpI,ypI 15651 quit() 15652 mean = 0. 15653 for iz in range(dimz): 15654 SWv = varobj[it0,iz,ypI,xpI] 15655 SEv = varobj[it0,iz,ypI,xpI+1] 15656 NWv = varobj[it0,iz,ypI+1,xpI] 15657 NEv = varobj[it0,iz,ypI+1,xpI+1] 15658 val = hor_weight_int(SEv, SWv, NEv, NWv, xp-xpI, yp-ypI) 15659 print 'Lluis hor_weight_int(',SEv,',', SWv,',', NEv,',', NWv,',', xp-xpI,',', yp-ypI,')' 15660 print val 15661 mean = mean + val 15662 print 'mean:',mean 15663 quit() 15595 15664 15596 15665 slicev = [] … … 15833 15902 dimt = varobj.shape[0] 15834 15903 15835 varvals = np.ones(tuple([Ttraj,boxs,boxs1]), dtype=np.float) 15904 Nrad=1 15905 varvals = np.ones(tuple([Ttraj,boxs,boxs]), dtype=np.float) 15836 15906 lonvals = np.ones(tuple([Ttraj,boxs,boxs]), dtype=np.float) 15837 15907 latvals = np.ones(tuple([Ttraj,boxs,boxs]), dtype=np.float) … … 16135 16205 # [radii]: length in grid points of the radius 16136 16206 16137 compute_tevolboxtraj_radialsec('/bdd/PCER/workspace/lfita/etudes/FF/medic051215_2km/run/trajectory .dat@6,XLONG,XLAT,ZNU,Times,wrf,4,10', \16138 '/bdd/PCER/workspace/lfita/etudes/FF/medic051215_2km/run/wrfout/wrfout_d02_2005-12-1 2_00:00:00', 'U10')16207 compute_tevolboxtraj_radialsec('/bdd/PCER/workspace/lfita/etudes/FF/medic051215_2km/run/trajectory_shorten.dat@0,XLONG,XLAT,ZNU,Times,wrf,4,2', \ 16208 '/bdd/PCER/workspace/lfita/etudes/FF/medic051215_2km/run/wrfout/wrfout_d02_2005-12-13_00:00:00', 'QVAPOR') 16139 16209 quit() 16140 16210
Note: See TracChangeset
for help on using the changeset viewer.