;+ ; NAME: ; imagesc ; ; ; PURPOSE: ; plot 2d data using tv instead of contour, named after the equilivant ; procedure in matlab ; ; ; ; INPUTS: ; image_in: the 2d array to plot ; ; ; OPTIONAL INPUTS: ; xaxis_in: the xaxis values ; yaxis_in: the yaxis values ; ; ; KEYWORD PARAMETERS: ; CT: color table to use ; ZRANGE: zrange to plot, take presidence over zmin and zmax ; ZMIN: min z to plot ; ZMAX: max z to plot ; INTERPOLATION: interpolate the plot ; POSITION: the position of the plot ; CHARSIZE: the charsize of the plot and colorbar ; CHARTHICK: char thickness of the plot and cb ; CBPOSITION: colorbar position ; NCOLORS: number of colors to plot with ; CBTITLE: colorbar title ; ZLOG: plot with a log color scale ; CBWIDTH: width of the colorbar (normal coords) ; CBOFFSET: right offset of the colorbar from the plot (normal) ; NOCOLORBAR: dont plot a colorbar ; FINE: fine colorbar ticks for log ; CBFORMAT: format of the cololrbar ticks ; CBCOLOR: set the color of the colorbar ; EPS: output to EPS ; _EXTRA: others to spectro_plot, mostly the same as plot ; ; ; OUTPUTS: ; the plot to the current window ; ; ; SIDE EFFECTS: ; will overwrite current color table with the selected one ; ; ; RESTRICTIONS: ; something is wrong with setting the colors with background and color ; and does not handle !P.multi at all ; ; ; EXAMPLE: ; ; imagesc, dist(100), ct=12, /iso ; see: http://people.bu.edu/balarsen/Home/IDL/Entries/2007/12/18_imagesc_(updated_18Dec2007).html ; ; MODIFICATION HISTORY: ; ; Tue Sep 1 11:32:34 2009, Brian Larsen ; rewritten to use dfanning routines, tvimage, ; colorbar. Removed SSWIDL dependence, saves color ; table and restores on exit ; ; Fri Jan 23 10:16:05 2009, Brian Larsen ; fixed up and made it use plotimage ; ; Fri Jan 16 16:15:33 2009, Brian Larsen ; fixes with specifiny zrange outside of image data values ; ; Fri Dec 12 14:12:05 2008, Brian Larsen ; rewritten as a wrapper from pg_plotimage not spectro_plot ; ; Mon Sep 8 13:45:27 2008, Brian Larsen ; added eps output code, stolen from HD Winter ; ; Wed Jun 25 12:04:33 2008, Brian Larsen ; changed to use fannings ctload and brewer color tables ; ; Tue Feb 5 16:15:50 2008, Brian Larsen ; more documentation and added CBCOLOR keyword and ; changed default loadct behoviour, now does not load a ; new cb unless CB is specified ; ; Tue Dec 18 13:28:08 2007, Brian Larsen ; totally rewritten once again, but this time log works, ; setting x and y ranges work and everything is happy. ; Now requires spectro_plot from solarsoft. Overall ; this is much more simple than before. Tweaked around ; keywords, sorry ; ; Mon Nov 26 19:37:12 2007, Brian Larsen ; rewritten to make colors work better ; ; Fri Oct 12 14:34:21 2007, Brian Larsen ; totally rewritten, made it a lot cleaner and a made ; the log functoinality work. ; ; Wed Oct 10 10:16:30 2007, Brian Larsen ; removed a few keywords, redundant from _extra ; ; Wed Sep 26 2007, Anthony W. Case ; Fixed charsize, cbcharsize, charthick, and cbcharthick keywords ; ; Mon Jan 22 17:28:52 2007, Brian Larsen ; cleaned up, added message routine, fixed error with scale_vector ; ; Wed Jan 3 14:01:33 2007, Brian Larsen ; Documented, writted previously. I am SURE there are ; piles of bugs in here as it is quite complicated a routine ; ;- PRO imagesc2, image_in, $ ; 2-d array input xaxis_in, $ ; optional input for axis values yaxis_in, $ ; optional input for axis values CT=ct, $ ; color table to use ZRANGE=zrange, $ ; zrange to plot, take presidence over zmin and zmax ZMIN=zmin, $ ; min z to plot ZMAX=zmax, $ ; max z to plot INTERPOLATION=interp, $ ; interpolate the plot POSITION=position, $ ; the position of the plot XCHARSIZE=xcharsize, $ ; the charsize of the plot and colorbar YCHARSIZE=ycharsize, $ ; the charsize of the plot and colorbar CHARTHICK=charthick, $ ; char thickness of the plot and cb CBPOSITION=cbposition, $ ; colorbar position NCOLORS=ncolors, $ ; number of colors to plot with CBTITLE=cbtitle, $ ; colorbar title ZLOG=zlog, $ ; plot with a log color scale CBWIDTH=cbwidth, $ ; width of the colorbar (normal coords) CBOFFSET=cboffset, $ ; right offset of the colorbar from the plot (normal) NOCOLORBAR=nocolorbar, $ ; dont plot a colorbar FINE=fine, $ ; fine colorbar ticks for log CBFORMAT=cbformat, $ ; format of the cololrbar ticks CBCOLOR = cbcolor, $ ; set the color of the colorbar BREWER = brewer, $ ; use the Brewer colortables xrange = xrange, $ yrange = yrange, $ keep_aspect_ratio = keep_aspect_ratio, $ NOERASE = noerase, $ PLOTKEYWORDS = plotkeywords, $ backgroound = background, $ cbcharsize = cbcharsize, $ cbcharthick = cbcharthick, $ CBHORIZONTAL = cbhoriz, $ _EXTRA=_extra ; others to plotimage, compile_opt strictarr IF n_elements(size(image_in, /dim)) NE 2 THEN $ message, /ioerror, 'Must input a 2d array' image=image_in ; can I get away from having to copy? ;; some input checking size_in = size(image, /dim) IF N_ELEMENTS(xaxis_in) NE size_in[0] AND $ N_ELEMENTS(xaxis_in) NE 0 THEN $ message, /ioerror, 'X axis and image of incompatible sizes' IF N_ELEMENTS(yaxis_in) NE size_in[1] AND $ N_ELEMENTS(yaxis_in) NE 0 THEN $ message, /ioerror, 'Y axis and image of incompatible sizes' IF N_ELEMENTS(xaxis) NE 0 AND N_ELEMENTS(yaxis) EQ 0 OR $ N_ELEMENTS(xaxis) EQ 0 AND N_ELEMENTS(yaxis) NE 0 THEN $ message, /ioerror, 'both x and y axes must be specified not just one' ;; end input checking ;;;;;;;;;;;;;;;;;; if not supplied setup the axes ;;;;;;; IF n_elements(xaxis_in) EQ 0 THEN $ xaxis = lindgen(size_in[0]) ELSE $ xaxis = xaxis_in IF n_elements(yaxis_in) EQ 0 THEN $ yaxis = lindgen(size_in[1]) ELSE $ yaxis = yaxis_in IF n_elements(xrange) EQ 2 THEN BEGIN indminx = round2array(xaxis, xrange[0]) indmaxx = round2array(xaxis, xrange[1]) image = image[indminx:indmaxx, *] IF xrange[0] LT xaxis[0] THEN print, 'Axis outside range isnt implemented yet' IF xrange[1] GT xaxis[n_elements(xaxis)-1] THEN print, 'Axis outside range isnt implemented yet' ENDIF IF n_elements(yrange) EQ 2 THEN BEGIN indminy = round2array(yaxis, yrange[0]) indmaxy = round2array(yaxis, yrange[1]) image = image[*, indminy:indmaxy] IF yrange[0] LT yaxis[0] THEN print, 'Axis outside range isnt implemented yet' IF yrange[1] GT yaxis[n_elements(yaxis)-1] THEN print, 'Axis outside range isnt implemented yet' ENDIF SetDefaultValue, xrange, [min(xaxis, NAN = nan), max(xaxis, NAN = nan)] SetDefaultValue, yrange, [min(yaxis, NAN = nan), max(yaxis, NAN = nan)] ;;;;;;;;;;;;; end axes ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;; other keywords ;;;;;;;;;;;;;;;;;;;;;;;;;;; IF n_elements(zrange) EQ 2 THEN BEGIN zmin = zrange[0] zmax = zrange[1] ENDIF ELSE BEGIN IF exist(zmin) AND exist(zmax) THEN zrange=[zmin, zmax] IF exist(zmin) AND ~exist(zmax) THEN zrange=[zmin, max(image, NAN = nan)] IF ~exist(zmin) AND exist(zmax) THEN zrange=[min(image, NAN = nan), zmax] IF ~exist(zmin) AND ~exist(zmax) THEN zrange=[min(image, NAN = nan), max(image, NAN = nan)] zmin = zrange[0] zmax = zrange[1] ENDELSE SetDefaultValue, ncolors, 255 ;; scale the image based on what zrange is set to ;; image = scale_vector(image, 0, ncolors, minvalue=zrange[0], maxvalue=zrange[1]) ;; we need a clear colortable for the image IF n_elements(ct) NE 0 THEN BEGIN TVLCT, rsave, gsave, bsave, /Get ctload, ct, /silent, ncolors=ncolors, BREWER = brewer ; use fannngs ctload ENDIF ;;;;;;;;;;;;;;;;;; plot up the image ;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SetDefaultValue, position, [0.1, 0.1, 0.8, 0.9] IF n_elements(zlog) NE 0 THEN BEGIN image = alog10(image) IF n_elements(zrange) EQ 0 THEN $ zrange = alog10([min(image, nan = nan), max(image, nan = nan)]) $ ELSE $ zrange = alog10(zrange) ENDIF ELSE BEGIN IF n_elements(zrange) EQ 0 THEN $ zrange = [min(image, NAN = nan), max(image, NAN = nan)] ENDELSE imgxrange = [xaxis[0], xaxis[n_elements(xaxis)-1]] imgyrange = [yaxis[0], yaxis[n_elements(yaxis)-1]] SetDefaultValue, noerase, 0 tvimage, image, /axes, $ xrange = xrange, $ yrange = yrange, $ position=position, $ keep_aspect_ratio = keep_aspect_ratio, $ AXKEYWORDS = plotkeywords, $ erase = ~noerase, background = background, _strict_extra = extra ;;;;;;;;;;;;;;; deal with the colorbar ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; IF NOT KEYWORD_SET(nocolorbar) THEN BEGIN ;; get the fanning common block for info about the plot COMMON FSC_$TVIMAGE, _tvimage_xsize, _tvimage_ysize, $ _tvimage_winxsize, _tvimage_winysize, $ _tvimage_position, _tvimage_winID, $ _tvimage_current IF NOT keyword_set(cbhoriz) THEN BEGIN cbvertical=1 IF n_elements(cbposition) EQ 0 THEN BEGIN IF n_elements(cboffset) EQ 0 THEN cboffset = 0.02 IF n_elements(cbwidth) EQ 0 THEN cbwidth = 0.02 SetDefaultValue, cbposition, [_tvimage_position[2]+cboffset, $ _tvimage_position[1], $ _tvimage_position[2]+cboffset+cbwidth, $ _tvimage_position[3]] ENDIF ENDIF ELSE BEGIN cbvertical = 0 IF n_elements(cboffset) EQ 0 THEN cboffset = 0.02 IF n_elements(cbwidth) EQ 0 THEN cbwidth = 0.02 SetDefaultValue, cbposition, [_tvimage_position[0], $ _tvimage_position[3]+cboffset, $ _tvimage_position[2], $ _tvimage_position[3]+cboffset+cbwidth] SetDefaultValue, top, 1 ENDELSE IF keyword_set(zlog) THEN BEGIN ytickv = loglevels([zmin, zmax], fine=fine) SetDefaultValue, cbformat, '(d0.2)' ytickv = string(ytickv, format=cbformat) cbticks=n_elements(ytickv)-1 ENDIF ELSE SetDefaultValue, cbformat, '(d0.2)' Colorbar, Range = zrange, $ BOTTOM = cbbottom, $ POSITION = cbposition, $ NCOLORS = ncolors, $ TITLE = cbtitle, $ VERTICAL = cbvertical, $ ylog = zlog, $ tickname = ytickv, $ divisions = cbticks, $ format = cbformat, $ xtitle = cbxtitle, $ color = cbcolor, $ charsize = cbcharsize, $ charthick = cbcharthick, $ /right, $ TOP = TOP ENDIF IF n_elements(ct) NE 0 THEN BEGIN TVLCT, rsave, gsave, bsave ENDIF END