Changeset 490


Ignore:
Timestamp:
Jan 4, 2012, 1:25:44 AM (14 years ago)
Author:
aslmd
Message:

UTIL PYTHON: several lat/lon now works for mesoscale in 1D mode. also added a capability to plot wind module if one of the wind component is asked as field. some stuff was added as commented for demonstration

Location:
trunk/UTIL/PYTHON
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/UTIL/PYTHON/myplot.py

    r489 r490  
    751751             "QSURFICE":     "%.0f",\
    752752             "UM":           "%.0f",\
     753             "WIND":         "%.0f",\
    753754             "ALBBARE":      "%.2f",\
    754755             "TAU":          "%.1f",\
     
    779780             "QH2O":         "PuBu",\
    780781             "USTM":         "YlOrRd",\
     782             "WIND":         "YlOrRd",\
    781783             #"T_nadir_nit":  "RdBu_r",\
    782784             #"T_nadir_day":  "RdBu_r",\
  • trunk/UTIL/PYTHON/planetoplot.py

    r489 r490  
    7676    from matplotlib.pyplot import contour,contourf, subplot, figure, rcParams, savefig, colorbar, pcolor, show, plot, clabel, title, close, legend, xlabel, axis
    7777    from matplotlib.cm import get_cmap
     78    #from mpl_toolkits.basemap import cm
    7879    import numpy as np
    7980    from numpy.core.defchararray import find
    8081    from videosink import VideoSink
    8182    import subprocess
     83    #from singlet import singlet
    8284
    8385    ################################
     
    9496    ################################
    9597    nlon, nlat, nvert, ntime, mapmode, nslices = determineplot(slon, slat, svert, stime)
    96     vlon = None ; vlat = None
    97     if slon is not None: vlon = slon[0][0]
    98     if slat is not None: vlat = slat[0][0]
    9998    if mrate is not None and len(var) > 1: errormess("multivar not allowed in movies. should be fixed soon!")
    10099    zelen = len(namefiles)*len(var)
     
    157156         elif zarea is not None: [wlon,wlat] = latinterv(area=zarea)
    158157
    159 ########################################################## LOAD 4D DIMENSIONS : x, y, z, t
     158##########################################################
     159############ LOAD 4D DIMENSIONS : x, y, z, t #############
     160##########################################################
    160161      if typefile == "gcm":
    161           lat = nc.variables["latitude"][:] ; lon = nc.variables["longitude"][:]
     162          lat = nc.variables["latitude"][:] ; lon = nc.variables["longitude"][:] ; vert = nc.variables["altitude"][:]
    162163          if "Time" in nc.variables:      time = nc.variables["Time"][:]
    163164          elif "time" in nc.variables:    time = nc.variables["time"][:]
    164165          else:                           errormess("no time axis found.")
    165           vert = nc.variables["altitude"][:]
    166166          if axtime in ["ls","sol"]:   errormess("not supported. should not be too difficult though.")
    167167      elif typefile in ['meso','mesoapi','geo','mesoideal']:
    168           ### the following lines are kind of dirty... not possible to ask for several lats and lons
    169           if vlon is not None or vlat is not None:   
    170               if firstfile:  iwantawhereplot = nc
    171               else:          iwantawhereplot = None
    172               indices = bidimfind(lon2d,lat2d,vlon,vlat,file=iwantawhereplot)  #placer un point sur carte
    173               lonp,latp = ( lon2d[indices[0],indices[1]] , lat2d[indices[0],indices[1]] )
     168          ###### STUFF TO GET THE CORRECT LAT/LON FROM MESOSCALE FILES WITH 2D LAT/LON ARRAYS
     169          ###### principle: calculate correct indices then repopulate slon and slat
     170          if slon is not None or slat is not None:
     171              if firstfile and save == 'png' and typefile == 'meso':   iwantawhereplot = nc     #show a topo map with a cross on the chosen point
     172              else:                                                    iwantawhereplot = None   #do not show anything, just select indices
     173              numlon = 1 ; numlat = 1
     174              if slon is not None:   numlon = slon.shape[0]   
     175              if slat is not None:   numlat = slat.shape[0]
     176              indices = np.ones([numlon,numlat,2]) ; vlon = None ; vlat = None
     177              for iii in range(numlon): 
     178               for jjj in range(numlat):
     179                 if slon is not None:  vlon = slon[iii][0]  ### note: slon[:][0] does not work
     180                 if slat is not None:  vlat = slat[jjj][0]  ### note: slon[:][0] does not work
     181                 indices[iii,jjj,:] = bidimfind(lon2d,lat2d,vlon,vlat,file=iwantawhereplot) 
     182                 lonp,latp = ( lon2d[indices[iii,jjj,0],indices[iii,jjj,1]] , lat2d[indices[iii,jjj,0],indices[iii,jjj,1]] )
     183                 #print vlon, lonp, vlat, latp
     184              for iii in range(numlon):
     185               for jjj in range(numlat):
     186                 if slon is not None: slon[iii][0] = indices[iii,0,1] ; slon[iii][1] = indices[iii,0,1]  #...this is idx
     187                 if slat is not None: slat[jjj][0] = indices[0,jjj,0] ; slat[jjj][1] = indices[0,jjj,0]  #...this is idy
     188              lonp,latp = ( lon2d[indices[0,0,0],indices[0,0,1]] , lat2d[indices[0,0,0],indices[0,0,1]] )
     189          ######
    174190          if typefile in ['mesoapi','meso'] and mapmode == 1: lon2d = dumpbdy(lon2d,6) ; lat2d = dumpbdy(lat2d,6)  ### important to do that now and not before
    175           if slon is not None: slon[0][0] = indices[1] ; slon[0][1] = indices[1]  #...this is idx
    176           if slat is not None: slat[0][0] = indices[0] ; slat[0][1] = indices[0]  #...this is idy
     191          ######
    177192          if varname in ['PHTOT','W']:    vertdim='BOTTOM-TOP_PATCH_END_STAG'
    178193          else:                           vertdim='BOTTOM-TOP_PATCH_END_UNSTAG'
    179           if (var2 is not None and var2 not in ['PHTOT','W']):
    180                vertdim='BOTTOM-TOP_PATCH_END_UNSTAG'
    181                dumped_vert_stag=True
    182           else: dumped_vert_stag=False
     194          if (var2 is not None and var2 not in ['PHTOT','W']): dumped_vert_stag=True ; vertdim='BOTTOM-TOP_PATCH_END_UNSTAG'
     195          else:                                                dumped_vert_stag=False
    183196          if varname in ['V']:  latdim='SOUTH-NORTH_PATCH_END_STAG'
    184197          else:                 latdim='SOUTH-NORTH_PATCH_END_UNSTAG'
     
    213226       #   errormess("Not the same latitudes !", [lat,lat0])
    214227       ## Faire d'autre checks sur les compatibilites entre fichiers!!
     228##########################################################
     229##########################################################
    215230##########################################################
    216231
     
    297312       if typefile in ['mesoapi','meso'] and indextime is not None:  ltst = localtime ( interv[0]+indextime*interv[1], 0.5*(wlon[0]+wlon[1]) ) 
    298313       print "********** INDEX LON:",indexlon," LAT:",indexlat," VERT:",indexvert," TIME:",indextime
    299        #var = nc.variables["phisinit"][:,:]
    300        #contourf(np.transpose(var),30,cmap = get_cmap(name="Greys_r") ) ; axis('off') ; plot(indexlat,indexlon,'mx',mew=4.0,ms=20.0)
    301        #show()
    302        #exit()
     314       ##var = nc.variables["phisinit"][:,:]
     315       ##contourf(np.transpose(var),30,cmap = get_cmap(name="Greys_r") ) ; axis('off') ; plot(indexlat,indexlon,'mx',mew=4.0,ms=20.0)
     316       ##show()
     317       ##exit()
     318       #truc = True
     319       #truc = False
     320       #if truc: indexvert = None
    303321       ####################################################################
    304322       ########## REDUCE FIELDS
     
    316334           vecx, error = reducefield( all_windu[index_f], d4=indextime, d3=indexvert, yint=yintegral, alt=vert)
    317335           vecy, error = reducefield( all_windv[index_f], d4=indextime, d3=indexvert, yint=yintegral, alt=vert)
     336           if varname in [uchar,vchar]: what_I_plot = np.sqrt( np.square(vecx) + np.square(vecy) ) ; varname = "wind"
     337
     338       #####################################################################
     339       #if truc:
     340       #   nx = what_I_plot.shape[2] ; ny = what_I_plot.shape[1] ; nz = what_I_plot.shape[0]
     341       #   for k in range(nz): print k,' over ',nz ; what_I_plot[k,:,:] = what_I_plot[k,:,:] / smooth(what_I_plot[k,:,:],12)
     342       #   for iii in range(nx):
     343       #    for jjj in range(ny):
     344       #     deviation = what_I_plot[:,jjj,iii] ; mx = max(deviation) ; mn = min(deviation)
     345       #     if iii > 6 and iii < nx-6 and jjj > 6 and jjj < ny-6:   what_I_plot[0,jjj,iii],rel = singlet(deviation,vert/1000.)  ### z must be in km
     346       #     else:                                                   what_I_plot[0,jjj,iii]     = 0.
     347       #     if np.abs(what_I_plot[0,jjj,iii]) > 1.5:
     348       #         print iii,jjj,what_I_plot[0,jjj,iii],int(abs(1.-mx)*100.),int(abs(1.-mn)*100.)
     349       #         plot(rel)
     350       #   show()
     351       #   anomaly = True ### pour avoir les bons reglages plots
     352       #   what_I_plot = what_I_plot[0,:,:] 
     353       #####################################################################
     354
    318355       ####################################################################
    319356       ### General plot settings
     
    340377               if colorb in ["def","nobar"]:                           palette = get_cmap(name=defcolorb(fvar.upper()))
    341378               else:                                                   palette = get_cmap(name=colorb)
     379               #palette = cm.GMT_split
    342380               ##### 1. ELIMINATE 0D or >3D CASES
    343381               if len(what_I_plot.shape) == 0:   
     
    391429                        if indextime is not None: lbl = lbl + " it" + str(indextime[0])
    392430                        if mrate is not None: x = y  ## because swapaxes...
     431                        #what_I_plot_frame = np.diff(what_I_plot_frame, n=1) ; x = x[1:]
    393432                        if indexvert is not None or indextime is None:    plot(x,what_I_plot_frame,label=lbl)  ## regular plot
    394433                        else:                                             plot(what_I_plot_frame,x,label=lbl)  ## vertical profile
Note: See TracChangeset for help on using the changeset viewer.