1 | PRO tvnplot, image, MIN = min, MAX = max, GAMMA = gamma, MSK = msk, ERASE = erase, $ |
---|
2 | ibase = ibase, jbase = jbase, INTERP = interp, $ |
---|
3 | SCALE_X = scale_x, SCALE_Y = scale_y, PS = ps, _EXTRA = extra |
---|
4 | |
---|
5 | IF keyword_set(min) EQ 0 THEN min = min(image) |
---|
6 | IF keyword_set(max) EQ 0 THEN max = max(image) |
---|
7 | IF keyword_set(scale_x) EQ 0 THEN scale_x = 1. |
---|
8 | IF keyword_set(scale_y) EQ 0 THEN scale_y = 1. |
---|
9 | IF keyword_set(ibase) EQ 0 THEN ibase = 0. |
---|
10 | IF keyword_set(jbase) EQ 0 THEN jbase = 0. |
---|
11 | sample = 0 |
---|
12 | IF keyword_set(interp) EQ 0 THEN sample = 1 |
---|
13 | |
---|
14 | |
---|
15 | x_env_save = !x |
---|
16 | y_env_save = !y |
---|
17 | p_env_save = !p |
---|
18 | |
---|
19 | !p.background = 255 |
---|
20 | !p.color = 0 |
---|
21 | !p.charsize=1 |
---|
22 | |
---|
23 | image = reform(image) |
---|
24 | IF (size(image))[0] NE 2 THEN BEGIN |
---|
25 | print, ' tvnplot needs a 2D array' |
---|
26 | stop |
---|
27 | ENDIF |
---|
28 | |
---|
29 | ni = (size(image))[1] |
---|
30 | nj = (size(image))[2] |
---|
31 | |
---|
32 | IF keyword_set(gamma) EQ 0 THEN BEGIN |
---|
33 | gamma = 600/max([ni, nj]) |
---|
34 | ENDIF |
---|
35 | IF n_elements(ps) EQ 1 THEN BEGIN |
---|
36 | gamma = 5 |
---|
37 | ENDIF |
---|
38 | |
---|
39 | image2 = ((min > image < max) -min)*(!d.n_colors-2)/(max-min)+1 |
---|
40 | IF n_elements(msk) NE 0 THEN BEGIN |
---|
41 | image2(where(msk EQ 0)) = 0 |
---|
42 | ENDIF |
---|
43 | image2 = rebin(image2, gamma*ni, gamma*nj, sample = sample) |
---|
44 | |
---|
45 | IF n_elements(ps) EQ 0 THEN BEGIN |
---|
46 | xsize = ni*gamma+200 |
---|
47 | ysize = nj*gamma+200 |
---|
48 | IF (!d.x_size LT xsize) OR (!d.y_size LT ysize) THEN $ |
---|
49 | window, xsize = ni*gamma+200, ysize = nj*gamma+200 |
---|
50 | |
---|
51 | xcmperpix = 1. |
---|
52 | ycmperpix = 1. |
---|
53 | ENDIF ELSE BEGIN |
---|
54 | set_plot, 'ps' |
---|
55 | device, xsize = 19, ysize = 20, xoffset = 1, yoffset = 1, bits = 8, /color |
---|
56 | device, xsize = 25, ysize = 19, xoffset = 1, yoffset = 28, bits = 8, /color, /land |
---|
57 | |
---|
58 | xcmperpix = !d.X_PX_CM/50. |
---|
59 | ycmperpix = !d.y_PX_CM/50. |
---|
60 | print, xcmperpix, ycmperpix |
---|
61 | ENDELSE |
---|
62 | |
---|
63 | xsize = gamma*ni*xcmperpix |
---|
64 | ysize = gamma*nj*ycmperpix |
---|
65 | |
---|
66 | x0 = (!d.x_size-xsize)/2. ; coordonnees de l''image |
---|
67 | y0 = (!d.y_size-ysize)/2. ; |
---|
68 | x1 = x0/!d.x_size |
---|
69 | y1 = y0/!d.y_size |
---|
70 | |
---|
71 | !x.range = ibase+[0, ni*scale_x] |
---|
72 | !y.range = jbase+[0, nj*scale_y] |
---|
73 | !x.style = 1 |
---|
74 | !y.style = 1 |
---|
75 | !p.position = [x1, y1, 1-x1, 1-y1] ; position du cadre |
---|
76 | subtitle = 'MIN='+string(min)+' / MAX='+string(max) |
---|
77 | |
---|
78 | IF keyword_set(erase) NE 0 THEN erase, 255 |
---|
79 | |
---|
80 | tv, image2, x0, y0, xsize = xsize, ysize = ysize, _extra = extra |
---|
81 | plot, !x.crange, !y.crange, subtitle = subtitle, /nodata, /noerase, $ |
---|
82 | xticklen = 1, yticklen = 1, color = 0, _extra = extra ; cadre |
---|
83 | |
---|
84 | x0 = !x.window(0) |
---|
85 | y0 = !y.window(0) |
---|
86 | dx = !x.window(1)-!x.window(0) |
---|
87 | dy = !y.window(1)-!y.window(0) |
---|
88 | |
---|
89 | deltax = (!x.window[1]-!x.window[0]) |
---|
90 | deltay = (!y.window[1]-!y.window[0]) |
---|
91 | x00 = !x.window[1] |
---|
92 | y00 = !y.window[0] |
---|
93 | |
---|
94 | colorbar,/vert,color=0,bottom = 1, $ |
---|
95 | min=min,max=max,$ |
---|
96 | divisions=10, /right, $ |
---|
97 | position =[x00+deltax*0.01,y00+deltay*0.1,x00+deltax*0.04,y00+deltay*0.9] |
---|
98 | |
---|
99 | IF n_elements(ps) EQ 0 THEN BEGIN |
---|
100 | print, 'button 1 = value / button 2 = zoom / button 3 = exit' |
---|
101 | REPEAT BEGIN |
---|
102 | cursor,x,y,/normal, /down |
---|
103 | button = !mouse.button |
---|
104 | i=0 > floor(ni*(x-x0)/dx) < (ni-1) |
---|
105 | j=0 > floor(nj*(y-y0)/dy) < (nj-1) |
---|
106 | CASE button OF |
---|
107 | 1: BEGIN |
---|
108 | print, 'i=', i+ibase, ' / j=', j+jbase, ' / z(i,j)=', image(i, j) |
---|
109 | wait, .2 |
---|
110 | END |
---|
111 | 2: BEGIN |
---|
112 | i0 = i |
---|
113 | j0 = j |
---|
114 | cursor,x,y,/normal, /down |
---|
115 | i1=0 > floor(ni*(x-x0)/dx) < (ni-1) |
---|
116 | j1=0 > floor(nj*(y-y0)/dy) < (nj-1) |
---|
117 | IF i1 LE i0 THEN i1 = (i0+10) < (ni-1) |
---|
118 | IF j1 LE j0 THEN j1 = (j0+10) < (nj-1) |
---|
119 | tvnplot, image(i0:i1, j0:j1), _extra = extra, /erase, $ |
---|
120 | ibase = i0+ibase, jbase = j0+jbase, MIN = min, Max = max |
---|
121 | END |
---|
122 | 4: return |
---|
123 | ELSE: |
---|
124 | ENDCASE |
---|
125 | ENDREP UNTIL (button EQ 4) |
---|
126 | ENDIF |
---|
127 | |
---|
128 | x_env_save = !x |
---|
129 | y_env_save = !y |
---|
130 | p_env_save = !p |
---|
131 | |
---|
132 | |
---|
133 | IF n_elements(ps) EQ 0 THEN BEGIN |
---|
134 | |
---|
135 | ENDIF ELSE BEGIN |
---|
136 | device, /close |
---|
137 | ; tvlct, r, g, b |
---|
138 | set_plot, 'x' |
---|
139 | ENDELSE |
---|
140 | |
---|
141 | !x = x_env_save |
---|
142 | !y = y_env_save |
---|
143 | !p = p_env_save |
---|
144 | |
---|
145 | END |
---|
146 | |
---|
147 | ;+ |
---|
148 | ; NAME: |
---|
149 | ; COLORBARTV |
---|
150 | ; |
---|
151 | ; PURPOSE: |
---|
152 | ; The purpose of this routine is to add a color bar to the current |
---|
153 | ; graphics window. |
---|
154 | ; |
---|
155 | ; CATEGORY: |
---|
156 | ; Graphics, Widgets. |
---|
157 | ; |
---|
158 | ; CALLING SEQUENCE: |
---|
159 | ; COLORBAR |
---|
160 | ; |
---|
161 | ; INPUTS: |
---|
162 | ; None. |
---|
163 | ; |
---|
164 | ; KEYWORD PARAMETERS: |
---|
165 | ; |
---|
166 | ; BOTTOM: The lowest color index of the colors to be loaded in |
---|
167 | ; the bar. |
---|
168 | ; |
---|
169 | ; CHARSIZE: The character size of the color bar annotations. Default is 1.0. |
---|
170 | ; |
---|
171 | ; COLOR: The color index of the bar outline and characters. Default |
---|
172 | ; is ncolors - 1 + bottom. |
---|
173 | ; |
---|
174 | ; DISCRET: Vecteur contenant les incices des couleurs a tracer en barre |
---|
175 | ; de couleur. On obtient ainsi une barre de couleur discrete ne comportant que |
---|
176 | ; les couleurs specifiees ds l'ordre ou elles apparaissent ds le vecteur. |
---|
177 | ; |
---|
178 | ; DIVISIONS: The number of divisions to divide the bar into. There will |
---|
179 | ; be (divisions + 1) annotations. The default is 2. |
---|
180 | ; |
---|
181 | ; FORMAT: The format of the bar annotations. Default is '(F6.2)'. |
---|
182 | ; |
---|
183 | ; MAX: The maximum data value for the bar annotation. Default is |
---|
184 | ; NCOLORS-1. |
---|
185 | ; |
---|
186 | ; MIN: The minimum data value for the bar annotation. Default is 0. |
---|
187 | ; |
---|
188 | ; NCOLORS: This is the number of colors in the color bar. |
---|
189 | ; |
---|
190 | ; POSITION: A four-element array of normalized coordinates in the same |
---|
191 | ; form as the POSITION keyword on a plot. Default is |
---|
192 | ; [0.88, 0.15, 0.95, 0.95] for a vertical bar and |
---|
193 | ; [0.15, 0.88, 0.95, 0.95] for a horizontal bar. |
---|
194 | ; |
---|
195 | ; PSCOLOR: This keyword is only applied if the output is being sent to |
---|
196 | ; a PostScript file. It indicates that the PostScript device |
---|
197 | ; is configured for color output. If this keyword is set, then |
---|
198 | ; the annotation is drawn in the color specified by the COLOR |
---|
199 | ; keyword. If the keyword is not set, the annotation is drawn |
---|
200 | ; in the color specified by the !P.COLOR system variable |
---|
201 | ; (usually this will be the color black). In general, this |
---|
202 | ; gives better looking output on non-color or gray-scale |
---|
203 | ; printers. If you are not specifically setting the annotation |
---|
204 | ; color (with the COLOR keyword), it will probably |
---|
205 | ; be better NOT to set this keyword either, even if you |
---|
206 | ; are outputting to a color PostScript printer. |
---|
207 | ; |
---|
208 | ; RIGHT: This puts the labels on the right-hand side of a vertical |
---|
209 | ; color bar. It applies only to vertical color bars. |
---|
210 | ; |
---|
211 | ; TITLE: This is title for the color bar. The default is to have |
---|
212 | ; no title. |
---|
213 | ; |
---|
214 | ; TOP: This puts the labels on top of the bar rather than under it. |
---|
215 | ; The keyword only applies if a horizontal color bar is rendered. |
---|
216 | ; |
---|
217 | ; VERTICAL: Setting this keyword give a vertical color bar. The default |
---|
218 | ; is a horizontal color bar. |
---|
219 | ; |
---|
220 | ; COMMON BLOCKS: |
---|
221 | ; None. |
---|
222 | ; |
---|
223 | ; SIDE EFFECTS: |
---|
224 | ; Color bar is drawn in the current graphics window. |
---|
225 | ; |
---|
226 | ; RESTRICTIONS: |
---|
227 | ; The number of colors available on the display device (not the |
---|
228 | ; PostScript device) is used unless the NCOLORS keyword is used. |
---|
229 | ; |
---|
230 | ; EXAMPLE: |
---|
231 | ; To display a horizontal color bar above a contour plot, type: |
---|
232 | ; |
---|
233 | ; LOADCT, 5, NCOLORS=100 |
---|
234 | ; CONTOUR, DIST(31,41), POSITION=[0.15, 0.15, 0.95, 0.75], $ |
---|
235 | ; C_COLORS=INDGEN(25)*4, NLEVELS=25 |
---|
236 | ; COLORBAR, NCOLORS=100 |
---|
237 | ; |
---|
238 | ; MODIFICATION HISTORY: |
---|
239 | ; Written by: David Fanning, 10 JUNE 96. |
---|
240 | ; 10/27/96: Added the ability to send output to PostScript. DWF |
---|
241 | ; 11/4/96: Substantially rewritten to go to screen or PostScript |
---|
242 | ; file without having to know much about the PostScript device |
---|
243 | ; or even what the current graphics device is. DWF |
---|
244 | ; 1/27/97: Added the RIGHT and TOP keywords. Also modified the |
---|
245 | ; way the TITLE keyword works. DWF |
---|
246 | ; 7/15/97: Fixed a problem some machines have with plots that have |
---|
247 | ; no valid data range in them. DWF |
---|
248 | ; 3/3/98: ajout du keyword discret par |
---|
249 | ; sebastien (smasson@lodyc.jussieu.fr) |
---|
250 | ;- |
---|
251 | |
---|
252 | PRO COLORBARTV, BOTTOM=bottom, CHARSIZE=charsize, COLOR=color, $ |
---|
253 | DIVISIONS=divisions, DISCRET=discret, $ |
---|
254 | FORMAT=format, POSITION=position, MAX=max, MIN=min, NCOLORS=ncolors, $ |
---|
255 | PSCOLOR=pscolor, TITLE=title, VERTICAL=vertical, TOP=top, RIGHT=right |
---|
256 | ; Is the PostScript device selected? |
---|
257 | |
---|
258 | postScriptDevice = (!D.NAME EQ 'PS') |
---|
259 | |
---|
260 | ; Check and define keywords. |
---|
261 | |
---|
262 | IF N_ELEMENTS(ncolors) EQ 0 THEN BEGIN |
---|
263 | |
---|
264 | ; Most display devices to not use the 256 colors available to |
---|
265 | ; the PostScript device. This presents a problem when writing |
---|
266 | ; general-purpose programs that can be output to the display or |
---|
267 | ; to the PostScript device. This problem is especially bothersome |
---|
268 | ; if you don't specify the number of colors you are using in the |
---|
269 | ; program. One way to work around this problem is to make the |
---|
270 | ; default number of colors the same for the display device and for |
---|
271 | ; the PostScript device. Then, the colors you see in PostScript are |
---|
272 | ; identical to the colors you see on your display. Here is one way to |
---|
273 | ; do it. |
---|
274 | |
---|
275 | IF postScriptDevice THEN BEGIN |
---|
276 | oldDevice = !D.NAME |
---|
277 | |
---|
278 | ; What kind of computer are we using? SET_PLOT to appropriate |
---|
279 | ; display device. |
---|
280 | |
---|
281 | thisOS = !VERSION.OS_FAMILY |
---|
282 | thisOS = STRMID(thisOS, 0, 3) |
---|
283 | thisOS = STRUPCASE(thisOS) |
---|
284 | CASE thisOS of |
---|
285 | 'MAC': SET_PLOT, thisOS |
---|
286 | 'WIN': SET_PLOT, thisOS |
---|
287 | ELSE: SET_PLOT, 'X' |
---|
288 | ENDCASE |
---|
289 | |
---|
290 | ; Open a window (to make sure !D.N_COLORS is accurate). |
---|
291 | |
---|
292 | WINDOW, /FREE, /PIXMAP, XSIZE=10, YSIZE=10 |
---|
293 | WDELETE, !D.WINDOW |
---|
294 | |
---|
295 | ; Here is how many colors we should use. |
---|
296 | |
---|
297 | ncolors = !D.N_COLORS |
---|
298 | SET_PLOT, oldDevice |
---|
299 | ENDIF ELSE ncolors = !D.N_COLORS |
---|
300 | ENDIF |
---|
301 | IF N_ELEMENTS(bottom) EQ 0 THEN bottom = 0B |
---|
302 | IF N_ELEMENTS(charsize) EQ 0 THEN charsize = 1.0 |
---|
303 | IF N_ELEMENTS(format) EQ 0 THEN format = '(F8.2)' |
---|
304 | IF N_ELEMENTS(color) EQ 0 THEN color = ncolors - 1 + bottom |
---|
305 | IF N_ELEMENTS(min) EQ 0 THEN min = 0.0 |
---|
306 | IF N_ELEMENTS(max) EQ 0 THEN max = FLOAT(ncolors) - 1 |
---|
307 | IF N_ELEMENTS(divisions) EQ 0 THEN divisions = 2 |
---|
308 | IF N_ELEMENTS(title) EQ 0 THEN title = '' |
---|
309 | pscolor = KEYWORD_SET(pscolor) |
---|
310 | |
---|
311 | IF KEYWORD_SET(vertical) THEN BEGIN |
---|
312 | IF KEYWORD_SET(discret) THEN begin |
---|
313 | facteur=256/n_elements(discret) |
---|
314 | discret=reform(replicate(1,facteur) # discret,facteur*n_elements(discret)) |
---|
315 | bar = REPLICATE(1B,10) # discret |
---|
316 | endif else bar = REPLICATE(1B,10) # BINDGEN(256) |
---|
317 | IF N_ELEMENTS(position) EQ 0 THEN position = [0.88, 0.15, 0.95, 0.95] |
---|
318 | ENDIF ELSE BEGIN |
---|
319 | IF KEYWORD_SET(discret) THEN begin |
---|
320 | facteur=256/n_elements(discret) |
---|
321 | discret=reform(replicate(1,facteur) # discret,facteur*n_elements(discret)) |
---|
322 | bar = discret # REPLICATE(1B,10) |
---|
323 | endif else bar = BINDGEN(256) # REPLICATE(1B, 10) |
---|
324 | IF N_ELEMENTS(position) EQ 0 THEN position = [0.15, 0.88, 0.95, 0.95] |
---|
325 | ENDELSE |
---|
326 | |
---|
327 | ; Scale the color bar. |
---|
328 | IF NOT KEYWORD_SET(discret) THEN $ |
---|
329 | bar = BYTSCL(bar, TOP=ncolors-1) + bottom |
---|
330 | |
---|
331 | ; Get starting locations in DEVICE coordinates. |
---|
332 | |
---|
333 | xstart = position(0) * !D.X_VSIZE |
---|
334 | ystart = position(1) * !D.Y_VSIZE |
---|
335 | |
---|
336 | ; Get the size of the bar in DEVICE coordinates. |
---|
337 | |
---|
338 | xsize = (position(2) - position(0)) * !D.X_VSIZE |
---|
339 | ysize = (position(3) - position(1)) * !D.Y_VSIZE |
---|
340 | |
---|
341 | ; For PostScript output only, draw the annotation in !P.COLOR |
---|
342 | ; unless "pscolor" is set. This makes better output on grayscale |
---|
343 | ; printers. |
---|
344 | |
---|
345 | IF postScriptDevice AND (pscolor NE 1) THEN BEGIN |
---|
346 | oldcolor = color |
---|
347 | color = !P.COLOR |
---|
348 | ENDIF |
---|
349 | |
---|
350 | ; Display the color bar in the window. Sizing is |
---|
351 | ; different for PostScript and regular display. |
---|
352 | |
---|
353 | IF postScriptDevice THEN BEGIN |
---|
354 | |
---|
355 | TV, bar, xstart, ystart, XSIZE=xsize, YSIZE=ysize |
---|
356 | |
---|
357 | ENDIF ELSE BEGIN |
---|
358 | |
---|
359 | bar = CONGRID(bar, CEIL(xsize), CEIL(ysize), /INTERP) |
---|
360 | TV, bar, xstart, ystart |
---|
361 | |
---|
362 | ENDELSE |
---|
363 | |
---|
364 | ; Annotate the color bar. |
---|
365 | |
---|
366 | IF KEYWORD_SET(vertical) THEN BEGIN |
---|
367 | |
---|
368 | IF KEYWORD_SET(right) THEN BEGIN |
---|
369 | |
---|
370 | PLOT, [min,max], [min,max], /NODATA, XTICKS=1, $ |
---|
371 | YTICKS=divisions, XSTYLE=1, YSTYLE=9, $ |
---|
372 | POSITION=position, COLOR=color, CHARSIZE=charsize, /NOERASE, $ |
---|
373 | YTICKFORMAT='(A1)', XTICKFORMAT='(A1)', YTICKLEN=0.1 , $ |
---|
374 | YRANGE=[min, max], YTITLE=title |
---|
375 | |
---|
376 | AXIS, YAXIS=1, YRANGE=[min, max], YTICKFORMAT=format, YTICKS=divisions, $ |
---|
377 | YTICKLEN=0.1, YSTYLE=1, COLOR=color, CHARSIZE=charsize |
---|
378 | |
---|
379 | ENDIF ELSE BEGIN |
---|
380 | |
---|
381 | PLOT, [min,max], [min,max], /NODATA, XTICKS=1, $ |
---|
382 | YTICKS=divisions, XSTYLE=1, YSTYLE=9, $ |
---|
383 | POSITION=position, COLOR=color, CHARSIZE=charsize, /NOERASE, $ |
---|
384 | YTICKFORMAT=format, XTICKFORMAT='(A1)', YTICKLEN=0.1 , $ |
---|
385 | YRANGE=[min, max] |
---|
386 | |
---|
387 | AXIS, YAXIS=1, YRANGE=[min, max], YTICKFORMAT='(A1)', YTICKS=divisions, $ |
---|
388 | YTICKLEN=0.1, YTITLE=title, YSTYLE=1, COLOR=color, CHARSIZE=charsize |
---|
389 | |
---|
390 | ENDELSE |
---|
391 | |
---|
392 | ENDIF ELSE BEGIN |
---|
393 | |
---|
394 | IF KEYWORD_SET(top) THEN BEGIN |
---|
395 | |
---|
396 | PLOT, [min,max], [min,max], /NODATA, XTICKS=divisions, $ |
---|
397 | YTICKS=1, XSTYLE=9, YSTYLE=1, $ |
---|
398 | POSITION=position, COLOR=color, CHARSIZE=charsize, /NOERASE, $ |
---|
399 | YTICKFORMAT='(A1)', XTICKFORMAT='(A1)', XTICKLEN=0.1, $ |
---|
400 | XRANGE=[min, max], XTITLE=title |
---|
401 | |
---|
402 | AXIS, XTICKS=divisions, XSTYLE=1, COLOR=color, CHARSIZE=charsize, $ |
---|
403 | XTICKFORMAT=format, XTICKLEN=0.1, XRANGE=[min, max], XAXIS=1 |
---|
404 | |
---|
405 | ENDIF ELSE BEGIN |
---|
406 | |
---|
407 | PLOT, [min,max], [min,max], /NODATA, XTICKS=divisions, $ |
---|
408 | YTICKS=1, XSTYLE=1, YSTYLE=1, $ |
---|
409 | POSITION=position, COLOR=color, CHARSIZE=charsize, /NOERASE, $ |
---|
410 | YTICKFORMAT='(A1)', XTICKFORMAT=format, XTICKLEN=0.1, $ |
---|
411 | XRANGE=[min, max], TITLE=title |
---|
412 | |
---|
413 | ENDELSE |
---|
414 | |
---|
415 | ENDELSE |
---|
416 | |
---|
417 | ; Restore color variable if changed for PostScript. |
---|
418 | |
---|
419 | IF postScriptDevice AND (pscolor NE 1) THEN color = oldcolor |
---|
420 | |
---|
421 | END |
---|
422 | |
---|
423 | |
---|
424 | |
---|