Changeset 1132 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
Oct 3, 2016, 6:04:16 PM (9 years ago)
Author:
lfita
Message:

Fixing:

  • `transform': by adding:

ax[x/y]kind= kind of axis reference

'fixpixel': pixel preserves size all along axis (default)
'data': pixel follows data values (as in a georeferenced map)

  • including right use of `transform' in plot_2D_shadow
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/drawing_tools.py

    r1129 r1132  
    14651465
    14661466def transform(vals, trans, dxv='0', dyv='0', dxt='0', dyt='0', dxl='0',         \
    1467   dyl='0', dxtit='0', dytit='0'):
     1467  dyl='0', dxtit='0', dytit='0', axxkind='fixpixel', axykind='fixpixel'):
    14681468    """ Function to transform the values and the axes
    14691469      vals= values to transform
     
    14751475      d[x/y]l= original tick-labels for the [x/y]-axis
    14761476      d[x/y]tit= original titles for the [x/y]-axis
     1477      ax[x/y]kind= kind of axis reference
     1478        'fixpixel': pixel preserves size all along axis
     1479        'data': pixel follows data values (as in a georeferenced map)
    14771480
    14781481    >>> mat = np.arange(15).reshape(3,5)
     
    16311634            if flip == 'x':
    16321635                newvals = newvals[...,::-1]
    1633 #                if wdvx:
    1634 #                    if len(newdxv.shape) > 1:
    1635 #                        newdxv = newdxv[...,::-1]
    1636 #                    else:
    1637 #                        newdxv = newdxv[::-1]
    1638 #                if wdtx:
    1639 #                    newdxt = newdxt[::-1]
    1640                 if wdlx:
    1641                     newdxl = newdxl[::-1]
     1636                if axxkind == 'fixpixel':
     1637                    if wdtx:
     1638                        # No pixel deformation
     1639                        newdxt = 1.-newdxt
     1640                elif axxkind == 'data':
     1641                    if wdvx:
     1642                        if len(newdxv.shape) > 1:
     1643                            newdxv = newdxv[...,::-1]
     1644                        else:
     1645                            newdxv = newdxv[::-1]
     1646                    if wdtx:
     1647                        newdxt = newdxt[::-1]
     1648#                if wdlx:
     1649#                    newdxl = newdxl[::-1]
    16421650            elif flip == 'y':
    16431651                newvals = newvals[...,::-1,:]
    1644 #                if wdvy:
    1645 #                    Ny=len(newdyt)
    1646 #                    if len(newdyv.shape) > 1:
    1647 #                        newdyv = newdyv[...,::-1]
    1648 #                    else:
    1649 #                        newdyv = newdyv[::-1]
    1650 #                if wdty:
    1651 #                    newdyt = newdyt[::-1]
    1652                 if wdly:
    1653                     newdyl = newdyl[::-1]
     1652                # No pixel deformation
     1653                if axykind == 'fixpixel':
     1654                    if wdty:
     1655                        # No pixel deformation
     1656                        newdyt = 1.-newdyt
     1657                elif axykind == 'data':
     1658                    if wdvy:
     1659                        if len(newdyv.shape) > 1:
     1660                            newdyv = newdyv[...,::-1]
     1661                        else:
     1662                            newdyv = newdyv[::-1]
     1663                    if wdty:
     1664                        newdyt = newdyt[::-1]
     1665#                if wdly:
     1666#                    newdyl = newdyl[::-1]
    16541667            elif flip == 'z':
    16551668                newvals = newvals[...,::-1,:,:]
     
    38383851    dimxv0 = dimxv.copy()
    38393852    dimyv0 = dimyv.copy()
    3840     dimxt0 = np.array(pretty_int(dimxv.min(),dimxv.max(),10))
    3841     dimyt0 = np.array(pretty_int(dimyv.min(),dimyv.max(),10))
     3853
     3854    dimxt0 = np.array(pretty_int(dimxv.min(),dimxv.max(),5))
     3855    dimyt0 = np.array(pretty_int(dimyv.min(),dimyv.max(),5))
    38423856    dimxl0 = []
    38433857    for i in range(len(dimxt0)): dimxl0.append('{:.1f}'.format(dimxt0[i]))
    38443858    dimyl0 = []
    38453859    for i in range(len(dimyt0)): dimyl0.append('{:.1f}'.format(dimyt0[i]))
     3860
    38463861    dimxT0 = variables_values(dimn[0])[0] + ' (' + units_lunits(dimxu) + ')'
    38473862    dimyT0 = variables_values(dimn[1])[0] + ' (' + units_lunits(dimyu) + ')'
     3863
     3864    if mapv is not None:
     3865        pixkind = 'data'
     3866    else:
     3867        # No following data values
     3868        dimxt0 = np.arange(len(dimxt0),dtype=np.float)/(len(dimxt0))
     3869        dimyt0 = np.arange(len(dimyt0),dtype=np.float)/(len(dimyt0))
     3870        pixkind = 'fixpixel'
    38483871
    38493872    if reva is not None:
     
    39333956
    39343957    else:
    3935         x = lon0
    3936         y = lat0
     3958        # No following data values
     3959        #x = dimxv
     3960        #y = dimyv
     3961        x = (dimxv-np.min(dimxv))/(np.max(dimxv) - np.min(dimxv))
     3962        y = (dimyv-np.min(dimyv))/(np.max(dimyv) - np.min(dimyv))
    39373963
    39383964    vsend = np.zeros((2), dtype=np.float)
     
    40344060        plt.ylabel(dimyT)
    40354061
    4036     txpos = pretty_int(x.min(),x.max(),5)
    4037     typos = pretty_int(y.min(),y.max(),5)
    4038     txlabels = list(txpos)
    4039     for i in range(len(txlabels)): txlabels[i] = '{:6g}'.format(txlabels[i])
    4040     tylabels = list(typos)
    4041     for i in range(len(tylabels)): tylabels[i] = '{:6g}'.format(tylabels[i])
     4062    # Using output from transform
     4063#    print 'x min:', x.min(),'max:',x.max()
     4064#    print 'y min:', y.min(),'max:',y.max()
     4065#    txpos = pretty_int(x.min(),x.max(),5)
     4066#    typos = pretty_int(y.min(),y.max(),5)
     4067#    txlabels = list(txpos)
     4068#    for i in range(len(txlabels)): txlabels[i] = '{:6g}'.format(txlabels[i])
     4069#    tylabels = list(typos)
     4070#    for i in range(len(tylabels)): tylabels[i] = '{:6g}'.format(tylabels[i])
    40424071
    40434072    plt.axis([x.min(), x.max(), y.min(), y.max()])
    40444073
    40454074    if mapv is None:
    4046         plt.xticks(txpos, txlabels)
    4047         plt.yticks(typos, tylabels)
     4075#        plt.xticks(txpos, txlabels)
     4076#        plt.yticks(typos, tylabels)
     4077        plt.xticks(dimxt, dimxl)
     4078        plt.yticks(dimyt, dimyl)
    40484079
    40494080# units labels
     
    75087539       
    75097540#    graphtit = gtitle.replace('_','\_').replace('&','\&')
    7510     graphtit = gtitle
     7541    graphtit = gen.latex_text(gtitle)
    75117542
    75127543    plt.title(graphtit,position=titleloc)
Note: See TracChangeset for help on using the changeset viewer.