Changeset 41720 for trunk/tools/eam/teleff/camstats.sh
- Timestamp:
- Jul 14, 2021, 3:30:26 PM (5 years ago)
- File:
-
- 1 edited
-
trunk/tools/eam/teleff/camstats.sh (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/eam/teleff/camstats.sh
r41716 r41720 1 1 2 macro camstats.glob2 macro load.camstats 3 3 if ($0 != 2) 4 echo "USAGE: camstats (glob)"4 echo "USAGE: load.camstats (glob)" 5 5 break 6 6 end 7 7 8 delete -q Rref Dref Xref Yref Q1ref Xpsf Ypsf Q1psf 8 # accumulate these fields for comparison plots 9 $FIELDS = RA_PSF DEC_PSF CAL_PSF_MAG PSF_QF Rref Dref Mref 10 11 # delete accumulation vectors 12 delete -q $FIELDS 9 13 10 14 list name -glob $1 11 15 for i 0 $name:n 12 16 17 echo "reading from $name:$i" 13 18 data $name:$i 14 19 read -fits DATA -sizes … … 20 25 calc.camstats 21 26 if ($i == 0) 22 set magFound_sum = magFound27 set numTotal_sum = numTotal 23 28 set numFound_sum = numFound 24 set numTotal_sum = numTotal25 29 set numPoss_sum = numPoss 26 set num OK_sum = numOK30 set numGood_sum = numGood 27 31 else 28 set numOK_sum = numOK + numOK_sum 32 set numTotal_sum = numTotal + numTotal_sum 33 set numFound_sum = numFound + numFound_sum 29 34 set numPoss_sum = numPoss + numPoss_sum 30 set numFound_sum = numFound + numFound_sum 31 set numTotal_sum = numTotal + numTotal_sum 35 set numGood_sum = numGood + numGood_sum 32 36 end 33 concat RrefSS Rref 34 concat DrefSS Dref 35 concat XrefSS Xref 36 concat YrefSS Yref 37 concat Q1refSS Q1ref 38 concat X_PSF_found Xpsf 39 concat Y_PSF_found Ypsf 40 concat Q1_PSF_found Q1psf 37 foreach field $FIELDS 38 concat $field\_out $field 39 end 40 41 # cleanup by deleting the loaded vectors 42 delete -q $allfields 41 43 end 42 44 43 set magFound = magFound_sum45 set numTotal = numTotal_sum 44 46 set numFound = numFound_sum 45 set numTotal = numTotal_sum 46 set numOK = numOK_sum 47 48 set fracFound = numFound_sum / numTotal_sum 49 set fracPoss = numPoss_sum / numTotal_sum 50 set fracOK = numOK_sum / numTotal_sum 51 set dfracFound = sqrt(numFound_sum) / numTotal_sum 52 set dfracOK = sqrt(numOK_sum) / numTotal_sum 53 54 break -auto off 55 threshold -q -r magFound fracFound 0.25 -range 25 {magFound[]-1} 56 break -auto on 57 $MagLim = $threshold 58 59 plot.camstats 60 end 61 62 macro camstats.single 63 if ($0 != 2) 64 echo "USAGE: camstats (file)" 65 break 66 end 67 68 data $1 69 read -fits DATA -list-fields -q 70 list tfields -join allfields 71 read -fits DATA $allfields 72 73 # assumes data has been loaded 74 # results in magFound, fracFound, numFound 75 calc.camstats 76 77 break -auto off 78 threshold -q -r magFound fracFound 0.25 -range 25 {magFound[]-1} 79 break -auto on 80 $MagLim = $threshold 81 82 plot.camstats 83 end 84 85 macro plot.camstats 47 set numPoss = numPoss_sum 48 set numGood = numGood_sum 49 delete numTotal_sum numFound_sum numPoss_sum numGood_sum 50 51 set fracFound = (numTotal > 0) ? numFound / numTotal : zero(numTotal) 52 set fracPoss = (numTotal > 0) ? numPoss / numTotal : zero(numTotal) 53 set fracGood = (numTotal > 0) ? numGood / numTotal : zero(numTotal) 54 end 55 56 if (not($?HISTBIN)) set HISTBIN = 0.01 57 macro plot.camstats.resid 58 59 clear -s 60 resize 1800 1800 61 label -fn helvetica 18 62 $BST1 = -tickpad 0.2 -xpad 3.5 -labelpadx 3.0 -ypad 4.5 -labelpady 4.0 +ypad 0.5 +labelpady 0.0 63 $BST2 = -tickpad 0.2 -xpad 3.5 -labelpadx 3.0 -ypad 0.5 -labelpady 0.0 +ypad 4.5 +labelpady 4.0 -labels 1001 64 65 section aM 0.00 0.66 0.65 0.33 66 section aR 0.00 0.33 0.65 0.33 67 section aD 0.00 0.00 0.65 0.33 68 69 section bM 0.65 0.66 0.35 0.33 70 section bR 0.65 0.33 0.35 0.33 71 section bD 0.65 0.00 0.35 0.33 72 73 set dR = 3600*(RA_PSF - Rref)*dcos(Dref) 74 set dD = 3600*(DEC_PSF - Dref) 75 set dM = CAL_PSF_MAG - Mref 76 77 set keepGood = (PSF_QF > 0.85) 78 set keepBright = keepGood && (Mref > 15) && (Mref < 17) 79 80 subset dRs = dR where keepBright 81 subset dDs = dD where keepBright 82 subset dMs = dM where keepBright 83 84 # allow mag and pos histograms to have different bin sizes? 85 histogram dRs NdRs -0.5 0.5 $HISTBIN -range dx 86 histogram dDs NdDs -0.5 0.5 $HISTBIN -range dx 87 histogram dMs NdMs -0.5 0.5 $HISTBIN -range dx 88 89 NdRs[0] = 0; NdRs[-1] = 0 90 NdDs[0] = 0; NdDs[-1] = 0 91 NdMs[0] = 0; NdMs[-1] = 0 92 93 $C3 = 0.0 94 95 peak -q dx NdRs; $C0 = $peakpos; $C2 = $peaknum; $C1 = 3*$HISTBIN; vgauss dx NdRs con NdRf 96 peak -q dx NdDs; $C0 = $peakpos; $C2 = $peaknum; $C1 = 3*$HISTBIN; vgauss dx NdDs con NdDf 97 peak -q dx NdMs; $C0 = $peakpos; $C2 = $peaknum; $C1 = 3*$HISTBIN; vgauss dx NdMs con NdMf 98 99 section aM; lim 13 23 -0.5 0.5; box $BST1 100 plot CAL_PSF_MAG dM -pt box -sz 0.5 -op 0.2 where keepGood 101 label -x mag -y "&sd&h mag" 102 103 section aR; lim 13 23 -0.5 0.5; box $BST1 104 plot CAL_PSF_MAG dR -pt box -sz 0.5 -op 0.2 where keepGood 105 label -x mag -y "&sd&h R.A." 106 107 section aD; lim 13 23 -0.5 0.5; box $BST1 108 plot CAL_PSF_MAG dD -pt box -sz 0.5 -op 0.2 where keepGood 109 label -x mag -y "&sd&h Dec" 110 111 section bM; lim dx NdMs; box $BST2 112 plot dx NdMs -x hist -lw 3 113 plot dx NdMf -x line -c red -lw 2 114 label -x "&sd&h mag" +y "N (15 < mag < 17)" 115 116 section bR; lim dx NdRs; box $BST2 117 plot dx NdRs -x hist -lw 3 118 plot dx NdRf -x line -c red -lw 2 119 label -x "&sd&h R.A" +y "N (15 < mag < 17)" 120 121 section bD; lim dx NdDs; box $BST2 122 plot dx NdDs -x hist -lw 3 123 plot dx NdDf -x line -c red -lw 2 124 label -x "&sd&h Dec" +y "N (15 < mag < 17)" 125 end 126 127 # assumes we have loaded values from the stf tables 128 # magBin, numTotal, numFound, numPoss, numGood 129 macro plot.camstats.fracs 130 86 131 clear -s 87 132 resize 1800 1200 88 133 label -fn helvetica 18 134 $BSTY = -tickpad 0.2 -xpad 3.5 -labelpadx 3.0 -ypad 4.5 -labelpady 4.0 +ypad 4.5 +labelpady 4.0 135 136 ## calculate the rough detection threshold (50%) 137 # find the bin with the most detections 138 peak -q magBin numFound 139 140 # search backwards along the fracFound curve until it crosses 50% 141 break -auto off 142 threshold -q -r magBin fracFound 0.5 -range $peaknum {magBin[]-1} 143 break -auto on 144 $MagLim = $threshold 145 146 # fraction error bars 147 set dfracFound = sqrt(numFound) / numTotal 148 set dfracGood = sqrt(numGood) / numTotal 149 150 # plot the detection fractions, using left axis 89 151 section a 0 0 1 1 90 $BSTY = -tickpad 0.2 -xpad 3.5 -labelpadx 3.0 -ypad 4.5 -labelpady 4.0 +ypad 4.5 +labelpady 4.0 91 lim magFound -0.02 1.02; box $BSTY -ticks 1110; 92 plot -x hist magFound fracFound -lw 3 -c red70 93 plot -x hist magFound fracPoss -lw 3 -c blue70 94 plot -x hist magFound fracOK -lw 3 -c red 152 lim magBin -0.02 1.02; box $BSTY -ticks 1110; 153 154 plot -x hist magBin fracFound -lw 3 -c red70 155 plot -x hist magBin fracPoss -lw 3 -c blue70 156 plot -x hist magBin fracGood -lw 3 -c red 157 158 subset tmp = fracGood where (magBin > 15) && (magBin < 20); vstat -q tmp; $FracBrightGood = $MEDIAN 159 subset tmp = fracPoss where (magBin > 15) && (magBin < 20); vstat -q tmp; $FracBrightPoss = $MEDIAN 160 subset tmp = fracFound where (magBin > 15) && (magBin < 20); vstat -q tmp; $FracBrightFound = $MEDIAN 161 162 line -c red -lt dot -lw 2 100 $FracBrightGood to 0 $FracBrightGood 163 line -c blue -lt dot -lw 2 100 $FracBrightPoss to 0 $FracBrightPoss 164 165 fprintf "%.1f-pct of all bright sources were detected unmasked" {100*$FracBrightGood} 166 fprintf "%.1f-pct of unmasked bright sources were found" {100*$FracBrightFound / $FracBrightPoss} 167 fprintf "%.1f-pct of unmasked bright sources were detected unmasked" {100*$FracBrightGood / $FracBrightPoss} 168 fprintf "mag limit %.1f" $MagLim 169 95 170 label -x mag -y "detected fraction" 96 subset tmp = fracOK where (magFound > 15) && (magFound < 20); vstat -q tmp; $FracBrightOK = $MEDIAN 97 subset tmp = fracPoss where (magFound > 15) && (magFound < 20); vstat -q tmp; $FracBrightPoss = $MEDIAN 98 subset tmp = fracFound where (magFound > 15) && (magFound < 20); vstat -q tmp; $FracBrightFound = $MEDIAN 99 line -c red -lt dot -lw 2 100 $FracBrightOK to 0 $FracBrightOK 100 line -c blue -lt dot -lw 2 100 $FracBrightPoss to 0 $FracBrightPoss 101 fprintf "%.1f-pct of all bright sources were detected unmasked" {100*$FracBrightOK} 102 fprintf "%.1f-pct of unmasked bright sources were found" {100*$FracBrightFound / $FracBrightPoss} 103 fprintf "%.1f-pct of unmasked bright sources were detected unmasked" {100*$FracBrightOK / $FracBrightPoss} 104 fprintf "mag limit %.1f" $MagLim 105 171 172 # plot the total number of detected sources, using the right axis 106 173 section b 0 0 1 1 107 lim magFound numFound; box $BSTY -ticks 1011 -labels 0001; plot -x hist magFound numFound -c grey70 -lw 2 174 lim magBin numTotal; box $BSTY -ticks 1011 -labels 0001 175 176 plot -x hist magBin numFound -c grey50 -lw 2 177 plot -x hist magBin numTotal -c grey80 -lw 2 178 108 179 line -c red -lt dot -lw 2 $MagLim -100 to $MagLim 10000 109 180 label +y "detected number" 110 181 111 182 vstat -q numFound; $Nfound = $TOTAL 112 vstat -q num OK; $Nok= $TOTAL113 114 fprintf "%d total sources detected, %d unmasked" $Nfound $N ok183 vstat -q numGood; $Ngood = $TOTAL 184 185 fprintf "%d total sources detected, %d unmasked" $Nfound $Ngood 115 186 116 187 $Xlegend = 0.02; $dXlegend = 0.03 … … 121 192 end 122 193 194 # generate histograms as a function of magnitude for the following: 195 # number of sources (numTotal) 196 # number of sources which were not masked, possibly detected (numPoss) 197 # number detected (numFound) 198 # number of detections with good quality (numGood) 199 200 # relies on the following vectors: Mref_out, Q1ref_out, PSF_QF_out, X_PSF_out 123 201 macro calc.camstats 124 202 $Mmin = 10 125 203 $Mmax = 25 126 $Mdel = 0. 5127 128 delete -q fracFound magFound numFound numTotal numPoss fracPoss numOK fracOK204 $Mdel = 0.25 205 206 delete -q magBin numTotal numPoss numFound numGood 129 207 for mag $Mmin $Mmax $Mdel 130 concat $mag magFound 131 132 # what fraction of the sources were actually detected? 133 set keep = (MrefSS > $mag - 0.5*$Mdel) && (MrefSS <= $mag + 0.5*$Mdel) 134 # X_PSF_found is NAN if the source is not found (detected in smf), finite otherwise 135 subset XinBin = X_PSF_found if keep 136 vstat -q XinBin 137 concat {$NPTS/XinBin[]} fracFound 138 concat XinBin[] numTotal 208 concat $mag magBin 209 210 # sources in mag bin 211 set keepSrc = (Mref_out > $mag - 0.5*$Mdel) && (Mref_out <= $mag + 0.5*$Mdel) 212 subset tmp = X_PSF_out if keepSrc 213 concat tmp[] numTotal 214 215 # NOTE: X_PSF_out is NAN if the source is not found (detected in smf), finite otherwise 216 # vstat ignores NAN values, so NPTS is count of non-NAN values 217 vstat -q tmp 139 218 concat $NPTS numFound 140 219 220 # what fraction of the sources could have been detected (mask fraction > 0.85 at position)? 221 set keepMsk = keepSrc && (Q1ref_out > 0.85) 222 subset tmp = X_PSF_out if keepMsk 223 concat tmp[] numPoss 224 141 225 # what fraction of the sources were actually detected with good quality? 142 set keep = (MrefSS > $mag - 0.5*$Mdel) && (MrefSS <= $mag + 0.5*$Mdel) && (Q1_PSF_found > 0.85) && not(isnan(Q1_PSF_found)) 143 # X_PSF_found is NAN if the source is not found (detected in smf), finite otherwise 144 subset XinBinOK = X_PSF_found if keep 145 concat {XinBinOK[]/XinBin[]} fracOK 146 concat XinBinOK[] numOK 147 148 # what fraction of the sources could have been detected (mask fraction > 0.85 at position)? 149 set keep = (MrefSS > $mag - 0.5*$Mdel) && (MrefSS <= $mag + 0.5*$Mdel) && (Q1refSS > 0.85) 150 subset XinBinGood = X_PSF_found if keep 151 concat {XinBinGood[]/XinBin[]} fracPoss 152 concat XinBinGood[] numPoss 153 end 226 set keepDet = keepSrc && (PSF_QF_out > 0.85) && not(isnan(PSF_QF_out)) 227 subset tmp = X_PSF_out if keepDet 228 concat tmp[] numGood 229 end 230 231 delete -q tmp keepSrc keepMsk keepDet 154 232 end 155 233 … … 234 312 end 235 313 236 macro load.camstats.glob 314 macro load.camstats.glob.old 237 315 if ($0 != 2) 238 316 echo "USAGE: load.camstats.glob (glob)" … … 265 343 end 266 344 345 # relies on the following vectors: Mref_out, Q1ref_out, PSF_QF_out, X_PSF_out 346 macro test.camstats 347 $Mmin = 10 348 $Mmax = 25 349 $Mdel = 0.25 350 351 delete -q magBin numTotal numFound 352 for mag $Mmin $Mmax $Mdel 353 concat $mag magBin 354 355 # sources in mag bin 356 set keepSrc = (MrefDiff_onchp > $mag - 0.5*$Mdel) && (MrefDiff_onchp <= $mag + 0.5*$Mdel) 357 subset tmp = RpsfDiff_onchp if keepSrc 358 concat tmp[] numTotal 359 360 # NOTE: X_PSF_out is NAN if the source is not found (detected in smf), finite otherwise 361 # vstat ignores NAN values, so NPTS is count of non-NAN values 362 vstat -q tmp 363 concat $NPTS numFound 364 end 365 366 delete -q tmp keepSrc 367 end
Note:
See TracChangeset
for help on using the changeset viewer.
