Changeset 1559 in lmdz_wrf


Ignore:
Timestamp:
May 9, 2017, 3:51:13 PM (8 years ago)
Author:
lfita
Message:

Adding:

`draw_ensembles_time': Function to plot an ensembles of data following an axis-time

Replacing:

'%' character of separation by '#' in list of files for `bar' plots

Location:
trunk/tools
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/documentation/plotting/gallery.html

    r1554 r1559  
    2525      <A HREF="barbs.html"><IMG SRC="figs/wind_barbs_2001111003_uw.png" ALT="wind-barbs" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A>
    2626      <A HREF="basins.html"><IMG SRC="figs/basins_named.png" ALT="ORCHIDEE's basin description" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A>
     27      <A HREF="ensemble_time.html"><IMG SRC="figs/Forcing_pr_spacemean.png" ALT="Ensemble time" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A>
     28      <A HREF="ensemble_time.html"><IMG SRC="figs/T2_spaceensembleIndiv.png" ALT="Ensemble time" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A>
    2729      <A HREF="Neighbourgh_evol.html"><IMG SRC="figs/Neighbourghood_evol.png" ALT="Neighbourghood evolution" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A>
    2830      <A HREF="Nlines.html"><IMG SRC="figs/Nlines_hurs_wrfout_tturb-xmean-last.png" ALT="Nlines" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A>
  • trunk/tools/documentation/plotting/plotting.html

    r1553 r1559  
    2020      <A CLASS="lc" HREF="barbs.html" TARGET="value">barbs</A><BR>
    2121      <A CLASS="lc" HREF="basins.html" TARGET="value">ORCHIDEE's basins</A><BR>
     22      <A CLASS="lc" HREF="ensemble_time.html" TARGET="value">Ensemble time</A><BR>
    2223      <A CLASS="lc" HREF="Neighbourgh_evol.html" TARGET="value">Neighbourghood evolution</A><BR>
    2324      <A CLASS="lc" HREF="Nlines.html" TARGET="value">Nlines</A><BR>
  • trunk/tools/drawing.py

    r1553 r1559  
    5050## e.g. # drawing.py -o draw_bar_line_time -f 'Forcing_rainstats_OKstomate_SESA_DJFmean_norm_meanstd_stat2.nc;time_centered,-1;time_centered;rainnorm;bar:Forcing_rainstats_OKstomate_SACZ_DJFmean_norm_meanstd_stat2.nc;time_centered,-1;time_centered;rainnorm;bar:DiPolo_evapstats_OKstomate_SESA_DJFmean_stat2.nc;time_centered,-1;time_centered;evap_stats;line:DiPolo_evapnustats_OKstomate_SESA_DJFmean_stat2.nc;time_centered,-1;time_centered;evapnu_stats;line:DiPolo_evspsblvegstats_OKstomate_SESA_DJFmean_stat2.nc;time_centered,-1;time_centered;evspsblveg_stats;line:DiPolo_transpirstats_OKstomate_SESA_DJFmean_stat2.nc;time_centered,-1;time_centered;transpir_stats;line:DiPolo_evapstats_OKstomate_SACZ_DJFmean_stat2.nc;time_centered,-1;time_centered;evap_stats;line:DiPolo_evapnustats_OKstomate_SACZ_DJFmean_stat2.nc;time_centered,-1;time_centered;evapnu_stats;line:DiPolo_evspsblvegstats_OKstomate_SACZ_DJFmean_stat2.nc;time_centered,-1;time_centered;evspsblveg_stats;line:DiPolo_transpirstats_OKstomate_SACZ_DJFmean_stat2.nc;time_centered,-1;time_centered;transpir_stats;line' -S 'auto;pr;y;None;1;year|seconds!since!1958-01-01!00:00:00|exct,5,y|%Y;SESA,SACZ,SESA!evap,evapnu,evspblveg,transpir,SACZ!evap,None,None,None;#AA0000,#0000AA;10000000.;#AAAA00,#00AAAA,#AA00AA,#AAAAAA,#AAAA00,#00AAAA,#AA00AA,#AAAAAA;-,-,-,-,--,--,--,--;,;2.;2.;all;normalized!evolution!of!DJFmean!with!WFD3!forcing;0|10;png;bar_time_rain_CRU-NCEP_DJFmean_norm;yes'
    5151## e.g. # drawing.py -o draw_time_lag -f 'Forcing_rainstats_OKstomate_SESA_norm_meanstd_stat2.nc;time_centered,-1;time_counter;rainnorm%DiPolo_evapstats_SESA_norm_meanstd_OKstomate.nc;time_counter,-1|stats,2;time_counter;evapnorm:Forcing_rainstats_OKstomate_SACZ_norm_meanstd_stat2.nc;time_centered,-1;time_counter;rainnorm%DiPolo_evapstats_SACZ_norm_meanstd_OKstomate.nc;time_counter,-1|stats,2;time_counter;evapnorm' -S 'auto;centered;pr;1;evap;1;-5,5;-2,2;year|seconds!since!1958-01-01!00:00:00|exct,5,y|%Y;SESA,SACZ;simplepts,1,#AA0000@#0000AA,x,2.;1-month!time-lag!at!SACZ!between!pr!&!evap!normalized!by!mean/stddev;0|12;png;mon1_timelag_pr-evap_SACZ;yes'
     52## e.g. # drawing.py -o draw_ensembles_time -f 'Forcing_rain_SESA.nc;time_counter,-1|stats,0;time_centered;rain_stats;ensemble#Forcing_rain_SESA.nc;time_counter,-1|stats,1;time_centered;rain_stats;ensemble#Forcing_rain_SESA.nc;time_counter,-1|stats,2;time_centered;rain_stats;data' -S 'auto;y;tas;mm/d;auto,auto;#0000FF:-:2.:,:2.;year|seconds!since!1958-01-01!00:00:00|exct,5,y|%Y;FromFile;$pr_{space-mean}^{SESA}$;cloud,#AAAADD,auto;$pr_{space-mean}$!evolution!at!SESA;0|10;png;Forcing_pr_spacemean;no;yes'
     53
    5254
    5355#######
     
    6971# draw_barbs: Function to plot wind barbs
    7072# draw_basins: Function to plot river basins with their discharge vector and basins id (from 'routing.nc')
     73# draw_ensembles_time: Function to plot an ensembles of data following an axis-time
    7174# draw_lines: Function to draw different lines at the same time from different files
    7275# draw_lines_time: Function to draw different lines at the same time from different files with times
     
    100103  'draw_2D_shad_line',                                                               \
    101104  'draw_2D_shad_line_time', 'draw_bar', 'draw_bar_line', 'draw_bar_line_time',       \
    102   'draw_bar_time', 'draw_barbs', 'draw_basins',                                      \
     105  'draw_bar_time', 'draw_barbs', 'draw_basins', 'draw_ensembles_time',               \
    103106  'draw_2lines', 'draw_2lines_time', 'draw_lines', 'draw_lines_time',                \
    104107  'draw_Neighbourghood_evol',                                                        \
     
    64216424def draw_bar(ncfile, values):
    64226425    """ Function to plot a bar char figure with multiple sources
    6423       ncfile = ':' list of [filen];[dimslice];[xvarn];[yvarn]
     6426      ncfile = '#' list of [filen];[dimslice];[xvarn];[yvarn]
    64246427        [filen]: name of the file
    64256428        [dimslice]: '|' list of [dimn],[dimrange]
     
    64956498
    64966499    # files and values
    6497     filedvs = ncfile.split(':')
     6500    filedvs = ncfile.split('#')
    64986501    xvals = []
    64996502    yvals = []
     
    65666569def draw_bar_time(ncfile, values):
    65676570    """ Function to plot a bar char figure with multiple sources and time-axis
    6568       ncfile = ':' list of [filen];[dimslice];[tvarn];[yvarn]
     6571      ncfile = '#' list of [filen];[dimslice];[tvarn];[yvarn]
    65696572        [filen]: name of the file
    65706573        [dimslice]: '|' list of [dimn],[dimrange]
     
    66526655
    66536656    # files and values
    6654     filedvs = ncfile.split(':')
     6657    filedvs = ncfile.split('#')
    66556658    tvals = []
    66566659    yvals = []
     
    67766779def draw_bar_line(ncfile, values):
    67776780    """ Function to plot a bar char and lines plot figure with multiple sources
    6778       ncfile = ':' list of [filen];[dimslice];[xvarn];[yvarn];[kind]
     6781      ncfile = '#' list of [filen];[dimslice];[xvarn];[yvarn];[kind]
    67796782        [filen]: name of the file
    67806783        [dimslice]: '|' list of [dimn],[dimrange]
     
    68726875
    68736876    # files and values
    6874     filedvs = ncfile.split(':')
     6877    filedvs = ncfile.split('#')
    68756878    barxvals = []
    68766879    baryvals = []
     
    69916994def draw_bar_line_time(ncfile, values):
    69926995    """ Function to plot a bar char and lines plot figure with multiple sources and time-axis
    6993       ncfile = ':' list of [filen];[dimslice];[xvarn];[yvarn];[kind]
     6996      ncfile = '#' list of [filen];[dimslice];[xvarn];[yvarn];[kind]
    69946997        [filen]: name of the file
    69956998        [dimslice]: '|' list of [dimn],[dimrange]
     
    70957098
    70967099    # files and values
    7097     filedvs = ncfile.split(':')
     7100    filedvs = ncfile.split('#')
    70987101    bartvals = []
    70997102    baryvals = []
     
    72547257def draw_time_lag(ncfile, values):
    72557258    """ Function to plot a time-lag figure with multiple sources (x, previous values; y, future values)
    7256       ncfile = ':' list of couples ('%' formed) [prefilen];[predslice];[pretvarn];[prevarn]%[futfilen];
     7259      ncfile = '#' list of couples ('%' formed) [prefilen];[predslice];[pretvarn];[prevarn]%[futfilen];
    72577260          [futdslice];[futtvarn];[futvarn]
    72587261        'pre': values to act as previous values
     
    73807383
    73817384    # files and values
    7382     filedvs = ncfile.split(':')
     7385    filedvs = ncfile.split('#')
    73837386    timevalues = []
    73847387    prevalues = []
     
    75477550    return
    75487551
     7552def draw_ensembles_time(ncfile, values):
     7553    """ Function to plot an ensembles of data following an axis-time
     7554      ncfile = '#' list of files [filen];[slice];[tvarn];[varn];[kinddata]
     7555        [filen]: name of the file
     7556        [dimslice]: '|' list of [dimn],[dimrange]
     7557          [dimn]: name of the dimension
     7558          [dimrange]: range for the slice
     7559            * [integer]: which value of the dimension
     7560            * -1: all along the dimension
     7561            * -9: last value of the dimension
     7562            * [beg]@[end]@[inc] slice from [beg] to [end] every [inc]
     7563            * NOTE, no dim name all the dimension size
     7564        [tvarn]: name of the variable time ('WRFtime', for times from WRF)
     7565        [varn]: name of the variable to use for the values
     7566        [kinddata]: which kind of use should be done:
     7567          'data': to be plot as data
     7568          'ensemble': to be used as a member of the ensemble
     7569      values = [dimxyfmt];[valaxis];[axislab];[axisunits];[rangevals];[datavals];[timevals];[valskind];
     7570          [labels];[figenskind];[graphtit];[legvalues];[kindfig];[fign];[outfile];[close]
     7571        [dimxyfmt]=[dxs],[dxf],[Ndx],[ordx],[dys],[dyf],[Ndy],[ordy]: format of the values at each
     7572            axis (or single 'auto' for 'auto','auto')
     7573          [dxs]: style of x-axis ('auto' for 'pretty')
     7574            'Nfix', values computed at even 'Ndx'
     7575            'Stringlist', a given list of strings
     7576            'Vfix', values computed at even 'Ndx' increments
     7577            'pretty', values computed following aprox. 'Ndx' at 'pretty' intervals (2.,2.5,4,5,10)
     7578          [dxf]: format of the labels at the x-axis
     7579          [Ndx]: Number of ticks at the x-axis (for 'Stringlist', '@' list of labels)
     7580          [ordx]: angle of orientation of ticks at the x-axis ('auto' for horizontal)
     7581          [dys]: style of y-axis ('auto' for 'pretty')
     7582          [dyf]: format of the labels at the y-axis
     7583          [Ndy]: Number of ticks at the y-axis
     7584          [ordy]: angle of orientation of ticks at the y-axis ('auto' for horizontal)
     7585        [valaxis]: which axes should be used for the data
     7586        [axislab]: Label for the values-axis ('!' for spaces)
     7587        [axisunits]: units of the values-label
     7588        [rangevals]: Range of the axis with the values (single 'None' for 'auto','auto')
     7589         [vmin],[vmax]: minimum and maximum values
     7590           'auto': the computed minimumm or maximum of the values
     7591        [datavals]: [color]:[linetype]:[linewidht]:[markertype]:[markersize] values for the data-lines
     7592          [color]: '@' list of colors of the lines (single value for the same, or 'auto')
     7593          [linetype]: '@' list of type of the lines (single value for the same, or 'auto')
     7594          [linewidht]: '@' list of width of the lines (single value for the same, or 'auto')
     7595          [markertype]: '@' list of type of the markers (single value for the same, or 'auto')
     7596          [markersize]: '@' list of size of the markers (single value for the same, or 'auto')
     7597        [timevals]: [timen]|[units]|[kind]|[tfmt] time labels characteristics
     7598          [timen]; name of the time variable
     7599          [units]; units string according to CF conventions ([tunits] since
     7600            [YYYY]-[MM]-[DD] [[HH]:[MI]:[SS]], '!' for spaces)
     7601          [kind]; kind of output
     7602            'Nval': according to a given number of values as 'Nval',[Nval]
     7603            'exct': according to an exact time unit as 'exct',[tunit];
     7604              tunit= [Nunits],[tu]; [tu]= 'c': centuries, 'y': year, 'm': month,
     7605               'w': week, 'd': day, 'h': hour, 'i': minute, 's': second,
     7606               'l': milisecond
     7607          [tfmt]; desired format
     7608        [valskind]: way to compute the values to be plotted
     7609          'FromFile': from the files with the 'data' flag
     7610          'FromEns',[usedims],[stats]: from all the files with the 'ensemble' flag with statistics [stats],
     7611              throughout dimensions [usedims]
     7612            [usedims]= '@' list of dimensions to take to compute the statistics
     7613            [stats]= statistics to use
     7614              'direct': without statistics
     7615              'mean': mean value of all files with ensemble flag
     7616              'median': median value of all files with ensemble flag
     7617              'weightedmean,[stats],[weights]': weighted mean value all files with ensemble flag
     7618                [stats] = statistics to use from each member: 'direct', 'mean', 'median'
     7619                [weights] = '@' list of weights [0,1]
     7620          'FromIndivEns',[usedims],[stats]: from each files with the 'ensemble' flag with statistics [stats],
     7621              throughout dimensions [usedims]
     7622            [usedims]= '@' list of dimensions to take to compute the statistics
     7623            [stats]= statistics to use:
     7624              'mean': mean value of each file with ensemble flag
     7625              'median': median value of each file with ensemble flag
     7626        [labels]: ',' list of labels for the legend ('None' for no-labels, '!' for spaces)
     7627        [figenskind]=[kindname],[valueskind] kind of ensemble plot
     7628          'cloud',[color],[limits]: ensembles values as a cloud
     7629            [color]: name of the color to use ('auto' for '#DDDDDD')
     7630            [limits]: which stadistics to use for the plot ('auto' for extremes)
     7631              '5quantile': 5quantile,95quantile of the values
     7632              'direct': below and up values are tacking directly from the provided data
     7633              'extremes': min,max of the values
     7634              'stddev': standard deviation fo the values (only available if there is one line)
     7635          'spaghetti',[color],[width],[type]: a line for each member
     7636            [color]: name of the color to use for all lines ('auto' for '#DDDDDD')
     7637            [width]: width of the line to use for all lines ('auto' for 0.5)
     7638            [type]: type of the line to use for all lines ('auto' for '-')
     7639        [graphtit]: title of the figure '!' for spaces
     7640        [legvalues]=[locleg]|[fontsize]:
     7641          [locleg]: location of the legend (0, autmoatic)
     7642            1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
     7643            5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     7644            9: 'upper center', 10: 'center'
     7645          [fontsize]: font size for the legend (auto for 12)
     7646        [kindfig]: kind of output figure (png, pdf, ps)
     7647        [fign]: name of the figure (without extension)
     7648        [outfile]: wehter or not a file with the result of the computation of the ensemble should be
     7649          written or not (labelled 'ensemble_ofile.nc')
     7650        [close]: whether figure should be close or not
     7651    """
     7652    fname = 'draw_ensembles_time'
     7653
     7654    if values == 'h':
     7655        print fname + '____________________________________________________________'
     7656        print draw_ensembles_time.__doc__
     7657        quit()
     7658
     7659    expectargs = '[dimxyfmt];[axeskind];[axislab];[axisunits];[rangevals];' +        \
     7660      '[datavals];[timevals];[valskind];[labels];[figenskind];[graphtit];' +         \
     7661      '[legvalues];[kindfig];[fign];[outfile];[close]'
     7662    drw.check_arguments(fname,values,expectargs,';')
     7663
     7664    dimxyfmt = values.split(';')[0]
     7665    valaxis = values.split(';')[1]
     7666    axislab = values.split(';')[2].replace('!',' ')
     7667    axisunits = values.split(';')[3]
     7668    rangevals = values.split(';')[4]
     7669    datavals = values.split(';')[5]
     7670    timevals = values.split(';')[6]
     7671    valskind = values.split(';')[7]
     7672    labels = gen.str_list(values.split(';')[8].replace('!', ' '), ',')
     7673    figenskind = values.split(';')[9]
     7674    graphtit = values.split(';')[10].replace('!',' ')
     7675    legvalues = values.split(';')[11]
     7676    kindfig = values.split(';')[12]
     7677    fign = values.split(';')[13]
     7678    outfile = gen.Str_Bool(values.split(';')[14])
     7679    close = gen.Str_Bool(values.split(';')[15])
     7680
     7681    ofilen = 'ensemble_ofile.nc'
     7682
     7683    # files
     7684    valfiles = gen.str_list(ncfile, '#')
     7685
     7686    # time-values
     7687    expectargs = '[timen]|[units]|[kind]|[tfmt]'
     7688    drw.check_arguments('timevals: '+fname,timevals,expectargs,'|')
     7689
     7690    timen = timevals.split('|')[0].replace('!',' ')
     7691    timeunit = timevals.split('|')[1].replace('!',' ')
     7692    timekind = timevals.split('|')[2]
     7693    timefmt = timevals.split('|')[3]
     7694
     7695    linevals = []
     7696    ltimevals = []
     7697    ensvals = []
     7698    etimevals = []
     7699
     7700    # List of files used for the ensemble
     7701    ensfilens = []
     7702    # List of files used for the ensemble with its dimension and variable name
     7703    edv_filens = []
     7704    # Dictionary with the dimensions of the values from a given file
     7705    dimsfile = {}
     7706
     7707    mintval = gen.fillValueF
     7708    maxtval = -gen.fillValueF
     7709    minvval = gen.fillValueF
     7710    maxvval = -gen.fillValueF
     7711
     7712    ensfilens = []
     7713    ifile = 0
     7714    dimt = -gen.fillValueF
     7715    for fdv in valfiles:
     7716        fvals = fdv.split(';')
     7717        expectedargs = '[filen];[slice];[tvarn];[varn];[kinddata]'
     7718        gen.check_arguments('filevals: '+fname, fdv, expectedargs, ';')
     7719        filen = fvals[0]
     7720        dimrange = fvals[1]
     7721        tvarn = fvals[2]
     7722        yvarn = fvals[3]
     7723        datatype = fvals[4]
     7724
     7725        edv = filen + '#' + dimrange + '#' + yvarn
     7726
     7727        if not os.path.isfile(filen):
     7728            print errormsg
     7729            print '  ' + fname + ': file "' + filen + '" does not exist !!'
     7730            quit(-1)
     7731
     7732        onc = NetCDFFile(filen, 'r')
     7733        if tvarn == 'WRFtime':
     7734            datesv = []
     7735            if tvarn == 'WRFtime':
     7736                fdates = onc.variables['Times'][:]
     7737                for it in range(fdates.shape[0]):
     7738                    datesv.append(gen.datetimeStr_conversion(fdates[it,:],           \
     7739                      'WRFdatetime','cfTime,' + timeunit))
     7740            tvs = np.array(datesv, dtype=np.float)
     7741            tunitsvar = timeunit
     7742        else:
     7743            if not onc.variables.has_key(tvarn):
     7744                print errormsg
     7745                print '  ' +fname+ ': file "' +filen+ "' does not have variable '" + \
     7746                  tvarn + "' for the time-values !!"
     7747                print '    available ones:', onc.variables.keys()
     7748                onc.close()
     7749                quit(-1)
     7750            otvar = onc.variables[tvarn]
     7751            tvs, tdims = ncvar.slice_variable(otvar, dimrange.replace(',',':'))
     7752            tunitsvar = otvar.units
     7753
     7754        if not onc.variables.has_key(yvarn):
     7755            print errormsg
     7756            print '  ' +fname+ ': file "' +filen+ "' does not have variable '" +     \
     7757              yvarn + "' for the y-values !!"
     7758            print '    available ones:', onc.variables.keys()
     7759            onc.close()
     7760            quit(-1)
     7761
     7762        oyvar = onc.variables[yvarn]
     7763        yvs, ydims = ncvar.slice_variable(oyvar, dimrange.replace(',',':'))
     7764        dimsfile[edv] = ydims
     7765
     7766        # Referring all times to the same reference time!
     7767        reftvals = gen.coincident_CFtimes(tvs, timeunit, tunitsvar)
     7768
     7769        onc.close()
     7770
     7771        if len(reftvals) > dimt: dimt = len(reftvals)
     7772
     7773        reftn = reftvals.min()
     7774        reftx = reftvals.max()
     7775        if reftn < mintval: mintval = reftn
     7776        if reftx > maxtval: maxtval = reftx
     7777        refvn = yvs.min()
     7778        refvx = yvs.max()
     7779        if refvn < minvval: minvval = refvn
     7780        if refvx > maxvval: maxvval = refvx
     7781
     7782        if datatype == 'data':
     7783            if len(tvs.shape) != 1:
     7784                print errormsg
     7785                print '  ' +fname+ ': provided slice:', dimrange, "for variable '" +     \
     7786                 tvarn + "' and '" + datatype + "' does not provide a rank-1 value !!"
     7787                print '    resultant shape:', tvs.shape, 'dimensions:',tdims,'fix it !!'
     7788                quit(-1)
     7789            if len(yvs.shape) != 1:
     7790                print errormsg
     7791                print '  ' +fname+ ': provided slice:', dimrange, "for variable '" +     \
     7792                  yvarn + "' and '" + datatype + "'does not provide a rank-1 value !!"
     7793                print '    resultant shape:',yvs.shape, 'dimensions:',ydims,'fix it !!'
     7794                quit(-1)
     7795            linevals.append(yvs)
     7796            ltimevals.append(reftvals)
     7797        else:
     7798            ensfilens.append(filen)
     7799            edv_filens.append(edv)
     7800            ensvals.append(yvs)
     7801            etimevals.append(reftvals)
     7802
     7803        ifile = ifile + 1
     7804
     7805    Nens = len(ensvals)
     7806
     7807    valskindn = gen.str_list(valskind, ',')[0]
     7808
     7809    ENSvals = []
     7810    TENSvals = []
     7811
     7812    # Getting values to draw as lines
     7813    if valskindn == 'FromFile':
     7814        if len(linevals) == 0:
     7815            print errormsg
     7816            print '  ' + fname + ": you asked to get data '" + valskind +            \
     7817              "' but no file with flag 'data' was provided !!"
     7818            print '    provided file characteristics _______'
     7819            for fdv in prefutdv:
     7820                print fdv.split(';')
     7821            quit(-1)
     7822        ENSvals = list(ensvals)
     7823        TENSvals = list(etimevals)
     7824    elif valskindn == 'FromEns':
     7825        eSvals = valskind.split(',')
     7826
     7827        expectedargs='FromEns,[usedims],[stats]'
     7828        gen.check_arguments('FromEns: '+fname, valskind, expectedargs, ',')
     7829
     7830        ensdims = eSvals[1].split('@')
     7831        ensn = eSvals[2]
     7832        iedv = 0
     7833        # Temporal slices for each file/variable
     7834        Tslices = {}
     7835        for edv in edv_filens:
     7836            vvalues = ensvals[iedv]
     7837            edv_dims = dimsfile[edv]
     7838            idim = []
     7839            for dsts in ensdims:
     7840                idim.append(edv_dims.index(dsts))
     7841            # Adding each running value as a new member of the ensemble
     7842            NOTusedim = []
     7843            for dn in dimsfile[edv]:
     7844                if not gen.searchInlist(ensdims, dn): NOTusedim.append(dn)
     7845            varslices = gen.provide_slices(dimsfile[edv], vvalues.shape, NOTusedim)
     7846            Tslices[edv] = varslices
     7847
     7848            if iedv == 0: dimt = len(varslices)
     7849            else:
     7850                if dimt != len(varslices):
     7851                    print errormsg
     7852                    print '  ' + fname + ': this is too complicated !!'
     7853                    print '    for file:', iedv, ' with ', len(varslices),           \
     7854                      'and initial dimt:', dimt
     7855                    print '    not ready to deal with files with different number '+ \
     7856                      'of time-steps!!'
     7857                    quit(-1)
     7858            # Adding each not runnuning grid-point as a new ensemble member
     7859            varslices = gen.provide_slices(dimsfile[edv], vvalues.shape, ensdims)
     7860            for slc in varslices:
     7861                ENSvals.append(np.squeeze(vvalues[tuple(slc)]))
     7862                TENSvals.append(np.squeeze(np.array(etimevals[iedv])))
     7863
     7864            iedv = iedv + 1
     7865
     7866        lvals = np.zeros((dimt), dtype=np.float)
     7867        for it in range(dimt):
     7868            iedv = 0     
     7869            Tvals = []
     7870            Tvalse = {}
     7871            for edv in edv_filens:
     7872                vvalues = ensvals[iedv]
     7873                varslics = Tslices[edv]
     7874                Tvals = Tvals + list(np.squeeze(vvalues[tuple(varslics[dimt-it-1])]).flatten())
     7875                Tvalse[edv] = np.squeeze(vvalues[tuple(varslics[dimt-it-1])])
     7876
     7877            aTvals = np.array(Tvals)
     7878            if ensn == 'mean':
     7879                lvals[it] = np.mean(aTvals)
     7880            elif ensn == 'median':
     7881                lvals[it] = np.median(aTvals)
     7882            elif ensn[0:12] == 'weightedmean':
     7883                expectedargs='FromEns,[usedims],weightedmean,[stats],[weights]'
     7884                gen.check_arguments('FromEns: '+fname, valskind, expectedargs, ',')
     7885
     7886                stats = eSvals[3]
     7887                wgths = eSvals[4].split('@')
     7888                wghtvs = np.array(wgths, dtype=np.float)
     7889                if len(wgths) != Nens:
     7890                    print errormsg
     7891                    print '  ' + fname + ': the number of members of the ensemble:', \
     7892                      Nens, 'and the number of provided weights:', len(wghts),       \
     7893                      'do not coincide !!'
     7894                    print '    provided weights:', wgths
     7895                    print '    provided file characteristics _______'
     7896                    for fdv in prefutdv:
     7897                        print fdv.split(';')
     7898                    quit(-1)
     7899                wgthvals = np.zeros((Nens), dtype=np.float)
     7900                iedv = 0
     7901                for edv in edv_filens:
     7902                    if stats == 'mean':
     7903                        wgthvals[iedv] = np.mean(Tvalse[edv])
     7904                    elif stats == 'median':
     7905                        wgthvals[iedv] = np.median(Tvalse[edv])
     7906                    else:
     7907                        print errormsg
     7908                        print '  ' +fname+ ": statistics '" + eSvals[2] + "' not ready !!"
     7909                        print '    available ones:', ['mean', 'median']
     7910                        quit(-1)
     7911                lvals[it] = np.sum(wghtvals*wghtvs)/np.sum(wghtvs)
     7912            else:
     7913                print errormsg
     7914                print '  ' + fname + ": for '" + valskindn + "'statistics '" +       \
     7915                  eSvals[2] + "' not ready !!"
     7916                print '    available ones:', ['mean', 'median', 'weightedmean']
     7917                quit(-1)
     7918            iedv = iedv + 1
     7919        linevals.append(lvals)
     7920        ltimevals.append(np.squeeze(np.array(etimevals[0], dtype=np.float)))
     7921    elif valskindn == 'FromIndivEns':
     7922        indenfns = []
     7923        eSvals = valskind.split(',')
     7924
     7925        expectedargs='FromIndivEns,[usedims],[stats]'
     7926        gen.check_arguments('FromEns: '+fname, valskind, expectedargs, ',')
     7927
     7928        ensdims = eSvals[1].split('@')
     7929        ensn = eSvals[2]
     7930        iedv = 0
     7931        evals = np.zeros((dimt, Nens), dtype=np.float)
     7932        for edv in edv_filens:
     7933            vvalues = ensvals[iedv]
     7934            edv_dims = dimsfile[edv]
     7935            filen = edv.split('#')[0]
     7936            indenfns.append(filen)
     7937
     7938            idim = []
     7939            for dsts in ensdims:
     7940                idim.append(edv_dims.index(dsts))
     7941            # Adding each running value as a new member of the ensemble
     7942            NOTusedim = []
     7943            for dn in dimsfile[edv]:
     7944                if not gen.searchInlist(ensdims, dn): NOTusedim.append(dn)
     7945            varslices = gen.provide_slices(dimsfile[edv], vvalues.shape, ensdims)
     7946            for varslc in varslices:
     7947                ENSvals.append(np.squeeze(vvalues[tuple(varslc)]))
     7948                TENSvals.append(np.squeeze(np.array(etimevals[iedv], dtype=np.float)))
     7949                # No need to repeat File name len(varslices)0 times
     7950                # ensfilens.append(filen)
     7951            if ensn == 'mean':
     7952                linevals.append(np.mean(vvalues, axis=tuple(idim)))
     7953            elif ensn == 'median':
     7954                linevals.append(np.median(vvalues, axis=tuple(idim)))
     7955            elif ensn == 'direct':
     7956                if len(values.shape) != 1:
     7957                    print errormsg
     7958                    print '  ' +fname+ ': provided slice:', dimrange,                \
     7959                      "for variable '" + yvarn + "' and '" + datatype +              \
     7960                      "'does not provide a rank-1 value !!"
     7961                    print '    resultant shape:', yvs.shape, 'dimensions:', ydims,   \
     7962                      'fix it !!'
     7963                    quit(-1)
     7964                linevals.append(vvalues)
     7965            else:
     7966                print errormsg
     7967                print '  ' + fname + ": for '" + valskindn + "' statistics '" +      \
     7968                  eSvals[2] + "' not ready !!"
     7969                print '    available ones:', ['mean', 'median']
     7970                quit(-1)
     7971            ltimevals.append(np.squeeze(np.array(etimevals[iedv], dtype=np.float)))
     7972            iedv = iedv + 1
     7973    else:
     7974        print errormsg
     7975        print '  ' + fname + ": kind of values '" + valskindn + "' not ready !!"
     7976        print '    available ones:', ['FromFile', 'FromEns', 'FromIndivEns']
     7977        quit(-1)
     7978
     7979    Ndata = len(linevals)
     7980    Nens = len(ENSvals)
     7981
     7982    # Times
     7983    dtvals = (maxtval - mintval)/10
     7984    dti = mintval
     7985    dte = maxtval
     7986    tvalsticks = np.arange(dti, dte+dtvals, dtvals)
     7987
     7988    dtiS = drw.datetimeStr_conversion(str(dti) + ',' + timeunit, 'cfTime',           \
     7989     'Y/m/d H-M-S')
     7990    dteS = drw.datetimeStr_conversion(str(dte) + ',' + timeunit, 'cfTime',           \
     7991     'Y/m/d H-M-S')
     7992
     7993    print '  ' + fname + ': plotting from: ' + dtiS + ' to ' + dteS
     7994
     7995    timepos, timelabels = drw.CFtimes_plot(tvalsticks, timeunit, timekind, timefmt)
     7996
     7997    # ranges
     7998    if rangevals == 'None':
     7999        valmin = minvval
     8000        valmax = maxvval
     8001    else:
     8002        if rangevals.split(',')[0] != 'auto':
     8003            valmin = np.float(rangevals.split(',')[0])
     8004        else:
     8005            valmin = minvval
     8006        if rangevals.split(',')[1] != 'auto':
     8007            valmax = np.float(rangevals.split(',')[1])
     8008        else:
     8009            valmax = maxvval
     8010
     8011    xstyl, xaxf, Nxax, xaxor, ystyl, yaxf, Nyax, yaxor = drw.format_axes(dimxyfmt,',')
     8012    xaxis = [xstyl, xaxf, Nxax, xaxor]
     8013    yaxis = [ystyl, yaxf, Nyax, yaxor]
     8014
     8015    # Legend
     8016    legloc, legsiz = drw.legend_values(legvalues,'|')
     8017
     8018    valuesvals = [valaxis, axislab, axisunits, [valmin, valmax]]
     8019
     8020    # line-characteristics
     8021    expectargs = '[color]:[linetype]:[linewidht]:[markertype]:[markersize]'
     8022    Lvals = datavals.split(':')
     8023    gen.check_arguments('data-line characterisitcs: '+fname,datavals,expectargs,':')
     8024
     8025    Lcol = Lvals[0]
     8026    Ltype = Lvals[1]
     8027    Lwidth = Lvals[2]
     8028    Lmarker = Lvals[3]
     8029    Lsizem = Lvals[4]
     8030
     8031    if len(labels) != len(linevals):
     8032        print errormsg
     8033        print '  ' + fname + ': There are', len(linevals), 'lines to plot but',      \
     8034          len(labels), 'labels provided !!'
     8035        print '    provided labels:', labels
     8036        quit(-1)
     8037
     8038    if outfile:
     8039        onew = NetCDFFile(ofilen, 'w')
     8040        Lstr = 250
     8041   
     8042        # Dimensions
     8043        newdim = onew.createDimension('data', Ndata)
     8044        newdim = onew.createDimension('ensemble', Nens)
     8045        newdim = onew.createDimension('time', dimt)
     8046        newdim = onew.createDimension('Lstring', Lstr)
     8047   
     8048        # Dimension variables
     8049        newvar = onew.createVariable('time', 'f8', ('time'))
     8050        ncvar.basicvardef(newvar, 'time', 'Time', timeunit)
     8051        newvar.setncattr('axis', 'T')
     8052        newvar.setncattr('_CoordinateAxisType', 'Time')
     8053        newvar.setncattr('calendar', 'gregorian')
     8054        newvar[:] = etimevals[0]
     8055
     8056        newvar = onew.createVariable('ensfilen', 'c', ('ensemble', 'Lstring'))
     8057        ncvar.basicvardef(newvar, 'ensfilen', 'name of files of the ensemble data',  \
     8058          '-')
     8059        newvals = ncvar.writing_str_nc(newvar, ensfilens, Lstr)
     8060        onew.sync()
     8061   
     8062        # Global attributes
     8063        ncvar.add_global_PyNCplot(onew, mainn, fname, '1.0')
     8064
     8065    else:
     8066        onew = None
     8067
     8068    drw.plot_TimeEnsembles(linevals, ENSvals, ltimevals, TENSvals, xaxis, yaxis,     \
     8069      valuesvals, Lcol, Ltype, Lwidth, Lmarker, Lsizem, labels, figenskind, timen,   \
     8070      timepos, timelabels, graphtit, legloc, legsiz, kindfig, fign, onew, close)
     8071
     8072    if onew is not None:
     8073        ovals = onew.variables['vals']
     8074        if valskindn == 'FromEns':
     8075            eSvals = valskind.split(',')
     8076            ensdims = eSvals[1].split('@')
     8077            ensn = eSvals[2]
     8078
     8079            if ensn != 'weightedmean':
     8080                txt = 'values retrieved from all ensembles file as ' + ensn +        \
     8081                  ' along dimensions ' + ','.join(ensdims)
     8082            else:
     8083                newvar = onew.createVariable('weight', 'f', ('ensemble'))
     8084                ncvar.basicvardef(newvar, 'weight', 'weights for the weighted mean', \
     8085                  '-')
     8086                newvar[:] = wghtvs
     8087                txt = 'values retrieved from all ensembles file as weighted mean' +  \
     8088                  ' along dimensions ' + ','.join(ensdims)
     8089
     8090            newattr = ncvar.set_attribute(ovals, 'data_origin', txt)
     8091
     8092            onew.sync()
     8093
     8094        elif valskindn == 'FromIndivEns':
     8095            eSvals = valskind.split(',')
     8096            ensdims = eSvals[1].split('@')
     8097            ensn = eSvals[2]
     8098
     8099            txt = 'values retrieved from each ensembles file as ' + ensn +           \
     8100              ' along dimensions ' + ','.join(ensdims)
     8101            newattr = ncvar.set_attribute(ovals, 'data_origin', txt)
     8102
     8103            newvar = onew.createVariable('datafilen', 'c', ('data', 'Lstring'))
     8104            ncvar.basicvardef(newvar, 'datafilen', 'name of files for the ensemble ',\
     8105              'data', '-')
     8106            newvals = ncvar.writing_str_nc(newvar, indenfns, Lstr)
     8107            onew.sync()
     8108
     8109        onew.sync()
     8110        onew.close()
     8111
     8112        print fname + ": succesful writting of output file '" + ofilen + "' !!"
     8113
     8114    return
     8115
    75498116#quit()
    75508117
     
    75698136  'draw_2D_shad_cont_time',                                                          \
    75708137  'draw_2D_shad_line', 'draw_2D_shad_line_time', 'draw_2lines', 'draw_2lines_time',  \
    7571   'draw_bar', 'draw_bar_line', 'draw_bar_line_time', 'draw_bar_time', 'draw_lines',  \
     8138  'draw_bar', 'draw_bar_line', 'draw_bar_line_time', 'draw_bar_time',                \
     8139  'draw_ensembles_time', 'draw_lines',                                               \
    75728140  'draw_lines_time', 'draw_points', 'draw_Taylor', 'draw_time_lag',                  \
    75738141  'draw_topo_geogrid_boxes',                                                         \
     
    76388206    elif oper == 'draw_basins':
    76398207        draw_basins(opts.ncfile, opts.values)
     8208    elif oper == 'draw_ensembles_time':
     8209        draw_ensembles_time(opts.ncfile, opts.values)
    76408210    elif oper == 'draw_Neighbourghood_evol':
    76418211        draw_Neighbourghood_evol(opts.ncfile, opts.values, opts.varname)
  • trunk/tools/drawing_tools.py

    r1555 r1559  
    9191# plot_lines: Function to plot a collection of lines
    9292# plot_Taylor: Function to draw a Taylor diagram (Taylor 2001)
     93# plot_TimeEnsembles: Function to plot a of an Ensemble of values with a time-axis
    9394# plot_WindRose: Function to plot a wind rose (from where the dinw blows)
    9495# plot_ZQradii: Function to plot following radial averages only at exact grid poins
     
    1015410155    return
    1015510156
     10157def plot_TimeEnsembles(linevals, ensvals, ltimevals, etimevals, xaxv, yaxv,          \
     10158  valuesvals, Lcol, Ltype, Lwidth, Lmarker, Lsizem, labels, figtype, tname, tpos,    \
     10159  tlabs, gtit, lloc, lsiz, kfig, figname, ofile, ifclose):
     10160    """ Function to plot a of an Ensemble of values with a time-axis
     10161      linevals= list of values to be plotted with lines
     10162      ensvals= list of values of the ensemble
     10163      ltimevals= list with the time-values of the lines
     10164      etimevals= list with the time-values of the ensemble values
     10165      [x/y]axv= values at the axes x and y
     10166      valuesvals = list with characteristics of the values axis
     10167        axisvalues= in which axis should the values be plotted ('x', 'y')
     10168        valueslab= label of the axis values
     10169        valuesunits= units of the axis values
     10170        valrange: range of the axis values
     10171      figtype= [kindname],[valueskind] kind of time-Ensembles plot
     10172        'cloud',[color],[limits]: ensembles values as a cloud
     10173          [color]: name of the color to use ('auto' for '#DDDDDD')
     10174          [limits]: which stadistics to use for the plot ('auto' for extremes)
     10175            '5quantile': 5quantile,95quantile of the values
     10176            'direct': below and up values are tacking directly from the provided data
     10177            'extremes': min,max of the values
     10178            'stddev': standard deviation fo the values (only available if there is one line)
     10179       'spaghetti',[color],[width],[type]: a line for each member
     10180          [color]: name of the color to use for all lines ('auto' for '#DDDDDD')
     10181          [width]: width of the line to use for all lines ('auto' for 0.5)
     10182          [type]: type of the line to use for all lines ('auto' for '-')
     10183      Lcol= '@' list of color for the lines (single value for the same)
     10184      Ltype= '@' list of types for the lines (single value for the same)
     10185      Lwidth= '@' list of widths for the lines (single value for the same)
     10186      Lmarker= '@' list of markers for the lines (single value for the same)
     10187      Lsizem= '@' list of size markers for the lines (single value for the same)
     10188      labels= list of labels for legend of lines (None for no legend, and 'None' for no specific label)
     10189      tname= label of the time-axis
     10190      tpos= position of the time-ticks
     10191      tlabs= labels of the time-ticks
     10192      gtit= title of the figure
     10193      lloc= location of the legend (0, autmoatic)
     10194        1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
     10195        5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     10196        9: 'upper center', 10: 'center'
     10197      lsiz= font size of the legend
     10198      kfig= kind of output: pdf, png, ps
     10199      figname= name of the figure
     10200      ofile= object of the output file with the ensemble statistics (None if it is not required)
     10201      ifclose= whether figure should be closed
     10202    """
     10203    fname = 'plot_TimeEnsembles'
     10204
     10205    # List of available limits to compute from the ensemble
     10206    availim = ['5quantile', 'extremes', 'stddev']
     10207
     10208    Nlvalues = len(linevals)
     10209    Nevalues = len(ensvals)
     10210
     10211    print gen.infmsg
     10212    print '    ' + fname + ': plotting ', Nlvalues, 'lines', Nevalues,               \
     10213      'ensemble members'
     10214
     10215    dyn = gen.fillValue
     10216    dyx = -gen.fillValue
     10217
     10218    for iv in range(Nlvalues):
     10219        minv = np.min(linevals[iv])
     10220        maxv = np.max(linevals[iv])
     10221        if minv < dyn: dyn = minv
     10222        if maxv > dyx: dyx = maxv
     10223    for iv in range(Nevalues):
     10224        minv = np.min(ensvals[iv])
     10225        maxv = np.max(ensvals[iv])
     10226        if minv < dyn: dyn = minv
     10227        if maxv > dyx: dyx = maxv
     10228
     10229    if yaxv[0] == 'pretty':
     10230        dimyt = np.array(gen.pretty_int(dyn,dyx,yaxv[2]))
     10231        dimyl = np.array(dimyt, dtype=str)
     10232    elif yaxv[0] == 'Nfix':
     10233        dimyt = np.arange(dyn,dyx,(dyx-dyn)/(yaxv[2]+1))
     10234        dimyl = np.arange(dyn,dyx,(dyx-dyn)/Lymaxvals)
     10235        axytype='fixpixel'
     10236    elif yaxv[0] == 'Vfix':
     10237        dynvfix = int(dyn/yaxv[2])
     10238        dimyt = np.arange(dynvfix*xaxv[2],dyx,yaxv[2])
     10239        axytype='data'
     10240    else:
     10241        print errormsg
     10242        print '  ' + fname + ": x-xais style '" + xaxv[0] + "' not ready !!"
     10243        print '    available ones: ', axstyles
     10244        quit(-1)
     10245
     10246    # kind of ensembles figure:
     10247    figv = figtype.split(',')
     10248    figtypen = figv[0]
     10249
     10250    # Ensemble values to use in the figure
     10251    dimt = etimevals[0].shape[len(etimevals[0].shape)-1]
     10252
     10253    evs = np.zeros((dimt,Nevalues), dtype=np.float)
     10254    for iv in range(Nevalues):
     10255        xvs = ensvals[iv]
     10256        if xvs.shape[0] != dimt:
     10257            print errormsg
     10258            print '  ' +fname+ ': ensemble values', iv, 'has different number:', \
     10259              xvs.shape[0], 'of time-steps:', dimt ,'!!'
     10260            quit(-1)
     10261        evs[:,iv] = xvs
     10262
     10263    plt.rc('text', usetex=True)
     10264    fig = plt.subplot(1,1,1)
     10265
     10266    if figtypen == 'cloud':
     10267        expectargs = "'cloud',[color],[limits]"
     10268        gen.check_arguments(fname + " & 'cloud'",figtype, expectargs,',')
     10269
     10270        col = gen.auto_val(figv[1], '#DDDDDD')
     10271        limits = gen.auto_val(figv[2], 'extremes')
     10272       
     10273        cloudlims = np.zeros((dimt,2), dtype=np.float)
     10274        # Computing limits of the data-ensemble
     10275        if limits == '5quantile':
     10276            for it in range(dimt):
     10277                quants = gen.mask_quantiles(evs[it,:], 20, Notenough=True)
     10278                cloudlims[it,0] = quants[1]-100.
     10279                cloudlims[it,1] = quants[18]+100.
     10280                Llimits = '5quantile,95quantile of the values of the ensemble'
     10281                glimits = '5-95 quantile'
     10282        elif limits == 'direct':
     10283            for it in range(dimt):
     10284                cloudlims[it,0] = evs[it,0]
     10285                cloudlims[it,1] = evs[it,1]
     10286                Llimits = 'first 2 values'
     10287                glimits = 'values'
     10288        elif limits == 'extremes':
     10289            for it in range(dimt):
     10290                cloudlims[it,0] = evs[it,:].min()
     10291                cloudlims[it,1] = evs[it,:].max()
     10292                Llimits = 'min,max of the values of the ensemble'
     10293                glimits = 'min,max'
     10294        elif limits == 'stddev':
     10295            if Nlvalues != 1:
     10296                print errormsg
     10297                print '  ' +fname+ ": with ensemble-limits '" + limits + "' only " + \
     10298                  '1-line is allowed', Nlvalues, 'provided !!'
     10299                quit(-1)
     10300            lvals = linevals[0]
     10301            for it in range(dimt):
     10302                sttdev = evs[it,:].std()
     10303                cloudlims[it,0] = lvals[it] - sttdev
     10304                cloudlims[it,1] = lvals[it] + sttdev
     10305            Llimits = 'val+/-standard deviation of the values of the ensemble'
     10306            glimits = 'val$\pm\sigma$'
     10307        else:
     10308            print errormsg
     10309            print '  ' +fname+ ": type of cloud-limits '" + limits + "' not ready !!"
     10310            print '    available ones:', availim
     10311            quit(-1)
     10312
     10313        if valuesvals[0] == 'x':
     10314            print errrormsg
     10315            print '  ' + fname + ": for '" + figtypen + "' there is no way to use " +\
     10316              "'x'-axis as axis-value !!"
     10317            print "    matplotlib: 'fill_between' does not allow it !!"
     10318            quit(-1)
     10319        else:
     10320            plt.fill_between(etimevals[0], cloudlims[:,0], cloudlims[:,1],           \
     10321              facecolor=col, label=glimits)
     10322    elif figtypen == 'spaghetti':
     10323        expectargs = "'spaghetti',[color],[width],[type]"
     10324        gen.check_arguments(fname + " & 'spaghetti'",figtype, expectargs,',')
     10325
     10326        col = gen.auto_val(figv[1], '#DDDDDD')
     10327        width = gen.auto_val(figv[2], 0.5)
     10328        ltype = gen.auto_val(figv[3], '-')
     10329        if valuesvals[0] == 'x':
     10330            for iv in range(Nevalues):
     10331                plt.plot(ensvals[iv], etimevals[iv], ltype, color=col, linewidth=width)
     10332        else:
     10333            for iv in range(Nevalues):
     10334                plt.plot(etimevals[iv], ensvals[iv], ltype, color=col, linewidth=width)           
     10335
     10336    else:
     10337        print errormsg
     10338        print '  ' + fname + ": '" + figtypen + "' not ready !!"
     10339        print '    available ones:', ['cloud', 'spaghetti']
     10340        quit(-1)
     10341
     10342    fig = plt.subplot(1,1,1)
     10343    # Plotting lines
     10344    lcols = gen.str_list_rep(Lcol, '@', Nlvalues)
     10345    ltypes = gen.str_list_rep(Ltype, '@', Nlvalues)
     10346    lwdths = gen.str_list_rep(Lwidth, '@', Nlvalues)
     10347    mtypes = gen.str_list_rep(Lmarker, '@', Nlvalues)
     10348    msizes = gen.str_list_rep(Lsizem, '@', Nlvalues)
     10349
     10350    for iv in range(Nlvalues):
     10351        if valuesvals[0] == 'x':
     10352            xvs = linevals[iv]
     10353            yvs = ltimevals[iv]
     10354        else:
     10355            xvs = ltimevals[iv]
     10356            yvs = linevals[iv]
     10357
     10358        if labels is not None and labels[iv] != 'None':
     10359            plt.plot(xvs, yvs, ltypes[iv], color=lcols[iv], linewidth=lwdths[iv],    \
     10360              marker=mtypes[iv], markersize=msizes[iv], label=labels[iv])
     10361        else:
     10362            plt.plot(xvs, yvs, ltypes[iv], color=lcols[iv], linewidth=lwdths[iv],    \
     10363              marker=mtypes[iv], markersize=msizes[iv])
     10364
     10365    # Axis
     10366    vrange = valuesvals[3]
     10367    if valuesvals[0] == 'x':
     10368        plt.xticks(dimyt, list(dimyl), rotation=yaxv[3])
     10369        plt.yticks(tpos, tlabs, rotation=xaxv[3])
     10370        if valuesvals[2] != 'None':
     10371            plt.xlabel(gen.latex_text(valuesvals[1]) + ' (' +                        \
     10372              units_lunits(valuesvals[2]) + ')')
     10373        else:
     10374            plt.xlabel(gen.latex_text(valuesvals[1]))
     10375        plt.ylabel(gen.latex(tname))
     10376        plt.xlim(vrange[0], vrange[1])
     10377        plt.ylim(tpos[0], tpos[len(tpos)-1])
     10378    else:
     10379        plt.xticks(tpos, tlabs, rotation=xaxv[3])
     10380        plt.yticks(dimyt, list(dimyl), rotation=yaxv[3])
     10381        plt.xlabel(gen.latex_text(tname))
     10382        if valuesvals[2] != 'None':
     10383            plt.ylabel(gen.latex_text(valuesvals[1]) + ' (' +                        \
     10384              units_lunits(valuesvals[2]) + ')')
     10385        else:
     10386            plt.ylabel(gen.latex_text(valuesvals[1]))
     10387        plt.xlim(tpos[0], tpos[len(tpos)-1])
     10388        plt.ylim(vrange[0], vrange[1])
     10389
     10390    if labels is not None:
     10391        plt.legend(loc=lloc, prop={'size':lsiz})
     10392
     10393    plt.title(gen.latex_text(gtit))
     10394   
     10395    output_kind(kfig, figname, ifclose)
     10396
     10397    # Creation of the output file
     10398    if ofile is not None:       
     10399        # Data of the lines
     10400        newvar = ofile.createVariable('vals', 'f4', ('time','data'),                 \
     10401          fill_value=gen.fillValueF)
     10402        basicvardef(newvar, 'vals', 'direct data plotted with lines', valuesvals[2])
     10403        newvar[:] = np.array(linevals)
     10404
     10405        # Data of the ensemble
     10406        newvar = ofile.createVariable('ensvals', 'f4', ('time','ensemble'),          \
     10407          fill_value=gen.fillValueF)
     10408        basicvardef(newvar, 'ensvals', 'data of the ensemble', valuesvals[2])
     10409        newvar[:] = evs
     10410
     10411        # cloud particularities
     10412        if figtypen == 'cloud':
     10413            newvar.setncattr('ensemble_limits', Llimits)
     10414            newdim = ofile.createDimension('cloudlims',2)
     10415            newvar = ofile.createVariable('cloudlims', 'f4', ('time','cloudlims'),   \
     10416              fill_value=gen.fillValueF)
     10417            basicvardef(newvar, 'cloudlims', 'limits of the cloud plot',             \
     10418              valuesvals[2])
     10419            newvar[:] = cloudlims[:]
     10420
     10421    return
Note: See TracChangeset for help on using the changeset viewer.