IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 6, 2011, 1:56:22 PM (15 years ago)
Author:
watersc1
Message:

merge from trunk before working on new stacking code

Location:
branches/czw_branch/20110406
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20110406

  • branches/czw_branch/20110406/psModules/src/objects/pmSourcePhotometry.c

    r31153 r31606  
    8282   - apMag  : only if S/N > AP_MIN_SN
    8383   : is optionally corrected for curve-of-growth if:
    84    - the source is a STAR (PSF)
    8584   - the option is selected (mode & PM_SOURCE_PHOT_GROWTH)
    8685   - psfMag : all sources with non-NULL modelPSF
    8786   : is optionally corrected for aperture residual if:
    88    - the source is a STAR (PSF)
    8987   - the option is selected (mode & PM_SOURCE_PHOT_APCORR)
    90 
    9188   - extMag : all sources with non-NULL modelEXT
    9289**/
     
    10097
    10198    int status = false;
    102     bool isPSF;
    10399    float x, y;
    104     float rflux;
    105100    float SN;
    106     pmModel *model;
    107101
    108102    source->psfMag    = NAN;
    109103    source->extMag    = NAN;
    110     source->errMag    = NAN;
     104    source->psfMagErr = NAN;
    111105    source->apMag     = NAN;
    112106    source->apMagRaw  = NAN;
     
    114108    source->apFluxErr = NAN;
    115109
    116     // we must have a valid model
    117     // XXX allow aperture magnitudes for sources without a model
    118     model = pmSourceGetModel (&isPSF, source);
    119     if (model == NULL) {
    120         psTrace ("psModules.objects", 3, "fail mag : no valid model");
     110    // XXXXXX review:
     111    // Select the 'best' model -- this is used for PSF_QF,_PERFECT & ???. isPSF is true if this
     112    // object is a PSF (not extended).  We must have a valid model.  XXX NOTE: allow aperture
     113    // magnitudes for sources without a model
     114
     115    // select the psf model
     116    pmModel *modelPSF = source->modelPSF;
     117    if (modelPSF == NULL) {
     118        psTrace ("psModules.objects", 3, "fail mag : no valid PSF model");
    121119        return false;
    122120    }
    123121
    124     // XXX handle negative flux, low-significance
    125     if (model->dparams->data.F32[PM_PAR_I0] > 0) {
    126         SN = fabs(model->params->data.F32[PM_PAR_I0] / model->dparams->data.F32[PM_PAR_I0]);
    127         source->errMag = 1.0 / SN;
     122    // get the error on the PSF model magnitude
     123    if (modelPSF->dparams->data.F32[PM_PAR_I0] > 0) {
     124        SN = fabs(modelPSF->params->data.F32[PM_PAR_I0] / modelPSF->dparams->data.F32[PM_PAR_I0]);
     125        source->psfMagErr = 1.0 / SN;
    128126    } else {
    129127        SN = NAN;
    130         source->errMag = NAN;
    131     }
    132     x = model->params->data.F32[PM_PAR_XPOS];
    133     y = model->params->data.F32[PM_PAR_YPOS];
     128        source->psfMagErr = NAN;
     129    }
     130    // the source position is used to recenter the aperture for ap photometry
     131    x = modelPSF->params->data.F32[PM_PAR_XPOS];
     132    y = modelPSF->params->data.F32[PM_PAR_YPOS];
    134133
    135134    // measure PSF model photometry
    136     // XXX TEST: do not use flux scale
    137     // XXX NOTE: turn this back on?
    138     if (0 && psf->FluxScale) {
    139         // the source peak pixel is guaranteed to be on the image, and only minimally different from the source center
    140         double fluxScale = pmTrend2DEval (psf->FluxScale, (float)source->peak->x, (float)source->peak->y);
    141         psAssert (isfinite(fluxScale), "how can the flux scale be invalid? source at %d, %d\n", source->peak->x, source->peak->y);
    142         psAssert (fluxScale > 0.0, "how can the flux scale be negative? source at %d, %d\n", source->peak->x, source->peak->y);
    143         source->psfFlux = fluxScale * source->modelPSF->params->data.F32[PM_PAR_I0];
    144         source->psfFluxErr = fluxScale * source->modelPSF->dparams->data.F32[PM_PAR_I0];
    145         source->psfMag = -2.5*log10(source->psfFlux);
    146     } else {
    147         status = pmSourcePhotometryModel (&source->psfMag, &source->psfFlux, source->modelPSF);
    148         source->psfFluxErr = source->psfFlux * (source->modelPSF->dparams->data.F32[PM_PAR_I0] / source->modelPSF->params->data.F32[PM_PAR_I0]);
    149     }
     135    status = pmSourcePhotometryModel (&source->psfMag, &source->psfFlux, modelPSF);
     136    source->psfFluxErr = source->psfFlux * source->psfMagErr;
     137
     138# if (0)
     139    // XXX NOTE: old code to use the flux scale.  test & turn this back on?  if so, need to save with psf model
     140    // the source peak pixel is guaranteed to be on the image, and only minimally different from the source center
     141    double fluxScale = pmTrend2DEval (psf->FluxScale, (float)source->peak->x, (float)source->peak->y);
     142    psAssert (isfinite(fluxScale), "how can the flux scale be invalid? source at %d, %d\n", source->peak->x, source->peak->y);
     143    psAssert (fluxScale > 0.0, "how can the flux scale be negative? source at %d, %d\n", source->peak->x, source->peak->y);
     144    source->psfFlux = fluxScale * modelPSF->params->data.F32[PM_PAR_I0];
     145    source->psfFluxErr = fluxScale * modelPSF->dparams->data.F32[PM_PAR_I0];
     146    source->psfMag = -2.5*log10(source->psfFlux);
     147# endif
    150148
    151149    if (mode == PM_SOURCE_PHOT_PSFONLY) {
     
    153151    }
    154152
     153    // get the EXT model photometry (all EXT models)
    155154    // if we have a collection of model fits, check if one of them is a pointer to modelEXT
    156155    if (source->modelFits) {
     
    173172    }
    174173
    175     // for PSFs, correct both apMag and psfMag to same system, consistent with infinite flux star in aperture RADIUS
    176     // XXX add a flag for "ap_mag is corrected?"
    177     if ((mode & PM_SOURCE_PHOT_APCORR) && isPSF && psf && psf->ApTrend) {
     174    // Correct psfMag to match aperture magnitude system (NOTE : Growth curve is already applied to ApTrend)
     175    if ((mode & PM_SOURCE_PHOT_APCORR) && psf && psf->ApTrend) {
    178176        // the source peak pixel is guaranteed to be on the image, and only minimally different from the source center
    179177        double apTrend = pmTrend2DEval (psf->ApTrend, (float)source->peak->x, (float)source->peak->y);
    180178        source->psfMag += apTrend;
    181     }
    182 
    183     // measure the contribution of included pixels
     179        source->psfFlux *= pow(10.0, -0.4*apTrend);
     180        source->psfFluxErr *= pow(10.0, -0.4*apTrend);
     181    }
     182
     183    // measure the contribution of included pixels to the PSF model fit
    184184    if (mode & PM_SOURCE_PHOT_WEIGHT) {
    185         pmSourcePixelWeight (source, model, source->maskObj, maskVal, radius);
     185        pmSourcePixelWeight (source, modelPSF, source->maskObj, maskVal, radius);
    186186    }
    187187
     
    217217        y += dy;
    218218
    219         if (!psImageShiftMask(&flux, &mask, source->pixels, source->maskObj, maskVal, dx, dy,
    220                               NAN, 0xff, PS_INTERPOLATE_BIQUADRATIC)) {
     219        // if (!psImageShiftMask(&flux, &mask, source->pixels, source->maskObj, maskVal, dx, dy, NAN, 0xff, PS_INTERPOLATE_LANCZOS2)) {
     220        // if (!psImageShiftMask(&flux, &mask, source->pixels, source->maskObj, maskVal, dx, dy, NAN, 0xff, PS_INTERPOLATE_BIQUADRATIC)) {
     221        if (!psImageShiftMask(&flux, &mask, source->pixels, source->maskObj, maskVal, dx, dy, NAN, 0xff, PS_INTERPOLATE_BILINEAR)) {
    221222            // Not much we can do about it
    222223            psErrorClear();
     
    232233
    233234    // measure object aperture photometry
    234     status = pmSourcePhotometryAperSource (source, model, flux, variance, mask, maskVal);
     235    status = pmSourcePhotometryAperSource (source, modelPSF, flux, variance, mask, maskVal);
    235236    if (!status) {
    236237        psTrace ("psModules.objects", 3, "fail mag : bad Ap Mag");
     
    241242    // detection limits (esp near bright neighbors)
    242243    source->apMag = source->apMagRaw;
    243     if (isfinite (source->apMag) && isPSF && psf) {
     244    if (isfinite (source->apMag) && psf) {
    244245        if (psf->growth && (mode & PM_SOURCE_PHOT_GROWTH)) {
    245             source->apMag = source->apMagRaw + pmGrowthCurveCorrect (psf->growth, source->apRadius);
    246             // XXX correct the apFlux?
    247         }
    248         if (mode & PM_SOURCE_PHOT_APCORR) {
    249             // XXX this should be removed -- we no longer fit for the 'sky bias'
    250             // XXX is this happening???
    251             rflux   = pow (10.0, 0.4*source->psfMag);
    252             psAssert (psf->skyBias == 0.0, "sky bias not 0");
    253             psAssert (psf->skySat == 0.0, "sky sat not 0");
    254             source->apMag -= PS_SQR(source->apRadius)*rflux * psf->skyBias + psf->skySat / rflux;
     246            float apOffset = pmGrowthCurveCorrect (psf->growth, source->apRadius);
     247            source->apMag = source->apMagRaw + apOffset;
     248            source->apFlux *= pow(10.0, -0.4*apOffset);
     249            source->apFluxErr *= pow(10.0, -0.4*apOffset);
    255250        }
    256251    }
     
    309304
    310305    bool status;
    311     status = pmSourcePhotometryAper(&source->apMagRaw, &source->apFlux, &source->apFluxErr, model, image, variance, mask, maskVal);
    312 
     306    int nPix = 0;
     307    status = pmSourcePhotometryAper(&nPix, &source->apMagRaw, &source->apFlux, &source->apFluxErr, model, image, variance, mask, maskVal);
     308    if (status) {
     309        source->mode |= PM_SOURCE_MODE_AP_MAGS;
     310    }
    313311    return status;
    314312}
    315313
    316314// return source aperture magnitude
    317 bool pmSourcePhotometryAper (float *apMag, float *apFluxOut, float *apFluxErr, pmModel *model, psImage *image, psImage *variance, psImage *mask, psImageMaskType maskVal)
     315bool pmSourcePhotometryAper (int *nPixOut, float *apMag, float *apFluxOut, float *apFluxErr, pmModel *model, psImage *image, psImage *variance, psImage *mask, psImageMaskType maskVal)
    318316{
    319317    PS_ASSERT_PTR_NON_NULL(apMag, false);
     
    328326    float apFlux = 0;
    329327    float apFluxVar = 0;
     328    int nPix = 0;
    330329
    331330    if (DO_SKY) {
     
    345344            apFlux += imData[iy][ix] - sky;
    346345            apFluxVar += varData[iy][ix];
    347         }
    348     }
     346            nPix ++;
     347        }
     348    }
     349   
    349350    if (apFluxOut) *apFluxOut = apFlux;
    350351    if (apFluxErr) *apFluxErr = sqrt(fabs(apFluxVar));
     352    if (nPixOut) *nPixOut = nPix;
    351353
    352354    if (apFlux <= 0) {
     
    412414    psImageMaskType maskBad = maskVal;
    413415    maskBad &= ~maskSuspect;
     416
     417    psImageMaskType maskPoor = maskVal | maskSuspect;
    414418
    415419    // measure modelSum and validSum.  this function is applied to a sources' subimage.  the
     
    446450
    447451            // count pixels which are masked with an mask bit (bad or poor)
    448             if (!(mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & maskVal)) {
     452            if (!(mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & maskPoor)) {
    449453                notPoorSum += value;
    450454            }
     
    487491
    488492    if (isfinite(source->pixWeightNotBad) && isfinite(source->pixWeightNotPoor)) {
    489         psAssert (source->pixWeightNotBad <= source->pixWeightNotPoor, "error: all bad pixels should also be poor");
     493        psAssert (source->pixWeightNotPoor <= source->pixWeightNotBad, "error: all bad pixels should also be poor");
    490494    }
    491495
Note: See TracChangeset for help on using the changeset viewer.