parameter ibuf string=name snointer !snointer==0 : mark coordinates, auto mask, interactive mask ! 1 : mark coordinates, auto mask, but not interactive mask ! 2 : mark coordinates, interactive mask only (?) ! 3 : auto mask only, no display if snointer==3 goto maskit2 end_if ! Display unmask clip $ibuf min=lowbad max=highbad maskonly daosky $ibuf mask !mn $ibuf pix=9 silent tv $ibuf l=max[15.,5+2.*sky] z=-5 ! Do this mark just to get the initial markstar text out of the way mark new exit ! Mark reference stars err goto gettemp ! If we have a file already, we are done. Recentroid in case pos file was rough get coo=pos/{name} sr=0 sc=0 mark auto exit save coo=pos/{name} sr=0 sc=0 goto maskit ! Otherwise try out the last marked positions gettemp: err goto markit get coo=pos/last sr=0 sc=0 open incoo pos/last.coo read incoo read incoo read incoo read incoo r0=@incoo.3 c0=@incoo.2 close incoo box 1 n=20 cr=r0 cc=c0 tvbox box=1 color=2 printf 'If the displayed positions are OK, hit E in display to use them' printf 'If the positions are OK, but offset, hit the 1 key on the star' printf ' corresponding to the green box, then E to exit' printf 'To start with a new set of stars, hit Q in the display window,' printf ' then E to exit' r1=0 c1=0 mark auto if r1>0 get coo=pos/last sr=0 sc=0 clear vec mark auto dr=r1-r0 dc=c1-c0 printf 'If the displayed positions are OK, hit E in display to use them' printf 'To start with a new set of stars, hit Q in the display window,' printf ' then E to exit' end_if err goto markit save coo=pos/{name} sr=0 sc=0 goto maskit markit: clear vec printf 'Hit several stars using C in display window, E to exit' mark new save coo=pos/{name} sr=0 sc=0 maskit: save coo=pos/last sr=0 sc=0 maskit2: ! Get old mask if it exists. If it doesn't put a unmasked image in buffer 102 create 102 nr=nr[ibuf] sr=sr[ibuf] nc=nc[ibuf] sc=sc[ibuf] const=1 unmask err goto instmask get mask=msk/{name} masktoim 102 nr=nr[ibuf] sr=sr[ibuf] nc=nc[ibuf] sc=sc[ibuf] ! Add mask for instrument instmask: ! If wfpc, then add mask from data quality file if wfpc==1 printf '{name}' >./tmp.dat $'rm' tmp.out $awk '\{print substr($1,2,8), substr($1,10,1)\}' tmp.dat >./tmp.out open tmp ./tmp.out string rname {tmp} rchip=@tmp.2 close tmp rd 201 archive/u{rname}_c1f nim=rchip ! dont mask fixable warm pixels clip 201 max=1000 vmax=0 ! dont mask calibration file defect-set (too many!) copy 202 201 clip 202 min=1.9 vmin=0 clip 202 max=2.1 vmax=0 sub 201 202 ! mask out all others clip 201 max=0.5 maskonly ! Now select out saturated pixels (mask=8) and set them to a large number in ! data file, set all other bad pixels to a small number to make sure they ! arent counted as saturated pixels (and get circular masks around them ! as a result) copy 202 201 ! 202 will have saturated pixels only set to 32767 ! 203 will have mask of unsaturated pixels clip 202 max=9 vmax=0 min=7 vmin=0 div 202 202 copy 203 202 sub 203 c=1 mul 203 c=-1 mul 202 c=32767 mul $ibuf 203 add $ibuf 202 ! Now set 203 to have all other bad pixels set to -100 ! 202 to have mask of all other pixels mul 203 201 div 203 203 copy 202 203 sub 202 c=1 mul 202 c=-1 mul 203 c=-100 mul $ibuf 202 add $ibuf 203 end_if if snointer==2 mul $ibuf 102 tv $ibuf l=max[15.,5+2.*sky] z=-5 goto nextbox end_if err continue get mask=/usr/tmp/blank ! Mask around saturated stars with circular mask clip $ibuf maskonly max=maxbad rad=ps ! Mask other bad pixels as single pixels clip $ibuf maskonly min=lowbad masktoim 101 nr=nr[ibuf] sr=sr[ibuf] nc=nc[ibuf] sc=sc[ibuf] ! Add old mask into current mask mul 101 102 clip 102 min=0.5 maskonly ! Multiply by mask mul $ibuf 101 ! Display if snointer<3 tv $ibuf l=max[15.,5+2.*sky] z=-5 end_if if snointer==1|snointer==3 goto moveon end_if nextbox: printf 'Mark rectangular regions (in display window) to mask (E to quit)' aedit $ibuf mask int printf 'Mark circular regions (in display window) to mask (E to quit)' aedit $ibuf circ mask int printf 'Mark polygon regions (in display window) to mask (E to quit)' err goto moveon mpoly: markpoly 1 clip $ibuf poly=1 max=-1e10 maskonly goto mpoly moveon: ! Multiply by mask masktoim 101 nr=nr[ibuf] sr=sr[ibuf] nc=nc[ibuf] sc=sc[ibuf] mul $ibuf 101 ! Display if snointer~=3 tv $ibuf l=max[15.,5+2.*sky] z=-5 end_if ! Save mask $mkdir msk save mask=msk/{name} printf 'Add to mask if desired and save in ./{name}' end