Changeset 41989
- Timestamp:
- Jan 19, 2022, 6:37:34 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20211108/ippTests/ippCheck/smfcheck.pro
r41983 r41989 1 1 # compare smf-to-smf 2 if (not($?SAVEPLOT)) set SAVEPLOT = 0 3 if (not($?PLOTROOT)) 4 $PLOTROOT = smfcompare 5 end 2 6 3 7 input tap.sh … … 31 35 echo ippCheckKeys $1 $Next $2 $Next 32 36 exec ippCheckKeys $1 $Next $2 $Next 33 break34 37 end 35 end 36 end 37 38 macro check.keywords 38 39 # if extname is XYnn.psf, compare the headers AND compare the table values 40 strstr -q $w0:0 .psf -start s1 41 if ($s1 == 4) 42 $Next = $i - 1 43 echo $w0:0 == $Next 44 echo ippCheckKeys $1 $Next $2 $Next 45 exec ippCheckKeys $1 $Next $2 $Next 46 end 47 end 48 end 49 50 51 # for a single chip, I want outputs with names like: 52 # expname.chipID.smfcmp.field.png 53 # expname.chipID.smfcmp.txt 54 55 ### example of plotting all outputs for a single chip: 56 macro go.sample 57 $SAVEPLOT = 1 58 $KAPA = kapa -noX 59 smf.compare.onechip o9451g0319o/o9451g0319o.XY01 o9451g0319o.1833521.cm.2467375.smf o9451g0319o.1833521.cm.2467377.smf 2 60 end 61 62 # generate plot and comparison txt file for one chip (extension) 63 macro smf.compare.onechip 39 64 if ($0 != 5) 40 echo "USAGE: check.keywords (smf1) (ext1) (smf2) (ext2)" 41 break 42 end 43 44 exec fhead -x $2 $1 > t1.hdr 45 exec fhead -x $4 $3 > t2.hdr 46 47 48 # this comparison compares FITS Table fields 49 exec grep "^TTYPE" t1.hdr | prcol 3 > f1.hdr 50 exec grep "^TTYPE" t2.hdr | prcol 3 > f2.hdr 51 52 break -auto off 53 echo "fields added to $3" 54 exec diff f1.hdr f2.hdr | grep '>' 55 56 echo "fields removed from $1" 57 exec diff f1.hdr f2.hdr | grep '<' 58 break -auto on 59 end 60 61 macro match.keywords 65 echo "USAGE: smf.compare.onechip (output) (smf1) (smf2) (extension)" 66 break 67 end 68 69 local output smf1 smf2 extnum 70 $output = $1 71 $smf1 = $2 72 $smf2 = $3 73 $extnum = $4 74 75 dirname $output -var mydir 76 mkdir $mydir 77 78 load.smf.fields $smf1 $extnum t0 79 load.smf.fields $smf2 $extnum t1 80 81 smf.pos.compare t0 t1 82 smf.compare.fields $output t0 t1 83 output stdout 84 end 85 86 # load in the data for a pair of smf fields for a single chip 87 macro load.smf.fields 88 if ($0 != 4) 89 echo "USAGE: load.smf.fields (smffile) (extension) (version)" 90 echo " loads all fields and saves them with version appended to the names" 91 break 92 end 93 94 local version extnum filename 95 $filename = $1 96 $extnum = $2 97 $version = $3 98 99 data $filename 100 read -fits $extnum -extnum -list-fields -q; list tfields -join allfields 101 read -fits $extnum -extnum $allfields 102 103 foreach f $allfields 104 set $f\_$version = $f 105 delete $f 106 end 107 end 108 109 $MATCH_RADIUS = 1; # match radius in pixels 110 macro smf.pos.compare 111 if ($0 != 4) 112 echo "USAGE: smf.pos.compare (output) (v1) (v2)" 113 echo "generates matched position lists & stats" 114 break 115 end 116 117 local output v1 v2 i 118 $output = $1 119 $v1 = $2 120 $v2 = $3 121 122 match2d X_PSF_$v1 Y_PSF_$v1 X_PSF_$v1 Y_PSF_$v1 $MATCH_RADIUS -closest 123 124 # initial questions to answer: 125 # * how many sources from #1 are not in #2? 126 # * how many sources from #2 are not in #1? 127 reindex Xm_$v1 = X_PSF_$v1 using index2 -keep-unmatched 128 reindex Ym_$v1 = Y_PSF_$v1 using index2 -keep-unmatched 129 130 reindex Xm_$v1 = X_PSF_$v1 using index1 -keep-unmatched 131 reindex Ym_$v1 = Y_PSF_$v1 using index1 -keep-unmatched 132 133 vstat -q Xm_$v1 134 $N1_keep = $NPTS 135 $N1_miss = Xm_$v1[] - $N1_keep 136 137 vstat -q Xm_$v1 138 $N2_keep = $NPTS 139 $N2_miss = Xm_$v1[] - $N2_keep 140 141 142 echo "$N1_keep & $N1_miss vs $N2_keep & $N2_miss" 143 144 # positional consistency: 145 set dX = X_PSF_$v1 - Xm_$v1 146 set dY = Y_PSF_$v1 - Ym_$v1 147 148 vstat dX 149 vstat dY 150 end 151 152 macro smf.compare.fields 153 if ($0 != 4) 154 echo "USAGE: smf.pos.compare (output) (v1) (v2)" 155 echo "generates matched position lists & stats" 156 break 157 end 158 159 local output v1 v2 i 160 $output = $1 161 $v1 = $2 162 $v2 = $3 163 164 smf.fields.magrange.init 165 exec rm -f $output.txt 166 167 # XXX this will fail if the two smfs do not have the same fields 168 list fields -split $allfields 169 for i 0 $fields:n 170 $f = $fields:$i 171 smf.fields.magrange.plot $output $f $v1 $v2 172 end 173 end 174 175 macro smf.fields.magrange.init 176 clear -s 177 antialias 0.4 178 label -fn helvetica 24 179 resize 2000 800 180 section a 0.0 0.0 0.7 1.0 181 section b 0.7 0.0 0.3 1.0 182 $BSTY = -tickpad 0.1 -labelpadx 3.0 -xpad 3.5 +xpad 1.0 183 end 184 185 macro smf.fields.magrange.plot 62 186 if ($0 != 5) 63 echo "USAGE test.keywords (smf1) (ext1) (smf2) (ext2)" 64 break 65 end 66 67 # smf1/ext1 holds the referece list 68 list keys -x "smfkeys.sh $1 $2" 69 70 rd h1 $1 -x $2 71 rd h2 $3 -x $4 72 73 for i 0 $keys:n 74 if ("$keys:$i" == "XTENSION") continue; # opihi transforms XTENSION to SIMPLE 75 76 $mykey = $keys:$i 77 keyword h1 $mykey val1 78 keyword h2 $mykey val2 79 80 # XXX I do not have a good way to test the 81 # type of the header value. I can just check 82 83 # empty string needs to be specially handled 84 if (("$val1" == "") || ("$val2" == "")) 85 if ("$val1" == "$val2") 86 # echo "matched values $keys:$i : $val1 vs $val2" 87 else 88 echo "mismatched values $keys:$i : $val1 vs $val2" 89 end 90 continue 91 end 92 93 # multi-word strings need to be specially handled 94 getchr "$val1" " " s1 95 getchr "$val2" " " s2 96 if (($s1 > -1) || ($s2 > -1)) 97 # echo "multiword: $val1 : $s1" 98 # echo "multiword: $val2 : $s2" 99 if ("$val1" == "$val2") 100 # echo "matched multivalues $keys:$i : $val1 vs $val2" 101 else 102 echo "mismatched multivalues $keys:$i : $val1 vs $val2" 103 end 104 continue 105 end 106 107 # strings with +,-,*,/,^ need to be specially handled 108 $hasmath1 = 0 109 $hasmath2 = 0 110 foreach mychar + - * / ^ : , 111 getchr "$val1" "$mychar" s1 112 if ($s1 > -1) 113 $hasmath1 = 1 114 end 115 getchr "$val2" "$mychar" s2 116 if ($s2 > -1) 117 $hasmath2 = 1 118 end 119 end 120 121 if ($hasmath1 || $hasmath2) 122 #echo "math: $val1 : $s1" 123 #echo "math: $val2 : $s2" 124 if ("$val1" == "$val2") 125 # echo "matched multivalues $keys:$i : $val1 vs $val2" 126 else 127 echo "mismatched multivalues $keys:$i : $val1 vs $val2" 128 end 129 continue 130 end 131 132 if (isword($val1)) 133 if ("$val1" == "$val2") continue 134 else 135 if ($val1 == $val2) continue 136 end 137 echo "mismatched values $keys:$i : $val1 vs $val2" 138 end 139 end 187 echo "USAGE: smf.fields.magrange.plot (output) {field) (v1) (v2)" 188 echo " NOTE: run smf.pos.compare (or equiv) first to generate index1, index2" 189 break 190 end 191 192 local output field v1 v2 193 $output = $1 194 $field = $2 195 $v1 = $3 196 $v2 = $4 197 198 # plot the new values vs the old values (all old values) 199 reindex tmp_$v2 = $field\_$v2 using index1 -keep-unmatched 200 set dtmp = tmp_$v2 - $field\_$v1 201 hist.range dtmp Ntmp dx 202 vstat -q dtmp 203 204 # save the summary line to be written to a file by the calling function 205 output $output.txt 206 fprintf "%24s : %12.6g %12.6g : %12.6g : %12.6g - %12.6g" $field $MEAN $SIGMA $hist:median $hist:minVal $hist:maxVal 207 output stdout 208 209 if (isnan($hist:median)) 210 continue 211 end 212 213 clear 214 section a 215 lim PSF_INST_MAG_$v1 $hist:minVal $hist:maxVal; box $BSTY; plot PSF_INST_MAG_$v1 dtmp -pt cir -op 0.3 216 section b 217 if (dx[] == 1) 218 lim dx Ntmp; box $BSTY; plot -pt cir dx Ntmp; label -x $field 219 else 220 lim dx Ntmp; box $BSTY; plot -x hist dx Ntmp; label -x $field 221 end 222 223 if ($SAVEPLOT) 224 png -name $output.$field.png 225 end 226 end 227 228 macro hist.range 229 if ($0 != 4) 230 echo "USAGE: hist.range (value) (Nvalue) (dvalue)" 231 break 232 end 233 234 # assume we have a small enough vector to sort and select 235 # the min and max percentile explicitly 236 237 local Nm Np No value10 value50 value90 range 238 239 set _tmp_sort = $1 240 sort _tmp_sort 241 $Nm = 0.1*_tmp_sort[] 242 $Np = 0.9*_tmp_sort[] 243 $No = 0.5*_tmp_sort[] 244 245 # 10 and 90 percentile values 246 $value10 = _tmp_sort[$Nm] 247 $value90 = _tmp_sort[$Np] 248 $value50 = _tmp_sort[$No] 249 250 # set the range to be 2x the 10 - 90 percentile range 251 $range = 3*($value90 - $value10) 252 $hist:minVal = $value50 - 0.5*$range 253 $hist:maxVal = $value50 + 0.5*$range 254 $hist:delVal = $range / 250 255 $hist:median = $value50 256 257 if ($range == 0.0) 258 # if all values are the same, generate a vector with a single value of all points 259 create $3 $hist:median {$hist:median + 1.5} 260 set $2 = zero($3) + 0.0 261 $2[0] = _tmp_sort[] 262 return 263 end 264 265 if (isnan($range)) 266 # if all values are the same, generate a vector with a single value of all points 267 create $3 0 1 268 set $2 = zero($3) + 0.0 269 $2[0] = _tmp_sort[] 270 return 271 end 272 273 # XXX add histogram option to ignore out-of-range values 274 histogram $1 $2 $hist:minVal $hist:maxVal $hist:delVal -range $3 275 $2[0] = 0; $2[-1] = 0 276 end 277 278 # NOTE: in this method, match2d + reindex gives two pairs of vectors: the matched sources 279 macro test.m1 280 281 $v1 = t0 282 $v2 = t1 283 284 match2d X_PSF_$v1 Y_PSF_$v1 X_PSF_$v2 Y_PSF_$v2 $MATCH_RADIUS 285 reindex Xm_$v1 = X_PSF_$v1 using index1 286 reindex Ym_$v1 = Y_PSF_$v1 using index1 287 288 reindex Xm_$v2 = X_PSF_$v2 using index2 289 reindex Ym_$v2 = Y_PSF_$v2 using index2 290 291 set dX = Xm_$v1 - Xm_$v2 292 set dY = Ym_$v1 - Ym_$v2 293 294 vstat dX 295 vstat dY 296 end 297 298 # NOTE: in this method, match2d -closest + reindex -keep-unmatched gives two pairs of vectors which match the original 299 # source lists (unmatched are NAN) 300 macro test.m2 301 302 $v1 = t0 303 $v2 = t1 304 305 match2d X_PSF_$v1 Y_PSF_$v1 X_PSF_$v2 Y_PSF_$v2 $MATCH_RADIUS -closest 306 reindex Xm_$v1 = X_PSF_$v1 using index2 -keep-unmatched 307 reindex Ym_$v1 = Y_PSF_$v1 using index2 -keep-unmatched 308 set dX1 = Xm_$v1 - X_PSF_$v2 309 set dY1 = Ym_$v1 - Y_PSF_$v2 310 vstat dX1 311 vstat dY1 312 313 reindex Xm_$v2 = X_PSF_$v2 using index1 -keep-unmatched 314 reindex Ym_$v2 = Y_PSF_$v2 using index1 -keep-unmatched 315 set dX2 = X_PSF_$v1 - Xm_$v2 316 set dY2 = Y_PSF_$v1 - Ym_$v2 317 vstat dX2 318 vstat dY2 319 end 320
Note:
See TracChangeset
for help on using the changeset viewer.
