Changeset 687


Ignore:
Timestamp:
Jun 2, 2012, 1:16:31 AM (13 years ago)
Author:
aslmd
Message:

UTIL PYTHON 1. make planetoplot work for API-generated files directly 2. if there is a problem with areas the program keeps on moving and print a warning while setting mesharea and totalarea to 1 so that it is harmless

Location:
trunk/UTIL/PYTHON
Files:
2 edited

Legend:

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

    r647 r687  
    194194        elif max(d1) >= shape[1]: error = True
    195195        elif d1 is not None and d2 is not None:
    196           totalarea = np.ma.masked_where(getmask(output),mesharea)
    197           totalarea = mean(totalarea[d2,:],axis=0);totalarea = mean(totalarea[d1])
     196          try:
     197            totalarea = np.ma.masked_where(getmask(output),mesharea)
     198            totalarea = mean(totalarea[d2,:],axis=0);totalarea = mean(totalarea[d1])
     199          except: print "(problem with areas. I skip this)" ; mesharea = 1. ; totalarea = 1.
    198200          output = output*mesharea; output = mean(output[d2,:],axis=0); output = mean(output[d1])/totalarea
    199201        elif d1 is not None:         output = mean(input[:,d1],axis=1)
    200202        elif d2 is not None:
    201           totalarea = np.ma.masked_where(getmask(output),mesharea)
    202           totalarea = mean(totalarea[d2,:],axis=0)
     203          try:
     204            totalarea = np.ma.masked_where(getmask(output),mesharea)
     205            totalarea = mean(totalarea[d2,:],axis=0)
     206          except: print "(problem with areas. I skip this)" ; mesharea = 1. ; totalarea = 1.
    203207          output = output*mesharea; output = mean(output[d2,:],axis=0)/totalarea
    204208    elif dimension == 3:
     
    209213        elif d4 is not None and d2 is not None and d1 is not None:
    210214          output = mean(input[d4,:,:],axis=0)
    211           totalarea = np.ma.masked_where(getmask(output),mesharea)
    212           totalarea = mean(totalarea[d2,:],axis=0);totalarea = mean(totalarea[d1])
     215          try:
     216            totalarea = np.ma.masked_where(getmask(output),mesharea)
     217            totalarea = mean(totalarea[d2,:],axis=0);totalarea = mean(totalarea[d1])
     218          except: print "(problem with areas. I skip this)" ; mesharea = 1. ; totalarea = 1.
    213219          output = output*mesharea; output = mean(output[d2,:],axis=0); output = mean(output[d1])/totalarea
    214220        elif d4 is not None and d2 is not None:
    215221          output = mean(input[d4,:,:],axis=0)
    216           totalarea = np.ma.masked_where(getmask(output),mesharea)
    217           totalarea = mean(totalarea[d2,:],axis=0)
     222          try:
     223            totalarea = np.ma.masked_where(getmask(output),mesharea)
     224            totalarea = mean(totalarea[d2,:],axis=0)
     225          except: print "(problem with areas. I skip this)" ; mesharea = 1. ; totalarea = 1.
    218226          output = output*mesharea; output = mean(output[d2,:],axis=0)/totalarea
    219227        elif d4 is not None and d1 is not None:    output = mean(input[d4,:,:],axis=0); output=mean(output[:,d1],axis=1)
    220228        elif d2 is not None and d1 is not None:
    221           totalarea = np.tile(mesharea,(output.shape[0],1,1))
    222           totalarea = np.ma.masked_where(getmask(output),totalarea)
    223           totalarea = mean(totalarea[:,d2,:],axis=1);totalarea = mean(totalarea[:,d1],axis=1)
     229          try:
     230            totalarea = np.tile(mesharea,(output.shape[0],1,1))
     231            totalarea = np.ma.masked_where(getmask(output),totalarea)
     232            totalarea = mean(totalarea[:,d2,:],axis=1);totalarea = mean(totalarea[:,d1],axis=1)
     233          except: print "(problem with areas. I skip this)" ; mesharea = 1. ; totalarea = 1.
    224234          output = output*mesharea; output = mean(output[:,d2,:],axis=1); output = mean(output[:,d1],axis=1)/totalarea
    225235        elif d1 is not None:   output = mean(input[:,:,d1],axis=2)
    226236        elif d2 is not None:   
    227           totalarea = np.tile(mesharea,(output.shape[0],1,1))
    228           totalarea = np.ma.masked_where(getmask(output),totalarea)
    229           totalarea = mean(totalarea[:,d2,:],axis=1)
     237          try:
     238            totalarea = np.tile(mesharea,(output.shape[0],1,1))
     239            totalarea = np.ma.masked_where(getmask(output),totalarea)
     240            totalarea = mean(totalarea[:,d2,:],axis=1)
     241          except: print "(problem with areas. I skip this)" ; mesharea = 1. ; totalarea = 1.
    230242          output = output*mesharea; output = mean(output[:,d2,:],axis=1)/totalarea
    231243        elif d4 is not None:   output = mean(input[d4,:,:],axis=0)
     
    240252             output = reduce_zaxis(output[d3,:,:],ax=0,yint=yint,vert=alt,indice=d3)
    241253             if anomaly: output = 100. * ((output / smooth(output,csmooth)) - 1.)
    242              totalarea = np.ma.masked_where(np.isnan(output),mesharea)
    243              totalarea = mean(totalarea[d2,:],axis=0); totalarea = mean(totalarea[d1])
     254             try:
     255               totalarea = np.ma.masked_where(np.isnan(output),mesharea)
     256               totalarea = mean(totalarea[d2,:],axis=0); totalarea = mean(totalarea[d1])
     257             except: print "(problem with areas. I skip this)" ; mesharea = 1. ; totalarea = 1.
    244258             output = output*mesharea; output = mean(output[d2,:],axis=0); output = mean(output[d1])/totalarea
    245259        elif d4 is not None and d3 is not None and d2 is not None:
     
    247261             output = reduce_zaxis(output[d3,:,:],ax=0,yint=yint,vert=alt,indice=d3)
    248262             if anomaly: output = 100. * ((output / smooth(output,csmooth)) - 1.)
    249              totalarea = np.ma.masked_where(np.isnan(output),mesharea)
    250              totalarea = mean(totalarea[d2,:],axis=0)
     263             try:
     264               totalarea = np.ma.masked_where(np.isnan(output),mesharea)
     265               totalarea = mean(totalarea[d2,:],axis=0)
     266             except: print "(problem with areas. I skip this)" ; mesharea = 1. ; totalarea = 1.
    251267             output = output*mesharea; output = mean(output[d2,:],axis=0)/totalarea
    252268        elif d4 is not None and d3 is not None and d1 is not None:
     
    259275             if anomaly:
    260276                 for k in range(output.shape[0]):  output[k,:,:] = 100. * ((output[k,:,:] / smooth(output[k,:,:],csmooth)) - 1.)
    261              totalarea = np.tile(mesharea,(output.shape[0],1,1))
    262              totalarea = np.ma.masked_where(getmask(output),mesharea)
    263              totalarea = mean(totalarea[:,d2,:],axis=1); totalarea = mean(totalarea[:,d1],axis=1)
     277             try:
     278               totalarea = np.tile(mesharea,(output.shape[0],1,1))
     279               totalarea = np.ma.masked_where(getmask(output),mesharea)
     280               totalarea = mean(totalarea[:,d2,:],axis=1); totalarea = mean(totalarea[:,d1],axis=1)
     281             except: print "(problem with areas. I skip this)" ; mesharea = 1. ; totalarea = 1.
    264282             output = output*mesharea; output = mean(output[:,d2,:],axis=1); output = mean(output[:,d1],axis=1)/totalarea
    265283             #noperturb = smooth1d(output,window_len=7)
     
    270288             if anomaly:
    271289                 for k in range(output.shape[0]):  output[k,:,:] = 100. * ((output[k,:,:] / smooth(output[k,:,:],csmooth)) - 1.)
    272              totalarea = np.tile(mesharea,(output.shape[0],1,1))
    273              totalarea = np.ma.masked_where(getmask(output),totalarea)
    274              totalarea = mean(totalarea[:,d2,:],axis=1); totalarea = mean(totalarea[:,d1],axis=1)
     290             try:
     291               totalarea = np.tile(mesharea,(output.shape[0],1,1))
     292               totalarea = np.ma.masked_where(getmask(output),totalarea)
     293               totalarea = mean(totalarea[:,d2,:],axis=1); totalarea = mean(totalarea[:,d1],axis=1)
     294             except: print "(problem with areas. I skip this)" ; mesharea = 1. ; totalarea = 1.
    275295             output = output*mesharea; output = mean(output[:,d2,:],axis=1); output = mean(output[:,d1],axis=1)/totalarea
    276296        elif d4 is not None and d3 is not None: 
     
    280300        elif d4 is not None and d2 is not None: 
    281301             output = mean(input[d4,:,:,:],axis=0)
    282              totalarea = np.tile(mesharea,(output.shape[0],1,1))
    283              totalarea = np.ma.masked_where(getmask(output),mesharea)
    284              totalarea = mean(totalarea[:,d2,:],axis=1)
     302             try:
     303               totalarea = np.tile(mesharea,(output.shape[0],1,1))
     304               totalarea = np.ma.masked_where(getmask(output),mesharea)
     305               totalarea = mean(totalarea[:,d2,:],axis=1)
     306             except: print "(problem with areas. I skip this)" ; mesharea = 1. ; totalarea = 1.
    285307             output = output*mesharea; output = mean(output[:,d2,:],axis=1)/totalarea
    286308        elif d4 is not None and d1 is not None: 
     
    289311        elif d3 is not None and d2 is not None:
    290312             output = reduce_zaxis(input[:,d3,:,:],ax=1,yint=yint,vert=alt,indice=d3)
    291              totalarea = np.tile(mesharea,(output.shape[0],1,1))
    292              totalarea = np.ma.masked_where(getmask(output),mesharea)
    293              totalarea = mean(totalarea[:,d2,:],axis=1)
     313             try:
     314               totalarea = np.tile(mesharea,(output.shape[0],1,1))
     315               totalarea = np.ma.masked_where(getmask(output),mesharea)
     316               totalarea = mean(totalarea[:,d2,:],axis=1)
     317             except: print "(problem with areas. I skip this)" ; mesharea = 1. ; totalarea = 1.
    294318             output = output*mesharea; output = mean(output[:,d2,:],axis=1)/totalarea
    295319        elif d3 is not None and d1 is not None: 
     
    297321             output = mean(output[:,:,d1],axis=2)
    298322        elif d2 is not None and d1 is not None:
    299              totalarea = np.tile(mesharea,(output.shape[0],output.shape[1],1,1))
    300              totalarea = np.ma.masked_where(getmask(output),totalarea)
    301              totalarea = mean(totalarea[:,:,d2,:],axis=2); totalarea = mean(totalarea[:,:,d1],axis=1)
     323             try:
     324               totalarea = np.tile(mesharea,(output.shape[0],output.shape[1],1,1))
     325               totalarea = np.ma.masked_where(getmask(output),totalarea)
     326               totalarea = mean(totalarea[:,:,d2,:],axis=2); totalarea = mean(totalarea[:,:,d1],axis=1)
     327             except: print "(problem with areas. I skip this)" ; mesharea = 1. ; totalarea = 1.
    302328             output = output*mesharea; output = mean(output[:,:,d2,:],axis=2); output = mean(output[:,:,d1],axis=1)/totalarea
    303329        elif d1 is not None:        output = mean(input[:,:,:,d1],axis=3)
    304330        elif d2 is not None:
    305              totalarea = np.tile(mesharea,(output.shape[0],output.shape[1],1,output.shape[3]))
    306              totalarea = np.ma.masked_where(getmask(output),totalarea)
    307              totalarea = mean(totalarea[:,:,d2,:],axis=2)
     331             try:
     332               totalarea = np.tile(mesharea,(output.shape[0],output.shape[1],1,output.shape[3]))
     333               totalarea = np.ma.masked_where(getmask(output),totalarea)
     334               totalarea = mean(totalarea[:,:,d2,:],axis=2)
     335             except: print "(problem with areas. I skip this)" ; mesharea = 1. ; totalarea = 1.
    308336             output = output*mesharea; output = mean(output[:,:,d2,:],axis=2)/totalarea
    309337        elif d3 is not None:        output = reduce_zaxis(input[:,d3,:,:],ax=1,yint=yint,vert=alt,indice=d3)
     
    407435    from numpy import array
    408436    from string import rstrip
    409     namefile = rstrip( rstrip( rstrip( namefile, chars="_z"), chars="_zabg"), chars="_p")
    410     #### we assume that wrfout is next to wrfout_z and wrfout_zabg
    411     nc  = Dataset(namefile)
     437    import os as daos
     438    namefiletest = rstrip( rstrip( rstrip( namefile, chars="_z"), chars="_zabg"), chars="_p")
     439    testexist = daos.path.isfile(namefiletest)
    412440    zetime = None
    413     days_in_month = [61, 66, 66, 65, 60, 54, 50, 46, 47, 47, 51, 56]
    414     plus_in_month = [ 0, 61,127,193,258,318,372,422,468,515,562,613]
    415     if 'Times' in nc.variables:
     441    if testexist: 
     442      namefile = namefiletest
     443      #### we assume that wrfout is next to wrfout_z and wrfout_zabg
     444      nc  = Dataset(namefile)
     445      zetime = None
     446      days_in_month = [61, 66, 66, 65, 60, 54, 50, 46, 47, 47, 51, 56]
     447      plus_in_month = [ 0, 61,127,193,258,318,372,422,468,515,562,613]
     448      if 'Times' in nc.variables:
    416449        zetime = nc.variables['Times'][0]
    417450        shape = array(nc.variables['Times']).shape
  • trunk/UTIL/PYTHON/planetoplot.py

    r673 r687  
    271271          else:
    272272              if vertmode is None:  vertmode=0
    273               if vertmode == 0:     vert = np.arange(0,getattr(nc,vertdim),1)
     273              if vertmode == 0:     
     274                  if "vert" in nc.variables: vert = nc.variables["vert"][:]/1000. ; vertmode = 1
     275                  else:                      vert = np.arange(0,getattr(nc,vertdim),1)
    274276              elif vertmode == -1:  vert = nc.variables["PHTOT"][0,:,0,0]/3.72 ; vert = np.array(vert[0:len(vert)-1]) #; print vert
    275277              elif vertmode == 1 or vertmode == 2:  vert = nc.variables["vert"][:]        ## pressure in Pa
Note: See TracChangeset for help on using the changeset viewer.