Changeset 625 in lmdz_wrf
- Timestamp:
- Sep 13, 2015, 7:37:36 PM (9 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing_tools.py
r621 r625 57 57 # plot_2D_shadow_line: 58 58 # plot_lines: Function to plot a collection of lines 59 # plot_ZQradii: Function to plot following radial averages only at exact grid poins 59 60 60 61 # From nc_var_tools.py … … 5448 5449 5449 5450 return 5451 5452 def plot_ZQradii(Zmeans, graphtit, kfig, figname): 5453 """ Function to plot following radial averages only at exact grid poins 5454 Zmeans= radial means 5455 radii= values of the taken radii 5456 graphtit= title of the graph ('|', for spaces) 5457 kfig= kind of figure 5458 figname= name of the figure 5459 """ 5460 5461 fname = 'plot_ZQradii' 5462 5463 output_kind(kfig, figname, True) 5464 5465 return -
trunk/tools/nc_var_tools.py
r624 r625 15155 15155 return radpos 15156 15156 15157 def grid_combinations(x,y): 15158 """ Function to provide all the possible grid points combination for a given pair of values 15159 x,y= pair of grid points 15160 >>>grid_combinations(1,2) 15161 [[1, 2], [-1, 2], [-1, -2], [1, -2], [2, 1], [-2, 1], [-2, -1], [2, -1]] 15162 """ 15163 fname = 'grid_combinations' 15164 15165 gridcomb = [] 15166 gridcomb.append([x,y]) 15167 gridcomb.append([-x,y]) 15168 gridcomb.append([-x,-y]) 15169 gridcomb.append([x,-y]) 15170 15171 if x != y: 15172 gridcomb.append([y,x]) 15173 gridcomb.append([-y,x]) 15174 gridcomb.append([-y,-x]) 15175 gridcomb.append([y,-x]) 15176 15177 return gridcomb 15178 15179 def radii_points(xpos,ypos,Lrad,Nang,dx,dy): 15180 """ Function to provide the grid points for radial cross sections, by angle and radii and `squared' radii 15181 xpos= x position of the center 15182 ypos= y position of the center 15183 Lrad= length of the maximum radi in grid points 15184 Nang= number of equivalent angles 15185 dx= x size of the domain of values 15186 dy= y size of the domain of values 15187 """ 15188 fname = 'radii_points' 15189 15190 radiipos = np.zeros((Nangle, radii, 2), dtype = int) 15191 SQradiipos = {} 15192 15193 # Getting the range of radii: 15194 pairsSQradii = read_SQradii(Npt=Lrad) 15195 SQradii = pairsSQradii.keys() 15196 Nradii = len(SQradii) 15197 15198 # Angle loop 15199 for ia in range(Nang): 15200 angle = 2.*np.pi*ia/Nang 15201 15202 # Points at that given angle 15203 pangle = radial_points(angle,radii) 15204 posangle[:,0] = pangle[:,0] + xpos 15205 posangle[:,1] = pangle[:,1] + ypos 15206 15207 for ip in range(radii): 15208 iipos = int(posangle[ip,0]) 15209 jjpos = int(posangle[ip,1]) 15210 15211 # Creation of a matrix with all the grid points at each time-step 15212 if iipos >= 0 and iipos < dx and jjpos >= 0 and jjpos < dy: 15213 radiipos[ia,ip,0] = iipos 15214 radiipos[ia,ip,1] = jjpos 15215 15216 # SQ radii values 15217 15218 # Radii loop (avoiding 0) 15219 pairswithin = {} 15220 for ir in range(1,Nradii): 15221 pairs = pairsSQradii[SQradii[ir]] 15222 15223 # pairs loop 15224 pairsw = [] 15225 for ip in range(len(pairs)): 15226 allpairs = grid_combinations(pairs[ip*2],pairs[ip*2+1]) 15227 15228 for iap in range(len(allpairs)): 15229 ppos = allpairs[iap] 15230 iipos = trajvals[it,1] + ppos[0] 15231 jjpos = trajvals[it,1] + ppos[0] 15232 15233 # Creation of a matrix with all the grid points at each time-step 15234 if iipos >= 0 and iipos < dx and jjpos >= 0 and jjpos < dy: 15235 pairsw.append([iipos,jjpos]) 15236 15237 SQradiipos[SQradii[ir]] = pairsw 15238 15239 return radiipos, SQradiipos 15240 15157 15241 def compute_tevolboxtraj_radialsec(values, ncfile, varn): 15158 15242 """ Function to compute tevolboxtraj_radialsec: temporal evolution at a given point along … … 15245 15329 # Trajectory values/slices 15246 15330 ## 15331 # This is how we're going to proceed: 15332 # Creation of 1 matrix and 1 dictionay with the grid points where values have to be taken 15333 # trjradii(dimt,Nangle,Nrad,2): x,y pairs at each radii, angle and time step. 15334 # Ditance interpolation might be required! 15335 # SQtrjradii(dimt,2): x,y pairs at each radii, number of pairs (Npair) and time 15336 # step. Flip/rotation of points might be required! 15337 15338 trjradii = np.zeros((dimt, Nangle, radii, 2), dtype = int) 15339 trjSQradii = {} 15340 15247 15341 iline = 0 15248 15342 it = 0 15249 15250 xrangeslice = []15251 yrangeslice = []15252 xrangeslice2D = []15253 yrangeslice2D = []15254 15255 cslicev = []15256 cslice2D = []15257 cslicevnoT = []15258 15259 gtrajvals = np.zeros((Ttraj,3), dtype=int)15260 trajvals = np.zeros((Ttraj,3), dtype=np.float)15261 15343 15262 15344 trajpos = np.zeros(Ttraj,Nangle,raddi) … … 15283 15365 trajvals[it,0] = realdatetime1_CFcompilant(gdate, '19491201000000', \ 15284 15366 'hours') 15367 15285 15368 tunits = 'hours since 1949-12-01 00:00:00' 15286 15369 elif timekind == 'cf': … … 15292 15375 quit(-1) 15293 15376 15294 trajvals[it,1] = lonv[gtrajvals[it,2],gtrajvals[it,1]]15295 trajvals[it,2] = latv[gtrajvals[it,2],gtrajvals[it,1]]15296 15297 15377 # print iline, it,'time:',trajvals[it,0],'lon lat:', trajvals[it,1], \ 15298 15378 # trajvals[it,2] … … 15305 15385 posangle = np.zeros((radii,2), dtype=np.float) 15306 15386 15307 # Angle loop 15308 for ia in range(Nangle): 15309 angle = 2.*np.pi*ia/Nangle 15310 15311 # Points at that given angle 15312 pangle = radial_points(angle,radii) 15313 posangle[:,0] = pangle[:,0] + trajvals[it,1] 15314 posangle[:,1] = pangle[:,1] + trajvals[it,2] 15315 15316 for ip in range(radii): 15317 iipos = int(posangle[ip,0]) 15318 jjpos = int(posangle[ip,1]) 15319 15320 # Creation of a matrix with all the grid points at each time-step 15321 if iipos >= 0 and iipos < dimx and jjpos >= 0 and jjpos < dimy: 15322 print 'Hola' 15323 quit() 15324 # varvalst[ia,ip] = 15325 15326 15327 if gtrajvals[it,2]-radii < 0: 15328 yinit = 0 15329 yinit2D = radii - gtrajvals[it,2] 15330 else: 15331 yinit = gtrajvals[it,2]-radii 15332 yinit2D = 0 15333 15334 if gtrajvals[it,2]+radii + 1 > dimy + 1: 15335 yend = dimy + 1 15336 yend2D = dimy + 1 - gtrajvals[it,2] + radii 15337 else: 15338 yend = gtrajvals[it,2]+radii + 1 15339 yend2D = radi 15340 15341 if gtrajvals[it,1]-box2 < 0: 15342 xinit = 0 15343 xinit2D = box2 - gtrajvals[it,1] 15344 else: 15345 xinit = gtrajvals[it,1]-box2 15346 xinit2D = 0 15347 15348 if gtrajvals[it,1]+box2 + 1 > dimx + 1: 15349 xend = dimx + 1 15350 xend2D = dimx + 1 - gtrajvals[it,1] - box2 15351 else: 15352 xend = gtrajvals[it,1]+box2 + 1 15353 xend2D = boxs 15354 15355 yrangeslice.append([yinit, yend]) 15356 xrangeslice.append([xinit, xend]) 15357 yrangeslice2D.append([yinit2D, yend2D]) 15358 xrangeslice2D.append([xinit2D, xend2D]) 15359 else: 15360 yrangeslice.append([gtrajvals[it,2]-box2, gtrajvals[it,2]+box2 + 1]) 15361 xrangeslice.append([gtrajvals[it,1]-box2, gtrajvals[it,1]+box2 + 1]) 15362 yrangeslice2D.append([gtrajvals[it,2]-box2, gtrajvals[it,2]+box2 + 1]) 15363 xrangeslice2D.append([gtrajvals[it,1]-box2, gtrajvals[it,1]+box2 + 1]) 15364 15365 # circle values 15366 circdist[it,:,:] = radius_dist(dimy,dimx,gtrajvals[it,2],gtrajvals[it,1]) 15367 15368 if gtrajvals[it,2]-Nrad < 0 or gtrajvals[it,2]+Nrad + 1 > dimy + 1 \ 15369 or gtrajvals[it,1]-Nrad < 0 or gtrajvals[it,1]+Nrad + 1 > dimx + 1: 15370 15371 if gtrajvals[it,2]-Nrad < 0: 15372 yinit = 0 15373 yinit2D = Nrad - gtrajvals[it,2] 15374 else: 15375 yinit = gtrajvals[it,2]-Nrad 15376 yinit2D = 0 15377 15378 if gtrajvals[it,2]+Nrad + 1 > dimy + 1: 15379 yend = dimy + 1 15380 yend2D = dimy + 1 - gtrajvals[it,2] + Nrad 15381 else: 15382 yend = gtrajvals[it,2]+Nrad + 1 15383 yend2D = 2*Nrad+1 15384 15385 if gtrajvals[it,1]-Nrad < 0: 15386 xinit = 0 15387 xinit2D = Nrad - gtrajvals[it,1] 15388 else: 15389 xinit = gtrajvals[it,1]-Nrad 15390 xinit2D = 0 15391 15392 if gtrajvals[it,1]+Nrad + 1 > dimx + 1: 15393 xend = dimx + 1 15394 xend2D = dimx + 1 - gtrajvals[it,1] - Nrad 15395 else: 15396 xend = gtrajvals[it,1]+Nrad + 1 15397 xend2D = 2*Nrad+1 15398 15399 cyrangeslice.append([yinit, yend]) 15400 cxrangeslice.append([xinit, xend]) 15401 cyrangeslice2D.append([yinit2D, yend2D]) 15402 cxrangeslice2D.append([xinit2D, xend2D]) 15403 else: 15404 cyrangeslice.append([gtrajvals[it,2]-Nrad, gtrajvals[it,2]+Nrad + 1]) 15405 cxrangeslice.append([gtrajvals[it,1]-Nrad, gtrajvals[it,1]+Nrad + 1]) 15406 cyrangeslice2D.append([gtrajvals[it,2]-Nrad, gtrajvals[it,2]+Nrad+1]) 15407 cxrangeslice2D.append([gtrajvals[it,1]-Nrad, gtrajvals[it,1]+Nrad+1]) 15387 trjradii[it,:,:,:], trjSQradii[it] = radii_points(trajvals[it,0], \ 15388 trajvals[it,1],radii,Nangle,dimx,dimy) 15389 15408 15390 it = it + 1 15409 15391 iline = iline + 1 15392 quit() 15410 15393 15411 15394 trajobj.close()
Note: See TracChangeset
for help on using the changeset viewer.