Changeset 1948 in lmdz_wrf for trunk


Ignore:
Timestamp:
Jul 21, 2018, 3:14:01 AM (6 years ago)
Author:
lfita
Message:

Improving

  • create_OBSnetcdf by including the fixed line function to get the values
  • Including 2Dshad_contdisc_time
  • Fixing help issues
Location:
trunk/tools
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/create_OBSnetcdf.py

    r648 r1948  
    4141        return True
    4242    return False
     43
     44
     45def typemod(value, typeval):
     46    """ Function to give back a value in a given dtype
     47    >>> print(typemod(8.2223, 'np.float64'))
     48    <type 'numpy.float64'>
     49    >>> print(typemod(8.2223, 'tuple'))
     50    <type 'tuple'>
     51    """
     52    fname='typemod'
     53
     54    if typeval == 'int' or typeval == 'I':
     55        return int(value)
     56    elif typeval == 'long':
     57        return long(value)
     58    elif typeval == 'float' or typeval == 'F' or typeval == 'R':
     59        return float(value)
     60    elif typeval == 'complex':
     61        return complex(value)
     62    elif typeval == 'str' or typeval == 'S':
     63        return str(value)
     64    elif typeval == 'bool':
     65        return bool(value)
     66    elif typeval == 'B':
     67        return Str_Bool(value)
     68    elif typeval == 'list':
     69        newval = []
     70        newval.append(value)
     71        return newval
     72    elif typeval == 'dic':
     73        newval = {}
     74        newval[value] = value
     75        return newval
     76    elif typeval == 'tuple':
     77        newv = []
     78        newv.append(value)
     79        newval = tuple(newv)
     80        return newval
     81    elif typeval == 'np.int8':
     82        return np.int8(value)
     83    elif typeval == 'np.int16':
     84        return np.int16(value)
     85    elif typeval == 'np.int32':
     86        return np.int32(value)
     87    elif typeval == 'np.int64':
     88        return np.int64(value)
     89    elif typeval == 'np.uint8':
     90        return np.uint8(value)
     91    elif typeval == 'np.uint16':
     92        return np.uint16(value)
     93    elif typeval == 'np.np.uint32':
     94        return np.uint32(value)
     95    elif typeval == 'np.uint64':
     96        return np.uint64(value)
     97    elif typeval == 'np.float' or typeval == 'R':
     98        return np.float(value)
     99    elif typeval == 'np.float16':
     100        return np.float16(value)
     101    elif typeval == 'np.float32':
     102        return np.float32(value)
     103    elif typeval == 'float32':
     104        return np.float32(value)
     105    elif typeval == 'np.float64' or typeval == 'D':
     106        return np.float64(value)
     107    elif typeval == 'float64':
     108        return np.float64(value)
     109    elif typeval == 'np.complex':
     110        return np.complex(value)
     111    elif typeval == 'np.complex64':
     112        return np.complex64(value)
     113    elif typeval == 'np.complex128':
     114        return np.complex128(value)
     115    else:
     116        print errormsg
     117        print fname + ':  data type "' + typeval + '" is not ready !'
     118        print errormsg
     119        quit(-1)
     120
     121    return
     122
     123def str_list_k(string, cdiv, kind):
     124    """ Function to obtain a list of types of values from a string giving a split character
     125      string= String from which to obtain a list ('None' for None)
     126      cdiv= character to use to split the string
     127      kind= kind of desired value (as string like: 'np.float', 'int', 'np.float64', ....)
     128    >>> str_list_k('1:@#:$:56', ':', 'S')
     129    ['1', '@#', '$', '56']
     130    >>> str_list_k('1:3.4:12.3', ':', 'np.float64')
     131    [1.0, 3.3999999999999999, 12.300000000000001]
     132    """
     133    fname = 'str_list'
     134
     135    if string.find(cdiv) != -1:
     136        listv = string.split(cdiv)
     137    else:
     138        if string == 'None':
     139            listv = None
     140        else:
     141            listv = [string]
     142
     143    if listv is not None:
     144        finalist = []
     145        for lv in listv:
     146            finalist.append(typemod(lv, kind))
     147    else:
     148        finalist = None
     149
     150    return finalist
     151
    43152
    44153def set_attribute(ncvar, attrname, attrvalue):
     
    227336            else:
    228337                opern = 'sumc'
    229                 operv = '0.'
     338                operv = '0'
    230339
    231340            if not searchInlist(fmts, fmt):
     
    328437    return newval
    329438
     439def getting_fixedline(line, cuts, types, dbg=False):
     440    """ Function to get the values from a line of text with fixed lenght of different values
     441      line: line with values
     442      cuts: character number where a value ends
     443      types: consecutive type of values
     444        'I': integer
     445        'R': real
     446        'D': float64
     447        'S': string
     448        'B': boolean
     449      dbg: debug mode (default False)
     450    >>> Sline='   87007 03012015  25.6   6.4             9.4    5   15'
     451    >>> getting_fixedline(Sline, [8, 17, 23, 29, 36, 40, 45, 50], ['I', 'R', 'R', 'R', 'I', 'R', 'R', 'R'])
     452    [87007, 3012015.0, 25.6, 6.4, -99999, -99999, 9.4, 5.0, 15.0]
     453    """
     454    fname = 'getting_fixedline'
     455
     456    if len(cuts) + 1 != len(types):
     457        print errormsg
     458        print '  ' + fname + ': The number of types :', len(types), 'must be +1',    \
     459          'number of cuts:', len(cuts)
     460        quit(-1)
     461
     462    values = []
     463    val = line[0:cuts[0]]
     464    if len(val.replace(' ','')) >= 1:
     465        values.append(typemod(val, types[0]))
     466    else:
     467        if types[0] == 'I': values.append(fillValueI)
     468        elif types[0] == 'R': values.append(fillValueF)
     469        elif types[0] == 'D': values.append(fillValueF)
     470        elif types[0] == 'S': values.append(fillValueS)
     471        elif types[0] == 'B': values.append(fillValueB)
     472
     473    Ncuts = len(cuts)
     474    for ic in range(1,Ncuts):
     475        val = line[cuts[ic-1]:cuts[ic]]
     476        if dbg: print ic, ':', val, '-->', types[ic]
     477        if len(val.replace(' ','')) >= 1:
     478            values.append(typemod(val, types[ic]))
     479        else:
     480            if types[ic] == 'I': values.append(fillValueI)
     481            elif types[ic] == 'R': values.append(fillValueF)
     482            elif types[ic] == 'D': values.append(fillValueF)
     483            elif types[ic] == 'S': values.append(fillValueS)
     484            elif types[ic] == 'B': values.append(fillValueB)
     485
     486    # Last value
     487    Lline = len(line)
     488    val = line[cuts[Ncuts-1]:Lline]
     489    if len(val.replace(' ','')) >= 1:
     490        values.append(typemod(val, types[Ncuts]))
     491    else:
     492        if types[Ncuts] == 'I': values.append(fillValueI)
     493        elif types[Ncuts] == 'R': values.append(fillValueF)
     494        elif types[Ncuts] == 'D': values.append(fillValueF)
     495        elif types[Ncuts] == 'S': values.append(fillValueS)
     496        elif types[Ncuts] == 'B': values.append(fillValueB)
     497
     498    return values
     499
     500
     501def getting_fixedline_NOk(line, cuts, miss, dbg=False):
     502    """ Function to get the values from a line of text with fixed lenght of
     503        different values without types
     504      line: line with values
     505      cuts: character number where a value ends
     506      miss: character form issed values
     507      dbg: debug mode (default False)
     508    >>> Sline='   87007 03012015  25.6   6.4             9.4    5   15'
     509    >>> getting_fixedline_NOk(Sline, [8, 17, 23, 29, 36, 40, 45, 50], '#')
     510    ['87007', '03012015', '25.6', '6.4', '#', '#', '9.4', '5', '15']
     511    """
     512    fname = 'getting_fixedline_NOk'
     513
     514    values = []
     515    val = line[0:cuts[0]]
     516    if len(val.replace(' ','')) >= 1:
     517        values.append(val.replace(' ',''))
     518    else:
     519        values.append(miss)
     520
     521    Ncuts = len(cuts)
     522    for ic in range(1,Ncuts):
     523        val = line[cuts[ic-1]:cuts[ic]]
     524        if dbg: print ic, ':', val
     525        if len(val.replace(' ','')) >= 1:
     526            values.append(val.replace(' ',''))
     527        else:
     528            values.append(miss)
     529
     530    # Last value
     531    Lline = len(line)
     532    val = line[cuts[Ncuts-1]:Lline]
     533    if len(val.replace(' ','')) >= 1:
     534        values.append(val.replace(' ',''))
     535    else:
     536        values.append(miss)
     537
     538    return values
     539
    330540def read_datavalues(dataf, comchar, colchar, fmt, oper, miss, varns, dbg):
    331541    """ Function to read from an ASCII file values in column
     
    358568        line = line.replace('\n','').replace(chr(13),'')
    359569        if not searchInlist(comchar,line[0:1]) and len(line) > 1:
    360             values0 = line.split(colchar)
     570            # Getting values
     571            if colchar[0:4] != 'None':
     572                values0 = line.split(colchar)
     573            else:
     574                ltypes=str_list_k(colchar[5:len(colchar)+1],',','I')
     575                values0 = getting_fixedline_NOk(line, ltypes, miss[0], dbg=dbg)
    361576# Removing no-value columns
    362577            values = []
     
    8261041  help="description file to use" + read_description.__doc__, metavar="FILE")
    8271042parser.add_option("-e", "--end_column", dest="endcol",
    828   help="character to indicate end of the column ('space', for ' ')", metavar="VALUE")
     1043  help="character to indicate end of the column ('space', for ' ', or 'None,[fixcoljumps]' for fixed size columns with [fixcoljumps]: ',' separated list of positions of column ends within line)", metavar="VALUE")
    8291044parser.add_option("-f", "--file", dest="obsfile",
    8301045  help="observational file to use", metavar="FILE")
     
    10671282    basicvardef(newvar, timeCFname, 'time', tunits )
    10681283else:
    1069     newdim = objfile.createDimension('time',None)
     1284    if searchInlist(objfile.dimensions, 'time'):
     1285        print warnmsg
     1286        print '  ' + main + ": dimension 'time' already exist !!"
     1287        print "    renaming it as 'CFtime'"
     1288        tdimn = 'CFtime'
     1289        newdim = objfile.renameDimension('time','CFtime')
     1290    else:
     1291        tdmin = 'time'
     1292        newdim = objfile.createDimension(tdimn,None)
    10701293    timeCFname = 'time'
    1071     newvar = objfile.createVariable( timeCFname, 'f8', ('time'))
     1294    newvar = objfile.createVariable( timeCFname, 'f8', (tdimn))
     1295    newvar[:] = np.zeros(timevals.shape[0])
    10721296    basicvardef(newvar, timeCFname, 'time', tunits )
    10731297
     
    10761300    newvar[:] = timevals[0]
    10771301else:
     1302    print 'Lluis shapes: newvar:', newvar.shape, 'timevals:', timevals.shape
    10781303    newvar[:] = timevals
    10791304
  • trunk/tools/documentation/plotting/gallery.html

    r1876 r1948  
    1515      <A HREF="2Dshad_time.html"><IMG SRC="figs/ta_valley_fixpixel-grid.png" ALT="2D shadow time" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A>
    1616      <A HREF="2Dshad_cont.html"><IMG SRC="figs/huss-tas_Blues_shad-cont.png" ALT="2D shadow contour" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A>
     17      <A HREF="2Dshad_contdisc_time.html"><IMG SRC="figs/2Dshad_obs-sim_comparison_time.png" ALT="2D shadow continuous and discrete" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A>
    1718      <A HREF="2Dshad_2cont.html"><IMG SRC="figs/2Dfields_shadow-2contour.png" ALT="2D shadow 2 contour" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A>
    1819      <A HREF="2Dshad_cont_time.html"><IMG SRC="figs/huss-tas_shad_cont_time_BuPu.png" ALT="2D shadow contour time" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A>
  • trunk/tools/documentation/plotting/intro.html

    r1876 r1948  
    3939      Available plots:
    4040      <UL>
    41        <LI><SPAN CLASS="codetxt"> create_movie:</SPAN> Function to create a movie assuming ImageMagick installed! </LI>
    42        <LI><SPAN CLASS="codetxt"> draw_2D_shad:</SPAN> plotting a fields with shading </LI>
    43        <LI><SPAN CLASS="codetxt"> draw_2D_shad_cont:</SPAN> plotting two fields, one with shading and the other with contour lines </LI>
     41       <LI><SPAN CLASS="codetxt">create_movie:</SPAN> Function to create a movie assuming ImageMagick installed! </LI>
     42       <LI><SPAN CLASS="codetxt">draw_2D_shad:</SPAN> plotting a fields with shading </LI>
     43       <LI><SPAN CLASS="codetxt">draw_2D_shad_cont:</SPAN> plotting two fields, one with shading and the other with contour lines </LI>
     44       <LI><SPAN CLASS="codetxt">draw_2D_shad_contdisc_time:</SPAN> plotting one continuous fields with shading and another discrete one with points with a time-axis </LI>
    4445       <LI><SPAN CLASS="codetxt"> draw_2D_shad_cont_time:</SPAN> plotting two fields, one with shading and the other with contour lines being one of the dimensions of time characteristics </LI>
    4546       <LI><SPAN CLASS="codetxt">draw_2D_shad_line:</SPAN> plotting a fields with shading and another with line </LI>
  • trunk/tools/documentation/plotting/plotting.html

    r1875 r1948  
    1010      <A CLASS="lc" HREF="2Dshad_time.html" TARGET="value">2D shadow time</A><BR>
    1111      <A CLASS="lc" HREF="2Dshad_cont.html" TARGET="value">2D shadow contour</A><BR>
     12      <A CLASS="lc" HREF="2Dshad_contdisc_time.html" TARGET="value">2D shadow cont. & disc. time</A><BR>
    1213      <A CLASS="lc" HREF="2Dshad_2cont.html" TARGET="value">2D shadow 2 contour</A><BR>
    1314      <A CLASS="lc" HREF="2Dshad_cont_time.html" TARGET="value">2D shadow contour time</A><BR>
  • trunk/tools/drawing.py

    r1947 r1948  
    5959# movie_2D_shad -f '../PY/wrfout_d01_1995-01-01_00:00:00' -S 'tas:west_east|-1,south_north|-1,Time|-1:XLONG:XLAT:auto:rainbow,auto,auto:Srange,Srange:png:None:cyl,l:Time,Times:WRFdate,$%d^{%H}$:15:mp4' -v T2
    6060## e.g. # drawing.py -o draw_SkewT -f UWyoming_snd_87576.nc -S 'time|0:auto:auto:Sounding!at!Ezeiza!airport!on!3rd!July!1998:png:yes' -v ta,tda,pres
    61 ## e.g. # drawing.py -o draw_multi_SkewT -f '/home/lluis/estudios/ChemGBsAs/tests/199807/obs/snd/UWyoming_snd_87576.nc:pres|-1,time|0:ta,pres;/home/lluis/estudios/ChemGBsAs/tests/199807/obs/snd/UWyoming_snd_87576.nc:pres|-1,time|0:tda,pres' -S 'auto:auto:multilines!ta,tda!#6464FF,#FF6464!-!,!2:0,auto:Sounding!at!Ezeiza!airport!on!3rd!July!1998:png:yes'
    62 ## e.g. # drawing.py -o draw_2D_shad_contdisc -f '/home/lluis/estudios/ChemGBsAs/tests/199501/simout_snddiags.nc;ta;time;pres;time|-1,pres|-1@/home/lluis/estudios/ChemGBsAs/tests/199501/obs/snd/UWyoming_snd_87576.nc;ta;time;pres;time|-1,pres|-1' -S 'ta:time,bottom_top:Vfix,auto,3600.,auto,Vfix,auto,50.,auto:auto:Srange,Srange:auto:obs!&!sim!Ezeiza!airport!sounding:pdf:flip@y:None:yes'
     61## e.g. # drawing.py -o draw_multi_SkewT -f 'UWyoming_snd_87576.nc:pres|-1,time|0:ta,pres;UWyoming_snd_87576.nc:pres|-1,time|0:tda,pres' -S 'auto:auto:multilines!ta,tda!#6464FF,#FF6464!-!,!2:0,auto:Sounding!at!Ezeiza!airport!on!3rd!July!1998:png:yes'
     62## e.g. # drawing.py -o draw_2D_shad_contdisc -f 'simout_snddiags.nc;ta;time;pres;time|-1,pres|-1@UWyoming_snd_87576.nc;ta;time;pres;time|-1,pres|-1' -S 'ta:time,bottom_top:Vfix,auto,3600.,auto,Vfix,auto,50.,auto:auto:Srange,Srange:auto:obs!&!sim!Ezeiza!airport!sounding:pdf:flip@y:None:yes'
     63## e.g. # drawing.py -o draw_2D_shad_contdisc_time -f 'simout_snddiags.nc;ta;time;pres;time|-1,pres|-1@UWyoming_snd_87576.nc;ta;time;pres;time|-1,pres|-1' -S 'ta;y;auto|exct,12,h|%d$^{%H}$|time!($[DD]^{[HH]}$);Vfix,auto,50.,auto;auto;Srange,Srange;auto;obs!&!sim!Ezeiza!airport!sounding;pdf;flip@y;None;yes'
    6364
    6465#######
     
    6768# draw_2D_shad_cont: plotting two fields, one with shading and the other with contour lines
    6869# draw_2D_shad_contdisc: plotting one continuous fields with shading and another discrete one with points
     70# draw_2D_shad_contdisc_time: plotting one continuous fields with shading and another discrete one with
     71#   points with a time-axis
    6972# draw_2D_shad_2cont: plotting three fields, one with shading and the other two with contour lines
    7073# draw_2D_shad_cont_time: plotting two fields, one with shading and the other with contour lines being
     
    115118
    116119namegraphics = ['create_movie', 'draw_2D_shad', 'draw_2D_shad_time',                 \
    117   'draw_2D_shad_cont', 'draw_2D_shad_contdisc', 'draw_2D_shad_2cont',                \
    118   'draw_2D_shad_cont_time',                                                          \
     120  'draw_2D_shad_cont', 'draw_2D_shad_contdisc', 'draw_2D_shad_contdisc_time',        \
     121  'draw_2D_shad_2cont', 'draw_2D_shad_cont_time',                                    \
    119122  'draw_2D_shad_line',                                                               \
    120123  'draw_2D_shad_line_time', 'draw_bar', 'draw_bar_line', 'draw_bar_line_time',       \
     
    94829485   
    94839486def draw_2D_shad_contdisc_time(ncfiles, values, axfig=None, fig=None):
    9484     """ plotting one continuous fields with shading and another discrete one with points
    9485     draw_2D_shad_contdisc(ncfile, values)
     9487    """ plotting one continuous fields with shading and another discrete one with
     9488    points with a time-axis
     9489    draw_2D_shad_contdisc_time(ncfile, values)
    94869490      ncfiles= [contfilen];[contvarn];[dimtvarn];[dimvvarn];[dimvals]@[discfilen];
    94879491          [discvarn];[dimtvarn];[dimvvarn];[dimvals] files and variables to use
     
    94999503        [discvarn]: name of the discrete variable
    95009504        * NOTE: limits of the graph will be computed from the continuous variable
    9501       values=[vnamefs];[varaxis];[timevals];[dimxyfmt];[colorbarvals];[sminv],[smaxv];
     9505      values=[vnamefs];[varaxis];[timevals];[dimvfmt];[colorbarvals];[sminv],[smaxv];
    95029506       [discvals];[figt];[kindfig];[reverse];[mapv];[close]
    95039507        [vnamefs]: Name in the figure of the variable to be shaded
    95049508        [varaxis]: axis in the figure for the variable-axis ('x' or 'y')
    9505         [timevals]: [timen]|[units]|[kind]|[tfmt]|[label]|[timeaxis] time labels characteristics
    9506           [timen]: name of the time variable ('WRFtime' for WRF times)
     9509        [timevals]: [units]|[kind]|[tfmt]|[label] time labels characteristics
    95079510          [units]: units string according to CF conventions ([tunits] since
    9508             [YYYY]-[MM]-[DD] [[HH]:[MI]:[SS]], '!' for spaces)
     9511            [YYYY]-[MM]-[DD] [[HH]:[MI]:[SS]], '!' for spaces),
     9512            'auto' for minutes!since!1949-12-01!00:00:00
    95099513          [kind]: kind of output
    95109514            'Nval': according to a given number of values as 'Nval',[Nval]
     
    95139517               'w': week, 'd': day, 'h': hour, 'i': minute, 's': second,
    95149518               'l': milisecond
    9515           [tfmt]: desired format
    9516           [label]: label at the graph ('!' for spaces)
     9519          [tfmt]: desired format (combination of 'C'-style values and LaTeX)
     9520          [label]: label at the graph ('!' for spaces, combination of 'C'-style
     9521            values and LaTeX)
    95179522        [dimvfmt]=[[dvs],[dvf],[Ndv],[ordv]: format of the values at variable-axis
    95189523          (or 'auto')
     
    95729577        quit()
    95739578
    9574     expectargs = '[vnamefs];[varaxis];[timevals];[dimxyfmt];[colorbarvals];' +       \
    9575        '[sminv],[smaxv];[discvals];[figt];[kindfig];[reverse];[mapv];[close]';;;
     9579    expectargs = '[vnamefs];[varaxis];[timevals];[dimvfmt];[colorbarvals];' +       \
     9580       '[sminv],[smaxv];[discvals];[figt];[kindfig];[reverse];[mapv];[close]'
    95769581
    95779582    drw.check_arguments(fname,values,expectargs,';')
     
    95799584    vnamesfig = values.split(';')[0]
    95809585    varaxis = values.split(';')[1]
    9581     timevals = values.split(';')[2].split(',')
    9582     colorbarvals = values.split(';')[3]
    9583     shadminmax = values.split(';')[4]
    9584     discvals = values.split(';')[5]
    9585     figt = values.split(';')[6].replace('!',' ')
    9586     kindfig = values.split(';')[7]
    9587     revals = values.split(';')[8]
    9588     mapvalue = values.split(';')[9]
    9589     close = gen.Str_Bool(values.split(';')[10])
     9586    timevals = values.split(';')[2].split('|')
     9587    dimvfmt = values.split(';')[3]
     9588    colorbarvals = values.split(';')[4]
     9589    shadminmax = values.split(';')[5]
     9590    discvals = values.split(';')[6]
     9591    figt = values.split(';')[7].replace('!',' ')
     9592    kindfig = values.split(';')[8]
     9593    revals = values.split(';')[9]
     9594    mapvalue = values.split(';')[10]
     9595    close = gen.Str_Bool(values.split(';')[11])
     9596
     9597    if timevals[0] == 'auto':
     9598        timevals[0] = 'minutes since 1949-12-01 00:00:00'
     9599    else:
     9600        timevals[0] = timevals[0].replace('!',' ')
    95909601
    95919602    ncs = ncfiles.split('@')
     
    96149625        if not os.path.isfile(ncfilen):
    96159626            print errormsg
    9616             print '  ' + fname + ": '" + hfn + "' file '" + ncfile + "' does " +     \
     9627            print '  ' + fname + ": '" + hfn + "' file '" + ncfilen + "' does " +    \
    96179628              "not exist !!"
    96189629            quit(-1)
     
    96229633        if  not onc.variables.has_key(varn):
    96239634            print errormsg
    9624             print '  ' + fname + ": '" + hfn + "' file '" + ncfile +                 \
     9635            print '  ' + fname + ": '" + hfn + "' file '" + ncfilen +                \
    96259636              "' does not have variable '" + varn + "' !!"
    96269637            varns = sorted(onc.variables.keys())
     
    96889699          objdimt.dimensions, objdimv.dimensions, dimvals.replace(':','|').split(','),\
    96899700          False)
     9701        # Getting same times
     9702        odimxv0 = gen.coincident_CFtimes(odimxv0, timevals[0], odimxu)
    96909703
    96919704        # Some statistics
     
    97049717
    97059718        if hfn == 'cont':
    9706             timeinfo = []
    9707 
    9708             if varaxis == 'x':
    9709                 # Getting the right shape of dimensions
    9710                 if vals.shape[0] != odimxv0.shape[0]: gdimx = vals.shape[0]
    9711                 else: gdimx = vals.shape[1]
    9712                 gdimy = odimxv0.shape[0]
    9713             else:
    9714                 if vals.shape[0] != odimxv0.shape[0]: gdimy = vals.shape[0]
    9715                 else: gdimy = vals.shape[1]
    9716                 gdimx = odimxv0.shape[0]
     9719
     9720            # Getting time initialy as x-axis the right shape of dimensions
     9721            gdimx = odimxv0.shape[0]
     9722            if vals.shape[0] != gdimx: gdimy = vals.shape[0]
     9723            else: gdimy = vals.shape[1]
    97179724
    97189725            if vals.shape[1] == gdimx: contv = vals[:]
     
    97379744
    97389745            diminfo = {}
    9739             diminfo['units'] = [odimxu, odimyu]
    9740             diminfo['names'] = [gen.variables_values(vdimxn)[0],                     \
    9741               gen.variables_values(vdimyn)[1]]
     9746            diminfo['units'] = [timevals[0], odimvu]
     9747            diminfo['names'] = [gen.variables_values(vdimtn)[0],                     \
     9748              gen.variables_values(vdimvn)[1]]
    97429749            varinfo = {}
    97439750            varinfo['units'] = varunits
     
    97529759        else:
    97539760            discvarv = []
    9754             discx0 = []
    9755             discy0 = []
     9761            discx = []
     9762            discy = []
    97569763            # Assuming that discrete values are masked
    97579764            if type(vals) != type(gen.mamat):
     
    97799786                        discx.append(d2Dx[j,i])
    97809787                        discy.append(d2Dy[j,i])
    9781             if varaxis == 'x':
    9782                 discx = list(discy0)
    9783                 # Getting same times
    9784                 discy = gen.coincident_CFtimes(discx0, timeinfo[], varunits)
    9785             else:
    9786                 discx = list(discx0)
    9787                 discy = list(discy0)
    9788 
    97899788
    97909789            Ndiscvals = len(discvarv)
     
    98299828    colormapv = [colbarn, fmtcolbar, colbaror]
    98309829
    9831     xstyl, xaxf, Nxax, xaxor, ystyl, yaxf, Nyax, yaxor = drw.format_axes(dimxyf,',')
    9832     xaxis = [xstyl, xaxf, Nxax, xaxor]
    9833     yaxis = [ystyl, yaxf, Nyax, yaxor]
     9830    # format axes
     9831    if dimvfmt == 'auto': axfmt = 'auto,auto,auto,auto,auto,auto,auto,auto'
     9832    else: axfmt = 'auto,auto,auto,auto,' + dimvfmt
     9833    xstyl, xaxf, Nxax, xaxor, ystyl, yaxf, Nyax, yaxor = drw.format_axes(axfmt, ',')
     9834    valaxis = [ystyl, yaxf, Nyax, yaxor]
    98349835
    98359836    if revals == 'None':
    98369837        revals = None
    98379838
    9838     drw.plot_2Dshad_obssim_time(discv, contv, odxv, odyv, revals, diminfo, xaxis,    \
    9839       yaxis, colormapv, shading_nx, varinfo, discinfo, mapvalue, graphnx, figt,      \
    9840       kindfig, close)
     9839    # time values
     9840    timeinfo = {}
     9841    timeinfo['units'] = timevals[0]
     9842    timeinfo['name'] = timevals[3].replace('!', ' ')
     9843    timeinfo['tpos'], timeinfo['tlabs'] = drw.CFtimes_plot([dxn, dxx], timevals[0],  \
     9844      timevals[1], timevals[2])
     9845
     9846    drw.plot_2Dshad_obssim_time(discv, contv, odxv, odyv, varaxis, revals, diminfo,  \
     9847      valaxis, timeinfo, colormapv, shading_nx, varinfo, discinfo, mapvalue, graphnx,\
     9848      figt, kindfig, close)
    98419849
    98429850    return
    98439851
    9844 contfilen = '/home/lluis/estudios/ChemGBsAs/tests/199501/simout_snddiags.nc;ta;time;pres;time|-1,pres|-1'
    9845 discfilen = '/home/lluis/estudios/ChemGBsAs/tests/199501/obs/snd/UWyoming_snd_87576.nc;ta;time;pres;time|-1,pres|-1'
    9846 
    9847 values = 'ta:time,bottom_top:Vfix,auto,3600.,auto,Vfix,auto,50.,auto:auto:Srange,Srange:o,5.:obs!&!sim!Ezeiza!airport!sounding:pdf:flip@y:None:yes'
    9848 
    9849 draw_2D_shad_contdisc_time(contfilen+'@'+discfilen, values, axfig=None, fig=None)
     9852#contfilen = '/home/lluis/estudios/ChemGBsAs/tests/199501/simout_snddiags.nc;ta;time;pres;time|-1,pres|-1'
     9853#discfilen = '/home/lluis/estudios/ChemGBsAs/tests/199501/obs/snd/UWyoming_snd_87576.nc;ta;time;pres;time|-1,pres|-1'
     9854#values = 'ta;y;auto|exct,12,h|%d$^{%H}$|time!($[DD]^{[HH]}$);Vfix,auto,50.,auto;auto;Srange,Srange;auto;obs!&!sim!Ezeiza!airport!sounding;pdf;flip@y;None;yes'
     9855
     9856#draw_2D_shad_contdisc_time(contfilen+'@'+discfilen, values, axfig=None, fig=None)
    98509857
    98519858
     
    98709877# Not checking file operation
    98719878Notcheckingfile = ['draw_2D_shad_cont', 'draw_2D_shad_contdisc',                     \
    9872   'draw_2D_shad_2cont', 'draw_2D_shad_cont_time',                                    \
     9879  'draw_2D_shad_contdisc_time', 'draw_2D_shad_2cont', 'draw_2D_shad_cont_time',      \
    98739880  'draw_2D_shad_line', 'draw_2D_shad_line_time', 'draw_2lines', 'draw_2lines_time',  \
    98749881  'draw_bar', 'draw_bar_line', 'draw_bar_line_time', 'draw_bar_time',                \
     
    99309937    elif oper == 'draw_2D_shad_contdisc':
    99319938        draw_2D_shad_contdisc(opts.ncfile, opts.values)
     9939    elif oper == 'draw_2D_shad_contdisc_time':
     9940        draw_2D_shad_contdisc_time(opts.ncfile, opts.values)
    99329941    elif oper == 'draw_2D_shad_2cont':
    99339942        draw_2D_shad_2cont(opts.ncfile, opts.values, opts.varname)
  • trunk/tools/drawing_tools.py

    r1947 r1948  
    165165# plot_time_lag: Function to plot a time-lag figure (x, previous values; y, future values)
    166166# plot_Trajectories
     167# plot_2Dshad_obssim: Function to plot a 2D shadding plot with comparison
     168#   between observations (as filled colored circles) and simulation (shadded
     169#   continuous field)
     170# plot_2Dshad_obssim_time: Function to plot a 2D shadding plot with comparison
     171#   between observations (as filled colored circles) and simulation (shadded
     172#   continuous field) with a time-axis
    167173# plot_2D_shadow_contour:
    168174# plot_2D_shadow_2contour: Plotting 3 2D fields, 1 with shadow and two with contour lines
     
    1203612042    return
    1203712043
    12038 def plot_2Dshad_obssim_time(obsv, varsv, dimvv, dimtv, dataxis, reva, diminf, vaxv,  \
     12044def plot_2Dshad_obssim_time(obsv, varsv, dimtv, dimvv, dataxis, reva, diminf, vaxv,  \
    1203912045  timeinf, cbarv, vs, varinf, discinf, mapv, gmaxmin, figtitle, kfig, close):
    1204012046    """ Function to plot a 2D shadding plot with comparison between observations (as
    12041      filled colored circles) and simulation (shadded continuous field)
     12047     filled colored circles) and simulation (shadded continuous field) with a time-axis
    1204212048      obsv= 3-column with observational values (x, y, value)
    1204312049      varsv= 2D matrix of simulation values
     12050      dimtv= values for t-coordinate from simulation
    1204412051      dimvv= values for v-coordinate from simulation
    12045       dimtv= values for t-coordinate from simulation
    1204612052      dataxis= which axis 'x' or 'y' should be use for the non-temporal dimension
    1204712053      reva= in case of modification of the plotting of 2D variables ('|' can be used for combination)
     
    1205212058        diminf['names']= [dimxn, dimyn]: names of the dimension
    1205312059      vaxv= list with the v-axis paramteres [style, format, number and orientation]
    12054       timeinf= list with information for the time-axis
    12055         [timepos]: positions of the markers
    12056         [timelabs]: labels of the markers
    12057         [ttitle]: title in graphic
     12060      timeinf= dictionary with information for the time-axis
     12061        'tpos': positions of the markers
     12062        'tlabs': labels of the markers
     12063        'name': name in graphic
     12064        'units': units
    1205812065      cbarv= list with the parameters of the color bar [colorbar, cbarfmt, cbaror]
    1205912066        colorbar: name of the color bar to use
     
    1211012117    # Usually axis > x must be the time, thus...
    1211112118    dimxv0 = dimtv.copy()
    12112     dimyv0 = dimyv.copy()
     12119    dimyv0 = dimvv.copy()
    1211312120
    1211412121    dxn = dimtv.min()
    1211512122    dxx = dimtv.max()
    12116     dyn = dimyv.min()
    12117     dyx = dimyv.max()
    12118 
    12119     dimxt0 = timeinf[0]
    12120     dimxl0 = timeinf[1]
     12123    dyn = dimvv.min()
     12124    dyx = dimvv.max()
     12125
     12126    dimxt0 = timeinf['tpos']
     12127    dimxl0 = timeinf['tlabs']
    1212112128
    1212212129    if vaxv[0] == 'pretty':
     
    1212812135
    1212912136    dimyl0 = []
    12130     for i in range(len(dimyt0)): dimyl0.append('{:{style}}'.format(dimyt0[i], style=yaxv[1]))
    12131 
     12137    for i in range(len(dimyt0)): dimyl0.append('{:{style}}'.format(dimyt0[i],        \
     12138      style=vaxv[1]))
     12139
     12140    dimn = diminf['names']
    1213212141    dimyu = diminf['units'][1]
    1213312142
    12134     dimxT0 = timeinf[2]
     12143    dimxT0 = timeinf['name']
    1213512144    dimyT0 = variables_values(dimn[1])[0] + ' (' + units_lunits(dimyu) + ')'
    1213612145
     
    1231012319
    1231112320        if signxl != signxt:
    12312             plt.xticks(1.-dimxt, dimxl, rotation=xaxv[3])
     12321            plt.xticks(1.-dimxt, dimxl)
    1231312322        else:
    12314             plt.xticks(dimxt, dimxl, rotation=xaxv[3])
     12323            plt.xticks(dimxt, dimxl)
    1231512324        if signyl != signyt:
    12316             plt.yticks(1.-dimyt, dimyl, rotation=yaxv[3])
     12325            plt.yticks(1.-dimyt, dimyl, rotation=vaxv[3])
    1231712326        else:
    12318             plt.yticks(dimyt, dimyl, rotation=yaxv[3])
     12327            plt.yticks(dimyt, dimyl, rotation=vaxv[3])
    1231912328
    1232012329        # Only if gmaxmin is used to compute limits of the figure !!
     
    1234212351    plt.title(gen.latex_text(figtitle))
    1234312352
    12344     figname = '2Dshad_obs-sim_comparison_time.png'
     12353    figname = '2Dshad_obs-sim_comparison_time'
    1234512354    output_kind(kfig, figname, close)
    1234612355
  • trunk/tools/nc_var_tools.py

    r1939 r1948  
    1448814488
    1448914489    arguments = '[longitude]:[latitude]:[dnames]:[vdnames]'
    14490     check_arguments(fname, values, arguments, ':')
     14490    gen.check_arguments(fname, values, arguments, ':')
    1449114491
    1449214492    longitude = np.float(values.split(':')[0])
     
    1449814498
    1449914499    for dn in dnames:
    14500         if not searchInlist(onc.dimensions, dn):
     14500        if not gen.searchInlist(onc.dimensions, dn):
    1450114501            print errormsg
    1450214502            print '  ' + fname + ": file '" + ncfile + "' does not have dimension '"+\
     
    1450514505
    1450614506    for vdn in dvnames:
    14507         if not searchInlist(onc.variables, vdn):
     14507        if not gen.searchInlist(onc.variables, vdn):
    1450814508            print errormsg
    1450914509            print '  ' + fname + ": file '" + ncfile + "' does not have variable '"+ \
     
    1451314513# Getting grid point localization
    1451414514##
    14515     lon2d, lat2d = lonlat2D(onc.variables[dvnames[0]], onc.variables[dvnames[1]])
     14515    lon2d, lat2d = gen.lonlat2D(onc.variables[dvnames[0]], onc.variables[dvnames[1]])
    1451614516   
    1451714517    dimx = lon2d.shape[1]
     
    1452114521    dist=np.sqrt((longitude - lon2d)**2. + (latitude - lat2d)**2.)
    1452214522    mindist = np.min(dist)
    14523     minydist, minxdist = index_mat(dist,mindist)
     14523    minydist, minxdist = gen.index_mat(dist,mindist)
    1452414524    mappairs[:] = [minydist, minxdist]
    1452514525
     
    1453114531    vals = vals + dnames[0] + ',' + str(mappairs[0]) + ',' + str(mappairs[0]) + ',1'
    1453214532
    14533     DataSetSection_multidims(vals, ncfile)
     14533    DataSetSection_multidims(vals, ncfile, 'all')
    1453414534    of = ncfile.split('.')[0] + '_' +  dnames[1] + '_B' + str(mappairs[1]) + '-E' +  \
    1453514535      str(mappairs[1]) + '-I1_' + dnames[0] + '_B' + str(mappairs[0]) + '-E' +       \
Note: See TracChangeset for help on using the changeset viewer.