Ignore:
Timestamp:
Mar 14, 2012, 1:22:19 AM (13 years ago)
Author:
aslmd
Message:

PYTHON UTIL. improved comments for the first part. corrected a bug: for 3D fields xyt it was necessary to add --vert 0 to have x,y,or t as abscissae, this is no longer the case.

File:
1 edited

Legend:

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

    r578 r579  
    1010### A. Spiga     -- LMD --    12/2011 -- Added HTML animated page capability + general tests of consistency [winds, etc...] + consistent generic movie loop
    1111### J. Leconte   -- LMD --    02/2012 -- Added area weighted averaging. Compatibility with terrestrial gcm.
     12### A. Spiga     -- LMD --    03/2012 -- Cleaning and improved comments
    1213def planetoplot (namefiles,\
    1314           level=0,\
     
    8687    #from singlet import singlet
    8788
    88     ################################
    89     ### Preliminary stuff
    90     ################################
     89#########################
     90### PRELIMINARY STUFF ###
     91#########################
     92### we say hello
    9193    print "********************************************"
    9294    print "********** WELCOME TO PLANETOPLOT **********"
    9395    print "********************************************"
     96### we ensure namefiles and var are arrays
    9497    if not isinstance(namefiles, np.ndarray): namefiles = [namefiles]
    9598    if not isinstance(var, np.ndarray):       var = [var]
    96     initime=-1
    97 
    98     ################################
    99     ### Which plot needs to be done?
    100     ################################
    101     sslon = None ; sslat = None
     99### we initialize a few variables
     100    initime=-1 ; sslon = None ; sslat = None
     101    k = 0 ; firstfile = True ; count = 0
     102### we avoid specific cases not yet implemented
     103    if mrate is not None and len(var) > 1: errormess("multivar not allowed in movies. should be fixed soon!")
     104### we prepare number of plot fields [zelen] and plot instances [numplot] according to user choices
     105### --> we support multifile and multivar plots : files + vars separated by commas are on the same figure
    102106    nlon, nlat, nvert, ntime, mapmode, nslices = determineplot(slon, slat, svert, stime)
    103     if mrate is not None and len(var) > 1: errormess("multivar not allowed in movies. should be fixed soon!")
    104107    zelen = len(namefiles)*len(var)
    105108    numplot = zelen*nslices
    106109    print "********** FILES, SLICES, VARS, TOTAL PLOTS: ", len(namefiles), nslices, len(var), numplot
     110    print "********** MAPMODE: ", mapmode
     111### we correct number of plot fields for possible operation (substract, etc...)
    107112    if ope is not None:
    108113        if fileref is not None:       zelen = zelen + 2
    109114        elif "var" in ope:            zelen = zelen + 1
    110     all_var  = [[]]*zelen ; all_var2  = [[]]*zelen ; all_title = [[]]*zelen ; all_varname = [[]]*zelen ; all_namefile = [[]]*zelen ; all_time = [[]]*zelen ; all_windu = [[]]*zelen ; all_windv = [[]]*zelen
     115### we define the arrays for plot fields -- which will be placed within multiplot loops
     116    all_var  = [[]]*zelen ; all_var2  = [[]]*zelen
     117    all_title = [[]]*zelen ; all_varname = [[]]*zelen ; all_namefile = [[]]*zelen ; all_time = [[]]*zelen
     118    all_windu = [[]]*zelen ; all_windv = [[]]*zelen
    111119 
    112     #################################################################################################
    113     ### Loop over the files + vars initially separated by commas to be plotted on the same figure ###
    114     #################################################################################################
    115     k = 0 ; firstfile = True ; count = 0
     120#############################
     121### LOOP OVER PLOT FIELDS ###
     122#############################
    116123    for nnn in range(len(namefiles)):
    117124     for vvv in range(len(var)):
    118125
    119       ######################
    120       ### Load NETCDF object
     126    ### we load each NETCDF objects in namefiles
    121127      namefile = namefiles[nnn]
    122128      nc  = Dataset(namefile)
     129    ### we explore the variables in the file
    123130      varinfile = nc.variables.keys()
    124131      if seevar: print varinfile ; exit()
    125 
    126       ##################################
    127       ### Initial checks and definitions
    128       ### ... TYPEFILE
     132    ### we define the type of file we have (gcm, meso, etc...)
    129133      typefile = whatkindfile(nc)
     134      if firstfile:                 typefile0 = typefile
     135      elif typefile != typefile0:   errormess("Not the same kind of files !", [typefile0, typefile])
     136    ### we care for input file being 1D simulations
    130137      if typefile in ['gcm'] and len(nc.variables["longitude"][:]) is 1 and len(nc.variables["latitude"][:]) is 1:       mapmode=0 ; winds=False
    131138      elif typefile in ['earthgcm'] and len(nc.variables["lon"][:]) is 1 and len(nc.variables["lat"][:]) is 1:           mapmode=0 ; winds=False
     139    ### we create default vert and time prescriptions if not here in case mapping mode is on (lat/lon maps)
    132140      if redope is None and mapmode == 1:
    133141          if svert is None:  svert = readslices(str(level)) ; nvert=1
     
    135143             stime = readslices(str(0)) ; ntime=1 ## this is a default choice
    136144             print "WELL... nothing about time axis. I took default: first time reference stored in file."
    137 
    138       if firstfile: print "********** MAPMODE: ", mapmode
    139       if firstfile:                 typefile0 = typefile
    140       elif typefile != typefile0:   errormess("Not the same kind of files !", [typefile0, typefile])
    141       ### ... VAR
     145    ### we get the names of variables to be read. in case only one available, we choose this one.
    142146      varname=var[vvv]
    143147      if ((varname not in nc.variables) and not ((typefile in ['meso']) and (varname in ['UV','uv','uvmet']))):
    144148          if len(varinfile) == 1:   varname = varinfile[0]
    145149          else:                     varname = False
    146       ### ... WINDS
     150    ### we get the names of wind variables to be read (if any)
    147151      if winds:                                                   
    148152         [uchar,vchar,metwind] = getwinddef(nc)             
    149153         if uchar == 'not found': winds = False
     154    ### we tell the user that either no var or no wind is not acceptable
    150155      if not varname and not winds: errormess("please set at least winds or var",printvar=nc.variables)
    151       ### ... COORDINATES, could be moved below
     156    ### we get the coordinates lat/lon to be used
    152157      [lon2d,lat2d] = getcoorddef(nc)
    153       ### ... PROJECTION
     158    ### we get an adapted map projection if none is provided by the user
    154159      if proj == None:   proj = getproj(nc)                 
    155 
     160    ### we define plot boundaries given projection or user choices
    156161      if firstfile:
    157          ##########################
    158          ### Define plot boundaries
    159          ### todo: possible areas in latinterv in argument (ex: "Far_South_Pole")
    160162         if proj in ["npstere","spstere"]: [wlon,wlat] = polarinterv(lon2d,lat2d)
    161163         elif proj in ["lcc","laea"]:      [wlon,wlat] = wrfinterv(lon2d,lat2d)
     
    493495                        if not tile:  zeline='-'
    494496                        else:         zeline=','
    495                         if indexvert is not None or indextime is None:    plot(x,what_I_plot_frame,zeline,label=lbl)  ## regular plot
    496                         else:                                             plot(what_I_plot_frame,x,zeline,label=lbl)  ## vertical profile
     497                        this_is_a_regular_plot = (indexvert is not None) or (indextime is None) or (indexlat is None) or (indexlon is None)
     498                        if this_is_a_regular_plot:   plot(x,what_I_plot_frame,zeline,label=lbl)  ## vertical profile
     499                        else:                        plot(what_I_plot_frame,x,zeline,label=lbl)  ## regular plot
    497500                        if nplot > 1: legend(loc='best')
    498501                        if indextime is None and axtime is not None and xlab is None:    xlabel(axtime.upper()) ## define the right label
Note: See TracChangeset for help on using the changeset viewer.