pro align1img, index, data, xc, yc, nx, ny, ox0, oy0, outres, $ fast=fast, roll=roll, ref_img_xy=ref_img_xy, $ qcor=qcor, typout=typout, typ_in=typ_in, oy=oy, $ ref_image=ref_image, override=override, $ norm_fact=norm_fact, $ qdebug=qdebug, qstop=qstop, $ ffi_shift=ffi_shift ; ;+ ;NAME: ; align1img ;PURPOSE: ; To align a single image ;INPUT/OUTPUT: ; index ; data - The data will be changed by this routine. ;INPUT: ; xc - The X CCD address which should be the lower left corner ; of the output image ; yc - The Y CCD address which should be the lower left corner ; of the output image ; nx - The number of x pixels ; ny - The number of y pixels ; outres - The output resolution ; ref_img_xy - index structure of the reference image. ; or ; ffi_shift - Position sun center of an FFI on frame without altering ; roll. Measured in arcseconds relative to window center. ; E.g., for YLA level-3 images ffi_shift=[0,-120] i ; If ffi_shift(0) is positive suncenter is left of frame center. ; If ffi_shift(1) is positive suncenter is below frame center. ;OPTIONAL KEYWORD INPUT: ; fast - If set, then perform the registration in "FAST" mode which ; is simple full pixel shifts instead of POLY2D. ; qcor - Set if corrections were enabled for this data ; typ_in - The data type of the input ; typout - The data type of the output ; override- If set, pass to MOD_RES and override the protection against ; changing the resolution on a byte type image. ; norm_fact - If set to 1, then do not normalize the signal level ; for the number of pixels binned/spread. ; The default is to divide by the number of pixels that ; the charge is being spread into. ; For example, when going from HR to FR the signal is ; from one pixel is spread into 4 pixels. The default ; is to divide the signal by 4. /NORM_FACTOR will ; leave the signal as is. ; If set to 2, then normalize by the sqrt(# pixels ; the charge is spread into. For the example above, ; divide the signal by 2. This is used for the handling ; the uncertainty arrays. ; ;OPTIONAL KEYWORD OUTPUT: ; oy - ;HISTORY: ; Written 16-Aug-93 by M.Morrison (breaking up ALIGN_PFI) ; 16-Sep-93 (MDM) - Added NORM_FACT option for MOD_RES ; 18-Nov-93 (MDM) - Minor mod ; - Added FIX statement to SXT_SUBIMG3 call ; ext_subimg3(index, data, fri=fix([xc,yc]), ...) ;V1.01 19-Nov-93 (MDM) - Corrected logging of ARCSEC_SHIFT. It was not ; logging the arceseconds properly for HR and QR cases ;V1.02 24-Nov-93 (MDM) - Corrected error with OR assembly. The problem was ; with EXT_SUBIMG3. Added the /TRIM option to the ; EXT_SUBIMG3 call ;V2.00 4-Jan-94 (MDM) - Added ROLL keyword option ; - Incorporated the shift correction of the optical images to ; be aligned with the x-ray images ;V2.01 22-Feb-94 (MDM) - Added FAST option ;V2.02 14-Nov-94 (MDM) - Corrected error which was resulting in no POLY2D sub-pixel ; adjustment being performed if "xoffset" or "yoffset" was ; zero (conditional used AND instead of OR). The number ; of cases where this would have caused an error is probably ; none because of the resolution of the pointing. ;V2.10 20-Nov-98 (DMcK)- Adjusted definition of ox0,oy0 by replacing ; "fix" with "round". Results in more consistent ; output for different values of nx,ny (which come ; from OUTSIZE optional input of SXT_PREP). ;V2.20 19-Nov-08 (LWA) - Force index.his.sun_center to agree with sxt_cen of ref_image. ; 18-Apr-11 (LWA) - Made history records consistent with use of ffi_shift. ; Fixed crash when /qdebug and not do_sunc. ;- ; progverno = 2.200*1000 qdebug=keyword_set(qdebug) if exist(outres) then do_sunc=1 else do_sunc=0 ;To prevent doing this when align1img called in get_leak_image. if (n_elements(qcor) eq 0) then qcor = 1 if (n_elements(typ_in) eq 0) then typ_in = -99 ; ;Note: Keyword ref_image=ref_image isn't included in the sxt_prep call of this routine. ; However, it is used in the get_leak_image call of if (keyword_set(ref_image)) then begin xc = gt_corner(ref_image, /x) yc = gt_corner(ref_image, /y) nx = gt_shape(ref_image, /x) ny = gt_shape(ref_image, /y) outres = gt_res(ref_image) end ;if exist(ffi_shift) then begin ; print,'FFI_SHIFT EXISTS.' ; HELP,do_sunc,ref_img_xy ;endif else begin ; print,'FFI_SHIFT DOES NOT EXIST' ; HELP,do_sunc,ref_img_xy ;endelse ; res0 = gt_res(index) pixout = 2.^outres ;1,2 or 4 if qdebug then help,index,data,pixout ; f1 = gt_shape(index, /x, /fr) / (nx*pixout) ;ratio of input image size to output image size in FR pixels f2 = gt_shape(index, /y, /fr) / (ny*pixout) ; if ((f1 ge 1.8) or (f2 ge 1.8)) then begin ;input image is larger than twice the size of the output ;so extract a sub-portion first if qdebug then print, 'ALIGN1IMG: Extracting a subportion of image: '+fmt_tim(index) margin = 1 factor = 2.^outres / 2.^gt_res(index) ;pass in HR, outres is FR means 1/2 as many pixels extracted data = ext_subimg3(index, data, fri=fix([xc,yc]), nx=nx*factor+margin*2, ny=ny*factor+margin*2, $ margin=margin, /update_index, /trim, qdebug=qdebug) if (keyword_set(qstop)) then stop end if (res0 ne outres) then begin ;change resolution if ((qcor eq 0) and (typ_in eq 1)) then begin message, 'WARNING - Changing the resolution (and therefore the signal level) ', /info message, ' and /NOCORRECTIONS was set and DATA is BYTE type - should be decompressed?', /info end if qdebug then print, 'Changing the resolution for image: ' + fmt_tim(index) data = mod_res(index, data, outres=outres, /update_index, override=override, norm_fact=norm_fact) if (keyword_set(qstop)) then stop end ; nx_in = gt_shape(index, /x) ny_in = gt_shape(index, /y) ; ;----- ix,iy and ox,oy pixel units are in the same resolution below (the output resolution) ; x00 = gt_corner(index, /x) ;original corner address of PFI y00 = gt_corner(index, /y) off = 0 if (keyword_set(fast)) then off=0.5 ;MDM added 22-Feb-94 if qdebug then print,'x00, y00, off =',x00, y00, off oy0 = round((y00-yc)/pixout + off) ;Redefined by DMcK 20-nov-98 ox0 = round((x00-xc)/pixout + off) ox1 = ox0 + nx_in-1 oy1 = oy0 + ny_in-1 xoffset = ((x00-xc)/pixout-ox0) ;should be less than 1 pixel yoffset = ((y00-yc)/pixout-oy0) if (keyword_set(fast)) then begin ;MDM added 22-Feb-94 xoffset = 0 ;do not do POLY_2D sub-pixel shift yoffset = 0 end if qdebug then help,data ;----- perform the sub-pixel shift before "trimming" the image because of the edge pixel effect. if ((xoffset ne 0) or (yoffset ne 0)) then begin data = poly_2d(temporary(data),[-xoffset,0,1,0],[-yoffset,1,0,0],1) endif ;----- perform the roll adjustment ;Note: Keyword roll=roll isn't included in the sxt_prep or get_leak_image calls of this routine! if (keyword_set(roll)) then begin xpiv = -gt_corner(index, /from_sc, /x) ;invert the sign ypiv = -gt_corner(index, /from_sc, /y) data = rot(data, -roll, 1, xpiv, ypiv, missing=0, /pivot) end ;----- insert it where it belongs ix0 = 0 & ix1 = nx_in-1 ;pixels to be used from the INPUT image iy0 = 0 & iy1 = ny_in-1 qtrim = 0 if (ox0 lt 0) then begin & ix0 = abs(ox0) & ox0 = 0 & qtrim = 1 & end ;input image falls outside on the left if (oy0 lt 0) then begin & iy0 = abs(oy0) & oy0 = 0 & qtrim = 1 & end ;input image falls outside on the bottom if (ox1 ge nx) then begin& ix1 = (nx_in-1)-(ox1-nx+1) & qtrim = 1 & end ;input image falls outside on the right if (oy1 ge ny) then begin& iy1 = (ny_in-1)-(oy1-ny+1) & qtrim = 1 & end ;input image falls outside on the top qtrim = (qtrim or (ix1 gt (nx_in-1)) or (iy1 gt (ny_in-1))) ;added 25-Aug-93 ix1 = ix1 < (nx_in-1) iy1 = iy1 < (ny_in-1) oy = [oy0, oy1] ;MDM 12-Aug-93 if qdebug then help,qtrim if ((iy0 ge ny_in) or (ix0 ge nx_in) or (ix1 lt 0) or (iy1 lt 0)) then begin print, 'Image ', fmt_tim(index), ' falls outside of the declared window' data = 0 end else begin if (qtrim eq 1) then data = data(ix0:ix1, iy0:iy1) end if qdebug then help,data if qdebug then print,'(nx-1-ox1) = ',nx-1-ox1 if qdebug then print,'(ny-1-oy1) = ',ny-1-oy1 if qdebug then print, 'ix0,ix1,iy0,iy1 = ',ix0,ix1,iy0,iy1 if qdebug then print, 'ox0,ox1,oy0,oy1 = ',ox0,ox1,oy0,oy1 if qdebug then print, 'xoffset,yoffset = ',xoffset, yoffset if qdebug then print, 'nx, ny = ',nx,ny if qdebug then print,'gt_pix_size(index) = ',gt_pix_size(index) if qdebug then print,'gt_pix_size(gt_res(index,/orig)) =',gt_pix_size(gt_res(index,/original)) ;if do_sunc and (exist(ref_img_xy) or exist(ffi_shift)) then begin case 1 of ;18-Apr-2011, LWA do_sunc and exist(ref_img_xy) : begin sunc = sxt_cen(ref_img_xy) ish = sxt_cen(index,roll=roll) ash = (sunc-ish)*gt_pix_size(index) his_index, index, 0, 'sun_center', [sunc, roll] his_index, index, 0, 'arcsec_shift', ash his_index, index, 0, 'corner_sav', gt_corner(ref_img_xy) end do_sunc and exist(ffi_shift) : begin sunc0=[514.,513.] sunc=sunc0-(ffi_shift/gt_pix_size(0)) roll=0.0 ish = sxt_cen(index) ash = (sunc-ish)*gt_pix_size(index) his_index, index, 0, 'sun_center', [sunc, roll] his_index, index, 0, 'arcsec_shift', ash his_index, index, 0, 'corner_sav',[1.5,0.5] end else : begin ;endif else begin case 1 of ox0 lt ix0 : tx=ix0 ox0 gt ix0 : tx=nx-1-ox1 else : tx=0 endcase case 1 of oy0 lt iy0 : ty=iy0 oy0 gt iy0 : ty=ny-1-oy1 else : ty=0 endcase xyoff= [xoffset,yoffset]*gt_pix_size(index) txy = [tx,ty]*gt_pix_size(index) ash = (xyoff-txy) his_index, index, 0, 'arcsec_shift', ash his_index, index, 0, 'corner_sav', [xc, yc] att=sxt_cen(index,roll=roll) xyoff_fr=ash/gt_pix_size() xyout=[att(0)+xyoff_fr(0), att(1)+xyoff_fr(1)] his_index, index, 0, 'sun_center', [xyout, roll] end endcase ;endelse his_index, index, 0, 'q_registered', progverno index.sxt.shape_sav = [nx, ny] if do_sunc and qdebug then print,'sunc, ish, roll =',sunc(0),sunc(1),ish(0),ish(1),roll if qdebug then print,'index.his.arcsec_shift = ',index.his.arcsec_shift if qdebug then print,'sxtcen(index) = ',sxt_cen(index) if qdebug then print,'index.his.sun_center in align1img_dev= ',index.his.sun_center if qdebug then print,'*****************' ;Note: Keyword roll=roll isn't included in the sxt_prep or get_leak_image calls of this routine! ;if (keyword_set(roll)) then his_index, index, 0, 'q_roll_corr', progverno ;MDM added 4-Jan-94 if (keyword_set(qstop)) then stop return end