Changeset 931 in lmdz_wrf for trunk/tools
- Timestamp:
- Jun 23, 2016, 5:09:37 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing_tools.py
r834 r931 69 69 # plot_lines: Function to plot a collection of lines 70 70 # plot_ZQradii: Function to plot following radial averages only at exact grid poins 71 # transform: Function to transform the values and the axes 71 72 72 73 # From nc_var_tools.py … … 3976 3977 #quit() 3977 3978 3978 def transform(vals, dxv, dyv, dxt, dyt, dxl, dyl, dxtit, dytit, trans): 3979 def transform(vals, trans, dxv= None, dyv= None, dxt= None, dyt= None, dxl= None, \ 3980 dyl= None, dxtit= None, dytit= None): 3979 3981 """ Function to transform the values and the axes 3980 3982 vals= values to transform 3983 trans= '|' separated list of operations of transformation 3984 'transpose': Transpose matrix of values (x-->y, y-->x) 3985 'flip@[x/y]': Flip the given axis 3981 3986 d[x/y]v= original values for the [x/y]-axis 3982 3987 d[x/y]t= original ticks for the [x/y]-axis 3983 3988 d[x/y]l= original tick-labels for the [x/y]-axis 3984 3989 d[x/y]tit= original titels for the [x/y]-axis 3985 trans= '|' separated list of operations of transformation 3986 'transpose': Transpose matrix of values (x-->y, y-->x) 3987 'flip@[x/y]': Flip the given axis 3990 3991 >>> mat = np.arange(15).reshape(3,5) 3992 >>> xvals = np.zeros((3,5), dtype=np.float) 3993 >>> yvals = np.zeros((3,5), dtype=np.float) 3994 >>> for i in range(5): 3995 >>> xvals[:,i] = -1.25 + i*0.5 3996 >>> for j in range(3): 3997 >>> yvals[j,:] = 40.25 + j*0.5 3998 >>> xticks = np.array([-1.25, -0.25, 0.25]) 3999 >>> yticks = np.array([40.25, 41.25]) 4000 >>> xticklab = ['1.25 W', '0.25 W', '0,25 E'] 4001 >>> yticklab = ['40.25 N', '41.25 N'] 4002 >>> xtit = 'Longitude' 4003 >>> ytit = 'Latitude' 4004 >>> nv, ndxv, ndyv, ndxt, ndyt, dxl, ndyl, ndxT, ndyT = transform(mat, 'transpose', \ 4005 xvals, yvals, xticks, yticks, xticklab, yticklab, xtit, ytit) 4006 [[ 0 5 10] 4007 [ 1 6 11] 4008 [ 2 7 12] 4009 [ 3 8 13] 4010 [ 4 9 14]] 4011 [[ 40.25 40.75 41.25] 4012 [ 40.25 40.75 41.25] 4013 [ 40.25 40.75 41.25] 4014 [ 40.25 40.75 41.25] 4015 [ 40.25 40.75 41.25]] 4016 [[-1.25 -1.25 -1.25] 4017 [-0.75 -0.75 -0.75] 4018 [-0.25 -0.25 -0.25] 4019 [ 0.25 0.25 0.25] 4020 [ 0.75 0.75 0.75]] 4021 [ 40.25 41.25] 4022 [-1.25 -0.25 0.25] 4023 ['41.25 N', '40.25 N'] 4024 ['0,25 E', '0.25 W', '1.25 W'] 4025 Latitude 4026 Longitude 3988 4027 """ 3989 4028 fname = 'transform' 3990 4029 3991 return newvals, newdxv, newdyv 4030 transforms = trans.split('|') 4031 Ntransforms = len(transforms) 4032 4033 newvals = vals.copy() 4034 dv = False 4035 if dxv is not None: 4036 newdxv = dxv.copy() 4037 newdyv = dyv.copy() 4038 dv = True 4039 else: 4040 newdxv = None 4041 newdyv = None 4042 4043 dt = False 4044 if dxt is not None: 4045 newdxt = dxt.copy() 4046 newdyt = dyt.copy() 4047 dt = True 4048 else: 4049 newdxt = None 4050 newdyt = None 4051 4052 dl = False 4053 if dxt is not None: 4054 newdxl = list(dxl) 4055 newdyl = list(dyl) 4056 dl = True 4057 else: 4058 newdxl = None 4059 newdyl = None 4060 4061 dT = False 4062 if dxt is not None: 4063 newdxtit = str(dxtit) 4064 newdytit = str(dytit) 4065 dT = True 4066 else: 4067 newdxtit = None 4068 newdytit = None 4069 4070 dx = newvals.shape[0] 4071 dy = newvals.shape[1] 4072 4073 for transform in transforms: 4074 if transform == 'transpose': 4075 newvals = np.transpose(newvals) 4076 if dv: 4077 copy = newdxv.copy() 4078 newdxv = np.transpose(newdyv) 4079 newdyv = np.transpose(copy) 4080 if dt: 4081 copy = newdxt.copy() 4082 newdxt = np.transpose(newdyt) 4083 newdyt = np.transpose(copy) 4084 if dl: 4085 copy = list(newdxl) 4086 newdxl = list(newdyl[::-1]) 4087 newdyl = list(copy[::-1]) 4088 if dT: 4089 copy = str(newdxtit) 4090 newdxtit = str(newdytit) 4091 newdytit = str(copy) 4092 4093 elif transform[0:4] == 'flip': 4094 flip = transform.split('@')[1] 4095 if flip == 'x': 4096 newvals = newvals[...,::-1] 4097 if dv: 4098 newdxv = newdxv[...,::-1] 4099 if dt: 4100 newdxt = newdxt[::-1] 4101 if dl: 4102 newdxl = newdxl[::-1] 4103 elif flip == 'y': 4104 newvals = newvals[...,::-1,:] 4105 if dv: 4106 newdyv = newdyv[...,::-1,:] 4107 if dt: 4108 newdyt = newdyt[::-1] 4109 if dl: 4110 newdyl = newdyl[::-1] 4111 elif flip == 'z': 4112 newvals = newvals[...,::-1,:,:] 4113 else: 4114 print errormsg 4115 print ' '+ fname + ": transformation '" + transform + "' not ready!!" 4116 quit(-1) 4117 4118 return newvals, newdxv, newdyv, newdxt, newdyt, newdxl, newdyl, newdxtit, newdytit 3992 4119 3993 4120 def plot_2D_shadow_time(varsv,vnames,dimxv,dimyv,dimxu,dimyu,dimn,colorbar,vs,uts, \ … … 4722 4849 # contour 4723 4850 ## 4851 print fname + '; Lluis: shapes x:', x.shape,'y:', y.shape, 'varcv:', varcv.shape 4724 4852 contkind = ckind.split(',')[0] 4725 4853 if contkind == 'cmap': … … 4731 4859 elif contkind == 'fixsigc': 4732 4860 coln = ckind.split(',')[1] 4733 cplot = plt.contour(x, y, varcv , levels=vc, colors=coln)4861 cplot = plt.contour(x, y, varcv.transpose(), levels=vc, colors=coln) 4734 4862 else: 4735 4863 print errormsg
Note: See TracChangeset
for help on using the changeset viewer.