;---------------------------------------------------------------------- ; NAME: ; sub_image2 ; PURPOSE: ; Subtract the chop and nod images in an chop/nod set from the ; source image. ; ; EXPLANATION: ; Subtracts chop and nod images from the source image if chop ; and nod images have been taken. If the images do not contain ; either the chop or nod set then only the sets that are present ; will be subtracted. If the bad_pixel mask is sent ; as an argument, all of the bad pixels are set to zero. ; ; CALLING SEQUENCE: ; sub_image, 'inputfile','outputfile' [,'badpixelmap'] ; INPUTS: ; imageName - name of the input fits image (full path name ; excepted). ; filename - name of the output file name. The output file name ; will be given the prefix 'd' meaning a ; 'differenced' file. ; ; ; OPTIONAL INPUTS: ; badPix - name of bad pixel map. Good pixels in the map should ; have a value of one. Bad pixels in the map should ; have a value of zero. ; ; OPTIONAL INPUT KEYWORDS: ; ; OPTIONAL OUTPUTS: ; ; NOTES: ; PROCEDURE CALLS: ; ; ; REVISION HISTORY: ;------------------------------------------------------------------------- PRO sub_image2, imageName, filename, badpix image_name = filename ;read the data data = READFITS(image_name, header, EXTEN_NO=0) data2 = READFITS(image_name, EXTEN_NO=1) data3 = READFITS(image_name, EXTEN_NO=2) data4 = READFITS(image_name, EXTEN_NO=3) ;perform the differencing if a chop or nod image exists. IF data2[0] ne -1 THEN BEGIN data = data - data2 history = 'Second image in a chop or nod set was subtracted: A-B' sxaddhist, history, header ENDIF ;perform the differencing if chop and nod images exist. IF data4[0] ne -1 THEN BEGIN data = data - data3 + data4 history = 'Full chop and nod images subtracted: (A-B)-(C-D)' sxaddhist, history, header ENDIF ; if a bad pixel map is supplied, multiply by the bad pixel ; map to make the bad pixels zero, and update the fits header. IF N_PARAMS() EQ 3 THEN BEGIN badMap = readfits(badPix) data = data * badMap history = 'Multiplied by a bad pixel map (BPM).' sxaddhist, history, header history = 'BPM = ' + badPix sxaddhist, history, header ENDIF ;save the new image with the 'd'suffix added to the image name imageName = 'd' + imageName writefits, imageName, data, header end