function mask_bright_stars,run,field,filterno,doplot=doplot,rerun=rerun,npix=npix if n_elements(rerun) eq 0 then rerun=315 maskfile = getenv('COADD_DATA_ROOT')+'/Masking/bright_star_mask.fits' astrfile = string(format='("asTrans-",i6.6,".fit")',run) ;astrfile = getenv('COADD_DATA_ROOT')+'/'+string(rerun,format='(I0)')+'/Scripts/'+astrfile astrfile = getenv('COADD_DATA_ROOT')+'/'+String(rerun,format='(I0)')+'/'+$ string(run,format='(I0)')+'/astrom/'+astrfile bright = mrdfits(maskfile,1) openw,1,'current run' printf,1,'*********************' printf,1,'MASKING RUN ',string(run,format='(I0)') printf,1,'*********************' close,1 ;Note that Chris actually puts a bunch of the key information in the ;header of the zeroth extension of the coadd astrans file. astr = mrdfits(astrfile,filterno) astr0 = mrdfits(astrfile,0,hdr0) node = sxpar(hdr0,'NODE') incl = sxpar(hdr0,'INCL') ;Note that 'filter' is assumed to be unit-indexed astr = astr(field-1) astr = jjadd_tag(astr,'NODE',node) astr = jjadd_tag(astr,'INCL',incl) ;There are many, many bright stars in here, and it behooves us to trim ;the bsc down astrom_xyad,astr,1000,1000,ra=ra,dec=dec dist = sqrt((bright.ra-ra)^2+(bright.dec-dec)^2) ind = where(dist lt 1.,ct) if ct gt 0 then begin bright = bright[ind] coaddpoly = astr2poly(astr,naxis1=2455,naxis2=2101) brightpoly = construct_polygon(ncaps=1,nelem=n_elements(bright)) nbright = n_elements(bright) for i = 0L,nbright-1 do begin (*brightpoly[i].caps).x = bright[i].xcaps (*brightpoly[i].caps).cm = bright[i].cmcaps brightpoly[i].use_caps=1 brightpoly[i].ncaps=1 brightpoly[i].weight=1. brightpoly[i].str = bright[i].str endfor if keyword_set(doplot) then balkan_plot,[coaddpoly,brightpoly] ;If we try to find the intersection of all of these polygons at once, ;the code will sometimes crash. This appears to be associated with ;cases where one of the star polygons is completely contained within ;another (doughnuts?). I'll avoid this by masking out the intersection ;of each star with each image one at a time. ;Note that this is less efficient, but mask failures cause segfaults, ;which are not recoverable. for i = 0,n_elements(brightpoly)-1 do begin masked_region = intersect(coaddpoly,brightpoly[i]) if size(masked_region,/type) eq 8 then begin col = findgen(2455) # replicate(1,2101) row = findgen(2101) ## replicate(1,2455) astrom_xyad,astr,col,row,ra=ra,dec=dec ret = is_in_window(ra=ra,dec=dec,masked_region) mask = reform(ret,2455,2101) mask = float(mask eq 0) npix = total(mask eq 0) endif else begin mask = replicate(1.,2455,2101) npix = 0 endelse if n_elements(globalmask) eq 0 then globalmask = mask else $ globalmask = globalmask AND mask endfor endif else begin globalmask = replicate(1.,2455,2101) npix = 0 endelse return,globalmask end