IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 4, 2011, 1:04:41 PM (15 years ago)
Author:
eugene
Message:

updates to pmPeak to better distinguish peak flux versions; updates to visualization; add bits for substantial suspect masking; consolidate assignment of source position and flux based on peak, moments, etc; improve footprint culling process; fix PSF_QF and PSF_QF_PERFECT calculations; fix source model chisq values

Location:
trunk/psModules
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules

    • Property svn:ignore
      •  

        old new  
        2828ChangeLog
        2929psmodules-*.tar.*
         30a.out.dSYM
  • trunk/psModules/src/objects/pmSourceIO_CMF_PS1_DV1.c

    r30621 r31153  
    4949
    5050#include "pmSourceIO.h"
     51#include "pmSourceOutputs.h"
    5152
    5253// panstarrs-style FITS table output (header + table in 1st extension)
     
    6263    PS_ASSERT_PTR_NON_NULL(extname, false);
    6364
    64     int i;
    6565    psArray *table;
    6666    psMetadata *row;
    67     psF32 *PAR, *dPAR;
    68     psEllipseAxes axes;
    69     psF32 xPos, yPos;
    70     psF32 xErr, yErr;
    71     psF32 errMag, chisq, apRadius;
    72     psS32 nPix, nDOF;
    7367
    7468    pmChip *chip = readout->parent->parent;
    75     pmFPA  *fpa  = chip->parent;
    76 
    77     bool status1 = false;
    78     bool status2 = false;
    79     float magOffset = NAN;
    80     float exptime   = psMetadataLookupF32 (&status1, fpa->concepts, "FPA.EXPOSURE");
    81     float zeropt    = psMetadataLookupF32(&status2, fpa->concepts, "FPA.ZP");
    82     if (!isfinite(zeropt)) {
    83         zeropt    = psMetadataLookupF32 (&status2, imageHeader, "ZPT_OBS");
    84     }
    85     if (status1 && status2 && (exptime > 0.0)) {
    86         magOffset = zeropt + 2.5*log10(exptime);
    87     }
    88     float zeroptErr = psMetadataLookupF32 (&status2, imageHeader, "ZPT_ERR");
     69
    8970
    9071    // if the sequence is defined, write these in seq order; otherwise
     
    9475        if (source->seq == -1) {
    9576          // let's write these out in S/N order
    96           sources = psArraySort (sources, pmSourceSortBySN);
     77          sources = psArraySort (sources, pmSourceSortByFlux);
    9778        } else {
    9879          sources = psArraySort (sources, pmSourceSortBySeq);
     
    10081    }
    10182
     83    short nImageOverlap;
     84    float magOffset;
     85    float zeroptErr;
     86    float fwhmMajor;
     87    float fwhmMinor;
     88    pmSourceOutputsCommonValues (&nImageOverlap, &magOffset, &zeroptErr, &fwhmMajor, &fwhmMinor, readout, imageHeader);
     89
    10290    table = psArrayAllocEmpty (sources->n);
    10391
    10492    // we write out PSF-fits for all sources, regardless of quality.  the source flags tell us the state
    10593    // by the time we call this function, all values should be assigned.  let's use asserts to be sure in some cases.
    106     for (i = 0; i < sources->n; i++) {
     94    for (int i = 0; i < sources->n; i++) {
    10795        pmSource *source = (pmSource *) sources->data[i];
    10896
     
    115103        }
    116104
    117         // no difference between PSF and non-PSF model
    118         pmModel *model = source->modelPSF;
    119 
    120         if (model != NULL) {
    121             PAR = model->params->data.F32;
    122             dPAR = model->dparams->data.F32;
    123             xPos = PAR[PM_PAR_XPOS];
    124             yPos = PAR[PM_PAR_YPOS];
    125             if (source->mode & PM_SOURCE_MODE_NONLINEAR_FIT) {
    126               xErr = dPAR[PM_PAR_XPOS];
    127               yErr = dPAR[PM_PAR_YPOS];
    128             } else {
    129               // in linear-fit mode, there is no error on the centroid
    130               xErr = source->peak->dx;
    131               yErr = source->peak->dy;
    132             }
    133             if (isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX])) {
    134                 axes = pmPSF_ModelToAxes (PAR, 20.0);
    135             } else {
    136                 axes.major = NAN;
    137                 axes.minor = NAN;
    138                 axes.theta = NAN;
    139             }
    140             chisq = model->chisq;
    141             nDOF = model->nDOF;
    142             nPix = model->nPix;
    143             apRadius = source->apRadius;
    144             errMag = model->dparams->data.F32[PM_PAR_I0] / model->params->data.F32[PM_PAR_I0];
    145         } else {
    146             xPos = source->peak->xf;
    147             yPos = source->peak->yf;
    148             xErr = source->peak->dx;
    149             yErr = source->peak->dy;
    150             axes.major = NAN;
    151             axes.minor = NAN;
    152             axes.theta = NAN;
    153             chisq = NAN;
    154             nDOF = 0;
    155             nPix = 0;
    156             apRadius = NAN;
    157             errMag = NAN;
    158         }
    159 
    160         float calMag = isfinite(magOffset) ? source->psfMag + magOffset : NAN;
    161         float peakMag = (source->peak->flux > 0) ? -2.5*log10(source->peak->flux) : NAN;
    162         psS16 nImageOverlap = 1;
    163 
    164         psSphere ptSky = {0.0, 0.0, 0.0, 0.0};
    165         float posAngle = 0.0;
    166         float pltScale = 0.0;
    167         pmSourceLocalAstrometry (&ptSky, &posAngle, &pltScale, chip, xPos, yPos);
     105        // set the 'best' values for various output fields:
     106        pmSourceOutputs outputs;
     107        pmSourceOutputsSetValues (&outputs, source, chip, fwhmMajor, fwhmMinor, magOffset);
     108
     109        pmSourceOutputsMoments moments;
     110        pmSourceOutputsSetMoments (&moments, source);
    168111
    169112        pmSourceDiffStats diffStats;
     
    175118        row = psMetadataAlloc ();
    176119        psMetadataAdd (row, PS_LIST_TAIL, "IPP_IDET",         PS_DATA_U32, "IPP detection identifier index",             source->seq);
    177         psMetadataAdd (row, PS_LIST_TAIL, "X_PSF",            PS_DATA_F32, "PSF x coordinate",                           xPos);
    178         psMetadataAdd (row, PS_LIST_TAIL, "Y_PSF",            PS_DATA_F32, "PSF y coordinate",                           yPos);
    179         psMetadataAdd (row, PS_LIST_TAIL, "X_PSF_SIG",        PS_DATA_F32, "Sigma in PSF x coordinate",                  xErr); // XXX this is only measured for non-linear fits
    180         psMetadataAdd (row, PS_LIST_TAIL, "Y_PSF_SIG",        PS_DATA_F32, "Sigma in PSF y coordinate",                  yErr); // XXX this is only measured for non-linear fits
    181         psMetadataAdd (row, PS_LIST_TAIL, "POSANGLE",         PS_DATA_F32, "position angle at source (degrees)",         posAngle*PS_DEG_RAD);
    182         psMetadataAdd (row, PS_LIST_TAIL, "PLTSCALE",         PS_DATA_F32, "plate scale at source (arcsec/pixel)",       pltScale*PS_DEG_RAD*3600.0);
     120        psMetadataAdd (row, PS_LIST_TAIL, "X_PSF",            PS_DATA_F32, "PSF x coordinate",                           outputs.xPos);
     121        psMetadataAdd (row, PS_LIST_TAIL, "Y_PSF",            PS_DATA_F32, "PSF y coordinate",                           outputs.yPos);
     122        psMetadataAdd (row, PS_LIST_TAIL, "X_PSF_SIG",        PS_DATA_F32, "Sigma in PSF x coordinate",                  outputs.xErr); // XXX this is only measured for non-linear fits
     123        psMetadataAdd (row, PS_LIST_TAIL, "Y_PSF_SIG",        PS_DATA_F32, "Sigma in PSF y coordinate",                  outputs.yErr); // XXX this is only measured for non-linear fits
     124        psMetadataAdd (row, PS_LIST_TAIL, "POSANGLE",         PS_DATA_F32, "position angle at source (degrees)",         outputs.posAngle);
     125        psMetadataAdd (row, PS_LIST_TAIL, "PLTSCALE",         PS_DATA_F32, "plate scale at source (arcsec/pixel)",       outputs.pltScale);
    183126        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG",     PS_DATA_F32, "PSF fit instrumental magnitude",             source->psfMag);
    184         psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG_SIG", PS_DATA_F32, "Sigma of PSF instrumental magnitude",        errMag);
     127        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG_SIG", PS_DATA_F32, "Sigma of PSF instrumental magnitude",        source->errMag);
    185128        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_FLUX",    PS_DATA_F32, "PSF fit instrumental magnitude",             source->psfFlux);
    186129        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_FLUX_SIG",PS_DATA_F32, "Sigma of PSF instrumental magnitude",        source->psfFluxErr);
    187130        psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG",           PS_DATA_F32, "magnitude in standard aperture",             source->apMag);
    188         psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG_RADIUS",    PS_DATA_F32, "radius used for aperture mags",              apRadius);
    189         psMetadataAdd (row, PS_LIST_TAIL, "PEAK_FLUX_AS_MAG", PS_DATA_F32, "Peak flux expressed as magnitude",           peakMag);
    190         psMetadataAdd (row, PS_LIST_TAIL, "CAL_PSF_MAG",      PS_DATA_F32, "PSF Magnitude using supplied calibration",   calMag);
     131        psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG_RADIUS",    PS_DATA_F32, "radius used for aperture mags",              outputs.apRadius);
     132        psMetadataAdd (row, PS_LIST_TAIL, "PEAK_FLUX_AS_MAG", PS_DATA_F32, "Peak flux expressed as magnitude",           outputs.peakMag);
     133        psMetadataAdd (row, PS_LIST_TAIL, "CAL_PSF_MAG",      PS_DATA_F32, "PSF Magnitude using supplied calibration",   outputs.calMag);
    191134        psMetadataAdd (row, PS_LIST_TAIL, "CAL_PSF_MAG_SIG",  PS_DATA_F32, "measured scatter of zero point calibration", zeroptErr);
    192         psMetadataAdd (row, PS_LIST_TAIL, "RA_PSF",           PS_DATA_F64, "PSF RA coordinate (degrees)",                ptSky.r*PS_DEG_RAD);
    193         psMetadataAdd (row, PS_LIST_TAIL, "DEC_PSF",          PS_DATA_F64, "PSF DEC coordinate (degrees)",               ptSky.d*PS_DEG_RAD);
     135        psMetadataAdd (row, PS_LIST_TAIL, "RA_PSF",           PS_DATA_F64, "PSF RA coordinate (degrees)",                outputs.ra);
     136        psMetadataAdd (row, PS_LIST_TAIL, "DEC_PSF",          PS_DATA_F64, "PSF DEC coordinate (degrees)",               outputs.dec);
    194137        psMetadataAdd (row, PS_LIST_TAIL, "SKY",              PS_DATA_F32, "Sky level",                                  source->sky);
    195138        psMetadataAdd (row, PS_LIST_TAIL, "SKY_SIGMA",        PS_DATA_F32, "Sigma of sky level",                         source->skyErr);
    196139
    197         psMetadataAdd (row, PS_LIST_TAIL, "PSF_CHISQ",        PS_DATA_F32, "Chisq of PSF-fit",                           chisq);
     140        psMetadataAdd (row, PS_LIST_TAIL, "PSF_CHISQ",        PS_DATA_F32, "Chisq of PSF-fit",                           outputs.chisq);
    198141        psMetadataAdd (row, PS_LIST_TAIL, "CR_NSIGMA",        PS_DATA_F32, "Nsigma deviations from PSF to CF",           source->crNsigma);
    199142        psMetadataAdd (row, PS_LIST_TAIL, "EXT_NSIGMA",       PS_DATA_F32, "Nsigma deviations from PSF to EXT",          source->extNsigma);
    200143
    201         psMetadataAdd (row, PS_LIST_TAIL, "PSF_MAJOR",        PS_DATA_F32, "PSF width (major axis)",                     axes.major);
    202         psMetadataAdd (row, PS_LIST_TAIL, "PSF_MINOR",        PS_DATA_F32, "PSF width (minor axis)",                     axes.minor);
    203         psMetadataAdd (row, PS_LIST_TAIL, "PSF_THETA",        PS_DATA_F32, "PSF orientation angle",                      axes.theta);
     144        psMetadataAdd (row, PS_LIST_TAIL, "PSF_MAJOR",        PS_DATA_F32, "PSF width (major axis)",                     outputs.psfMajor);
     145        psMetadataAdd (row, PS_LIST_TAIL, "PSF_MINOR",        PS_DATA_F32, "PSF width (minor axis)",                     outputs.psfMinor);
     146        psMetadataAdd (row, PS_LIST_TAIL, "PSF_THETA",        PS_DATA_F32, "PSF orientation angle",                      outputs.psfTheta);
    204147        psMetadataAdd (row, PS_LIST_TAIL, "PSF_QF",           PS_DATA_F32, "PSF coverage/quality factor",                source->pixWeightNotBad);
    205         psMetadataAdd (row, PS_LIST_TAIL, "PSF_NDOF",         PS_DATA_S32, "degrees of freedom",                         nDOF);
    206         psMetadataAdd (row, PS_LIST_TAIL, "PSF_NPIX",         PS_DATA_S32, "number of pixels in fit",                    nPix);
    207 
    208         // distinguish moments measure from window vs S/N > XX ??
    209         float mxx = source->moments ? source->moments->Mxx : NAN;
    210         float mxy = source->moments ? source->moments->Mxy : NAN;
    211         float myy = source->moments ? source->moments->Myy : NAN;
    212         psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_XX",       PS_DATA_F32, "second moments (X^2)",                      mxx);
    213         psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_XY",       PS_DATA_F32, "second moments (X*Y)",                      mxy);
    214         psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_YY",       PS_DATA_F32, "second moments (Y*Y)",                      myy);
    215 
    216         psMetadataAdd (row, PS_LIST_TAIL, "DIFF_NPOS",        PS_DATA_S32, "nPos (n pix > 3 sigma)",                    diffStats.nGood);
    217         psMetadataAdd (row, PS_LIST_TAIL, "DIFF_FRATIO",      PS_DATA_F32, "fPos / (fPos + fNeg)",                      diffStats.fRatio);
    218         psMetadataAdd (row, PS_LIST_TAIL, "DIFF_NRATIO_BAD",  PS_DATA_F32, "nPos / (nPos + nNeg)",                      diffStats.nRatioBad);
    219         psMetadataAdd (row, PS_LIST_TAIL, "DIFF_NRATIO_MASK", PS_DATA_F32, "nPos / (nPos + nMask)",                     diffStats.nRatioMask);
    220         psMetadataAdd (row, PS_LIST_TAIL, "DIFF_NRATIO_ALL",  PS_DATA_F32, "nPos / (nGood + nMask + nBad)",             diffStats.nRatioAll);
     148        psMetadataAdd (row, PS_LIST_TAIL, "PSF_NDOF",         PS_DATA_S32, "degrees of freedom",                         outputs.nDOF);
     149        psMetadataAdd (row, PS_LIST_TAIL, "PSF_NPIX",         PS_DATA_S32, "number of pixels in fit",                    outputs.nPix);
     150
     151        psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_XX",       PS_DATA_F32, "second moments (X^2)",                       moments.Mxx);
     152        psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_XY",       PS_DATA_F32, "second moments (X*Y)",                       moments.Mxy);
     153        psMetadataAdd (row, PS_LIST_TAIL, "MOMENTS_YY",       PS_DATA_F32, "second moments (Y*Y)",                       moments.Myy);
     154
     155        psMetadataAdd (row, PS_LIST_TAIL, "DIFF_NPOS",        PS_DATA_S32, "nPos (n pix > 3 sigma)",                     diffStats.nGood);
     156        psMetadataAdd (row, PS_LIST_TAIL, "DIFF_FRATIO",      PS_DATA_F32, "fPos / (fPos + fNeg)",                       diffStats.fRatio);
     157        psMetadataAdd (row, PS_LIST_TAIL, "DIFF_NRATIO_BAD",  PS_DATA_F32, "nPos / (nPos + nNeg)",                       diffStats.nRatioBad);
     158        psMetadataAdd (row, PS_LIST_TAIL, "DIFF_NRATIO_MASK", PS_DATA_F32, "nPos / (nPos + nMask)",                      diffStats.nRatioMask);
     159        psMetadataAdd (row, PS_LIST_TAIL, "DIFF_NRATIO_ALL",  PS_DATA_F32, "nPos / (nGood + nMask + nBad)",              diffStats.nRatioAll);
    221160
    222161        psMetadataAdd (row, PS_LIST_TAIL, "FLAGS",            PS_DATA_U32, "psphot analysis flags",                      source->mode);
     
    331270        // recreate the peak to match (xPos, yPos) +/- (xErr, yErr)
    332271        source->peak = pmPeakAlloc(PAR[PM_PAR_XPOS], PAR[PM_PAR_YPOS], peakFlux, PM_PEAK_LONE);
    333         source->peak->flux = peakFlux;
     272        source->peak->rawFlux = peakFlux;
     273        source->peak->smoothFlux = peakFlux;
    334274        source->peak->xf   = PAR[PM_PAR_XPOS]; // more accurate position
    335275        source->peak->yf   = PAR[PM_PAR_YPOS]; // more accurate position
    336276        source->peak->dx   = dPAR[PM_PAR_XPOS];
    337277        source->peak->dy   = dPAR[PM_PAR_YPOS];
    338         if (isfinite (source->errMag) && (source->errMag > 0.0)) {
    339           source->peak->SN = 1.0 / source->errMag;
    340         } else {
    341           source->peak->SN = sqrt(source->peak->flux); // an alternate proxy: various functions sort by peak S/N
    342         }
    343278
    344279        source->pixWeightNotBad = psMetadataLookupF32 (&status, row, "PSF_QF");
     
    353288
    354289        source->moments = pmMomentsAlloc ();
     290        source->moments->Mx = source->peak->xf; // we don't have both Mx,My and xf,yf in the cmf
     291        source->moments->My = source->peak->yf; // we don't have both Mx,My and xf,yf in the cmf
     292
    355293        source->moments->Mxx = psMetadataLookupF32 (&status, row, "MOMENTS_XX");
    356294        source->moments->Mxy = psMetadataLookupF32 (&status, row, "MOMENTS_XY");
     
    395333
    396334    // let's write these out in S/N order
    397     sources = psArraySort (sources, pmSourceSortBySN);
     335    sources = psArraySort (sources, pmSourceSortByFlux);
    398336
    399337    table = psArrayAllocEmpty (sources->n);
     
    568506
    569507    // let's write these out in S/N order
    570     sources = psArraySort (sources, pmSourceSortBySN);
     508    sources = psArraySort (sources, pmSourceSortByFlux);
    571509
    572510    // we are writing one row per model; we need to write out same number of columns for each row: find the max Nparams
Note: See TracChangeset for help on using the changeset viewer.