source: trunk/SRC/ToBeReviewed/PLOTS/DESSINE/tvplus.pro @ 226

Last change on this file since 226 was 226, checked in by pinsard, 17 years ago

corrections of some misspellings in some *.pro

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 12.3 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5;
6; @file_comments
7; Enhanced version of tvscl
8;
9; @categories quick exploration of 2D arrays
10;
11; @param Z2D {in}{required}
12; 2D array to visualize
13;
14; @param CELLSIZE {in}{optional}
15; This is the size (in pixel) of the square
16; representing 1 array element. By default, this size is computed
17; automatically in order that the size of the plotting window do
18; not exceed the screen size. If the user specify a large value
19; of cellsize that forces tvplus to create a window larger than
20; the screen, a "scrolling window" will be displayed instead of a
21; regular window. Unfortunately the nice functionalities of tvplus
22; are not coded for "scrolling window" case...
23;
24; @keyword BOTTOM {default=1}
25; The lowest color index of the colors to be used
26;
27; @keyword C_NAN {default=!d.n_colors < 255}
28; The color number that should be used for the NaN values.
29;
30; @keyword C_MASK {default=0}
31; The color number that should be used for the mask values.
32;
33; @keyword OFFSET
34; 2 elements vector used by tvplus itself when showing zoom.
35; It is used to shift the ranges of xaxis and yaxis.
36; For example: tvplus,sst[x1:x2,y1:y2],offset=[x1,y1]
37;
38; @keyword MASK
39; The mask value. Note that if abs(mask) < 1.e6, then the
40; exact value of the mask is used to find the maskwd point.
41; if abs(mask) > 1.e6, the test to find the masked value is ge
42; abs(mask)/10. This is necessary to avoid the rounding errors
43;
44; @keyword MIN
45; Scalar used to specify the min value to be drawn.
46;
47; @keyword MAX
48; Scalar used to specify the max value to be drawn.
49;
50; @keyword NCOLORS {default=(d.n_colors < 256) - 1 - bottom}
51; number of colors to be used.
52;
53; @keyword NOINTERP
54; Used this keyword if you don't want that the values
55; are interpolated from BOTTOM using NCOLORS colors.
56; This can be for example useful when working on byte type arrays.
57;
58; @keyword NOUSEINFOS
59; Activate to suppress the printed message explaining how to use tvplus
60;
61; @keyword WINDOW
62; Number of the window used to display the array values.
63; default is window number 0.
64;
65; @keyword _EXTRA
66; used to pass keywords to TV, PLOT, COLORBAR
67;
68; @restrictions
69; use your mouse to scan the array values...
70;     left button  : mouse position and associated array value
71;     middle button: use it twice to define a zoom box
72;     right button : quit
73;
74; the nice functionalities of tvplus are not coded
75; for "scrolling window" case...
76;
77; @examples
78; IDL> tvplus, dist(100)
79;
80; @history
81; Sebastien Masson (smasson\@lodyc.jussieu.fr)
82;                       18/12/98
83; Aug 2005: quick cleaning + english
84;
85; @version
86; $Id$
87;
88;-
89;------------------------------------------------------------
90;------------------------------------------------------------
91;------------------------------------------------------------
92PRO tvplus, z2d, cellsize, BOTTOM = bottom, C_MASK = c_mask, C_NAN = c_nan, WINDOW = window $
93            , MIN = min, MAX = max, MASK = mask, OFFSET = offset, NOUSEINFOS = NOUSEINFOS $
94            , NCOLORS = ncolors, NOINTERP = nointerp, _EXTRA = ex
95;
96;
97  compile_opt idl2, strictarrsubs
98;
99  IF n_elements(z2d) EQ 0 THEN return
100  arr = reform(float(z2d))
101;------------------------------------------------------------
102; check the size of the input array
103;------------------------------------------------------------
104  if (size(arr))[0] NE 2 then begin
105    ras = report('Input array must have only 2 dimensions and not '+ strtrim(size(arr, /n_dimensions), 1))
106    return
107  endif
108;------------------------------------------------------------
109; def of ncolmax, bottom, topcol et ncolors
110;------------------------------------------------------------
111  ncolmax = !d.n_colors < 256
112  IF N_ELEMENTS(bottom) EQ 0 THEN bottom = 1
113  if NOT keyword_set(ncolors) then ncolors = ncolmax - 1 - bottom
114  topcol = (bottom+ncolors-1) < (ncolmax-1)
115;------------------------------------------------------------
116; get default values of !x, !y, !z
117;------------------------------------------------------------
118;   xenvsauve = !x & yenvsauve = !y & penvsauve = !p
119  reinitplt, /z, /invert
120;------------------------------------------------------------
121; Do we have NaN values in arr???
122;------------------------------------------------------------
123  nan = total(finite(z2d, /nan)) < 1
124  if keyword_set(nan) then begin
125    nanindex = where(finite(z2d, /nan) EQ 1)
126    arr[nanindex] = min(arr, /nan)
127  endif
128;------------------------------------------------------------
129; Compute the size (in pixel) of the square representing 1
130; point of the input array
131;------------------------------------------------------------
132  dimensions = GET_SCREEN_SIZE()
133  if n_elements(cellsize) EQ 0 then BEGIN
134    cellsize = min(floor(dimensions/(size(z2d))[1: 2]*.75))
135  ENDIF ELSE $
136; we need to use a scrolling bar window
137  if cellsize GE min(floor(dimensions/(size(z2d))[1: 2]*.75)) then scrolling = 1
138  if cellsize LT 1 then begin
139    cellsize = 1
140    scrolling = 1
141  endif
142;------------------------------------------------------------
143; Change the value of the masked value for the min of the non-masked values
144;------------------------------------------------------------
145  if n_elements(mask) then BEGIN
146    if abs(mask) LT 1e6 then BEGIN
147      masked = where(arr EQ mask)
148      if masked[0] NE -1 then arr[masked] = min(arr[where(arr NE mask)])
149    ENDIF ELSE BEGIN
150      masked = where(abs(arr) GE abs(mask)/10.)
151      if masked[0] NE -1 then arr[masked] = min(arr[where(abs(arr) LT abs(mask)/10.)])
152    ENDELSE
153  ENDIF ELSE masked = -1
154;------------------------------------------------------------
155; apply min/max keywords
156;------------------------------------------------------------
157  if n_elements(min) NE 0 then BEGIN
158    arr = min > arr
159    truemin = min
160  ENDIF ELSE truemin = min(arr)
161  if n_elements(max) NE 0 then BEGIN
162    arr = arr < max
163    truemax = max
164  ENDIF ELSE truemax = max(arr)
165;
166  IF truemin EQ truemax THEN BEGIN
167    dummy = report('constant value everywhere: '+ strtrim(truemin, 1))
168    return
169  ENDIF
170;------------------------------------------------------------
171; apply other keywords (nointerp, c_nan, c_mask)
172;------------------------------------------------------------
173  if NOT keyword_set(nointerp) then BEGIN
174; interpolation between bottom and bottom+ncolors-1
175    m = 1.*(ncolors-1)/(truemax-truemin)
176    p = bottom-1.*truemin*m
177    arr = round(m*temporary(arr)+p)
178  endif
179; set c_nan for NaN values
180  if keyword_set(nan) then begin
181    if n_elements(c_nan) NE 0 THEN arr[nanindex] = c_nan <  (ncolmax -1) $
182    ELSE arr[nanindex] = topcol
183  endif
184; c_mask for masked values
185  if n_elements(c_mask) NE 0 AND masked[0] NE -1 THEN $
186    arr[masked] = c_mask < (ncolmax -1)
187; use byte type to save memory
188  arr = byte(temporary(arr))
189; increase the size of the array in order to be displayed
190; with the suitable size
191  szarr = size(arr, /dimensions)
192  arr = congrid(temporary(arr), szarr[0]*cellsize, szarr[1]*cellsize)
193;------------------------------------------------------------
194; open a window with the correct size
195;------------------------------------------------------------
196  nx = (size(arr))[1]
197  ny = (size(arr))[2]
198; margin size (in pixel)
199  xyaspect = 1.*nx/ny
200  if xyaspect GE 1 THEN marginpix = 1.*[25, 25, 75, 25] ELSE marginpix = 1.*[25, 100, 25, 25]
201;
202  if n_elements(scrolling) EQ 0 then BEGIN ; open the regular window
203    if NOT keyword_set(window) then window = 0
204    window, window, xsize = nx+marginpix[0]+marginpix[1] $
205            , ysize = ny+marginpix[2]+marginpix[3]
206; for 24 bits colors, make sure thate the background color is the good one...
207    if !d.n_colors gt 256 then BEGIN
208      device, decomposed = 1
209      !p.background = 'ffffff'x
210      plot, [0], [0], xstyle = 5, ystyle = 5
211      device, decomposed = 0
212    endif
213    tv, arr, marginpix[0], marginpix[2], _EXTRA = ex
214;
215; axis and plot frame
216;
217; get the normalized position of the tv (we just done above)
218; to know where the frame should be drawn
219    poscadre = fltarr(4)
220    poscadre[0] = marginpix[0]/!d.x_size
221    poscadre[2] = 1.-marginpix[1]/!d.x_size
222    poscadre[1] = marginpix[2]/!d.y_size
223    poscadre[3] = 1-marginpix[3]/!d.y_size
224; Use plot to draw the frame
225    if NOT keyword_set(offset) then offset = [0, 0]
226    !p.position = poscadre
227    plot, [0], [0], /nodata, /noerase, position = poscadre, color = 0 $
228          , xstyle = 1, ystyle = 1, xticklen = 1, yticklen = 1 $
229          , xrange = 1.*[0, nx]/cellsize-.5+offset[0] $
230          , yrange = 1.*[0, ny]/cellsize-.5+offset[1], _extra = ex
231    xenvsauve = !x & yenvsauve = !y & penvsauve = !p
232;
233; draw the colorbar
234;
235    IF truemin ne truemax THEN BEGIN
236      if xyaspect ge 1 then $
237        posbar = [25./!d.x_size, 25./!d.y_size, 1-25./!d.x_size, 50./!d.y_size] $
238        ELSE posbar = [1-75./!d.x_size, 25./!d.y_size, 1-50./!d.x_size, 1-25./!d.y_size]
239    if keyword_set(nointerp) then BEGIN & truemin = 0 & truemax = ncolmax & endif
240      colorbar, min = truemin, max = truemax, division = 10, cb_color = 0, position = posbar $
241                , vertical = xyaspect lt 1, /right, BOTTOM = bottom, NCOLORS = ncolors, _EXTRA = ex
242    ENDIF
243;      !p.position = poscadre
244  ENDIF ELSE BEGIN
245;------------------------------------------------------------
246; scrolling bar window case...
247;------------------------------------------------------------
248; for 24 bits colors, make sure thate the background color is the good one...
249    if !d.n_colors gt 256 then begin
250      window, /pixmap
251      device, decomposed = 1
252      !p.background = 'ffffff'x
253      plot, [0], [0]
254      device, decomposed = 0
255    endif
256    slide_image, arr $          ; We draw it in a window with a scrolling bar
257                 , xsize = nx, ysize = ny $
258                 , xvisible = round(.7*dimensions[0]) < (size(arr))[1] $
259                 , yvisible = round(.7*dimensions[1]) < (size(arr))[2], /register, congrid = 0, show_full = 0
260    return
261  ENDELSE
262;------------------------------------------------------------
263; Use the mouse to get nice functionalities
264;------------------------------------------------------------
265; format to print the mouse position
266  CASE 1 OF
267    nx LT 10:fmt1 = '(i1)'
268    nx LT 100:fmt1 = '(i2)'
269    nx LT 1000:fmt1 = '(i3)'
270    nx LT 10000:fmt1 = '(i4)'
271    ELSE:fmt1 = ''
272  ENDCASE
273  CASE 1 OF
274    ny LT 10:fmt2 = '(i1)'
275    ny LT 100:fmt2 = '(i2)'
276    ny LT 1000:fmt2 = '(i3)'
277    ny LT 10000:fmt2 = '(i4)'
278    ELSE:fmt2 = ''
279  ENDCASE
280;
281  if NOT keyword_set(nouseinfos) then begin
282    print, 'left button  : mouse position and associated array value'
283    print, 'middle button: use it twice to define a zoom box'
284    print, 'right button : quit'
285  endif
286  cursor, x, y, /device, /down
287  x = x-marginpix[0] & x = 0 > floor(x/cellsize) < ((size(arr))[1]/cellsize-1)
288  y = y-marginpix[2] & y = 0 > floor(y/cellsize) < ((size(arr))[2]/cellsize-1)
289  while (!mouse.button ne 4) do BEGIN
290    case !mouse.button of
291      0:return
292      1:BEGIN                   ; get value
293        if x LE nx/cellsize AND y LE ny/cellsize then begin
294          print, '(x, y) = (' + string(x+offset[0], format = fmt1) $
295                 + ', ' + string(y+offset[1], format = fmt2) $
296                 + '), value = '+strtrim(float((reform(z2d))[x, y]), 1)
297        ENDIF
298        cursor, x, y, /device, /down
299        x = x-marginpix[0] & x = 0 > floor(x/cellsize) < ((size(arr))[1]/cellsize-1)
300        y = y-marginpix[2] & y = 0 > floor(y/cellsize) < ((size(arr))[2]/cellsize-1)
301      END
302      2:BEGIN                   ; zoom
303        cursor, x2, y2, /device, /down
304        x2 = x2-marginpix[0] & x2 =  0 > floor(x2/cellsize) < ((size(arr))[1]/cellsize-1)
305        y2 = y2-marginpix[2] & y2 =  0 > floor(y2/cellsize) < ((size(arr))[2]/cellsize-1)
306        x =  [x, x2] & x =  x[sort(x)]
307        y =  [y, y2] & y =  y[sort(y)]
308        IF keyword_set(OFFSET) THEN offset = [x[0], y[0]]+offset ELSE offset = [x[0], y[0]]
309        tvplus, z2d[x[0]:x[1], y[0]:y[1] ], WINDOW = window, MIN = min, MAX = max $
310                , MASK = mask, C_MASK = c_mask, C_NAN = c_nan, /NOUSEINFOS, OFFSET = OFFSET $
311                , NCOLORS = ncolors, NOINTERP = nointerp, BOTTOM = bottom, _EXTRA = ex
312        return
313      END
314      ELSE:
315    endcase
316  ENDWHILE
317;------------------------------------------------------------
318  !x = xenvsauve & !y = yenvsauve & !p = penvsauve
319  !x.range = 1.*[0, nx]/cellsize-.5+offset[0]
320  !y.range = 1.*[0, ny]/cellsize-.5+offset[1]
321;------------------------------------------------------------
322  return
323end
Note: See TracBrowser for help on using the repository browser.