PRO HA_FLAT, wid, data ; This is a version of HALPHA_FLAT.PRO to be used with the ARCHIVE_TOOL.PRO ; ; INPUT: wid = Structure with widget IDs ; data = array with input data ;+ ; NAME: ; HALPHA_FLAT ; ; PURPOSE: ; This procedure centers H-alpha full disk images, applies the dark ; current and flat field, and subtracts the limb darkening function. ; ; CATEGORY: ; Data reduction of BBSO H-alpha full disk images. ; ; CALLING SEQUENCE: ; HALPHA_FLAT, dark_file, flat_file, limb_file, input_file ; [, OUT_DIR = out_dir, /NO_FITS, /JPG, /GIF, ; PURPOSE: ; This procedure centers H-alpha full disk images, applies the dark ; current and flat field, and subtracts the limb darkening function. ; ; INPUTS: ; wid: Structure of widget IDs ; data: Array with input data ; ; OUTPUTS: ; Writes the flat field corrected and limb darkening subtracted ; image as FITS, JPEG and/or GIF file of type integer to a directory. ; The filename of the ouput file is input_file + 'r.' + type ; (e.g.: input file 'hd35000.fts', output file 'hd35000ff.fts') ; ; KEYWORD PARAMETERS: ; OUT_DIR: Specify a directory where the data should go on output ; DEFAULT: working directory. ; SILENT: If set, no display of the corrected images and no ; information on progress, etc. ; CENTER: The center coordinates of the limb image is calculated ; rather than using the values given in the FITS header. ; NO_CLV: The limb darkening is not removed, i.e. the output is the ; dark current and flat field corrected input image. ; NO_FITS: Flat fielded files are NOT written as FITS files. ; JPG: Flat fielded files are written as JPG files. ; GIF: Flat fielded files are written as GIF files. ; ; MODIFICATION HISTORY: ; Written by: ; Carsten Denker, BBSO/NJIT, 6 December 1998 ; Modified by: ; Carsten Denker, BBSO/NJIT, 15 January 1999: Images are now saved ; as FITS images of type integer to allow feature tracking ; of very low contrast features. Also included better error ; handling. ; Michael Steinegger, BBSO/NJIT, 7 April 2000: Input files are ; FITS files rather than JPEG files. ; Correction for dark current included ; Michael Steinegger, BBSO/NJIT, 24 May 2000 ; Improved determination of disk center and radius ; ;- !QUIET = 1 ON_ERROR, 2 start = SYSTIME ( 1 ) ;----- check input data date = FIX( data ( 0 : 2 ) ) name = data( 3 : 6 ) dir = data( 7 : 11 ) FOR i = 0, 4 DO BEGIN l = STRLEN( dir( i ) ) IF STRMID( dir( i ), l - 1, 1 ) NE '/' THEN dir( i ) = dir( i ) + '/' ENDFOR dark_file = dir( 0 ) + name( 0 ) flat_file = dir( 1 ) + name( 1 ) limb_file = dir( 2 ) + name( 2 ) in_dir = dir( 3 ) out_dir = dir( 4 ) in_name = dir( 3 ) + name( 3 ) type = FIX( data( 12:14 ) ) IF type( 0 ) EQ 1 THEN no_fits = 0 ELSE no_fits = 1 IF type( 1 ) EQ 1 THEN jpg = 1 ELSE jpg = 0 IF type( 2 ) EQ 1 THEN gif = 1 ELSE gif = 0 ;----- date day = { CCYY: date( 0 ), MM: date( 1 ), DD: date( 2 ) } month = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', $ 'August', 'September', 'October', 'November', 'December' ] month = month( date( 1 ) - 1 ) WIDGET_CONTROL, wid.t1, /APPEND, SET_VALUE = $ [' Process data (correct DC, FF, limb) for '+$ month + ' ' + STRCOMPRESS( STRING( date( 2 ) ), /REMOVE_ALL) + ', ' + $ STRCOMPRESS( STRING( date( 0 ) ), /REMOVE_ALL), '' ] WIDGET_CONTROL, wid.d1, GET_VALUE = index WSET, index ERASE ;----- read images WIDGET_CONTROL, wid.t1, /APPEND, SET_VALUE = [ '', $ ' Read dark frame: ' + dark_file ] dark = READFITS ( dark_file, hdr_dark, /SILENT ) WIDGET_CONTROL, wid.t1, /APPEND, SET_VALUE = [ $ ' Read flat frame: ' + flat_file ] flat = READFITS ( flat_file, hdr_flat, /SILENT ) WIDGET_CONTROL, wid.t1, /APPEND, SET_VALUE = [ $ ' Read limb frame: ' + limb_file ] limb = READFITS ( limb_file, hdr_limb, /SILENT ) ;----- image size nx = SXPAR ( hdr_flat, 'NAXIS1' ) nx2 = nx / 2 ny = SXPAR ( hdr_flat, 'NAXIS2' ) ny2 = ny / 2 red = nx / 256. ;----- center, radius, intensity cenx = SXPAR ( hdr_limb, 'CENX' ) ceny = SXPAR ( hdr_limb, 'CENY' ) width = SXPAR ( hdr_limb, 'WIDT' ) maxc = SXPAR ( hdr_limb, 'MAXC' ) ;----- display of input images WSET, index WIDGET_CONTROL, wid.t1, /APPEND, SET_VALUE = [ '', $ ' Dark frame: ' + STRING( MIN( dark ) ) + ' ' + STRING( MAX( dark ) ) ] TVSCL, CONGRID( dark, nx / red, ny / red, /CUBIC ), 0 WIDGET_CONTROL, wid.t1, /APPEND, SET_VALUE = $ ' Flat frame: ' + STRING( MIN( flat ) ) + ' ' +STRING( MAX( flat ) ) TVSCL, CONGRID ( flat, nx / red, ny / red, /CUBIC ), 1 WIDGET_CONTROL, wid.t1, /APPEND, SET_VALUE = $ ' Limb image: ' + STRING( MIN( limb ) ) + ' ' + STRING( max( limb ) ) TVSCL, CONGRID( limb, nx / red, ny / red, /CUBIC ), 2 ;----- normalize flat field WIDGET_CONTROL, wid.t1, /APPEND, SET_VALUE = [ '', ' Normalize flat field.' ] mean_flat = MEDIAN ( flat ) index = WHERE ( flat LE 0, count ) IF count GT 0 THEN flat ( index ) = mean_flat flat = TEMPORARY ( flat ) / mean_flat ;----- center limb darkening image WIDGET_CONTROL, wid.t1, /APPEND, SET_VALUE = ['', ' Center limb image.' ] IF KEYWORD_SET ( center ) THEN BEGIN result = HALPHA_CENTER( limb, p ) cenx = result( 0 ) ceny = result( 1 ) width = result( 2 ) ENDIF disp_limb = [ nx2 - cenx, ny2 - ceny ] limb = SHIFT ( limb, disp_limb( 0 ), disp_limb( 1 ) ) WIDGET_CONTROL, wid.t1, /APPEND, SET_VALUE = $ ' Limb center: ' + STRING( cenx ) + ' ' + STRING( ceny ) + $ ' ' + STRING( width ) cenx = nx2 ceny = ny2 WIDGET_CONTROL, wid.t1, /APPEND, SET_VALUE = $ ' Limb center: ' + STRING( cenx ) + ' ' + STRING( ceny ) + $ ' ' + STRING( width ) ;----- disk center brightness int_l = MEDIAN( limb( cenx - 30 : cenx + 30, ceny - 30 : ceny + 30 ) ) ;----- normalize limb image limb = limb / FLOAT( int_l ) * 10000. ;----- get file names of images to be processed SPAWN, 'ls -1 ' + in_name, file pos = STRPOS( file, 'fts' ) wo = WHERE( pos NE -1 ) IF wo( 0 ) EQ -1 THEN BEGIN WIDGET_CONTROL, wid.t1, /APPEND, SET_VALUE = [ '', $ ' ERROR: NO FILES WITH THIS NAME ',$ ' ' + in_name, '', $ ' TERMINATED', ' ' ] WSET, index READ_JPEG, 'kso.jpg', img TV, img, TRUE = 1 RETURN ENDIF file = file( wo ) n = N_ELEMENTS( file ) WIDGET_CONTROL, wid.t1, /APPEND, SET_VALUE = [ '', $ ' Process ' + STRCOMPRESS( STRING( n ), /REMOVE_ALL ) + ' images' ] ;----- process n images FOR i = 0, n - 1 DO BEGIN input_file = file( i ) ;----- read image WIDGET_CONTROL, wid.t1, /APPEND, SET_VALUE = [ '', $ ' Read image: ' + input_file ] img = READFITS ( input_file, hdr_img, /SILENT ) ;----- display of input image TVSCL, CONGRID( img, nx / red, ny / red, /CUBIC ), 3 ;----- correct input image for DC img = ( img - dark ) > 0 ;----- correct input image for FF img = img / flat ;----- center DC and FF corrected image p = { nx: nx, ny:ny, xd:0, yd:0, xc:0, yc:0 } result = HALPHA_CENTER( img, p ) xc = result( 0 ) yc = result( 1 ) d = result( 2 ) disp_img = [ nx2 - xc, ny2 - yc ] img = SHIFT( img, disp_img( 0 ), disp_img( 1 ) ) WIDGET_CONTROL, wid.t1, /APPEND, SET_VALUE = $ ' Image center: ' + STRING( xc ) + ' ' + STRING( yc ) + $ ' ' + STRING( d ) xc = nx2 yc = ny2 WIDGET_CONTROL, wid.t1, /APPEND, SET_VALUE = $ ' Image center: ' + STRING( xc ) + ' ' + STRING( yc ) + $ ' ' + STRING( d ) ;----- disk center brightness int_i = MEDIAN( img( xc - 30 : xc + 30, yc - 30 : yc + 30 ) ) ;----- normalize input image img = img / FLOAT( int_i ) * 10000. ;----- remove bad parts at border img(0:15,*)=0 img(*,0:15)=0 img(*,ny-15:*)=0 img(nx-15:*,*)=0 ;----- Subtract limb darkening image res = img - limb ;----- display resulting images WIDGET_CONTROL, wid.t1, /APPEND, SET_VALUE = $ ' Corrected image: ' + STRING( MIN( img ) ) + ' ' + $ STRING ( MAX( img ) ) TVSCL, CONGRID( img, nx / red, ny / red, /CUBIC ), 4 TVCIRCLE, d / 2. / red, xc / red + nx / red, yc / red WIDGET_CONTROL, wid.t1, /APPEND, SET_VALUE = $ ' Enhanced image: ' +STRING( MIN( res ) ) + ' ' + $ STRING( MAX( res ) ) TVSCL, CONGRID( res, nx / red, ny / red, /CUBIC ), 5 TVCIRCLE, d / 2. / red, xc / red + nx / red * 2, yc / red ;----- convert data to integers IF MAX( res ) GT 32000. OR MAX( img ) GT 32000. THEN BEGIN WIDGET_CONTROL, wid.t1, /APPEND, SET_VALUE = [ '', $ 'ATTENTION: img: ' + ' ' + STRING( MIN( img ) ) + $ ' ' + STRING( MAX( img ) ), $ ' res: ' + ' ' + STRING( MIN( res ) ) + $ ' ' + STRING( MAX( res ) ) ] ENDIF img = FIX( ROUND( img ) ) res = FIX( ROUND( res ) ) ;----- output file name pos_dot = STRPOS( input_file, '.f' ) IF KEYWORD_SET( no_clv ) THEN BEGIN out_file = STRMID( input_file, 0, pos_dot ) + 'l.' ENDIF ELSE BEGIN out_file = STRMID( input_file, 0, pos_dot ) + 'r.' ENDELSE IF KEYWORD_SET( out_dir ) THEN BEGIN pos_slash = RSTRPOS( out_file, '/' ) IF pos_slash NE -1 THEN BEGIN l = STRLEN ( out_file ) out_file = STRMID( out_file, pos_slash + 1, l - pos_slash - 1 ) ENDIF pos_slash = RSTRPOS( out_dir, '/' ) l = STRLEN( out_dir ) IF pos_slash + 1 NE l THEN out_dir = out_dir + '/' out_file = out_dir + out_file ENDIF ;----- Write FITS image to directory IF NOT KEYWORD_SET( nofits ) THEN BEGIN WIDGET_CONTROL, wid.t1, /APPEND, SET_VALUE = $ ' Write FITS file: ' + out_file + 'fts' SXDELPAR, hdr_img, [ 'O_BZERO', 'O_BSCALE' ] SXADDPAR, hdr_img, 'ASP', FLOAT( d ) / d, ' Raw image aspect ratio' SXADDPAR, hdr_img, 'CENX', xc, ' Raw image disk center X' SXADDPAR, hdr_img, 'CENY', yc, ' Raw image disk center Y' SXADDPAR, hdr_img, 'MAXC', FIX( ROUND ( int_i ) ), ' Quiet Sun Max Brightness' SXADDPAR, hdr_img, 'WIDTH', ( d + d ) / 2., ' Width of disk (pixels)' IF KEYWORD_SET( no_clv ) THEN BEGIN WRITEFITS, out_file + 'fts', img, hdr_img ENDIF ELSE BEGIN WRITEFITS, out_file + 'fts', res, hdr_img ENDELSE ENDIF ;----- scale images IF KEYWORD_SET( jpg ) OR KEYWORD_SET( gif ) THEN BEGIN img = BYTSCL( img, MIN = 0, MAX = 12000 ) res = BYTSCL( res, -2000, 2000 ) ENDIF ;----- write JPEG images to directory IF KEYWORD_SET( jpg ) THEN BEGIN WIDGET_CONTROL, wid.t1, /APPEND, SET_VALUE = $ ' Write JPEG file: ' + out_file + 'jpg' IF KEYWORD_SET( no_clv ) THEN BEGIN WRITE_JPEG, out_file + 'jpg', img ENDIF ELSE BEGIN WRITE_JPEG, out_file + 'jpg', res ENDELSE ENDIF ;----- write GIF images to directory IF KEYWORD_SET( gif ) THEN BEGIN WIDGET_CONTROL, wid.t1, /APPEND, SET_VALUE = $ ' Write GIF file: ' + out_file + 'gif' IF KEYWORD_SET( no_clv ) THEN BEGIN WRITE_GIF, out_file + 'gif', img ENDIF ELSE BEGIN WRITE_GIF, out_file + 'gif', res ENDELSE ENDIF ENDFOR ;----- show the KSO image to indicate that we are done WIDGET_CONTROL, wid.d1, GET_VALUE = index WSET, index READ_JPEG, 'kso.jpg', img TV, img, TRUE = 1 ;----- how long did we have to wait? WIDGET_CONTROL, wid.t1, /APPEND, SET_VALUE=['',$ ' FINISHED CPU Time: '+STRCOMPRESS(STRING(SYSTIME(1)-start),/REMOVE_ALL),' '] RETURN END