Changeset 41716 for trunk/tools/eam/teleff/cammask.pro
- Timestamp:
- Jul 13, 2021, 10:31:53 AM (5 years ago)
- File:
-
- 1 edited
-
trunk/tools/eam/teleff/cammask.pro (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/eam/teleff/cammask.pro
r41712 r41716 8 8 if (not($?MATCH_RADIUS)) set MATCH_RADIUS = 2.0 9 9 10 macro get.camera.matches 11 if ($0 != 5) 12 echo "USAGE: get.camera.matches (smfreal) (refsrcs.fits) (outroot) (outversion)" 13 break 14 end 15 16 local i refsrcs 17 $smfreal = $1 18 $refsrcs = $2 19 $outroot = $3 20 $OUTVERSION = $4 21 22 dirname $outroot -var OUTDIR 23 mkdir $OUTDIR 24 25 # load the reference source table 26 # NOTE: Mref is chosen to match filter for this exposure 27 data $refsrcs; read -fits DATA Rref Dref Mref 28 set Nref = ramp(Rref) 29 30 # read in the PHU header 31 rd PHU $smfreal 32 33 # create the chipName list from the smffile and calculate the index numbers 34 list chipsRaw -x "ftable -list $smfreal | grep -n hdr | prcol 1 | sed s/.hdr//" 35 for i 0 $chipsRaw:n 36 list word -splitbychar : $chipsRaw:$i 37 $chipNseq:$i = $word:0 - 3 38 $chipName:$i = $word:1 39 end 40 $chipName:n = $chipsRaw:n 41 $chipNseq:n = $chipsRaw:n 42 43 # find matching entries in smf file 44 for i 0 $chipName:n 45 echo $chipName:$i 46 get.chip.detect.stats $chipName:$i $chipNseq:$i 47 # if we do not have masks, we have not measured Q1refSS, just set to 1.0 48 set Q1refSS = zero(RrefSS) + 1.0 49 50 sprintf output "%s.%s.%s.cam.stf" $outroot $chipName:$i $OUTVERSION 51 write -fits DATA $output RrefSS DrefSS MrefSS XrefSS YrefSS Q1refSS X_PSF_found Y_PSF_found M_PSF_found RA_PSF_found DEC_PSF_found Q1_PSF_found Q2_PSF_found 52 end 53 end 10 $SMF_FIELDS = X_PSF Y_PSF RA_PSF DEC_PSF CAL_PSF_MAG PSF_QF PSF_QF_PERFECT 11 $REF_FIELDS = Rref Dref Mref 12 $XTR_FIELDS = Xref Yref Nref Q1ref 54 13 55 14 macro get.camera.eff … … 87 46 # load the reference source table 88 47 # NOTE: Mref is chosen to match filter for this exposure 89 data $refsrcs; read -fits DATA Rref Dref Mref48 data $refsrcs; read -fits DATA $REF_FIELDS 90 49 set Nref = ramp(Rref) 91 50 … … 93 52 rd PHU $smfreal 94 53 95 # create the chipName list from the smffile and calculate the index numbers 96 # if a chip is missing from the smf, this may be inconsistent with chipMask:n 54 # create the chipName list from the smffile and calculate the index numbers. 55 # NOTE: if a chip is missing from the smf, this may be inconsistent with chipMask:n 56 # XXX for now, we fail is this happens 97 57 list chipsRaw -x "ftable -list $smfreal | grep -n hdr | prcol 1 | sed s/.hdr//" 98 58 for i 0 $chipsRaw:n 99 59 list word -splitbychar : $chipsRaw:$i 100 60 $chipNseq:$i = $word:0 - 3; # this number depends on the number of leading tables 101 $chipName:$i = $word:1 61 if ("$chipName:$i" != "$word:1") 62 echo "ERROR: missing chip from smffile: " $chipName:$i 63 break 64 end 102 65 end 103 66 … … 107 70 get.chip.mask.stats $camMask:$i 108 71 109 sprintf output "%s/%s.%s.%s.cam.stf" $OUTDIR $expname $chipName:$i $OUTVERSION 110 write -fits DATA $output RrefSS DrefSS MrefSS XrefSS YrefSS Q1refSS X_PSF_found Y_PSF_found M_PSF_found Q1_PSF_found Q2_PSF_found 111 end 112 end 113 114 macro get.chip.mask.stats 115 if ($0 != 2) 116 echo "USAGE: get.chip.mask.stats (cammask)" 117 echo " assumes existence of $smfreal vectors (Rref, Dref, Mref) and buffer (PHU)" 118 break 119 end 120 121 local cammask camreal 122 $cammask = $1 123 124 $camreal = `neb-locate -p $cammask` 125 rd -x 0 mk $camreal 126 127 # I have a mask file, now I need to calculate something equiv to psfQf 128 set mkPerfect = (mk == 0) ? zero(mk) + 1 : zero(mk) 129 130 # I want to set an image based on the bit values but I fear 131 # the mask has been converted to a float when read 132 forcedphot mkPerfect XrefSS YrefSS -output Q1refSS 133 134 subset tmp = Q1refSS where (Q1refSS > 0.85) 135 136 echo tmp[] of Q1refSS[] are unmasked 137 end 72 foreach field SMF_FIELDS 73 concat $field\_found $field\_out 74 delete $field\_found 75 end 76 foreach field REF_FIELDS $XTR_FIELDS 77 concat $field\_onchp $field\_out 78 delete $field\_onchp 79 end 80 end 81 82 $OUT_FIELDS = 83 foreach field $SMP_FIELDS $REF_FIELDS $XTR_FIELDS 84 $OUT_FIELDS = $OUT_FIELDS $field\_out 85 end 86 87 sprintf output "%s/%s.%s.%s.cam.stf" $OUTDIR $expname $chipName:$i $OUTVERSION 88 write -fits DATA $output $OUT_FIELDS 89 end 90 91 # We can read the data by EXTNAME or sequence number. Reading by 92 # EXTNAME is more robust against format changes but slow 93 $USE_EXTNAME = 0 138 94 139 95 macro get.chip.detect.stats … … 147 103 end 148 104 149 local chipname chipnseq 105 local chipname chipnseq field NAXIS1 NAXIS2 150 106 $chipname = $1 151 107 $chipnseq = $2 … … 153 109 # read in the CHIP header 154 110 155 # sprintf extname "%s.hdr" $chipname 156 # rd -n $extname hdr $smfreal 157 158 rd -x $chipnseq hdr $smfreal 111 if ($USE_EXTNAME) 112 sprintf extname "%s.hdr" $chipname 113 rd -n $extname hdr $smfreal 114 else 115 rd -x $chipnseq hdr $smfreal 116 end 159 117 160 118 keyword hdr NAXIS1 NAXIS1 … … 169 127 # do we need to grow the range at all? 170 128 set keep = (Rref >= $minR) && (Rref <= $maxR) && (Dref >= $minD) && (Dref <= $maxD) 171 subset RrefS = Rref if keep172 subset DrefS = Drefif keep173 subset MrefS = Mref if keep129 foreach field $REF_FIELDS Nref 130 subset $field\_tmp = $field if keep 131 end 174 132 175 133 # convert the subset coordinates to pixels 176 set Xref S = RrefS177 set Yref S = DrefS178 coords -q hdr -mosaic PHU -c Xref S YrefS134 set Xref_tmp = Rref_tmp 135 set Yref_tmp = Dref_tmp 136 coords -q hdr -mosaic PHU -c Xref_tmp Yref_tmp 179 137 180 138 # generate a subset of sources which are within the boundaries of the chip 181 set keep = (XrefS >= 0) && (XrefS <= $NAXIS1) && (YrefS >= 0) && (YrefS <= $NAXIS2) 182 subset XrefSS = XrefS if keep 183 subset YrefSS = YrefS if keep 184 subset RrefSS = RrefS if keep 185 subset DrefSS = DrefS if keep 186 subset MrefSS = MrefS if keep 139 set keep = (Xref_tmp >= 0) && (Xref_tmp <= $NAXIS1) && (Yref_tmp >= 0) && (Yref_tmp <= $NAXIS2) 140 foreach field $REF_FIELDS Nref Xref Yref 141 subset $field\_onchp = $field\_tmp if keep 142 delete $field\_tmp 143 end 187 144 188 145 # now read the smf detections 189 146 data $smfreal 190 #sprintf extname "%s.psf" $chipname 191 #read -fits $extname X_PSF Y_PSF RA_PSF DEC_PSF CAL_PSF_MAG PSF_QF PSF_QF_PERFECT 192 193 read -fits {$chipnseq+1} -extnum X_PSF Y_PSF RA_PSF DEC_PSF CAL_PSF_MAG PSF_QF PSF_QF_PERFECT 194 195 ## XXX note this is not very efficient because libfits needs to loop over all extensions 196 ## each time until it finds the one it wants (would be better to generate an index and 197 ## use -fits NN -extnum 147 148 if ($USE_EXTNAME) 149 sprintf extname "%s.psf" $chipname 150 read -fits $extname $SMF_FIELDS 151 else 152 read -fits {$chipnseq+1} -extnum $SMF_FIELDS 153 end 198 154 199 155 # match radius currently needs to be larger for MPC objects 200 match2d XrefSS YrefSS X_PSF Y_PSF $MATCH_RADIUS -closest 201 202 reindex X_PSF_found = X_PSF using index1 -keep-unmatched 203 reindex Y_PSF_found = Y_PSF using index1 -keep-unmatched 204 reindex M_PSF_found = CAL_PSF_MAG using index1 -keep-unmatched 205 reindex Q1_PSF_found = PSF_QF using index1 -keep-unmatched 206 reindex Q2_PSF_found = PSF_QF_PERFECT using index1 -keep-unmatched 207 reindex RA_PSF_found = RA_PSF using index1 -keep-unmatched 208 reindex DEC_PSF_found = DEC_PSF using index1 -keep-unmatched 209 210 # set dX = XrefSS - X_PSF_found; subset dXs = dX where (MrefSS < 18); vstat -q dXs 211 # set dY = YrefSS - Y_PSF_found; subset dYs = dY where (MrefSS < 18); vstat -q dYs 212 # set dM = MrefSS - M_PSF_found; subset dMs = dM where (MrefSS < 18); vstat -q dMs 213 214 # measure some stats, eg: 215 # * fraction detected vs mag, filter by PSF_QF, PSF_QF_PERFECT 216 end 217 156 match2d Xref_onchp Yref_onchp X_PSF Y_PSF $MATCH_RADIUS -closest 157 foreach field $SMF_FIELDS 158 reindex $field\_found = $field using index1 -keep-unmatched 159 end 160 end 161 162 macro get.chip.mask.stats 163 if ($0 != 2) 164 echo "USAGE: get.chip.mask.stats (cammask)" 165 echo " assumes existence of source chip positions (Xref_onchp, Yref_onchp)" 166 break 167 end 168 169 local cammask camreal 170 $cammask = $1 171 172 $camreal = `neb-locate -p $cammask` 173 rd -x 0 mk $camreal 174 175 # I have a mask file, now I need to calculate something equiv to psfQf 176 set mkPerfect = (mk == 0) ? zero(mk) + 1 : zero(mk) 177 178 # I want to set an image based on the bit values but I fear 179 # the mask has been converted to a float when read 180 forcedphot mkPerfect Xref_onchp Yref_onchp -output Q1ref_onchp 181 end 182 183 ### utilities 218 184 macro init.radec.range 219 185 $minR = $RA … … 341 307 book delete mybook 342 308 end 309 310 311 #### 312 313 macro get.camera.matches 314 if ($0 != 5) 315 echo "USAGE: get.camera.matches (smfreal) (refsrcs.fits) (outroot) (outversion)" 316 break 317 end 318 319 local i refsrcs 320 $smfreal = $1 321 $refsrcs = $2 322 $outroot = $3 323 $OUTVERSION = $4 324 325 dirname $outroot -var OUTDIR 326 mkdir $OUTDIR 327 328 # load the reference source table 329 # NOTE: Mref is chosen to match filter for this exposure 330 data $refsrcs; read -fits DATA $REF_FIELDS 331 set Nref = ramp(Rref) 332 333 # read in the PHU header 334 rd PHU $smfreal 335 336 # create the chipName list from the smffile and calculate the index numbers 337 list chipsRaw -x "ftable -list $smfreal | grep -n hdr | prcol 1 | sed s/.hdr//" 338 for i 0 $chipsRaw:n 339 list word -splitbychar : $chipsRaw:$i 340 $chipNseq:$i = $word:0 - 3 341 $chipName:$i = $word:1 342 end 343 $chipName:n = $chipsRaw:n 344 $chipNseq:n = $chipsRaw:n 345 346 # find matching entries in smf file 347 for i 0 $chipName:n 348 echo $chipName:$i 349 get.chip.detect.stats $chipName:$i $chipNseq:$i 350 # if we do not have masks, we have not measured Q1refSS, just set to 1.0 351 set Q1ref_onchp = zero(Rref_onchp) + 1.0 352 353 end 354 355 $REF_FIELDS_OUT = $REF_FIELDS Xref Yref Q1ref 356 357 sprintf output "%s.%s.%s.cam.stf" $outroot $chipName:$i $OUTVERSION 358 write -fits DATA $output RrefSS DrefSS MrefSS XrefSS YrefSS Q1refSS X_PSF_found Y_PSF_found M_PSF_found RA_PSF_found DEC_PSF_found Q1_PSF_found Q2_PSF_found 359 360 end 361
Note:
See TracChangeset
for help on using the changeset viewer.
