;+ ; NAME: ; refgen ; PURPOSE: (one line only) ; Generate a source/catalog cross-reference list ; DESCRIPTION: ; CATEGORY: ; Astrometry ; CALLING SEQUENCE: ; refgen,astinfo,fnsrc,catfile,ref ; INPUTS: ; astinfo - Anonymous structure that contains an astrometric description ; of a image-based coordinate system and its mapping to the ; celestial sphere. (see mkastinfo for more information) ; fnsrc - Name of source file to read (generated by findsrc.pro) ; catfile - Name of catalog sub-file to read (generated by refnet.pro) ; OPTIONAL INPUT PARAMETERS: ; KEYWORD INPUT PARAMETERS: ; MAGLIM - Faint limit for the catalog. Don't use anything fainter than ; this limit. Default is 30. ; MAXERR - Maximum allowed error on the instrumental magnitude ; (default=1 mag) ; NOROTSCAN - Flag, if set will suppress searching for a correlation ; at small rotations from nominal if the initial offset ; calculation fails. ; OUTPUTS: ; ref - Anonymous structure with the cross-linked list (see rdref/wrref) ; KEYWORD OUTPUT PARAMETERS: ; COMMON BLOCKS: ; SIDE EFFECTS: ; RESTRICTIONS: ; PROCEDURE: ; MODIFICATION HISTORY: ; Written by Marc W. Buie, Southwest Research Institute, 2010/01/14 ; 2010/07/26, MWB, minor mod for new frmdxdy error codes ; 2012/04/30, MWB, added NOROTSCAN (mostly as a debugging aid), added MAGLIM ; 2012/05/01, MWB, added MAXERR keyword ;- pro refgen,fnimage,astinfo,fnsrc,catfile,ref, $ EXTENSION=extension,NOROTSCAN=norotscan,MAGLIM=maglim, $ MAXERR=maxerr,SIGMAX=sigmax self='refgen: ' if badpar(fnimage,7,0,caller=self+'(fnimage) ') then return if badpar(astinfo,8,1,caller=self+'(astinfo) ') then return if badpar(fnsrc,7,0,caller=self+'(fnsrc) ') then return if badpar(catfile,7,0,caller=self+'(catfile) ') then return if badpar(maglim,[0,2,3,4,5],0,caller=self+'(MAGLIM) ', $ default=30) then return if badpar(maxerr,[0,2,3,4,5],0,caller=self+'(MAXERR) ', $ default=1) then return if badpar(sigmax,[0,2,3,4,5],0,caller=self+'(SIGMAX) ', $ default=65000.0) then return if badpar(extension,[0,2,3],0,caller=self+'(EXTENSION) ', $ default=0) then return if badpar(norotscan,[0,1,2,3],0,caller=self+'(NOROTSCAN) ', $ default=0) then return if not exists(fnimage) then begin print,self,'Image ',fnimage,' not found.' return endif if not exists(fnsrc) then begin print,self,'Source file ',fnsrc,' not found.' return endif ; get the image if not exists(catfile) then begin print,self,'Source file ',catfile,' not found.' return endif image=readfits(fnimage,hdr,exten=extension,/silent) ; get the star measurements list=readfits(fnsrc,hdrsrc,/silent) nlist=n_elements(list)/6 xpos=reform(list[*,0],nlist) ypos=reform(list[*,1],nlist) fwhm=reform(list[*,2],nlist) mag =reform(list[*,3],nlist) err =reform(list[*,4],nlist) objrad=sxpar(hdrsrc,'OBJRAD') peaksig = reform(image[fix(xpos+0.5),fix(ypos+0.5)],nlist) z=where(err lt maxerr and peaksig lt sigmax and mag lt 40.0,count) xpos=xpos[z] ypos=ypos[z] fwhm=fwhm[z] mag=mag[z] err=err[z] peaksig=peaksig[z] nlist=count ; convert to xi/eta astxy2sn,xpos,ypos,astinfo,sxi,seta,/full,/arcsec ; get the catalog rdstarc,catfile,cra,cdec,dummy,smag,nfound z=where(smag lt maglim,count) if count ne 0 then begin cra=cra[z] cdec=cdec[z] smag=smag[z] nfound=count endif ; convert to xi/eta astrd2sn,cra,cdec,astinfo.raref,astinfo.decref,cxi,ceta,/arcsec frmdxdy,sxi,seta,cxi,ceta,xoff,yoff,xyerror ; ,nx=30,ny=30 print,' shf > ',xoff,yoff,xyerror angoff=0. rotxc=0. rotyc=0. if xyerror gt 0 and not norotscan then begin frmdxyr,sxi,seta,cxi,ceta,-1.0,1.0,.1,xoff,yoff,angoff,xyerror, $ tolerance=0.001,xout=newcxi,yout=newceta print,' shfr> ',xoff,yoff,angoff,xyerror endif else begin newcxi = cxi - xoff newceta = ceta - yoff endelse if xyerror eq 0 then begin ; srcor,sxi,seta,cxi-xoff,ceta-yoff,2.0,ind1,ind2,option=1 srcor,sxi,seta,newcxi,newceta,2.0,ind1,ind2,option=1 nstars=n_elements(ind1) if nstars eq 1 then nstars=0 endif else begin nstars=0L endelse ; Pack the data up for return if nstars eq 0 then begin ref = { objrad: objrad, nstars: nstars } endif else begin ref = { $ objrad: objrad, $ nstars: nstars, $ xpos: xpos[ind1], $ ypos: ypos[ind1], $ fwhm: fwhm[ind1], $ mag: mag[ind1], $ err: err[ind1], $ sig_max: peaksig[ind1], $ ra: cra[ind2], $ dec: cdec[ind2], $ catmag: smag[ind2] $ } endelse end