IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.