;+ ; NAME fts2jpg_cps2.pro ; ; PURPOSE Convert a sequence of SMM C/P FITS images to JPEG format. ; ; SYNTAX fts2jpg_cps2, fits_list, cm='colormap.lut', wmin=0, wmax=5e-9 ; ; fits_list list of filenames of SMM C/P FITS images. ; gif write displayed image as a GIF file. ; cm pathname of ASCII colormap file. ; Each line has the syntax: index red green blue ; where index = 0, 1, 2, ... 255, ; and red/green/blue are in the range [0:255]. ; wmin display minimum value. ; wmax display maximum value. ; im display image only (no overlay). ; ov display image only with overlay graphics. ; (solar north, angular points). ; annotate display image with FITS parameter annotation ; (no overlay on image). ; NOTE: The default is to display the image with the overlay graphics ; and with FITS annotation (same as /ov /annotate). ; ; EXAMPLES fts2jpg_cps2, fits_list ; fts2jpg_cps2, fits_list, cm='/home/stanger/color/bwy.lut' ; fts2jpg_cps2, fits_list, wmax=1.e-9 ; fts2jpg_cps2, fits_list, /ov ; fts2jpg_cps2, fits_list, /ov, /annotate ; ; ov: JPEG file name: basename.ov.jpg ; annotate: JPEG file name: basename.an.jpg ; ov and annotate: JPEG file name: basename.oa.jpg ; ; EXTERNAL ; PROCEDURES fits_annotate.pro ; ; HISTORY Andrew L. Stanger HAO/NCAR 19 January 2006 ; Add ov and annotate options. ;- PRO fts2jpg_cps2, fits_list, cm=cm, wmin=wmin, wmax=wmax, gif=gif, $ im=im, ov=ov, annotate=annotate fits_name = '' black = 0 white = 255 ; --- Load color map. IF (KEYWORD_SET (cm)) THEN $ lct, cm $ ELSE $ lct, '/home/stanger/color/quallab.lut' ; Load default color table. ; --- Create storage for color look-up tables. rtab = BYTARR (256) gtab = BYTARR (256) btab = BYTARR (256) TVLCT, rtab, gtab, btab, /GET ; Fetch RGB color look-up tables. month_name = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', $ 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] ; --- Set character font size. cwidth = 8 cheight = FIX ((cwidth * 1.5) + 0.5) ; --- Define annotation borders: left & bottom. IF (KEYWORD_SET (annotate)) THEN $ BEGIN xb = 152 ; Left border width yb = 64 ; Bottom border height END $ ELSE $ BEGIN xb = 0 ; Left border width yb = 0 ; Bottom border width END ; --- Read first image in file list. ; --- Set the default output image size. CLOSE, 1 OPENR, 1, fits_list READF, 1, fits_name fits_img = readfits (fits_name, hdu) xdim = fxpar (hdu, 'NAXIS1') ydim = fxpar (hdu, 'NAXIS2') oxdim = xdim + xb oydim = ydim + yb xdim_prev = xdim ydim_prev = ydim CLOSE, 1 xdim_prev = 0 ydim_prev = 0 ; --- File list loop. OPENR, 1, fits_list WHILE (NOT EOF (1)) DO $ BEGIN ;{ READF, 1, fits_name ; Get file name from list. ; --- Extract "base name" for optional output file. ftspos = STRPOS (fits_name, '.fts') basename = STRMID (fits_name, 0, ftspos) ; print, 'basename: ', basename ; --- Read FITS image header & pixel data. img = readfits (fits_name, hdu) ; --- Read housekeeping extension. hk = readfits (fits_name, hdu_hk, exten_no=1) ; --- Extract information from header. xdim = fxpar (hdu, 'NAXIS1') ydim = fxpar (hdu, 'NAXIS2') xcen = fxpar (hdu, 'CRPIX1') ycen = fxpar (hdu, 'CRPIX2') crradius = fxpar (hdu, 'CRRADIUS') radius_occ = crradius * 1.5 ; --- Output image dimensions. oxdim = xdim + xb oydim = ydim + yb ; --- Resize window [if image size has changed]. ; SET_PLOT, 'X' ; window, xs=10, ys=10 ; if (xdim NE xdim_prev OR ydim NE ydim_prev) THEN $ ; WINDOW, xsize=oxdim, ys=oydim, RETAIN=2 SET_PLOT, 'Z' DEVICE, set_resolution = [oxdim, oydim], set_colors=256, z_buffering = 0 DEVICE, SET_CHARACTER_SIZE = [cwidth, cheight] ; Set character size. ; print, 'oxdim/oydim: ', oxdim, oydim xdim_prev = xdim ydim_prev = ydim dispmin = 0.0 dispmax = 0.0 ;--- Get information from FITS header. type_obs = fxpar (hdu, 'TYPE-OBS') telescop = fxpar (hdu, 'TELESCOP') instrume = fxpar (hdu, 'INSTRUME') dateobs = fxpar (hdu, 'DATE-OBS') timeobs = fxpar (hdu, 'TIME-OBS') datamin = fxpar (hdu, 'DATAMIN', count=cdatamin) datamax = fxpar (hdu, 'DATAMAX', count=cdatamax) dispmin = fxpar (hdu, 'DISPMIN', count=cdispmin) dispmax = fxpar (hdu, 'DISPMAX', count=cdispmax) imin = MIN (img, max=imax) ; print, 'imin/imax: ', imin, imax ;--- "Erase" left annotation area. IF (KEYWORD_SET (annotate)) THEN $ BEGIN winleft = BYTARR (xb, ydim) winleft [*, *] = white TV, winleft, 0, yb END ;--- "Erase" bottom annotation area. IF (KEYWORD_SET (annotate)) THEN $ BEGIN winbottom = BYTARR (xb + xdim, yb) winbottom [*, *] = white TV, winbottom, 0, 0 END ;--- Determine min/max intensity levels to display. dmin = datamin dmax = datamax IF (dispmin NE dispmax) THEN $ BEGIN dmin = dispmin dmax = dispmax END IF (KEYWORD_SET (wmin)) THEN dmin = wmin IF (KEYWORD_SET (wmax)) THEN dmax = wmax ; print, 'fts2jpg_cps> dmin/dmax: ', dmin, dmax ; --- Fill occulting disk with black. simg = BYTSCL (img, min=dmin, max=dmax, top=249) circfill, simg, xdim, ydim, xcen, ycen, radius_occ, black ;--- Display image. ; TV, BYTSCL (img, min=dispmin, max=dispmax, top=249), xb, yb TV, simg, xb, yb ;--- Draw overlays on image. IF (KEYWORD_SET (ov)) THEN $ smmcp_overlay, hdu, hdu_hk, xdim, ydim, xb, yb, wmin=dmin, wmax=dmax ;--- Annotate image. IF (KEYWORD_SET (annotate)) THEN $ fits_annotate_cp1, hdu, hdu_hk, xdim, ydim, xb, yb, wmin=dmin, wmax=dmax ;--- Create JPEG image [24 bits/pixel]. tvimg = TVRD () jpg_img = BYTARR (3, oxdim, oydim) jpg_img [0, *, *] = rtab [tvimg [*, *]] jpg_img [1, *, *] = gtab [tvimg [*, *]] jpg_img [2, *, *] = btab [tvimg [*, *]] ;--- Write displayed image as a JPG file. IF (KEYWORD_SET (ov)) THEN $ jpg_file = basename + '.ov.jpg' IF (KEYWORD_SET (annotate)) THEN $ jpg_file = basename + '.an.jpg' IF (KEYWORD_SET (annotate) AND KEYWORD_SET (ov)) THEN $ jpg_file = basename + '.oa.jpg' IF (NOT KEYWORD_SET (annotate) AND NOT KEYWORD_SET (ov)) THEN $ jpg_file = basename + '.im.jpg' WRITE_JPEG, jpg_file, jpg_img, true=1, quality=75 ; Write jpg file. PRINT, fits_name, ' ---> ', jpg_file ; --- Write GIF image. IF (KEYWORD_SET (gif)) THEN $ BEGIN IF (KEYWORD_SET (ov)) THEN $ gif_file = basename + '.ov.gif' IF (KEYWORD_SET (annotate)) THEN $ gif_file = basename + '.an.gif' IF (KEYWORD_SET (annotate) AND KEYWORD_SET (ov)) THEN $ gif_file = basename + '.oa.gif' IF (NOT KEYWORD_SET (annotate) AND NOT KEYWORD_SET (ov)) THEN $ gif_file = basename + '.im.gif' WRITE_GIF, gif_file, tvimg, rtab, gtab, btab PRINT, fits_name, ' ---> ', gif_file END END ;} END