Ignore:
Timestamp:
Nov 21, 2011, 1:00:48 PM (13 years ago)
Author:
aslmd
Message:

GRAPHICS: cosmetic cleaning. added possibility to output a 1D profile in a text file through -S txt.

File:
1 edited

Legend:

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

    r401 r402  
    6565                       zoomset,getcoorddef,getwinddef,whatkindfile,reducefield,bounds,getstralt,getfield,smooth,nolow,\
    6666                       getname,localtime,polarinterv,getsindex,define_axis,determineplot,readslices,bidimfind,getlschar
    67     from mymath import deg,max,min,mean,get_tsat
     67    from mymath import deg,max,min,mean,get_tsat,writeascii
    6868    import matplotlib as mpl
    6969    from matplotlib.pyplot import contour,contourf, subplot, figure, rcParams, savefig, colorbar, pcolor, show, plot, clabel, title
     
    135135##########################################################
    136136      if typefile == "gcm":
    137           lat = nc.variables["latitude"][:]
    138           lon = nc.variables["longitude"][:]
    139           if "Time" in nc.variables:
    140              time = nc.variables["Time"][:]
    141           elif "time" in nc.variables:
    142              time = nc.variables["time"][:]
    143           else:
    144              print "no time axis found."
    145              exit()
     137          lat = nc.variables["latitude"][:] ; lon = nc.variables["longitude"][:]
     138          if "Time" in nc.variables:      time = nc.variables["Time"][:]
     139          elif "time" in nc.variables:    time = nc.variables["time"][:]
     140          else:                           errormess("no time axis found.")
    146141          vert = nc.variables["altitude"][:]
    147142      elif typefile in ['meso','mesoapi']:
     
    155150          if varname in ['U']:  londim='WEST-EAST_PATCH_END_STAG'
    156151          else:                 londim='WEST-EAST_PATCH_END_UNSTAG'
    157           lon = np.arange(0,getattr(nc,londim),1)
    158           lat = np.arange(0,getattr(nc,latdim),1)
     152          lon = np.arange(0,getattr(nc,londim),1) ; lat = np.arange(0,getattr(nc,latdim),1)
    159153          if vertmode is None:  vertmode=0
    160154          if vertmode == 0:     vert = np.arange(0,getattr(nc,vertdim),1)
     
    179173         if zoom:                          [wlon,wlat] = zoomset(wlon,wlat,zoom)
    180174
     175      all_varname[k] = varname
     176      all_namefile[k] = namefile
     177      if var2: all_var2[k] = getfield(nc,var2)
    181178      ##### SPECIFIC
    182179      if varname in ["temp","t","T_nadir_nit","T_nadir_day","temp_day","temp_night"] and tsat:
     
    188185      ##### GENERAL STUFF HERE
    189186          all_var[k] = getfield(nc,varname)
    190       all_varname[k] = varname
    191       all_namefile[k] = namefile
    192       if var2: all_var2[k] = getfield(nc,var2)
    193      
    194187      print "********** all_var[k].shape", all_var[k].shape
    195188      k += 1
     
    207200                if ope == "-":     all_var[k+1]= all_var[k-1] - all_var[k]
    208201                elif ope == "+":   all_var[k+1]= all_var[k-1] + all_var[k]
    209                 all_varname[k+1] = all_varname[k]
    210                 numplot = numplot+2
     202                all_varname[k+1] = all_varname[k] ; numplot = numplot+2
    211203             elif ope in ["cat"]:
    212204                tab = all_var[0];k = 1
    213205                while k != len(namefiles)-1:
    214                     tab = np.append(tab,all_var[k],axis=0)
    215                     k += 1
    216                 time = np.arange(0,len(tab),1) ### AS: time reference is simple, should be better
    217                 all_var[0] = np.array(tab);numplot = 1
     206                    tab = np.append(tab,all_var[k],axis=0) ; k += 1
     207                time = np.arange(0,len(tab),1) ### AS: time reference is too simplistic, should be better
     208                all_var[0] = np.array(tab) ; numplot = 1
    218209             elif ope is not None:
    219210                errormess(ope+" : non-implemented operation. Available op. are + and -.")
     
    229220    if itstep is None and numplot > 0: itstep = int(24./numplot)
    230221    elif numplot <= 0:                 itstep = 1
    231    
    232222    print "********************************************"
    233223    while error is False:
     
    270260           indextime = getsindex(stime,((nplot-1)//(nlon*nlat*nvert))%ntime,time) 
    271261
    272        if fileref is not None:
    273            index_f = ((nplot-1)//(nlon*nlat*nvert*ntime))%(len(namefiles)+2)  ## OK only 1 var, see test in the beginning
    274        else:
    275            yeah = len(namefiles)*len(var)
    276            index_f = ((nplot-1)//(nlon*nlat*nvert*ntime))%yeah
    277        #print nlon, nlat, nvert, ntime 
    278        #print slon, slat, svert, stime       
    279        #print index_f
    280        #print "index lon,lat,vert,time", indexlon, indexlat, indexvert, indextime
    281        #if varname != all_varname[index_f]:  indextime = first
     262       if fileref is not None:      index_f = ((nplot-1)//(nlon*nlat*nvert*ntime))%(len(namefiles)+2)  ## OK only 1 var, see test in the beginning
     263       else:                        yeah = len(namefiles)*len(var) ; index_f = ((nplot-1)//(nlon*nlat*nvert*ntime))%yeah
    282264####################################################################
    283265
     
    341323                     #contourf(what_I_plot, zelevels, cmap = palette )
    342324
    343                      if mapmode == 1:
    344                        m.contourf( x, y, what_I_plot, zelevels, cmap = palette)
    345                      elif mapmode == 0:
    346                        contourf( x, y, what_I_plot, zelevels, cmap = palette)
    347 
    348                      zxmin, zxmax = xaxis
    349                      zymin, zymax = yaxis
     325                     if mapmode == 1:       m.contourf( x, y, what_I_plot, zelevels, cmap = palette)
     326                     elif mapmode == 0:     contourf( x, y, what_I_plot, zelevels, cmap = palette)
     327
     328                     zxmin, zxmax = xaxis ; zymin, zymax = yaxis
    350329                     if zxmin is not None: mpl.pyplot.xlim(xmin=zxmin)
    351330                     if zxmax is not None: mpl.pyplot.xlim(xmax=zxmax)
     
    376355               elif len(what_I_plot.shape) is 1:
    377356                 plot(x,what_I_plot)
     357                 if save == 'txt':  writeascii(np.transpose(what_I_plot),'profile'+str(nplot)+'.txt')
     358
    378359               #### Other cases: (maybe plot 3-D field one day or movie ??)
    379360               else:
     
    418399       else:
    419400            if fileref is not None:
    420                 if index_f is numplot-1:
    421                    plottitle = basename+' '+"fig(1) "+ope+" fig(2)"
    422                 elif index_f is numplot-2:
    423                    plottitle = basename+' '+fileref
    424                 else:
    425                    plottitle = basename+' '+namefiles[0]#index_f]
    426             else:
    427                 plottitle = basename+' '+namefiles[0]#index_f]
    428        if mult != 1:           plottitle = str(mult) + "*" + plottitle
    429        if zetitle != "fill":   
     401                if index_f is numplot-1:     plottitle = basename+' '+"fig(1) "+ope+" fig(2)"
     402                elif index_f is numplot-2:   plottitle = basename+' '+fileref
     403                else:                        plottitle = basename+' '+namefiles[0]#index_f]
     404            else:                            plottitle = basename+' '+namefiles[0]#index_f]
     405       if mult != 1:                         plottitle = str(mult) + "*" + plottitle
     406       if zetitle != "fill":                 
    430407          plottitle = zetitle
    431           if titleref is "fill":
    432              titleref=zetitle
     408          if titleref is "fill":             titleref=zetitle
    433409          if fileref is not None:
    434              if index_f is numplot-2:
    435                 plottitle = titleref
    436              if index_f is numplot-1:
    437                 plottitle = "fig(1) "+ope+" fig(2)"
    438 #       if indexlon is not None:
    439 #         plottitle = plottitle + " lon: " + str(min(lon[indexlon])) +" "+ str(max(lon[indexlon]))
    440 #       if indexlat is not None:
    441 #         plottitle = plottitle + " lat: " + str(min(lat[indexlat])) +" "+ str(max(lat[indexlat]))
    442 #       if indexvert is not None:
    443 #         plottitle = plottitle + " vert: " + str(min(vert[indexvert])) +" "+ str(max(vert[indexvert]))
    444 #       if indextime is not None:
    445 #         plottitle = plottitle + " time: " + str(min(time[indextime])) +" "+ str(max(time[indextime]))
     410             if index_f is numplot-2:        plottitle = titleref
     411             if index_f is numplot-1:        plottitle = "fig(1) "+ope+" fig(2)"
     412#       if indexlon is not None:      plottitle = plottitle + " lon: " + str(min(lon[indexlon])) +" "+ str(max(lon[indexlon]))
     413#       if indexlat is not None:      plottitle = plottitle + " lat: " + str(min(lat[indexlat])) +" "+ str(max(lat[indexlat]))
     414#       if indexvert is not None:     plottitle = plottitle + " vert: " + str(min(vert[indexvert])) +" "+ str(max(vert[indexvert]))
     415#       if indextime is not None:     plottitle = plottitle + " time: " + str(min(time[indextime])) +" "+ str(max(time[indextime]))
    446416       title( plottitle )
    447417       itime += itstep
    448        if nplot >= numplot:
    449           error = True
     418       if nplot >= numplot: error = True
    450419       nplot += 1
    451420
     
    480449            if display: makeplotres(zeplot,res=100.,pad_inches_value=pad_inches_value) #,erase=True)  ## a miniature
    481450            makeplotres(zeplot,res=resolution,pad_inches_value=pad_inches_value,disp=False)
    482         elif save in ['eps','svg','pdf']:
    483             makeplotres(zeplot,         pad_inches_value=pad_inches_value,disp=False,ext=save)
    484         elif save == 'gui':
    485             show()
     451        elif save in ['eps','svg','pdf']:     makeplotres(zeplot,pad_inches_value=pad_inches_value,disp=False,ext=save)
     452        elif save == 'gui':                   show()
     453        elif save == 'txt':                   print "Saved results in txt file."
    486454        else:
    487455            print "INFO: save mode not supported. using gui instead."
Note: See TracChangeset for help on using the changeset viewer.