Changeset 13080 for fact/tools/pyscripts/pyfact
- Timestamp:
- 03/13/12 12:00:16 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/pyscripts/pyfact/plotters.py
r13074 r13080 84 84 print 'not able to find file:', map_file_path 85 85 sys.exit(-2) 86 86 87 87 self.name = name 88 88 if ion: … … 103 103 self.vmax = vmax 104 104 105 def __call__(self, data): 105 def __call__(self, data, mask=None): 106 # define some shortcuts 106 107 xe = self.xe 107 108 ye = self.ye … … 112 113 vmax = self.vmax 113 114 115 # get the figure, clean it, and set it up nicely. 116 # maybe cleaning is not necessary and takes long, but 117 # I've got no time to test it at the moment. 114 118 plt.figure(self.fig_id) 115 119 plt.clf() … … 119 123 self.ax.grid(grid) 120 124 121 result = self.ax.scatter(xe,ye,s=25,alpha=1, c=data, marker=H, linewidths=0., vmin=vmin, vmax=vmax) 122 self.figure.colorbar( result, shrink=0.8, pad=-0.04 ) 123 124 plt.draw() 125 # throw data into numpy array for simplicity 126 data = np.array(data) 127 128 #handle masked case specially 129 if mask!= None: 130 if mask.dtype == bool and data.ndim ==1 and len(mask)==1440: 131 length = mask.sum() 132 mask = np.where(mask) 133 mxe = np.empty( length ) 134 mye = np.empty( length ) 135 mdata = np.empty( length ) 136 for i,chid in enumerate(mask): 137 mxe[i] = xe[chid] 138 mye[i] = ye[chid] 139 mdata[i] = data[chid] 140 141 self.ax.axis([-22,22,-22,22]) 142 self.ax.set_title(name) 143 self.ax.grid(grid) 144 # the next line is a stupid hack 145 # I plot invisible pixels, so that the axes show look ok. 146 # this must be possible differently, but I don't know how... 147 self.ax.scatter(xe,ye,s=25,alpha=0,marker=H) 148 149 result = self.ax.scatter(mxe,mye,s=25,alpha=1., 150 c=mdata, marker=H, linewidths=0., vmin=vmin, vmax=vmax) 151 self.figure.colorbar( result, shrink=0.8, pad=-0.04 ) 152 plt.draw() 153 154 155 if mask.dtype == int and data.ndim ==1: 156 length = len(mask) 157 mxe = np.empty( length ) 158 mye = np.empty( length ) 159 mdata = np.empty( length ) 160 for i,chid in enumerate(mask): 161 mxe[i] = xe[chid] 162 mye[i] = ye[chid] 163 mdata[i] = data[chid] 164 165 self.ax.axis([-22,22,-22,22]) 166 self.ax.set_title(name) 167 self.ax.grid(grid) 168 # the next line is a stupid hack 169 # I plot invisible pixels, so that the axes show look ok. 170 # this must be possible differently, but I don't know how... 171 self.ax.scatter(xe,ye,s=25,alpha=0,marker=H) 172 173 result = self.ax.scatter(mxe,mye,s=25,alpha=1., 174 c=mdata, marker=H, linewidths=0., vmin=vmin, vmax=vmax) 175 self.figure.colorbar( result, shrink=0.8, pad=-0.04 ) 176 plt.draw() 177 178 else: # i.e. when mask is None 179 # handle 1D and 2D case differently 180 if data.ndim == 1 and len(data)==1440: 181 result = self.ax.scatter(xe,ye,s=25,alpha=1, 182 c=data, marker=H, linewidths=0., vmin=vmin, vmax=vmax) 183 self.figure.colorbar( result, shrink=0.8, pad=-0.04 ) 184 plt.draw() 185 186 elif data.ndim == 2 and data.shape[0] == 2 and data.shape[1] <=1440: 187 # I assume the first row of data, contains the CHIDs 188 # and the 2nd row contains the actual data. 189 chids = data[0] 190 # check if there are double chids in chids 191 if len(chids)!=len(set(chids)): 192 print 'warning: there are doubled chids in input data', 193 print 'you might want to plot something else, but I plot it anyway...' 194 print chids 195 data = data[1] 196 # now I have to mask the xe, and ye vectors accordingly 197 mxe = np.empty( len(chids) ) 198 mye = np.empty( len(chids) ) 199 for i,chid in enumerate(chids): 200 mxe[i] = xe[chid] 201 mye[i] = ye[chid] 202 203 # check if I did it right 204 if len(mxe)!=len(data) or len(mye)!=len(data): 205 print 'the masking did not work:' 206 print 'len(mxe)', len(mxe) 207 print 'len(mye)', len(mye) 208 print 'len(data)', len(data) 209 210 self.ax.axis([-22,22,-22,22]) 211 self.ax.set_title(name) 212 self.ax.grid(grid) 213 # the next line is a stupid hack 214 # I plot invisible pixels, so that the axes show look ok. 215 # this must be possible differently, but I don't know how... 216 self.ax.scatter(xe,ye,s=25,alpha=0,marker=H) 217 218 result = self.ax.scatter(mxe,mye,s=25,alpha=1., 219 c=data, marker=H, linewidths=0., vmin=vmin, vmax=vmax) 220 self.figure.colorbar( result, shrink=0.8, pad=-0.04 ) 221 plt.draw() 222 223 else: 224 print 'CamPlotter call input data has bad format' 225 print 'data.ndim', data.ndim 226 print 'data.shape', data.shape 227 print 'data:----------------------------------' 228 print data 229 230 231 125 232 126 233 class HistPlotter(object): … … 196 303 """ test of CamPlotter """ 197 304 198 c1 = np.random.randn(1440) 305 c1 = np.array(range(20)) 306 chids1 = np.empty( len(c1) , dtype=int) 307 for i in range(len(chids1)-2): 308 chids1[i] = np.random.randint(1440) 309 chids1[-1] = 15 310 chids1[-2] = 15 311 199 312 c2 = np.linspace(0., 1., num=1440) 200 313 plot1 = CamPlotter('plot1') 201 314 plot2 = CamPlotter('plot2') 202 315 203 plot1( c1)316 plot1( (chids1,c1) ) 204 317 plot2(c2) 205 318 raw_input('next') … … 217 330 if __name__ == '__main__': 218 331 """ test the class """ 219 _test_Plotter()332 #_test_Plotter() 220 333 _test_CamPlotter() 221 _test_HistPlotter()334 #_test_HistPlotter()
Note:
See TracChangeset
for help on using the changeset viewer.