Changeset 1968 in lmdz_wrf


Ignore:
Timestamp:
Jul 24, 2018, 6:45:52 PM (7 years ago)
Author:
lfita
Message:

Adding to `draw_2D_shad_contdisc'

  • [plotrange]: range of the plot
  • Extremes of plots only from mapping area
Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/drawing.py

    r1948 r1968  
    91519151        * NOTE: limits of the graph will be computed from the continuous variable
    91529152      values=[vnamefs]:[dvarxn],[dvaryn]:[dimxyfmt]:[colorbarvals]:[sminv],[smaxv]:
    9153        [discvals]:[figt]:[kindfig]:[reverse]:[mapv]:[close]
     9153       [discvals]:[figt]:[kindfig]:[reverse]:[mapv]:[plotrange]:[close]
    91549154        [vnamefs]: Name in the figure of the variable to be shaded
    91559155        [dvarxn],[dvaryn]: name of the dimensions for the final x-axis and y-axis at
     
    92079207            * 'h', high
    92089208            * 'f', full
     9209        [plotrange]: range of the plot
     9210          'strict': map covers only the minimum and maximum lon,lats from the
     9211            locations of the discrtete points
     9212          'sponge,'[dlon],[dlat]: map covers an extended [dlon],[dlat] from the
     9213            minimum and maximum lon,lats from the locations of the discrtete points
     9214          'fullcontinuous': map covers all the shadding area
    92099215        [close]: Whether figure should be finished or not
    92109216    """
     
    92179223
    92189224    expectargs = '[vnamefs]:[dvarxn],[dvaryn]:[dimxyfmt]:[colorbarvals]:[sminv],' +  \
    9219       '[smaxv]:[discvals]:[figt]:[kindfig]:[reverse]:[mapv]:[close]'
     9225      '[smaxv]:[discvals]:[figt]:[kindfig]:[reverse]:[mapv]:[plotrange]:[close]'
    92209226 
    92219227    drw.check_arguments(fname,values,expectargs,':')
     
    92319237    revals = values.split(':')[8]
    92329238    mapvalue = values.split(':')[9]
    9233     close = gen.Str_Bool(values.split(':')[10])
     9239    plotrange = values.split(':')[10]
     9240    close = gen.Str_Bool(values.split(':')[11])
    92349241
    92359242    ncs = ncfiles.split('@')
     
    92669273        if  not onc.variables.has_key(varn):
    92679274            print errormsg
    9268             print '  ' + fname + ": '" + hfn + "' file '" + ncfile +                 \
     9275            print '  ' + fname + ": '" + hfn + "' file '" + ncfilen +                \
    92699276              "' does not have variable '" + varn + "' !!"
    92709277            varns = sorted(onc.variables.keys())
     
    92769283        vals, dims = drw.slice_variable(ovar, dimvals.replace(',','|'))
    92779284
    9278         # Values have to be 2D (might not be true for disc?)
    9279         if len(vals.shape) != 2:
     9285        # Values have to be 2D
     9286        if hfn == 'cont' and len(vals.shape) != 2:
    92809287            print errormsg
    92819288            print '  ' + fname + ": values have to be 2D !!"
     
    92949301        if  not onc.variables.has_key(vdimxn):
    92959302            print errormsg
    9296             print '  ' + fname + ": '" + hfn + "' file '" + ncfile +                 \
     9303            print '  ' + fname + ": '" + hfn + "' file '" + ncfilen +                \
    92979304              "' does not have x-dimension variable '" +  vdimxn + "' !!"
    92989305            varns = sorted(onc.variables.keys())
     
    93019308        if  not onc.variables.has_key(vdimyn):
    93029309            print errormsg
    9303             print '  ' + fname + ": '" + hfn + "' file '" + ncfile +                 \
     9310            print '  ' + fname + ": '" + hfn + "' file '" + ncfilen +                \
    93049311              "' does not have y-dimension variable '" +  vdimyn + "' !!"
    93059312            varns = sorted(onc.variables.keys())
     
    93929399            absyn = dyn
    93939400            absyx = dyx
     9401            contxynx = [dxn, dxx, dyn, dyx]
    93949402
    93959403        else:
     
    94039411                madiscvarv = vals
    94049412
    9405             # Getting 2D dimensions
    9406             [d2Dx, d2Dy] = np.meshgrid(odimxv0, odimyv0)
    9407 
    9408             # Checking for flipping axis?
    9409             if d2Dx.shape[0] == vals.shape[1] and d2Dx.shape[1] == vals.shape[0]:
    9410                 print '  rotating values !'
    9411                 #madiscvarv = madiscvarv.transpose()
    9412                 d2Dx = d2Dx.transpose()
    9413                 d2Dy = d2Dy.transpose()
    9414 
    9415             # vals have to be 2D otherwise... ?
    9416             dx = madiscvarv.shape[1]
    9417             dy = madiscvarv.shape[0]
    9418             for j in range(dy):
    9419                 for i in range(dx):
    9420                     if not madiscvarv.mask[j,i]:
    9421                         discvarv.append(madiscvarv[j,i])
    9422                         discx.append(d2Dx[j,i])
    9423                         discy.append(d2Dy[j,i])
     9413            if len(vals.shape) == 1:
     9414                if type(madiscvarv.mask) == type(np.True_):
     9415                    discvarv = list(madiscvarv[:])
     9416                    discx = list(odimxv0[:])
     9417                    discy = list(odimyv0[:])
     9418                else:
     9419                    for i in range(vals.shape[0]):
     9420                        if not madiscvarv.mask[i]:
     9421                            discvarv.append(madiscvarv[i])
     9422                            discx.append(odimxv0[i])
     9423                            discy.append(odimyv0[i])
     9424
     9425            elif len(vals.shape) == 2:
     9426                # Getting 2D dimensions
     9427                [d2Dx, d2Dy] = np.meshgrid(odimxv0, odimyv0)
     9428
     9429                # Checking for flipping axis?
     9430                if d2Dx.shape[0] == vals.shape[1] and d2Dx.shape[1] == vals.shape[0]:
     9431                    print '  rotating values !'
     9432                    #madiscvarv = madiscvarv.transpose()
     9433                    d2Dx = d2Dx.transpose()
     9434                    d2Dy = d2Dy.transpose()
     9435
     9436                # vals have to be 2D otherwise... ?
     9437                dx = madiscvarv.shape[1]
     9438                dy = madiscvarv.shape[0]
     9439                for j in range(dy):
     9440                    for i in range(dx):
     9441                        if not madiscvarv.mask[j,i]:
     9442                            discvarv.append(madiscvarv[j,i])
     9443                            discx.append(d2Dx[j,i])
     9444                            discy.append(d2Dy[j,i])
     9445            else:
     9446                # Values have to be 1D or 2D
     9447                print errormsg
     9448                print '  ' + fname + ": disc. values have to be 1D or 2D !!"
     9449                print '    provided shape:', vals.shape, 'for slice:', dimvals
     9450                quit(-1)
    94249451
    94259452            Ndiscvals = len(discvarv)
     
    94389465        onc.close()
    94399466
    9440     graphnx = [absxn, absxx, absyn, absyx]
    9441     print 'limits of the graphic:', graphnx
     9467    if plotrange[0:6] == 'strict':
     9468        graphnx = [absxn, absxx, absyn, absyx]
     9469    elif plotrange[0:6] == 'sponge':
     9470        dlon = np.float(plotrange.split(',')[1])
     9471        dlat = np.float(plotrange.split(',')[2])
     9472        graphnx = [absxn-dlon, absxx+dlon, absyn-dlat, absyx+dlat]
     9473    elif plotrange[0:14] == 'fullcontinuous':
     9474        graphnx = contxynx
     9475
     9476    print "  '" + plotrange + "' limits of the graphic:", graphnx
    94429477
    94439478    shading_nx = []
  • trunk/tools/drawing_tools.py

    r1948 r1968  
    1183711837    pixkind = 'data'
    1183811838
    11839     print 'reva:', reva
    1184011839    if reva is not None:
    1184111840        varsv, dimxv, dimyv, dimxt, dimyt, dimxl, dimyl, dimxT, dimyT, limx, limy =      \
     
    1186411863        dy = lat0.shape[0]
    1186511864
    11866         nlon = np.min(lon0)
    11867         xlon = np.max(lon0)
    11868         nlat = np.min(lat0)
    11869         xlat = np.max(lat0)
     11865        #nlon = np.min(lon0)
     11866        #xlon = np.max(lon0)
     11867        #nlat = np.min(lat0)
     11868        #xlat = np.max(lat0)
     11869        nlon = gmaxmin[0]
     11870        xlon = gmaxmin[1]
     11871        nlat = gmaxmin[2]
     11872        xlat = gmaxmin[3]
    1187011873
    1187111874        lon2 = lon0[dy/2,dx/2]
     
    1188811891 
    1188911892        x,y = m(lon0,lat0)
    11890 
    1189111893    else:
    1189211894        # No following data values
     
    1189811900    fvarsv = varsv.flatten()
    1189911901    fobsv = obsv[:,2].flatten()
    11900     allvals = np.array(list(fvarsv) + list(fobsv))
     11902
     11903    # Getting extremes only from the plotted area
     11904    stmapvals, ijmapvals = ncvar.stats_lonlat_box(varsv, lon0, lat0, nlon, xlon, nlat, xlat)
     11905    allvals = np.array(stmapvals[0:2] + list(fobsv))
     11906    #print '  Figure minmax:', stmapvals[0:2], 'absolute:', np.min(varsv), np.max(varsv)
    1190111907
    1190211908    vsend = graphic_range(vs, allvals)
     
    1192911935
    1193011936    for iobs in range(Nobs):
    11931         xobs = (obsv[iobs,0]-xmin)/(xmax-xmin)
    11932         yobs = (obsv[iobs,1]-ymin)/(ymax-ymin)
     11937        if mapv is None:
     11938            xobs = (obsv[iobs,0]-xmin)/(xmax-xmin)
     11939            yobs = (obsv[iobs,1]-ymin)/(ymax-ymin)
     11940        else:
     11941            xobs = obsv[iobs,0]
     11942            yobs = obsv[iobs,1]
    1193311943        clv = my_cmap(norm(obsv[iobs,2]))
    1193411944        plt.plot(xobs, yobs, discinf[0], color=clv, markersize=discinf[1], zorder=100)
     
    1203712047    plt.title(gen.latex_text(figtitle))
    1203812048
    12039     figname = '2Dshad_obs-sim_comparison.png'
     12049    figname = '2Dshad_obs-sim_comparison'
    1204012050    output_kind(kfig, figname, close)
    1204112051
Note: See TracChangeset for help on using the changeset viewer.