Changeset 571 for trunk


Ignore:
Timestamp:
Mar 7, 2012, 7:20:51 PM (13 years ago)
Author:
aslmd
Message:

UTIL PYTHON: moved windamplitude stuff into a so-called function.

Location:
trunk/UTIL/PYTHON
Files:
3 edited

Legend:

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

    r558 r571  
    2828area = "Whole"
    2929##########################################################################
     30var = ["130"]
     31fieldtype = "3d"
     32lev = ["1000.","900.","800.","700.","600."]
     33tim = ["00"]
     34date = ['01','09','2009','01','09','2009']
     35area = "Whole"
    3036
    3137##########################################################################
  • trunk/UTIL/PYTHON/myplot.py

    r569 r571  
    9191          else:out=field
    9292    return out
     93
     94## Author: AC
     95def windamplitude (nc)
     96    varinfile = nc.variables.keys()
     97    if "U" in varinfile: zu=getfield(nc,'U')
     98    elif "Um" in varinfile: zu=getfield(nc,'Um')
     99    if "V" in varinfile: zv=getfield(nc,'V')
     100    elif "Vm" in varinfile: zv=getfield(nc,'Vm')
     101    znt,znz,zny,znx = np.array(zu).shape
     102    if "U" in varinfile:znx=znx-1
     103    zuint = np.zeros([znt,znz,zny,znx])
     104    zvint = np.zeros([znt,znz,zny,znx])
     105    if "U" in varinfile:
     106       for xx in np.arange(znx):      zuint[:,:,:,xx] = (zu[:,:,:,xx] + zu[:,:,:,xx+1])/2.
     107       for yy in np.arange(zny):      zvint[:,:,yy,:] = (zv[:,:,yy,:] + zv[:,:,yy+1,:])/2.
     108    else:
     109       zuint=zu
     110       zvint=zv
     111    return np.sqrt(zuint**2 + zvint**2)
    93112
    94113## Author: AS + TN + AC
  • trunk/UTIL/PYTHON/planetoplot.py

    r570 r571  
    274274      if var2: all_var2[k] = getfield(nc,var2)
    275275      if winds: all_windu[k] = getfield(nc,uchar) ; all_windv[k] = getfield(nc,vchar)
    276       ##### SPECIFIC
     276      #####################
     277      ##### GETFIELDS #####
     278      #####################
     279      ##### SPECIFIC CASES
     280      ##### 1. saturation temperature
    277281      if varname in ["temp","t","T_nadir_nit","T_nadir_day","temp_day","temp_night"] and tsat:
    278282          tt=getfield(nc,varname) ; print "computing Tsat-T, I ASSUME Z-AXIS IS PRESSURE"
     
    280284          else:                                 tinput=tt
    281285          all_var[k]=get_tsat(vert,tinput,zlon=lon,zlat=lat,zalt=vert,ztime=time)
     286      ##### 2. wind amplitude
     287      elif ((varname in ['UV','uv','uvmet']) and (typefile in ['meso']) and (varname not in nc.variables)):
     288          all_var[k]=windamplitude(nc)
    282289      else:
    283290      ##### GENERAL STUFF HERE
    284           if ((varname in ['UV','uv','uvmet']) and (typefile in ['meso']) and (varname not in nc.variables)):
    285              if "U" in varinfile: zu=getfield(nc,'U')
    286              elif "Um" in varinfile: zu=getfield(nc,'Um')
    287              if "V" in varinfile: zv=getfield(nc,'V')
    288              elif "Vm" in varinfile: zv=getfield(nc,'Vm')
    289              znt,znz,zny,znx = np.array(zu).shape
    290              if "U" in varinfile:znx=znx-1
    291              zuint = np.zeros([znt,znz,zny,znx])
    292              zvint = np.zeros([znt,znz,zny,znx])
    293              if "U" in varinfile:
    294                 for xx in np.arange(znx):
    295                     zuint[:,:,:,xx] = (zu[:,:,:,xx] + zu[:,:,:,xx+1])/2.
    296                 for yy in np.arange(zny):
    297                     zvint[:,:,yy,:] = (zv[:,:,yy,:] + zv[:,:,yy+1,:])/2.
    298              else:
    299                     zuint=zu
    300                     zvint=zv
    301              all_var[k] = np.sqrt(zuint**2 + zvint**2)
    302           else:
    303              all_var[k] = getfield(nc,varname)
    304 
     291          all_var[k] = getfield(nc,varname)
    305292      print "**** GOT SUBDATA:",k," NAMEFILE:",namefile," VAR:",varname, var2 ; k += 1 ; firstfile = False
    306293      #### End of for namefile in namefiles
     
    314301             if ope in ["-","+","-%"]:
    315302                if fileref is not None:   
    316 
    317                    if ((all_varname[k-1] in ['UV','uv','uvmet']) and (typefile in ['meso']) and (all_varname[k-1] not in Dataset(fileref).variables)):
    318                       if "U" in varinfile: zu=getfield(Dataset(fileref),'U')
    319                       elif "Um" in varinfile: zu=getfield(Dataset(fileref),'Um')
    320                       if "V" in varinfile: zv=getfield(Dataset(fileref),'V')
    321                       elif "Vm" in varinfile: zv=getfield(Dataset(fileref),'Vm')
    322                       znt,znz,zny,znx = np.array(zu).shape
    323                       if "U" in varinfile:znx=znx-1
    324                       zuint = np.zeros([znt,znz,zny,znx])
    325                       zvint = np.zeros([znt,znz,zny,znx])
    326                       if "U" in varinfile:
    327                          for xx in np.arange(znx):
    328                              zuint[:,:,:,xx] = (zu[:,:,:,xx] + zu[:,:,:,xx+1])/2.
    329                          for yy in np.arange(zny):
    330                              zvint[:,:,yy,:] = (zv[:,:,yy,:] + zv[:,:,yy+1,:])/2.
    331                       else:
    332                          zuint=zu
    333                          zvint=zv
    334                       all_var[k] = np.sqrt(zuint**2 + zvint**2)
     303                   ncref = Dataset(fileref)
     304                   if ((all_varname[k-1] in ['UV','uv','uvmet']) and (typefile in ['meso']) and (all_varname[k-1] not in ncref.variables)):
     305                      all_var[k] = windamplitude(ncref)
    335306                   else:
    336                       all_var[k] = getfield(Dataset(fileref),all_varname[k-1])
    337          
     307                      all_var[k] = getfield(ncref,all_varname[k-1])
    338308                   all_varname[k] = all_varname[k-1] ; all_time[k] = all_time[k-1] ; all_namefile[k] = all_namefile[k-1] ; all_var2[k] = all_var2[k-1]
    339 
    340309                else: errormess("fileref is missing!")
    341310                if ope == "-":     all_var[k+1]= all_var[k-1] - all_var[k]
     
    510479
    511480                    if which == "unidim":
    512                         #lbls = ["<TH+RiSL+MY4> tau=0.5","<Convadj> tau=0.5","<TH+RiSL+MY4> tau=1","<Convadj> tau=1"]
    513481                        lbl = ""
    514482                        if indexlat is not None:  lbl = lbl + " ix" + str(indexlat[0])
Note: See TracChangeset for help on using the changeset viewer.