IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 41993


Ignore:
Timestamp:
Jan 20, 2022, 6:46:50 AM (4 years ago)
Author:
eugene
Message:

adding code to load a table of field definitions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20211108/ippTests/ippCheck/smfcheck.pro

    r41989 r41993  
    66
    77input tap.sh
     8
     9# for a single chip, I want outputs with names like:
     10# expname.chipID.smfcmp.field.png
     11# expname.chipID.smfcmp.txt
     12
     13### example of plotting all outputs for a single chip:
     14macro go.sample
     15  $SAVEPLOT = 0
     16  $KAPA = kapa -noX
     17  smf.compare.parse.book fields.bk psfFields
     18  smf.compare.onechip o9451g0319o/o9451g0319o.XY01 o9451g0319o.1833521.cm.2467375.smf o9451g0319o.1833521.cm.2467377.smf 2
     19end
    820
    921macro check.extensions
     
    4860end
    4961
    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 
    6262# generate plot and comparison txt file for one chip (extension)
    6363macro smf.compare.onechip
     
    7676  mkdir $mydir
    7777
    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
     78  # XXX TEMP: remove existing output file
     79  exec rm -f $output.txt
     80
     81  # load in the full set of data for this extension
     82  # NOTE : t0 and t1 are used to label the sets of vectors
     83  load.smf.fields $smf1 $extnum t1
     84  load.smf.fields $smf2 $extnum t2
     85
     86  # generate the matched lists (index1, index2)
     87  smf.compare.positions $output t1 t2
     88
     89  # compare the values in the matched pairs for each field
     90  smf.compare.fields $output t1 t2
    8491end
    8592
     
    108115
    109116$MATCH_RADIUS = 1; # match radius in pixels
    110 macro smf.pos.compare
     117macro smf.compare.positions
    111118  if ($0 != 4)
    112     echo "USAGE: smf.pos.compare (output) (v1) (v2)"
     119    echo "USAGE: smf.compare.positions (output) (v1) (v2)"
    113120    echo "generates matched position lists & stats"
    114121    break
     
    120127  $v2     = $3
    121128
    122   match2d X_PSF_$v1 Y_PSF_$v1 X_PSF_$v1 Y_PSF_$v1 $MATCH_RADIUS -closest
     129  match2d X_PSF_$v1 Y_PSF_$v1 X_PSF_$v2 Y_PSF_$v2 $MATCH_RADIUS -closest
    123130
    124131  # initial questions to answer:
     
    128135  reindex Ym_$v1 = Y_PSF_$v1 using index2 -keep-unmatched
    129136
    130   reindex Xm_$v1 = X_PSF_$v1 using index1 -keep-unmatched
    131   reindex Ym_$v1 = Y_PSF_$v1 using index1 -keep-unmatched
     137  reindex Xm_$v2 = X_PSF_$v2 using index1 -keep-unmatched
     138  reindex Ym_$v2 = Y_PSF_$v2 using index1 -keep-unmatched
    132139 
    133140  vstat -q Xm_$v1
     
    135142  $N1_miss = Xm_$v1[] - $N1_keep
    136143 
    137   vstat -q Xm_$v1
     144  vstat -q Xm_$v2
    138145  $N2_keep = $NPTS
    139   $N2_miss = Xm_$v1[] - $N2_keep
    140  
     146  $N2_miss = Xm_$v2[] - $N2_keep
    141147 
     148  #
     149  output $output.txt
    142150  echo "$N1_keep & $N1_miss vs $N2_keep & $N2_miss"
     151  output stdout
    143152
    144153  # positional consistency:
    145   set dX = X_PSF_$v1 - Xm_$v1
    146   set dY = Y_PSF_$v1 - Ym_$v1
     154  set dX = X_PSF_$v1 - Xm_$v2
     155  set dY = Y_PSF_$v1 - Ym_$v2
    147156
    148157  vstat dX
     
    162171  $v2     = $3
    163172
    164   smf.fields.magrange.init
     173  smf.fields.magplot.init
    165174  exec rm -f $output.txt
    166175
     
    168177  list fields -split $allfields
    169178  for i 0 $fields:n
    170     $f = $fields:$i
    171     smf.fields.magrange.plot $output $f $v1 $v2
     179    smf.compare.onefield   $output $fields:$i $v1 $v2
     180    smf.fields.magplot.foo $output $fields:$i $v1 $v2
    172181  end 
    173182end
    174183
    175 macro smf.fields.magrange.init
     184macro smf.fields.magplot.init
    176185  clear -s
    177186  antialias 0.4
     
    183192end
    184193
    185 macro smf.fields.magrange.plot
     194macro smf.fields.magplot.foo
    186195  if ($0 != 5)
    187     echo "USAGE: smf.fields.magrange.plot (output) {field) (v1) (v2)"
     196    echo "USAGE: smf.fields.magplot.foo (output) {field) (v1) (v2)"
    188197    echo " NOTE: run smf.pos.compare (or equiv) first to generate index1, index2"
    189198    break
     
    196205  $v2     = $4
    197206
    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
     207  if (not(dtmp?[])) return; # this happens if the field is not listed in the fields table (or stat is NONE)
     208  if (not($SAVEPLOT)) return
     209  if (isnan($hist:median)) return
    212210
    213211  clear
    214212  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
     213  lim PSF_INST_MAG_$v1 $hist:minPlt $hist:maxPlt; box $BSTY; plot PSF_INST_MAG_$v1 dtmp -pt cir -op 0.3
    216214  section b
    217215  if (dx[] == 1)
     
    221219  end
    222220 
    223   if ($SAVEPLOT)
    224     png -name $output.$field.png
     221  png -name $output.$field.png
     222end
     223
     224macro smf.compare.onefield
     225  if ($0 != 5)
     226    echo "USAGE: smf.fields.onefield (output) {field) (v1) (v2)"
     227    echo " NOTE: run smf.compare.position (or equiv) first to generate index1, index2"
     228    break
     229  end
     230 
     231  local output field v1 v2
     232  $output = $1
     233  $field  = $2
     234  $v1     = $3
     235  $v2     = $4
     236
     237  # confirm that this field exists in the list of fields:
     238  # XXX missing functions to test for book or page existence
     239
     240  # generate the comparison statistic
     241  reindex tmp_$v2 = $field\_$v2 using index1 -keep-unmatched
     242
     243  # what statistic do we use to compare?
     244  book getword psfFields $field STAT     -var useStat
     245  book getword psfFields $field SCALE    -var statScale
     246  book getword psfFields $field MIN_GOOD -var minGood
     247  book getword psfFields $field MAX_GOOD -var maxGood
     248  book getword psfFields $field MIN_MAG  -var minMag
     249  book getword psfFields $field MAX_MAG  -var maxMag
     250  echo $field $useStat
     251
     252  delete -q dtmp
     253  if ("$useStat" == "VALUE")
     254    set dtmp = $statScale*(tmp_$v2 - $field\_$v1)
     255    subset dtmpS = dtmp where ((PSF_INST_MAG_$v1 > $minMag) && (PSF_INST_MAG_$v1 < $maxMag))
     256  end
     257  if ("$useStat" == "IVALUE")
     258    set dtmp = tmp_$v2 - $field\_$v1
     259    subset dtmpS = dtmp where ((PSF_INST_MAG_$v1 > $minMag) && (PSF_INST_MAG_$v1 < $maxMag) && (tmp_$v2 != -4096) && ($field\_$v1 != -4096))
     260  end
     261  if ("$useStat" == "RATIO")
     262    set dtmp = $statScale(tmp_$v2 / $field\_$v1)
     263    subset dtmpS = dtmp where ((PSF_INST_MAG_$v1 > $minMag) && (PSF_INST_MAG_$v1 < $maxMag))
     264  end
     265  if ("$useStat" == "RVALUE")
     266    set dtmp = $statScale*(tmp_$v2 - $field\_$v1) / $field\_$v1
     267    subset dtmpS = dtmp where ((PSF_INST_MAG_$v1 > $minMag) && (PSF_INST_MAG_$v1 < $maxMag))
     268  end
     269  if (("$useStat" == "NONE") || ("$useStat" == "NULL"))
     270    output $output.txt
     271    fprintf "%24s :  1 : SKIP" $field
     272    output stdout
     273    return
     274  end
     275  if (dtmp?[] == 0)
     276    echo "unknown STAT value $useStat"
     277    break
     278  end
     279 
     280  # measure the stats on the subset for the defined mag range
     281  hist.range dtmpS Ntmp dx
     282  vstat -q dtmpS
     283
     284  $PASS = 1
     285  if ($hist:minVal < $minGood) set PASS = 0
     286  if ($hist:maxVal > $maxGood) set PASS = 0
     287
     288  # save the summary line to be written to a file by the calling function
     289  output $output.txt
     290  fprintf "%24s : %2d : %12.6g %12.6g : %12.6g : %12.6g - %12.6g" $field $PASS $MEAN $SIGMA $hist:median $hist:minVal $hist:maxVal
     291  output stdout
     292end
     293
     294macro smf.compare.parse.book
     295  if ($0 != 3)
     296    echo "USAGE: smf.compare.parse.book (file) (book)"
     297    break
     298  end
     299
     300  local filename bookname pagename i j tmpline myChar
     301  $filename = $1
     302  $bookname = $2
     303
     304  # the fields table has row-by-row pages with values:
     305  # LAYOUT   KEY   KEY   KEY
     306  # PAGENAME VALUE VALUE VALUE
     307
     308  # NOTE: this list parsing strips out extra spaces and empty lines
     309  # ALSO: the code below handles quotes in the input file poorly
     310  list tmplines -x "cat $filename"
     311
     312  book init $bookname; # creates the book if it does not exist
     313
     314  $myWords:n = 0
     315
     316  for i 0 $tmplines:n
     317    $tmpline = $tmplines:$i
     318    substr "$tmpline" 0 1 myChar
     319    if ("$myChar" == "#") continue
     320
     321    list words -split $tmpline
     322    if ($words:n < 2)
     323      echo "ERROR: no information on line $i"
     324      echo "$tmpline"
     325      break
     326    end
     327
     328    $pagename = $words:0
     329
     330    if ($myWords:n == 0)
     331     # the first uncommented line should define the list of words
     332     if ("$pagename" != "LAYOUT")
     333       echo "ERROR: invalid page layout on first line"
     334       echo "$tmpline"
     335       break
     336     end
     337
     338     # save these words on the list of words
     339     list myWords -copy words
     340     next
     341    end
     342
     343    if ($words:n != $myWords:n)
     344       echo "ERROR: missing words for page on line $i"
     345       echo "$tmpline"
     346       break
     347    end
     348
     349    # the first word on the line gives the page name
     350    book newpage $bookname $pagename
     351
     352    for j 1 $words:n
     353      book setword $bookname $pagename $myWords:$j $words:$j
     354    end
    225355  end
    226356end
     
    237367  local Nm Np No value10 value50 value90 range
    238368
    239   set _tmp_sort = $1
     369  $hist:minPlt = NAN
     370  $hist:maxPlt = NAN
     371  $hist:minVal = NAN
     372  $hist:maxVal = NAN
     373  $hist:delVal = NAN
     374  $hist:median = NAN
     375
     376  if (not($1?[]))
     377    echo "invalid vector $1"
     378    break
     379  end
     380
     381  subset _tmp_sort = $1 where not(isnan($1))
     382  if (_tmp_sort[] < 2) return
     383
    240384  sort _tmp_sort
    241385  $Nm = 0.1*_tmp_sort[]
     
    248392  $value50 = _tmp_sort[$No]
    249393
    250   # set the range to be 2x the 10 - 90 percentile range
     394  # save the 10 and 90 percentile values
     395  $hist:minVal = $value10
     396  $hist:maxVal = $value90
     397
     398  # set the plotting range to be 3x the 10 - 90 percentile range
    251399  $range = 3*($value90 - $value10)
    252   $hist:minVal = $value50 - 0.5*$range
    253   $hist:maxVal = $value50 + 0.5*$range
     400  $hist:minPlt = $value50 - 0.5*$range
     401  $hist:maxPlt = $value50 + 0.5*$range
     402
    254403  $hist:delVal = $range / 250
    255404  $hist:median = $value50
Note: See TracChangeset for help on using the changeset viewer.