IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 41716


Ignore:
Timestamp:
Jul 13, 2021, 10:31:53 AM (5 years ago)
Author:
eugene
Message:

code cleanup : try to simplify names of temp and output vectors, method to subset the group

Location:
trunk/tools/eam/teleff
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/eam/teleff/cammask.pro

    r41712 r41716  
    88if (not($?MATCH_RADIUS)) set MATCH_RADIUS = 2.0
    99
    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
    5413
    5514macro get.camera.eff
     
    8746 # load the reference source table
    8847 # NOTE: Mref is chosen to match filter for this exposure
    89  data $refsrcs; read -fits DATA Rref Dref Mref
     48 data $refsrcs; read -fits DATA $REF_FIELDS
    9049 set Nref = ramp(Rref)
    9150
     
    9352 rd PHU $smfreal
    9453
    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
    9757 list chipsRaw -x "ftable -list $smfreal | grep -n hdr | prcol 1 | sed s/.hdr//"
    9858 for i 0 $chipsRaw:n
    9959  list word -splitbychar : $chipsRaw:$i
    10060  $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
    10265 end
    10366
     
    10770   get.chip.mask.stats $camMask:$i
    10871
    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
     89end
     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
    13894
    13995macro get.chip.detect.stats
     
    147103  end
    148104
    149   local chipname chipnseq
     105  local chipname chipnseq field NAXIS1 NAXIS2
    150106  $chipname = $1
    151107  $chipnseq = $2
     
    153109  # read in the CHIP header
    154110
    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
    159117
    160118  keyword hdr NAXIS1 NAXIS1
     
    169127  # do we need to grow the range at all?
    170128  set keep = (Rref >= $minR) && (Rref <= $maxR) && (Dref >= $minD) && (Dref <= $maxD)
    171   subset RrefS = Rref if keep
    172   subset DrefS = Dref if keep
    173   subset MrefS = Mref if keep
     129  foreach field $REF_FIELDS Nref
     130    subset $field\_tmp = $field if keep
     131  end
    174132
    175133  # convert the subset coordinates to pixels
    176   set XrefS = RrefS
    177   set YrefS = DrefS
    178   coords -q hdr -mosaic PHU -c XrefS YrefS
     134  set Xref_tmp = Rref_tmp
     135  set Yref_tmp = Dref_tmp
     136  coords -q hdr -mosaic PHU -c Xref_tmp Yref_tmp
    179137
    180138  # 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
    187144
    188145  # now read the smf detections
    189146  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
    198154
    199155  # 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
     160end
     161
     162macro 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
     181end
     182
     183### utilities
    218184macro init.radec.range
    219185  $minR = $RA
     
    341307 book delete mybook
    342308end
     309
     310
     311####
     312
     313macro 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
     360end
     361
  • trunk/tools/eam/teleff/camstats.sh

    r41712 r41716  
    1 
    2 macro test.mpcfine
    3   if ($0 != 2)
    4     echo "USAGE: test.mpcfine (file)"
    5     break
    6   end
    7 
    8   data $1
    9   read Rr 1 Dr 2 Rc 4 Dc 5 Rp 7 Dp 8 Ra 10 Da 11 Rd 13 Dd 14
    10   set dRc = 3600*(Rc - Rr)*dcos(Dr)
    11   set dDc = 3600*(Dc - Dr)
    12   set dRp = 3600*(Rp - Rc)*dcos(Dr)
    13   set dDp = 3600*(Dp - Dc)
    14   set dRa = 3600*(Ra - Rp)*dcos(Dr)
    15   set dDa = 3600*(Da - Dp)
    16   set dRd = 3600*(Rd - Ra)*dcos(Dr)
    17   set dDd = 3600*(Dd - Da)
    18 
    19   vstat dRc
    20   vstat dRp
    21   vstat dRa
    22   vstat dRd
    23 
    24 end
    25 
    26 macro test.mpcorb
    27   if ($0 != 3)
    28     echo "USAGE: test.mpcorb (version) (options)"
    29     break
    30   end
    31 
    32   local Version
    33   $Version = $1
    34   $Options = $2
    35 
    36   echo mpcorb_predict moment trange.59396.fits 59375.31398 {200.738197150704-2} {200.738197150704+2} {6.13117829483755-2} {6.13117829483755+2} o9375g0065o.am$Version.fits $Options
    37   exec mpcorb_predict moment trange.59396.fits 59375.31398 {200.738197150704-2} {200.738197150704+2} {6.13117829483755-2} {6.13117829483755+2} o9375g0065o.am$Version.fits $Options
    38   get.camera.matches o9375g0065o.1795013.cm.2420887.smf o9375g0065o.am$Version.fits o9375g0065o.t1/o9375g0065o.t1 am$Version
    39   load.camstats.glob o9375g0065o.t1/o9375g0065o.t1.XY*.am$Version.cam.stf
    40 
    41   set dX$Version = Xpsf - Xref
    42   set dY$Version = Ypsf - Yref
    43 
    44   set dR$Version = 3600*(Rpsf - Rref)*dcos(Dref)
    45   set dD$Version = 3600*(Dpsf - Dref)
    46 
    47   plot -pt cir -sz 2 -op 0.3 dR$Version dD$Version
    48 end
    49 
    50 macro replot.mpcorb
    51   if ($0 != 3)
    52     echo "USAGE: test.mpcorb (version) (color)"
    53     break
    54   end
    55 
    56   plot -pt cir -sz 2 -op 0.3 dR$1 dD$1 -c $2
    57 end
    58 
    59 macro load.camstats.glob
    60  if ($0 != 2)
    61    echo "USAGE: load.camstats.glob (glob)"
    62    break
    63  end
    64  
    65  delete -q Rref Dref Xref Yref Q1ref Xpsf Ypsf Rpsf Dpsf Q1psf
    66 
    67  list name -glob $1
    68  for i 0 $name:n
    69 
    70    data $name:$i
    71    read -fits DATA -sizes
    72    if ($table:Ny == 0) continue
    73    read -fits DATA -list-fields -q; list tfields -join allfields; read -fits DATA $allfields
    74 
    75    concat RrefSS Rref
    76    concat DrefSS Dref
    77    concat XrefSS Xref
    78    concat YrefSS Yref
    79    concat Q1refSS Q1ref
    80    concat X_PSF_found Xpsf
    81    concat Y_PSF_found Ypsf
    82    concat RA_PSF_found Rpsf
    83    concat DEC_PSF_found Dpsf
    84    concat Q1_PSF_found Q1psf
    85  end
    86 end
    871
    882macro camstats.glob
     
    13852 set dfracOK    = sqrt(numOK_sum)    / numTotal_sum
    13953
     54 break -auto off
    14055 threshold -q -r magFound fracFound 0.25 -range 25 {magFound[]-1}
     56 break -auto on
    14157 $MagLim = $threshold
    14258
     
    208124 $Mmin = 10
    209125 $Mmax = 25
    210  $Mdel = 0.25
     126 $Mdel = 0.5
    211127 
    212128 delete -q fracFound magFound numFound numTotal numPoss fracPoss numOK fracOK
     
    258174  cplot -c red  -op 1.0 -pt box -sz 2.5 RrefCam DrefCam where (not(isnan(Xpsf)) && (Q1psf > 0.85))
    259175end
     176
     177############ macros used to test mpcorb_predict
     178
     179macro test.mpcfine
     180  if ($0 != 2)
     181    echo "USAGE: test.mpcfine (file)"
     182    break
     183  end
     184
     185  data $1
     186  read Rr 1 Dr 2 Rc 4 Dc 5 Rp 7 Dp 8 Ra 10 Da 11 Rd 13 Dd 14
     187  set dRc = 3600*(Rc - Rr)*dcos(Dr)
     188  set dDc = 3600*(Dc - Dr)
     189  set dRp = 3600*(Rp - Rc)*dcos(Dr)
     190  set dDp = 3600*(Dp - Dc)
     191  set dRa = 3600*(Ra - Rp)*dcos(Dr)
     192  set dDa = 3600*(Da - Dp)
     193  set dRd = 3600*(Rd - Ra)*dcos(Dr)
     194  set dDd = 3600*(Dd - Da)
     195
     196  vstat dRc
     197  vstat dRp
     198  vstat dRa
     199  vstat dRd
     200
     201end
     202
     203macro test.mpcorb
     204  if ($0 != 3)
     205    echo "USAGE: test.mpcorb (version) (options)"
     206    break
     207  end
     208
     209  local Version
     210  $Version = $1
     211  $Options = $2
     212
     213  echo mpcorb_predict moment trange.59396.v2.fits 59375.31398 {200.738197150704-2} {200.738197150704+2} {6.13117829483755-2} {6.13117829483755+2} o9375g0065o.am$Version.fits
     214  exec mpcorb_predict moment trange.59396.v2.fits 59375.31398 {200.738197150704-2} {200.738197150704+2} {6.13117829483755-2} {6.13117829483755+2} o9375g0065o.am$Version.fits
     215  get.camera.matches o9375g0065o.1795013.cm.2420887.smf o9375g0065o.am$Version.fits o9375g0065o.t1/o9375g0065o.t1 am$Version
     216  load.camstats.glob o9375g0065o.t1/o9375g0065o.t1.XY*.am$Version.cam.stf
     217
     218  set dX$Version = Xpsf - Xref
     219  set dY$Version = Ypsf - Yref
     220
     221  set dR$Version = 3600*(Rpsf - Rref)*dcos(Dref)
     222  set dD$Version = 3600*(Dpsf - Dref)
     223
     224  plot -pt cir -sz 2 -op 0.3 dR$Version dD$Version
     225end
     226
     227macro replot.mpcorb
     228  if ($0 != 3)
     229    echo "USAGE: test.mpcorb (version) (color)"
     230    break
     231  end
     232
     233  plot -pt cir -sz 2 -op 0.3 dR$1 dD$1 -c $2
     234end
     235
     236macro load.camstats.glob
     237 if ($0 != 2)
     238   echo "USAGE: load.camstats.glob (glob)"
     239   break
     240 end
     241 
     242 delete -q Rref Dref Mref Xref Yref Q1ref Xpsf Ypsf Rpsf Dpsf Mpsf Q1psf
     243
     244 list name -glob $1
     245 for i 0 $name:n
     246
     247   data $name:$i
     248   read -fits DATA -sizes
     249   if ($table:Ny == 0) continue
     250   read -fits DATA -list-fields -q; list tfields -join allfields; read -fits DATA $allfields
     251
     252   concat RrefSS Rref
     253   concat DrefSS Dref
     254   concat XrefSS Xref
     255   concat YrefSS Yref
     256   concat MrefSS Mref
     257   concat Q1refSS Q1ref
     258   concat X_PSF_found Xpsf
     259   concat Y_PSF_found Ypsf
     260   concat RA_PSF_found Rpsf
     261   concat DEC_PSF_found Dpsf
     262   concat M_PSF_found Mpsf
     263   concat Q1_PSF_found Q1psf
     264 end
     265end
     266
Note: See TracChangeset for help on using the changeset viewer.