Changeset 1763 in lmdz_wrf


Ignore:
Timestamp:
Jan 24, 2018, 4:06:22 PM (8 years ago)
Author:
lfita
Message:

Adgin variable slicing and improving in-line help

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/drawing.py

    r1589 r1763  
    23392339    """ Function to draw different lines at the same time from different files with times
    23402340    draw_lines_time(ncfilens, values, varname):
    2341       ncfilens= [filen] ',' separated list of netCDF files
     2341      ncfilens= [filen]%[dimval] ',' separated list of netCDF files and the 'slice'
     2342        along the dimensions of the file
     2343          [dimval]: ';' list of [dimn]|[dimval] to get the values for [varn]
     2344            [dimn]: name of the dimension
     2345            [dimval]: value of the dimension variable a given value is required:
     2346              * [integer]: which value of the dimension
     2347              * -1: all along the dimension
     2348              * -9: last value of the dimension
     2349              * [beg]@[end]@[inc] slice from [beg] to [end] every [inc]
     2350              * NOTE, no dim name all the dimension size
    23422351      values= [dimvname];[valuesaxis];[dimtit];[dimxyfmt];[leglabels];[vtit];[title];[rangevals];[timevals];
    23432352        [legvals];[graphk];[collines];[points];[linewidths];[pointsizes];[pointfreq];[period];[close]
    2344         [dimvname]: ',' list of names of the variables with he values of the common dimension ('WRFtime' for WRF Times variable)
     2353        [dimvname]: ',' list of names of the variables with the values of the common dimension for all lines ('WRFtime' for WRF Times variable)
    23452354        [valuesaxis]: which axis will be used for the values ('x', or 'y')
    23462355        [dimtit]: title for the common dimension ('|' for spaces)
     
    23662375           [timen]; name of the time variable
    23672376           [units]; units string according to CF conventions ([tunits] since
    2368              [YYYY]-[MM]-[DD] [[HH]:[MI]:[SS]], '!' for spaces)
     2377             [YYYY]-[MM]-[DD] [[HH]:[MI]:[SS]], '!' for spaces) this is used to
     2378             re-compute the time values to be the same reference for all the lines
    23692379           [kind]; kind of output
    23702380             'Nval': according to a given number of values as 'Nval',[Nval]
     
    23802390            9: 'upper center', 10: 'center'
    23812391          [fontsize]: font size for the legend (auto for 12)
    2382         [graphk]: kind of the graphic
    2383         [lines]: ',' list of type of lines, None for automatic, single value all the same
    2384         [collines]: ',' list of colors for the lines, None for automatic, single
    2385           value all the same
    2386         [points]: '@' list of type of points for the lines, None for automatic, single
    2387           value all the same
     2392        [graphk]: kind of the output of the graphic ('png', 'pdf', 'eps', ...)
     2393        [lines]: ',' list of type of lines (matplotlib syntax), 'None' for automatic,
     2394          providing a single value will be used the same for all the lines
     2395        [collines]: ',' list of colors for the lines (matplotlib syntax), 'None' for
     2396          automatic, single value all the same
     2397        [points]: '@' list of type of points (matplotlib syntax ',' no points) for
     2398          the lines, 'None' for automatic, single value all the same
    23882399        [linewidths]: ',' list of widths for the lines, None for automatic, single
    23892400          value all the same
    23902401        [pointsizes]: ',' list of widths for the lines, None for automatic, single
    23912402          value all the same
    2392         [pointfreq]: frequency of point plotting, 'all' for all time steps
    2393         [period]: which period to plot
    2394           '-1': all period
    2395           [beg],[end]: beginning and end of the period in reference time-units of first file
     2403        [pointfreq]: frequency of point plotting (every given number of values),
     2404          'all' to plot all values using all time steps
     2405        [period]: which period of the data to plot:
     2406          '-1': all period of data
     2407          [beg],[end]: beginning and end of the period in reference time-units of
     2408            first file
    23962409        [close]: Whether figure should be finished or not
    2397       varnames= ',' list of variable names to plot (assuming only 1 variable per file)
     2410      varnames= ',' list of variable names to plot (assuming only 1 variable per file
     2411        consecutively)
    23982412      values= 'time;y;time ([DD]${[HH]}$);32x32;$wss^{*}$;wss Taylor's turbulence term;time|hours!since!1949-12-01_00:00:00;exct,12,h|%d$^{%H}$;2;pdf'
    23992413    """
     
    24112425    drw.check_arguments(fname,values,expectargs,';')
    24122426
    2413     ncfiles = ncfilens.split(',')
     2427    ncfiledims = ncfilens.split(',')
    24142428    dimvname0 = values.split(';')[0]
    24152429    valuesaxis = values.split(';')[1]
     
    25312545    maxtval = -1.e20
    25322546
    2533     for ifile in ncfiles:
    2534         filen = ifile.split('@')[0]
    2535 
    2536         print '    filen:',filen
     2547    for ifile in ncfiledims:
     2548
     2549        filen = ifile.split('%')[0]
     2550        dims = ifile.split('%')[1]
     2551
     2552        print '    filen:', filen, 'section:', dims
    25372553
    25382554        if not os.path.isfile(filen):
     
    25892605            if objfile.variables.has_key(var):
    25902606                foundvar = True
    2591                 vvobj = objfile.variables[var]
     2607                vvobj0 = objfile.variables[var]
     2608
     2609                # Slicing variables
     2610                dictslice = {}
     2611                for dnv in dimvalues.split(';'):
     2612                    dimn = dnv.split('|')[0]
     2613                    dimv = dnv.split('|')[1]
     2614                    if dimv.find(',') != -1:
     2615                        dictslice[dimn] = list(np.array(dimv.split('@'), dtype=int))
     2616                    else:
     2617                        dictslice[dimn] = int(dimv)
     2618
     2619                slicev, ddv = ncvar.SliceVarDict(vvobj0, dictslice)
     2620                vvobj = timeobj[tuple(slicet)]
     2621
    25922622                if len(vvobj.shape) != 1:
    25932623                    print errormsg
     
    26712701
    26722702        if ifn == 0:
    2673             varunits = drw.units_lunits(vvobj.units)
     2703            varunits = drw.units_lunits(vvobj0.units)
     2704        else:
     2705            if varunits != drw.units_lunits(vvobj0.units):
     2706                print errormsg
     2707                print '  ' + fname + ': wrong units:', vvobj0.units, " of " +        \
     2708                  "variable '" + var +  "' with respect first variable '", varunits, \
     2709                  "' !!"
     2710                quit(-1)
    26742711
    26752712        objfile.close()
Note: See TracChangeset for help on using the changeset viewer.