IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 26, 2012, 11:33:10 AM (14 years ago)
Author:
eugene
Message:

re-enable MODEL_VAR option for linear photometry fit

Location:
trunk/psphot
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot

  • trunk/psphot/test/tap_psphot_varmodel.pro

    r33963 r34086  
    22# -*-sh-*-
    33
    4 # $KAPA = kapa -noX
    5 
    6 # PSF.CONVOLVE : if true, we insert delta functions (and optionally
    7 #                galaxies) and smooth the image with the psf model
    8 #                (uses a GAUSS regardless of the model). Note that
    9 #                PSF.CONVOLVE = T is faster than F, but (a) only
    10 #                allows Gauss models and (b) only yields quantized
    11 #                locations
    12 
    13 # config for ppImage to generate chip, mask, weight
    14 $ppImageConfig = -recipe PPIMAGE PPIMAGE_N
    15 $ppImageConfig = $ppImageConfig -Db BACKGROUND T
    16 $ppImageConfig = $ppImageConfig -Db CHIP.FITS T
    17 $ppImageConfig = $ppImageConfig -Db CHIP.MASK.FITS T
    18 $ppImageConfig = $ppImageConfig -Db CHIP.VARIANCE.FITS T
    19 $ppImageConfig = $ppImageConfig -Db BASE.FITS F
    20 $ppImageConfig = $ppImageConfig -Db VARIANCE.BUILD T
    21 $ppImageConfig = $ppImageConfig -Db PHOTOM F
    22 
    23 # basic options for the these images (filter, location, obstype)
    24 $BaseOptions = -type OBJECT -filter r -skymags 20.86 -ra 270.70 -dec -23.70 -pa 0.0
    25 $BaseOptions = $BaseOptions -Df PSASTRO:DVO.GETSTAR.MAX.RHO 50000.0
    26 
    27 # create an image with fake sources and insert the resulting cmf file into a dvodb
    28 $RefConfig = -camera SIMTEST
    29 $RefConfig = $RefConfig -recipe PPSIM STACKTEST.MAKE
    30 $RefConfig = $RefConfig -D PSASTRO:PSASTRO.CATDIR catdir.ref
    31 $RefConfig = $RefConfig -Db PSF.CONVOLVE F
    32 
    33 # options for the reference image
    34 $RefOptions = $BaseOptions -exptime 100.0
    35 $RefOptions = $RefOptions -seeing 1.0
    36 $RefOptions = $RefOptions -D PSF.MODEL PS_MODEL_GAUSS
    37 $RefOptions = $RefOptions -Df STARS.DENSITY 10.0
    38 $RefOptions = $RefOptions -Df STARS.SIGMA.LIM 0.5
    39 
    40 # basic config for ppSim with randomly distributed stars and NO galaxies
    41 $RealConfig = -camera SIMTEST
    42 $RealConfig = $RealConfig -recipe PPSIM STACKTEST.RUN
    43 $RealConfig = $RealConfig -D PSASTRO:PSASTRO.CATDIR catdir.ref
    44 $RealConfig = $RealConfig -Db STARS.FAKE F
    45 $RealConfig = $RealConfig -Db STARS.REAL T
    46 $RealConfig = $RealConfig -Db MATCH.DENSITY F
    47 $RealConfig = $RealConfig -Db PSF.CONVOLVE F
    48 $RealConfig = $RealConfig -Df STARS.DENSITY 10.0
    49 $RealConfig = $RealConfig -Df STARS.SIGMA.LIM 2.5
    50 $RealConfig = $RealConfig -Db GALAXY.FAKE F
    51 $RealConfig = $RealConfig -Db GALAXY.GRID F
    52 
    53 # options for the repeated images
    54 $RealOptions = $BaseOptions -exptime 30.0
    55  
    56 $ExtraOptions = -D PSF.MODEL PS_MODEL_GAUSS
    57 
    58 # sample alternate options:
    59 # $ppSimOptions = $FakeOptions -D PSF.MODEL PS_MODEL_PS1_V1
    60 # $ppSimOptions = $FakeOptions -Df PSF.ARATIO 1.2
    61 # $ppSimOptions = $FakeOptions -Df PSF.THETA +30.0
    62 # $ppSimOptions = $FakeOptions -D PSF.MODEL PS_MODEL_GAUSS
    63 
    64 list fwhm
    65  1.0
    66  1.1
    67  1.2
    68  1.5
     4# This script includes a set of tests to demonstrate the dependence of the faint-end bias on the weighting scheme
     5# We have 3 weighting schemes :
     6# CONSTANT -- per-pixel weight is fixed (disadvantage: lower S/N, especially for higher sky?)
     7# IMAGE_VAR - per-pixel weight is Poisson from image (disadvantage: faint-end bias)
     8# MODEL_VAR - per-pixel weight is Poisson from model (disadvantage: 2 linear-fit passes)
     9
     10# Functions:
     11#
     12# init  : initialize variables
     13# mkref : generate a fake reference catalog in a DVO database
     14# mkexp : generate a fake exposure from fake catalog and detrend it (saves basename.in.cmf & basename.fits)
     15# runphot : run psphot on an exposure (saves basename.cmf)
     16# ckchip.mags : generate a set of summary plots for the psphot analysis
     17
     18# I would like to produce a grid of tests:
     19# sky (bright, middle, dark)
     20# fwhm (1.0, 1.3, 1.6)
     21# PSF_MODEL input (GAUSS PS1_V1)
     22# PSF_MODEL apply (GAUSS PS1_V1)
     23# variance mode: CONSTANT, IMAGE_VAR, MODEL_VAR
     24
     25macro ppsimtest
     26  data $1
     27  # sf1 : measured flux inserted in image
     28  # sm2 : theoretical magnitude for star
     29  read x 1 y 2 sf1 3 sm2 5 Io 12
     30  set sm1 = -2.5*log(sf1)
     31  set dsm = sm1 - sm2
     32  lim -n 2 sm1 -0.2 0.2; clear; box; plot sm1 dsm
     33end
     34
     35macro go.one
     36  mkdir test
     37
     38  local sky fwhm psf_in psf_out
     39
     40  # mkref creates refimage.* and catdir.ref
     41  file catdir.ref found
     42  if (not($found))
     43    mkref
     44  end
     45
     46  $KAPA = kapa -noX
     47  if (not($?RefConfig)) init
     48
     49  foreach sky 20.0
     50    foreach fwhm 1.0
     51      foreach psf_in PS1_V1
     52
     53        sprintf name "test/test.%02d.%02d.%s" $sky {10*$fwhm} $psf_in
     54        mkexp $name $sky $fwhm $psf_in
     55        data $name.dat
     56        read fluxIn 3 MagPredIn 5
     57        set MagRealIn = -2.5*log(fluxIn)
     58        set dMagIn = MagRealIn - MagPredIn
     59       
     60        foreach psf_out GAUSS PS1_V1
     61          foreach mode CONSTANT IMAGE_VAR MODEL_VAR
     62            runphot $name $name.$psf_out.$mode "-D LINEAR_FIT_VARIANCE_MODE $mode -D PSF_MODEL PS_MODEL_$psf_out"
     63            ckchip.mags $name.in.cmf $name.$psf_out.$mode.cmf $name.$psf_out.$mode 0.0
     64          end
     65        end
     66      end
     67    end
     68  end
    6969end
    7070
    7171macro go
    72 
    7372  mkdir test
    7473
    75   $ExtraOptions = -D PSF.MODEL PS_MODEL_GAUSS
    76   mkexp test/image.00 1.0
    77   $ExtraOptions = -D PSF.MODEL PS_MODEL_PGAUSS
    78   mkexp test/image.01 1.0
    79   $ExtraOptions = -D PSF.MODEL PS_MODEL_PS1_V1
    80   mkexp test/image.02 1.0
     74  local sky fwhm psf_in psf_out
     75
     76  # mkref creates refimage.* and catdir.ref
     77  file catdir.ref found
     78  if (not($found))
     79    mkref
     80  end
     81
     82  $KAPA = kapa -noX
     83  if (not($?RefConfig)) init
     84
     85  foreach sky 19.0 20.0 21.0
     86    foreach fwhm 1.0 1.3 1.6
     87      foreach psf_in GAUSS PS1_V1
     88
     89        sprintf name "test/test.%02d.%02d.%s" $sky {10*$fwhm} $psf_in
     90        # mkexp $name $sky $fwhm $psf_in
     91        data $name.dat
     92        read fluxIn 3 MagPredIn 5
     93        set MagRealIn = -2.5*log(fluxIn)
     94        set dMagIn = MagRealIn - MagPredIn
     95       
     96        foreach psf_out GAUSS PS1_V1
     97          foreach mode CONSTANT IMAGE_VAR MODEL_VAR
     98            # runphot $name $name.$psf_out.$mode "-D LINEAR_FIT_VARIANCE_MODE $mode -D PSF_MODEL PS_MODEL_$psf_out"
     99            ckchip.mags $name.in.cmf $name.$psf_out.$mode.cmf $name.$psf_out.$mode 0.0
     100          end
     101        end
     102      end
     103    end
     104  end
    81105end
    82106
    83107# create a reference database of fake stars to be used by ppSim below
    84108macro mkref
     109  if (not($?RefConfig)) init
     110
    85111  exec rm -rf catdir.ref
    86112  exec rm -f refimage.fits
     
    100126# create a realistic distribution of fake stars, GAUSS PSF
    101127macro mkexp
     128  if ($0 != 5)
     129    echo "USAGE: mkexp basename sky fwhm psf_model"
     130    break
     131  end
     132
     133  local fwhm basename psf_model
     134  $basename = $1
     135  $sky = $2
     136  $fwhm = $3
     137  $psf_model = $4
     138
     139  $ExtraOptions = -D PSF.MODEL PS_MODEL_$psf_model
     140
     141  # create the raw image
     142  echo ppSim -seeing $fwhm -skymags $sky -nx 3000 -ny 3000 $RealConfig $RealOptions $ExtraOptions $basename
     143  exec ppSim -seeing $fwhm -skymags $sky -nx 3000 -ny 3000 $RealConfig $RealOptions $ExtraOptions $basename
     144  exec /bin/mv -f $basename.cmf $basename.in.cmf
     145
     146  # create the chip output
     147  echo ppImage $ppImageConfig -file $basename.fits $basename
     148  exec ppImage $ppImageConfig -file $basename.fits $basename
     149end
     150
     151# create a realistic distribution of fake stars, GAUSS PSF
     152macro mkexp.deep
    102153  if ($0 != 3)
    103154    echo "USAGE: mkexp basename fwhm"
     
    109160  $fwhm = $2
    110161
     162  $RealOptionsDeep = $BaseOptions -exptime 100
     163
    111164  # create the raw image
    112   echo ppSim -seeing $fwhm -nx 3000 -ny 3000 $RealConfig $RealOptions $ExtraOptions $basename
    113   exec ppSim -seeing $fwhm -nx 3000 -ny 3000 $RealConfig $RealOptions $ExtraOptions $basename
     165  echo ppSim -seeing $fwhm -nx 3000 -ny 3000 $RealConfig $RealOptionsDeep $ExtraOptions $basename
     166  exec ppSim -seeing $fwhm -nx 3000 -ny 3000 $RealConfig $RealOptionsDeep $ExtraOptions $basename
     167  exec /bin/mv -f $basename.cmf $basename.in.cmf
     168
     169  # create the chip output
     170  echo ppImage $ppImageConfig -file $basename.fits $basename
     171  exec ppImage $ppImageConfig -file $basename.fits $basename
     172end
     173
     174# create a realistic distribution of fake stars, GAUSS PSF
     175macro mkexp.bright
     176  if ($0 != 3)
     177    echo "USAGE: mkexp basename fwhm"
     178    break
     179  end
     180
     181  local fwhm basename
     182  $basename = $1
     183  $fwhm = $2
     184
     185  # basic options for the these images (filter, location, obstype)
     186  $BaseOptions = -type OBJECT -filter r -skymags 20.0 -ra 270.70 -dec -23.70 -pa 0.0
     187  $BaseOptions = $BaseOptions -Df PSASTRO:DVO.GETSTAR.MAX.RHO 50000.0
     188  $RealOptionsDeep = $BaseOptions -exptime 100
     189
     190  # create the raw image
     191  echo ppSim -seeing $fwhm -nx 3000 -ny 3000 $RealConfig $RealOptionsDeep $ExtraOptions $basename
     192  exec ppSim -seeing $fwhm -nx 3000 -ny 3000 $RealConfig $RealOptionsDeep $ExtraOptions $basename
    114193  exec /bin/mv -f $basename.cmf $basename.in.cmf
    115194
     
    133212  echo psphot -threads 4 -file $basename.ch.fits -mask $basename.ch.mk.fits -variance $basename.ch.wt.fits $outname $options
    134213  exec psphot -threads 4 -file $basename.ch.fits -mask $basename.ch.mk.fits -variance $basename.ch.wt.fits $outname $options
     214end
     215
     216# compare two cmf files with extname Chip.psf
     217# things to compare:
     218# * completeness (which sources in (1) are not detected in (2)
     219# * positions (X_PSF, Y_PSF)
     220# * instrumental psf mags
     221# * position errors (no input errors; use a model?)
     222# * measured FWHM?
     223# * kron mags (fluxes)
     224# * etc, etc
     225macro ckchip.mags
     226  if ($0 != 5)
     227    echo "USAGE: ckchip.mags (raw) (out) (output) (zpt_off)"
     228    break
     229  end
     230
     231list pairs
     232  PSF_INST_MAG_out      M_raw                 PSF_INST_MAG_raw 2 -0.21 0.21 V
     233  AP_MAG_out            M_raw                 PSF_INST_MAG_raw 2 -0.21 0.21 V
     234end
     235
     236  load.cmf $1 Chip.psf raw
     237  load.cmf $2 Chip.psf out
     238
     239  # images generated with convolution will not have the right output positions
     240  set X_raw = int(X_PSF_raw) + 0.5
     241  set Y_raw = int(Y_PSF_raw) + 0.5
     242  set M_raw = PSF_INST_MAG_raw + $4
     243  set K_out = -2.5*log(KRON_FLUX_out)
     244  match2d X_PSF_out Y_PSF_out X_PSF_raw Y_PSF_raw 1.5 -index1 index1 -index2 index2
     245
     246  local i NX NY nx ny N
     247
     248  resize 1000 1000
     249
     250  clear
     251  section a0 0.0 0.0 1.0 0.5
     252  label -fn courier 14;
     253  style -pt 0 -sz 0.4
     254  show.pair 0
     255  reindex ap = AP_MAG_out using index1
     256  set dap = ap - v2
     257  plot -c red -pt 2 -sz 0.5 rv dap
     258
     259  delete -q imag_V dmag_V smag_V Dmag_V dmag_Vraw
     260  for imag -11 -6 0.2
     261    subset dmsub = delta if (rv > $imag) && (rv < $imag + 0.2)
     262    vstat -q dmsub
     263    concat $imag imag_V
     264    concat $MEAN dmag_V
     265    concat $MEDIAN Dmag_V
     266    concat $SIGMA smag_V
     267  end
     268
     269  vstat -q dmag_V
     270  $offset = $MEDIAN
     271  set dmag_V = dmag_V - $offset
     272  set Dmag_V = Dmag_V - $offset
     273
     274  section a1 0.0 0.50 1.0 0.25
     275  lim rv -0.025 0.075; label -fn courier 14; box;
     276  # plot -c black -pt 0 -sz 0.3 MagPredIn dMagIn
     277  plot -c red   -pt 7 -sz 2.0 imag_V dmag_V
     278  plot -c darkgreen -pt 3 -sz 2.0 imag_V Dmag_V
     279  # plot -c gold -pt 4 -sz 2.0 imag_V dmag_Vraw
     280  plot -c blue  -pt 2 -sz 2.0 imag_V smag_V
     281  # label -y "mean (red), median (green), unclipped mean (gold), sigma (blue) of delta"
     282  label -y "mean (red), median (green), sigma (blue) of delta"
     283  sprintf line "OFFSET: %6.3f" $offset
     284  textline -frac 0.1 0.8 -fn courier 24 "$line"
     285
     286  subset dmsub = delta if (rv < -13) && (rv > -16)
     287  vstat -q dmsub
     288  sprintf line "STDEV: %6.3f" $SIGMA
     289  textline -frac 0.1 0.7 -fn courier 24 "$line"
     290
     291
     292  set lChiNorm = log(PSF_CHISQ_out / PSF_NDOF_out)
     293  reindex chi = lChiNorm using index1
     294  section a2 0.0 0.75 1.0 0.25
     295  label -fn courier 14;
     296  lim rv chi; box;
     297  plot -c red -pt 0 -sz 0.5 rv chi
     298
     299  label -y "chisq"
     300  png -name $3.png
     301
     302  # section a1 0.0 0.5 1.0 0.5
     303  # style -pt 0 -sz 0.4
     304  # show.pair 1
     305end
     306
     307macro go.phot
     308 runphot test.00 test.00.varmode.C "-Db SAVE.RESID T -D LINEAR_FIT_VARIANCE_MODE CONSTANT"
     309 runphot test.00 test.00.varmode.I "-Db SAVE.RESID T -D LINEAR_FIT_VARIANCE_MODE IMAGE_VAR"
     310 runphot test.00 test.00.varmode.M "-Db SAVE.RESID T -D LINEAR_FIT_VARIANCE_MODE MODEL_VAR"
     311 runphot test.00 test.00.varmode.S "-Db SAVE.RESID T -D LINEAR_FIT_VARIANCE_MODE MODEL_SKY"
     312end
     313
     314macro go.vars
     315 dev -n varC; ckchip.mags test.00.in.cmf test.00.varmode.C.cmf test.00.varmode.C 0.0
     316 dev -n varI; ckchip.mags test.00.in.cmf test.00.varmode.I.cmf test.00.varmode.I 0.0
     317 dev -n varM; ckchip.mags test.00.in.cmf test.00.varmode.M.cmf test.00.varmode.M 0.0
     318 dev -n varS; ckchip.mags test.00.in.cmf test.00.varmode.S.cmf test.00.varmode.S 0.0
    135319end
    136320
     
    347531    lim rv $word:4 $word:5; box; plot rv delta
    348532  end
    349   label -y '$word:0' -x '$word:2'
     533  $line = '$word:0' - '$word:1'
     534  label -y "$line" -x '$word:2'
    350535end
    351536
     
    637822end
    638823
     824macro init
     825  # config for ppImage to generate chip, mask, weight
     826  $ppImageConfig = -recipe PPIMAGE PPIMAGE_N
     827  $ppImageConfig = $ppImageConfig -Db BACKGROUND T
     828  $ppImageConfig = $ppImageConfig -Db CHIP.FITS T
     829  $ppImageConfig = $ppImageConfig -Db CHIP.MASK.FITS T
     830  $ppImageConfig = $ppImageConfig -Db CHIP.VARIANCE.FITS T
     831  $ppImageConfig = $ppImageConfig -Db BASE.FITS F
     832  $ppImageConfig = $ppImageConfig -Db VARIANCE.BUILD T
     833  $ppImageConfig = $ppImageConfig -Db PHOTOM F
     834 
     835  # basic options for the these images (filter, location, obstype)
     836  $BaseOptions = -type OBJECT -filter r -ra 270.70 -dec -23.70 -pa 0.0
     837  $BaseOptions = $BaseOptions -Df PSASTRO:DVO.GETSTAR.MAX.RHO 50000.0
     838 
     839  # PSF.CONVOLVE : if true, we insert delta functions (and optionally
     840  #                galaxies) and smooth the image with the psf model
     841  #                (uses a GAUSS regardless of the model). Note that
     842  #                PSF.CONVOLVE = T is faster than F, but (a) only
     843  #                allows Gauss models and (b) only yields quantized
     844  #                locations
     845
     846  # create an image with fake sources and insert the resulting cmf file into a dvodb
     847  $RefConfig = -camera SIMTEST
     848  $RefConfig = $RefConfig -recipe PPSIM STACKTEST.MAKE
     849  $RefConfig = $RefConfig -D PSASTRO:PSASTRO.CATDIR catdir.ref
     850  $RefConfig = $RefConfig -Db PSF.CONVOLVE F
     851 
     852  # options for the reference image
     853  $RefOptions = $BaseOptions
     854  $RefOptions = $RefOptions -exptime 100.0
     855  $RefOptions = $RefOptions -seeing 1.0
     856  $RefOptions = $RefOptions -skymags 21.0 
     857  $RefOptions = $RefOptions -D PSF.MODEL PS_MODEL_GAUSS
     858  $RefOptions = $RefOptions -Df STARS.DENSITY 10.0
     859  $RefOptions = $RefOptions -Df STARS.SIGMA.LIM 0.5
     860
     861  # basic config for ppSim with randomly distributed stars and NO galaxies
     862  $RealConfig = -camera SIMTEST
     863  $RealConfig = $RealConfig -recipe PPSIM STACKTEST.RUN
     864  $RealConfig = $RealConfig -D PSASTRO:PSASTRO.CATDIR catdir.ref
     865  $RealConfig = $RealConfig -Db STARS.FAKE F
     866  $RealConfig = $RealConfig -Db STARS.REAL T
     867  $RealConfig = $RealConfig -Db MATCH.DENSITY F
     868  $RealConfig = $RealConfig -Db PSF.CONVOLVE F
     869  $RealConfig = $RealConfig -Df STARS.DENSITY 10.0
     870  $RealConfig = $RealConfig -Df STARS.SIGMA.LIM 1.0
     871  $RealConfig = $RealConfig -Db GALAXY.FAKE F
     872  $RealConfig = $RealConfig -Db GALAXY.GRID F
     873 
     874  # options for the repeated images
     875  $RealOptions = $BaseOptions -exptime 30.0
     876   
     877  # sample alternate options:
     878  # $ppSimOptions = $FakeOptions -D PSF.MODEL PS_MODEL_PS1_V1
     879  # $ppSimOptions = $FakeOptions -Df PSF.ARATIO 1.2
     880  # $ppSimOptions = $FakeOptions -Df PSF.THETA +30.0
     881  # $ppSimOptions = $FakeOptions -D PSF.MODEL PS_MODEL_GAUSS
     882 
     883  list fwhm
     884   1.0
     885   1.1
     886   1.2
     887   1.5
     888  end
     889end
     890
    639891if ($SCRIPT)
    640892  fulltest 4
Note: See TracChangeset for help on using the changeset viewer.