Changeset 1588 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
Jul 3, 2017, 5:51:00 PM (8 years ago)
Author:
lfita
Message:

Getting finally working the flipping fo the axes and the fixed/data shape of the grid
Issue was related to the fact, that 'plt.axis' determine sense of the axes!
Modifcations only working for `plot_2D_shadow_time' by:

Adding function

`pixelgrid': Function to provide the kind of grid distribution for a plot in 'drawing_tools.py'
new version of `transform' in 'generic_tools'

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/drawing_tools.py

    r1587 r1588  
    6868# check_arguments:
    6969# Str_Bool:
     70# pixelgrid: Function to provide the kind of grid distribution for a plot
    7071# plot_points:
    7172# plot_2Dfield:
     
    353354    fname = 'interpolate_locs'
    354355
    355     if locs == 'h':
     356    if type(locs) == type('S') and locs == 'h':
    356357        print fname + '_____________________________________________________________'
    357358        print interpolate_locs.__doc__
     
    15421543    fname = 'transform'
    15431544
     1545    print fname + ' Lluis: input values trans:', trans, 'dxv:', dxv, 'dyv:', dyv, 'dxt', dxt, 'dyt', dyt, 'dxl', dxl, \
     1546      'dyl', dyl, 'dxtit', dxtit, 'dytit', dytit, 'axxkind', axxkind, 'axykind', axykind
     1547
    15441548    transforms = trans.split('|')
    15451549    Ntransforms = len(transforms)
     
    15941598    # axes' title
    15951599    wdTx = False
    1596     if type(dxt) == type('S') and dxt != 0:
     1600    if dxtit != 0:
    15971601        newdxtit = str(dxtit)
    15981602        wdTx = True
     1603        print fname + ': Lluis hey:', newdxtit
    15991604    else:
    16001605        newdxtit = None
    16011606
    16021607    wdTy = False
    1603     if type(dyt) == type('S') and dyt != '0':
     1608    if dytit != '0':
    16041609        newdytit = str(dytit)
    16051610        wdTy = True
     1611        print fname + ': Lluis hey:', newdytit
    16061612    else:
    16071613        newdytit = None
     
    16621668            if flip == 'x':
    16631669                newvals = newvals[...,::-1]
    1664                 if axxkind == 'fixpixel':
    1665                     if wdtx:
    1666                         # No pixel deformation
    1667                         newdxt = 1.-newdxt
    1668                 elif axxkind == 'data':
    1669                     if wdvx:
    1670                         if len(newdxv.shape) > 1:
    1671                             newdxv = newdxv[...,::-1]
    1672                         else:
    1673                             newdxv = newdxv[::-1]
    1674                     if wdtx:
    1675                         newdxt = newdxt[::-1]
    1676 #                if wdlx:
    1677 #                    newdxl = newdxl[::-1]
     1670                if wdvx:
     1671                    if len(newdxv.shape) > 1:
     1672                       newdxv = newdxv[...,::-1]
     1673                    else:
     1674                        newdxv = newdxv[::-1]
     1675                if wdtx:
     1676                    newdxt = newdxt[::-1]
    16781677            elif flip == 'y':
    16791678                newvals = newvals[...,::-1,:]
    1680                 # No pixel deformation
    1681                 if axykind == 'fixpixel':
    1682                     if wdty:
    1683                         # No pixel deformation
    1684                         newdyt = 1.-newdyt
    1685                 elif axykind == 'data':
    1686                     if wdvy:
    1687                         if len(newdyv.shape) > 1:
    1688                             newdyv = newdyv[...,::-1]
    1689                         else:
    1690                             newdyv = newdyv[::-1]
    1691                     if wdty:
    1692                         newdyt = newdyt[::-1]
    1693 #                if wdly:
    1694 #                    newdyl = newdyl[::-1]
     1679                #if wdvy:
     1680                #    if len(newdyv.shape) > 1:
     1681                #        newdyv = newdyv[...,::-1]
     1682                #    else:
     1683                #        newdyv = newdyv[::-1]
     1684                #if wdty:
     1685                #    newdyt = newdyt[::-1]
     1686                #if wdly:
     1687                #    newdyl = newdyl[::-1]
    16951688            elif flip == 'z':
    16961689                newvals = newvals[...,::-1,:,:]
     
    16981691            print errormsg
    16991692            print '  '+ fname + ": transformation '" + transform + "' not ready!!"
     1693            print '    available ones:', ['transpose', 'flip@x', 'flip@y']
    17001694            quit(-1)
     1695
     1696    print fname + ' Lluis: newdxv:', newdxv, 'newdyv:', newdyv, 'newdxt:', newdxt, 'newdyt:', newdyt, \
     1697      'newdxl', newdxl, 'newdyl', newdyl, 'newdxtit', newdxtit, 'newdytit', newdytit
    17011698
    17021699    return newvals, newdxv, newdyv, newdxt, newdyt, newdxl, newdyl, newdxtit, newdytit
     
    28572854    return xs, xf, Nx, orx, ys, yf, Ny, ory
    28582855
     2856def pixelgrid(daxisv, axist, axisL, axis, axiskind, trans):
     2857    """ Function to provide the kind of grid distribution for a plot
     2858    daxisv: values along the axis of the plot
     2859    axis: axis of the plot 'x/y'
     2860    axist: position of the ticks along the axis
     2861    axisL: limits of the axis
     2862    axiskind: kind of axis reference
     2863      'fixpixel': pixel preserves size all along axis
     2864      'data': pixel follows data values (as in a georeferenced map)
     2865    trans: transformation applied to the axes. '|' separated list of operations of transformation
     2866        'transpose': Transpose matrix of values (x-->y, y-->x)
     2867        'flip@[x/y]': Flip the given axis
     2868
     2869    output:
     2870      axisv: resultant values along the axis
     2871      newaxist: resultant position of the ticks along the axis
     2872      newaxisL: new limits of the axis
     2873    """
     2874    fname = 'pixelgrid'
     2875
     2876    available = ['data', 'fixpixel']
     2877    if not gen.searchInlist(available, axiskind):
     2878        print errormsg
     2879        print '  ' +fname+ ": wrong kind of grid-size for axis '" + axiskind + "' !!"
     2880        print '    available ones:', available
     2881        quit(-1)
     2882
     2883    if len(daxisv.shape) == 1:
     2884        dn = daxisv[0]
     2885        dx = daxisv[len(daxisv)-1]
     2886        Laxis = daxisv.shape[0]
     2887        axisint = daxisv
     2888        if axiskind == 'fixpixel':
     2889            axisv = np.arange(Laxis, dtype=np.float)/(Laxis-1)
     2890        elif axiskind == 'data':
     2891            axisv = daxisv
     2892    elif len(daxisv.shape) == 2:
     2893        dn = daxisv[0,0]
     2894        if axis == 'x':
     2895            Laxis = daxisv.shape[1]
     2896            dx = daxisv[0,Laxis-1]
     2897            axisint = daxisv[0,:]
     2898            if axiskind == 'fixpixel':
     2899                for iy in range(daxisv.shape[0]):
     2900                    axisv[iy,:] = np.arange(Laxis, dtype=np.float)/(Laxis-1)
     2901            elif axiskind == 'data':
     2902                axisv = daxisv
     2903        else:
     2904            Laxis = daxisv.shape[0]
     2905            dx = daxisv[Laxis-1,0]
     2906            axisint = daxisv[:,0]
     2907            if axiskind == 'fixpixel':
     2908                for ix in range(daxisv.shape[1]):
     2909                    axisv[:,ix] = np.arange(Laxis, dtype=np.float)/(Laxis-1)
     2910            elif axiskind == 'data':
     2911                axisv = daxisv
     2912
     2913    transforms = trans.split('|')
     2914
     2915    # Axis ticks and axis range
     2916    if axiskind == 'fixpixel':
     2917        newaxist = interpolate_locs(axist,axisint,'lin')/(Laxis-1)
     2918        if gen.searchInlist(transforms, 'flip@' + axis):
     2919            newaxisL = np.array([1., 0.])
     2920        else:
     2921            newaxisL = np.array([0., 1.])
     2922    elif axiskind == 'data':
     2923        newaxist = axist
     2924        newaxisL = axisL
     2925
     2926    return axisv, newaxist, newaxisL
     2927
    28592928####### ###### ##### #### ### ## # END of GENERIC functions
    28602929
     
    43704439#quit()
    43714440
    4372 def plot_2D_shadow_time(varsv, vnames, dimxv, dimyv, dimxu, dimyu, dimn, vaxv, cbarv,\
    4373   vs, uts, vtit, kfig, reva, taxis, tpos, tlabs, ifclose):
     4441def plot_2D_shadow_time(varsv, vnames, dimvv, dimtv, dimvu, dimn, vaxv, cbarv,       \
     4442  vs, uts, xpixk, ypixk, vtit, kfig, reva, taxis, tpos, tlabs, ifclose):
    43744443    """ Plotting a 2D field with one of the axes being time
    43754444      varsv= 2D values to plot with shading
    43764445      vnames= shading variable name for the figure
    4377       dim[x/y]v= values at the axes of x and y
    4378       dim[x/y]u= units at the axes of x and y
     4446      dimvv= values at the axis of values
     4447      dimtv= values at the axis of time
     4448      dimvu= units at the axes of values
    43794449      dimn= dimension names to plot
    43804450      vaxv= list with the non-temporal axis paramteres [style, format, number and orientation]
     
    43944464           percentile_(100-val)-median)
    43954465      uts= units of the variable to shadow
    4396       vtit= title of the variable
     4466      [x/ypixk]= kind of grid-pixel for the figure
     4467          'data': size pixel along the given axis change according to the values along the axis
     4468          'fixpixel': size pixel along the given axis does not change
     4469      vtit= title of the figure
    43974470      kfig= kind of figure (jpg, pdf, png)
    43984471      reva=
     
    44064479    fname = 'plot_2D_shadow_time'
    44074480
    4408     if varsv == 'h':
     4481    if type(varsv) == type('S') and varsv == 'h':
    44094482        print fname + '_____________________________________________________________'
    44104483        print plot_2D_shadow_time.__doc__
     
    44174490        quit(-1)
    44184491
    4419     dimxv0 = dimxv.copy()
    4420     dimyv0 = dimyv.copy()
    4421 
    4422     dxn = dimxv.min()
    4423     dxx = dimxv.max()
    4424     dyn = dimyv.min()
    4425     dyx = dimyv.max()
    4426 
    44274492# Definning ticks labels
    44284493    if taxis == 'x':
     4494        dimxv0 = dimtv.copy()
     4495        dimyv0 = dimvv.copy()
     4496
     4497        dxn = dimtv.min()
     4498        dxx = dimtv.max()
     4499        dyn = dimvv.min()
     4500        dyx = dimvv.max()
     4501
    44294502        dimxt0 = tpos
    44304503        dimxl0 = tlabs
    4431         dimxT0 = dimxu
     4504        dimxT0 = 'cf time'
     4505
    44324506        if vaxv[0] == 'pretty':
    4433             dimyt0 = np.array(gen.pretty_int(dyn,dyx,vaxv[2]))
     4507            dimyt0 = np.array(gen.pretty_int(dyn,dyx+(dyx-dyn)/vaxv[2],vaxv[2]))
    44344508        elif vaxv[0] == 'Nfix':
    44354509            dimyt0 = np.arange(dyn,dyx,(dyx-dyn)/(1.*vaxv[2]))
     
    44394513        for i in range(len(dimyt0)): dimyl0.append('{:{style}}'.format(dimyt0[i],    \
    44404514          style=vaxv[1]))
    4441         dimyT0 = variables_values(dimn[1])[0] + ' (' + units_lunits(dimyu) + ')'
     4515        dimyT0 = gen.latex_text(variables_values(dimn[1])[0]) + ' (' +               \
     4516          units_lunits(dimvu) + ')'
    44424517
    44434518        # No following data values
    4444         dimyt0 = np.arange(len(dimyt0),dtype=np.float)/(len(dimyt0))
    4445         pixkind = 'fixpixel'
    4446 
    4447     else:
     4519        #dimyt0 = np.arange(len(dimyt0),dtype=np.float)/(len(dimyt0))
     4520        #pixkind = 'fixpixel'
     4521
     4522    else:
     4523        dimxv0 = dimvv.copy()
     4524        dimyv0 = dimtv.copy()
     4525
     4526        dxn = dimvv.min()
     4527        dxx = dimvv.max()
     4528        dyn = dimtv.min()
     4529        dyx = dimtv.max()
     4530
    44484531        if vaxv[0] == 'pretty':
    4449             dimxt0 = np.array(gen.pretty_int(dxn,dxx,vaxv[2]))
     4532            dimxt0 = np.array(gen.pretty_int(dxn,dxx+(dxx-dxn)/vaxv[2],vaxv[2]))
    44504533        elif vaxv[0] == 'Nfix':
    44514534            dimxt0 = np.arange(dxn,dxx,(dxx-dxn)/(1.*vaxv[2]))
     
    44554538        for i in range(len(dimxt0)): dimxl0.append('{:{style}}'.format(dimxt0[i],    \
    44564539          style=vaxv[1]))
    4457         dimxT0 = variables_values(dimn[0])[0] + ' (' + units_lunits(dimxu) + ')'
     4540        dimxT0 = gen.latex_text(variables_values(dimn[0])[0]) + ' (' +               \
     4541          units_lunits(dimvu) + ')'
    44584542
    44594543        dimyt0 = tpos
    44604544        dimyl0 = tlabs
    4461         dimyT0 = dimyu
     4545        dimyT0 = 'cf time'
    44624546        # No following data values
    4463         dimxt0 = np.arange(len(dimxt0),dtype=np.float)/(len(dimxt0))
    4464         pixkind = 'fixpixel'
     4547        #dimxt0 = np.arange(len(dimxt0),dtype=np.float)/(len(dimxt0))
     4548        #pixkind = 'fixpixel'
    44654549
    44664550    if reva is not None:
    4467         varsv, dimxv, dimyv, dimxt, dimyt, dimxl, dimyl, dimxT, dimyT =              \
    4468           transform(varsv, reva, dxv=dimxv0, dyv=dimyv0, dxt=dimxt0, dyt=dimyt0,    \
     4551        varsv, dimxv, dimyv, dimxt, dimyt, dimxl, dimyl, dimxT, dimyT, xtrms, ytrms= \
     4552          gen.transform(varsv, reva, dxv=dimxv0, dyv=dimyv0, dxt=dimxt0, dyt=dimyt0, \
    44694553          dxl=dimxl0, dyl=dimyl0, dxtit=dimxT0, dytit=dimyT0)
    44704554    else:
     
    44784562        dimyT = dimyT0
    44794563
    4480     if len(dimxv.shape) == 3:
    4481         dxget='1,2'
    4482     elif len(dimxv.shape) == 2:
    4483         dxget='0,1'
    4484     elif len(dimxv.shape) == 1:
    4485         dxget='0'
    4486     else:
    4487         print errormsg
    4488         print '  ' + fname + ': shape of x-values:',dimxv.shape,'not ready!!'
    4489         quit(-1)
    4490 
    4491     if len(dimyv.shape) == 3:
    4492         dyget='1,2'
    4493     elif len(dimyv.shape) == 2:
    4494         dyget='0,1'
    4495     elif len(dimyv.shape) == 1:
    4496         dyget='0'
    4497     else:
    4498         print errormsg
    4499         print '  ' + fname + ': shape of y-values:',dimyv.shape,'not ready!!'
    4500         quit(-1)
    4501 
    4502     # No following data values
    4503     x = (dimxv-np.min(dimxv))/(np.max(dimxv) - np.min(dimxv))
    4504     y = (dimyv-np.min(dimyv))/(np.max(dimyv) - np.min(dimyv))
     4564    # Which kind of grid-pixel shape do we want?
     4565    x, dimxt, xtrms = pixelgrid(dimxv, dimxt, xtrms, 'x', xpixk, reva)
     4566    y, dimyt, ytrms = pixelgrid(dimyv, dimyt, ytrms, 'y', ypixk, reva)
    45054567
    45064568# Changing limits of the colors
     
    45094571    plt.rc('text', usetex=True)
    45104572
    4511     print fname + 'Lluis shapes x:', x.shape, 'y:', y.shape, 'varsv:', varsv.shape
    45124573    plt.pcolormesh(x, y, varsv, cmap=plt.get_cmap(cbarv[0]), vmin=vsend[0], vmax=vsend[1])
    45134574    if cbarv[2] == 'horizontal':
     
    45234584
    45244585    if taxis == 'x':
    4525         plt.xticks((dimxt-dxn)/(dxx-dxn), dimxl)
     4586        #plt.xticks((dimxt-dxn)/(dxx-dxn), dimxl)
     4587        plt.xticks(dimxt, dimxl)
    45264588        plt.yticks(dimyt, dimyl, rotation=vaxv[3])
    45274589    else:
    45284590        plt.xticks(dimxt, dimxl, rotation=vaxv[3])
    4529         plt.yticks((dimyt-dyn)/(dyx-dyn), dimyl)
     4591        #plt.yticks((dimyt-dyn)/(dyx-dyn), dimyl)
     4592        plt.yticks(dimyt, dimyl)
    45304593
    45314594    plt.xlabel(dimxT)
    45324595    plt.ylabel(dimyT)
    45334596
    4534     plt.axis([x.min(), x.max(), y.min(), y.max()])
     4597    plt.axis([xtrms[0], xtrms[1], ytrms[0], ytrms[1]])
    45354598
    45364599# units labels
  • trunk/tools/generic_tools.py

    r1570 r1588  
    57345734    fname = 'interpolate_locs'
    57355735
    5736     if locs == 'h':
     5736    if type(locs) == type('S') and locs == 'h':
    57375737        print fname + '_____________________________________________________________'
    57385738        print interpolate_locs.__doc__
     
    1201112011    return [valmin, valmax]
    1201212012
     12013def transform(vals, trans, dxv='0', dyv='0', dxt='0', dyt='0', dxl='0',         \
     12014  dyl='0', dxtit='0', dytit='0'):
     12015    """ Function to transform the values and the axes
     12016      vals= values to transform
     12017      trans= '|' separated list of operations of transformation
     12018        'transpose': Transpose matrix of values (x-->y, y-->x)
     12019        'flip@[x/y]': Flip the given axis
     12020      d[x/y]v= original values for the [x/y]-axis
     12021      d[x/y]t= original ticks for the [x/y]-axis
     12022      d[x/y]l= original tick-labels for the [x/y]-axis
     12023      d[x/y]tit= original titles for the [x/y]-axis
     12024
     12025    >>> mat = np.arange(15).reshape(3,5)
     12026    >>> xvals = np.zeros((3,5), dtype=np.float)
     12027    >>> yvals = np.zeros((3,5), dtype=np.float)
     12028    >>> for i in range(5):
     12029    >>>     xvals[:,i] = -1.25 + i*0.5
     12030    >>> for j in range(3):
     12031    >>>     yvals[j,:] = 40.25 + j*0.5
     12032    >>> xticks = np.array([-1.25, -0.25, 0.25])
     12033    >>> yticks = np.array([40.25, 41.25])
     12034    >>> xticklab = ['1.25 W', '0.25 W', '0,25 E']
     12035    >>> yticklab = ['40.25 N', '41.25 N']
     12036    >>> xtit = 'Longitude'
     12037    >>> ytit = 'Latitude'
     12038    >>> nv, ndxv, ndyv, ndxt, ndyt, dxl, ndyl, ndxT, ndyT = transform(mat, 'transpose', \
     12039      xvals, yvals, xticks, yticks, xticklab, yticklab, xtit, ytit)
     12040    [[ 0  5 10]
     12041     [ 1  6 11]
     12042     [ 2  7 12]
     12043     [ 3  8 13]
     12044     [ 4  9 14]]
     12045    [[ 40.25  40.75  41.25]
     12046     [ 40.25  40.75  41.25]
     12047     [ 40.25  40.75  41.25]
     12048     [ 40.25  40.75  41.25]
     12049     [ 40.25  40.75  41.25]]
     12050    [[-1.25 -1.25 -1.25]
     12051     [-0.75 -0.75 -0.75]
     12052     [-0.25 -0.25 -0.25]
     12053     [ 0.25  0.25  0.25]
     12054     [ 0.75  0.75  0.75]]
     12055    [ 40.25  41.25]
     12056    [-1.25 -0.25  0.25]
     12057    ['41.25 N', '40.25 N']
     12058    ['0,25 E', '0.25 W', '1.25 W']
     12059    Latitude
     12060    Longitude
     12061    """
     12062    fname = 'transform'
     12063
     12064    transforms = trans.split('|')
     12065    Ntransforms = len(transforms)
     12066
     12067    newvals = vals.copy()
     12068
     12069    # values
     12070    wdvx = False
     12071    if type(dxv) == type('S') and dxv == '0':
     12072        newdxv = None
     12073    else:
     12074        newdxv = dxv.copy()
     12075        wdvx = True
     12076
     12077    wdvy = False
     12078    if type(dyv) == type('S') and dyv == '0':
     12079        newdyv = None
     12080    else:
     12081        newdyv = dyv.copy()
     12082        wdvy = True
     12083
     12084    # ticks
     12085    wdtx = False
     12086    if type(dxt) == type('S') and dxt == '0':
     12087        newdxt = None
     12088    else:
     12089        newdxt = dxt.copy()
     12090        wdtx = True
     12091
     12092    wdty = False
     12093    if type(dyt) == type('S') and dyt == '0':
     12094        newdyt = None
     12095    else:
     12096        newdyt = dyt.copy()
     12097        wdty = True
     12098
     12099    # label in ticks
     12100    wdlx = False
     12101    if type(dxl) == type('S') and dxl == '0':
     12102        newdxl = None
     12103    else:
     12104        newdxl = list(dxl)
     12105        wdlx = True
     12106
     12107    wdly = False
     12108    if type(dyl) == type('S') and dyl == '0':
     12109        newdyl = None
     12110    else:
     12111        newdyl = list(dyl)
     12112        wdly = True
     12113
     12114    # axes' title
     12115    wdTx = False
     12116    if dxtit != 0:
     12117        newdxtit = str(dxtit)
     12118        wdTx = True
     12119    else:
     12120        newdxtit = None
     12121
     12122    wdTy = False
     12123    if dytit != '0':
     12124        newdytit = str(dytit)
     12125        wdTy = True
     12126    else:
     12127        newdytit = None
     12128
     12129    # axis limits. They will be used to flip the axis in plot if necessary
     12130    if len(dxv.shape) == 1:
     12131        newxaxislim = np.array([dxv[0], dxv[len(dxv)-1]])
     12132    elif len(dxv.shape) == 2:
     12133        newxaxislim = np.array([dxv[0,0], dxv[0,dxv.shape[1]-1]])
     12134    else:
     12135        print errormsg
     12136        print '  ' + fname + ": wrong rank of data for axis 'x':", dxv.shape, '!!'
     12137        print '    must be of rank 2!!'
     12138        quit(-1)
     12139
     12140    if len(dyv.shape) == 1:
     12141        newyaxislim = np.array([dyv[0], dyv[len(dyv)-1]])
     12142    elif len(dyv.shape) == 2:
     12143        newyaxislim = np.array([dyv[0,0], dyv[dyv.shape[0]-1],0])
     12144    else:
     12145        print errormsg
     12146        print '  ' + fname + ": wrong rank of data for axis 'y':", dyv.shape, '!!'
     12147        print '    must be of rank 2!!'
     12148        quit(-1)
     12149
     12150    for transform in transforms:
     12151        if transform == 'transpose':
     12152            newvals = np.transpose(newvals)
     12153            if wdvx and wdvy:
     12154                copy = newdxv.copy()
     12155                newdxv = np.transpose(newdyv)
     12156                newdyv = np.transpose(copy)
     12157#            else:
     12158#                print errormsg
     12159#                print '  ' + fname + ": it can not be '" + transform + "' without " +\
     12160#                  ' both dimxvals:', dxv, ' and dimyvals:', dyv, ' !!'
     12161#                quit(-1)
     12162
     12163            if wdtx and wdtx:
     12164                copy = newdxt.copy()
     12165                newdxt = np.transpose(newdyt)
     12166                newdyt = np.transpose(copy)
     12167#            else:
     12168#                print errormsg
     12169#                print '  ' + fname + ": it can not be '" + transform + "' without " +\
     12170#                  ' both dimxtickvals:', dxt, ' and dimytickvals:', dyt, ' !!'
     12171#                quit(-1)
     12172
     12173            if wdlx and wdly:
     12174                copy = list(newdxl)
     12175                newdxl = list(newdyl)
     12176                newdyl = list(copy)
     12177#            else:
     12178#                print errormsg
     12179#                print '  ' + fname + ": it can not be '" + transform + "' without " +\
     12180#                  ' both dimxlabels:', dxl, ' and dimylabels:', dyl, ' !!'
     12181#                quit(-1)
     12182
     12183            if wdTx and wdTy:
     12184                copy = str(newdxtit)
     12185                newdxtit = str(newdytit)
     12186                newdytit = str(copy)
     12187#            else:
     12188#                print errormsg
     12189#                print '  ' + fname + ": it can not be '" + transform + "' without " +\
     12190#                  ' both dimx title:', dxtit, ' and dimytitle:', dytit, ' !!'
     12191#                quit(-1)
     12192
     12193            copy = newxaxislim.copy()
     12194            newxaxislim = newyaxislim
     12195            newyaxislim = copy
     12196
     12197        elif transform[0:4] == 'flip':
     12198            if transform.find('@') == -1:
     12199                print errormsg
     12200                print '  ' + fname + ": no ax given for '" + transform + "' !!"
     12201                quit(-1)
     12202               
     12203            flip = transform.split('@')[1]
     12204            if flip == 'x':
     12205                if len(newxaxislim.shape) == 1:
     12206                    newxaxislim = newxaxislim[::-1]
     12207                else:
     12208                    for iy in len(newxaxislim.shape[0]):
     12209                        newxaxislim[iy,:] = newxaxislim[iy,::-1]
     12210            elif flip == 'y':
     12211                if len(newyaxislim.shape) == 1:
     12212                    newyaxislim = newyaxislim[::-1]
     12213                else:
     12214                    for ix in len(newyaxislim.shape[1]):
     12215                        newyaxislim[:,ix] = newyaxislim[::-1,ix]
     12216            elif flip == 'z':
     12217                newvals = newvals[...,::-1,:,:]
     12218        else:
     12219            print errormsg
     12220            print '  '+ fname + ": transformation '" + transform + "' not ready!!"
     12221            print '    available ones:', ['transpose', 'flip@x', 'flip@y']
     12222            quit(-1)
     12223
     12224    return newvals, newdxv, newdyv, newdxt, newdyt, newdxl, newdyl, newdxtit, newdytit, newxaxislim, newyaxislim
     12225
     12226#mat = np.arange(15).reshape(3,5)
     12227#xvals = np.zeros((3,5), dtype=np.float)
     12228#yvals = np.zeros((3,5), dtype=np.float)
     12229#for i in range(5):
     12230#    xvals[:,i] = -1.25 + i*0.5
     12231#for j in range(3):
     12232#    yvals[j,:] = 40.25 + j*0.5
     12233#xticks = np.array([-1.25, -0.25, 0.25])
     12234#yticks = np.array([40.25, 41.25])
     12235#xticklab = ['1.25 W', '0.25 W', '0,25 E']
     12236#yticklab = ['40.25 N', '41.25 N']
     12237#xtit = 'Longitude'
     12238#ytit = 'Latitude'
     12239#nv, ndxv, ndyv, ndxt, ndyt, dxl, ndyl, ndxT, ndyT = transform(mat, 'flip@y', \
     12240#      xvals, yvals, xticks, yticks, xticklab, yticklab, xtit, ytit)
     12241#
     12242#print nv, ndxv, ndyv, ndxt, ndyt, dxl, ndyl, ndxT, ndyT
    1201312243#quit()
     12244
     12245
     12246#quit()
Note: See TracChangeset for help on using the changeset viewer.