Changeset 545 in lmdz_wrf for trunk/tools/drawing_tools.py
- Timestamp:
- Jun 30, 2015, 6:24:47 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing_tools.py
r544 r545 58 58 59 59 # From nc_var_tools.py 60 def reduce_spaces(string): 61 """ Function to give words of a line of text removing any extra space 62 """ 63 values = string.replace('\n','').split(' ') 64 vals = [] 65 for val in values: 66 if len(val) > 0: 67 vals.append(val) 68 69 return vals 70 60 71 def searchInlist(listname, nameFind): 61 72 """ Function to search a value within a list … … 1368 1379 return varvals 1369 1380 1381 def lonlat2D(lon,lat): 1382 """ Function to return lon, lat 2D matrices from any lon,lat matrix 1383 lon= matrix with longitude values 1384 lat= matrix with latitude values 1385 """ 1386 fname = 'lonlat2D' 1387 1388 if len(lon.shape) != len(lat.shape): 1389 print errormsg 1390 print ' ' + fname + ': longitude values with shape:', lon.shape, \ 1391 'is different that latitude values with shape:', lat.shape, '(dif. size) !!' 1392 quit(-1) 1393 1394 if len(lon.shape) == 3: 1395 lonvv = lon[0,:,:] 1396 latvv = lat[0,:,:] 1397 elif len(lon.shape) == 2: 1398 lonvv = lon[:] 1399 latvv = lat[:] 1400 elif len(lon.shape) == 1: 1401 lonlatv = np.meshgrid(lon[:],lat[:]) 1402 lonvv = lonlatv[0] 1403 latvv = lonlatv[1] 1404 1405 return lonvv, latvv 1406 1370 1407 ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### 1371 1408 … … 2500 2537 #quit() 2501 2538 2502 def plot_points(xval, yval, ifile, vtit, kfig, mapv): 2539 def plot_points(xval, yval, vlon, vlat, extravals, extrapar, vtit, mapv, color, \ 2540 labels, lloc, kfig, figname): 2503 2541 """ plotting points 2504 2542 [x/yval]: x,y values to plot 2505 v n,vm= minmum and maximum values to plot2506 unit= units of the variable2507 ifile= name of the input file2508 vtit= title of thevariable2509 kfig= kind of figure (jpg, pdf, png)2543 vlon= 2D-matrix with the longitudes 2544 vlat= 2D-matrix with the latitudes 2545 extravals= extra values to be added into the plot (None for nothing) 2546 extrapar= [varname, min, max, cbar, varunits] of the extra variable 2547 vtit= title of the graph ('|' for spaces) 2510 2548 mapv= map characteristics: [proj],[res] 2511 2549 see full documentation: http://matplotlib.org/basemap/ 2512 2550 [proj]: projection 2513 2551 * 'cyl', cilindric 2552 * 'lcc', lambert-conformal 2514 2553 [res]: resolution: 2515 2554 * 'c', crude … … 2518 2557 * 'h', high 2519 2558 * 'f', full 2559 color= color for the points/labels ('auto', for "red") 2560 labels= list of labels for the points (None, no labels) 2561 lloc = localisation of the legend 2562 kfig= kind of figure (jpg, pdf, png) 2563 figname= name of the figure 2564 2520 2565 """ 2521 2566 fname = 'plot_points' 2522 2523 dx=xval.shape[0] 2524 dy=yval.shape[0] 2567 # Canging line kinds every 7 pts (end of standard colors) 2568 ptkinds=['.','x','o','*','+','8','>','D','h','p','s'] 2569 2570 Npts = len(xval) 2571 if Npts > len(ptkinds)*7: 2572 print errormsg 2573 print ' ' + fname + ': too many',Npts,'points!!' 2574 print " enlarge 'ptkinds' list" 2575 quit(-1) 2576 2577 N7pts = 0 2578 2579 if color == 'auto': 2580 ptcol = "red" 2581 else: 2582 ptcol = color 2583 2584 dx=vlon.shape[1] 2585 dy=vlat.shape[0] 2525 2586 2526 2587 plt.rc('text', usetex=True) 2527 2588 2528 2589 if not mapv is None: 2529 lon00 = np.where(xval[:] < 0., 360. + olon[:], olon[:]) 2530 lat00 = yval[:] 2531 lon0 = np.zeros( (len(lat00),len(lon00)), dtype=np.float ) 2532 lat0 = np.zeros( (len(lat00),len(lon00)), dtype=np.float ) 2533 2534 for iy in range(len(lat00)): 2535 lon0[iy,:] = lon00 2536 for ix in range(len(lon00)): 2537 lat0[:,ix] = lat00 2590 vlon = np.where(vlon[:] < 0., 360. + vlon[:], vlon[:]) 2538 2591 2539 2592 map_proj=mapv.split(',')[0] 2540 2593 map_res=mapv.split(',')[1] 2541 2594 2542 nlon = lon0[0,0]2543 xlon = lon0[dy-1,dx-1]2544 nlat = lat0[0,0]2545 xlat = lat0[dy-1,dx-1]2546 2547 lon2 = lon0[dy/2,dx/2]2548 lat2 = lat0[dy/2,dx/2]2595 nlon = np.min(vlon) 2596 xlon = np.max(vlon) 2597 nlat = np.min(vlat) 2598 xlat = np.max(vlat) 2599 2600 lon2 = vlon[dy/2,dx/2] 2601 lat2 = vlat[dy/2,dx/2] 2549 2602 2550 2603 print 'lon2:', lon2, 'lat2:', lat2, 'SW pt:', nlon, ',', nlat, 'NE pt:', \ … … 2558 2611 llcrnrlat=nlat, urcrnrlon=xlon, urcrnrlat= xlat, resolution=map_res) 2559 2612 2560 lons, lats = np.meshgrid(olon[:], olat[:]) 2561 lons = np.where(lons < 0., lons + 360., lons) 2562 2563 x,y = m(lons,lats) 2564 plt.plot(x,y) 2613 # lons, lats = np.meshgrid(vlon, vlat) 2614 # lons = np.where(lons < 0., lons + 360., lons) 2615 2616 x,y = m(vlon,vlat) 2565 2617 2566 2618 m.drawcoastlines() … … 2571 2623 parallels = pretty_int(nlat,xlat,5) 2572 2624 m.drawparallels(parallels,labels=[False,True,True,False]) 2573 else:2625 # else: 2574 2626 # plt.xlim(0,dx-1) 2575 2627 # plt.ylim(0,dy-1) 2576 2628 2577 plt.plot(xval, yval, '.') 2578 2579 figname = ifile.replace('.','_') + '_' + vtit 2629 # Extra values 2630 if extravals is not None: 2631 plt.pcolormesh(x, y, extravals, cmap=plt.get_cmap(extrapar[3]), \ 2632 vmin=extrapar[1], vmax=extrapar[2]) 2633 cbar = plt.colorbar() 2634 cbar.set_label(extrapar[0].replace('_','\_') +'('+ units_lunits(extrapar[4])+\ 2635 ')') 2636 2637 if labels is not None: 2638 for iv in range(len(xval)): 2639 # plt.annotate(labels[iv], xy=(xval[iv],yval[iv]), xycoords='data') 2640 2641 if np.mod(iv,7) == 0: N7pts = N7pts + 1 2642 # print iv,xval[iv],yval[iv],labels[iv],ptkinds[N7pts] 2643 2644 plt.plot(xval[iv],yval[iv], ptkinds[N7pts],label=labels[iv]) 2645 plt.legend(loc=lloc) 2646 2647 else: 2648 plt.plot(xval, yval, '.', color=ptcol) 2649 2580 2650 graphtit = vtit.replace('_','\_').replace('&','\&') 2581 2651 2582 plt.title(graphtit )2652 plt.title(graphtit.replace('|', ' ')) 2583 2653 2584 2654 output_kind(kfig, figname, True)
Note: See TracChangeset
for help on using the changeset viewer.