IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 24, 2011, 10:09:38 PM (15 years ago)
Author:
eugene
Message:

determine the min kron radius = radius for bright PSF stars; mask interpolation used index instead of pixel coordinates in psImageInterpolate; add minKronRadius to pmSource; change errMag to psfMagErr; in growth curve, avoid perfect int radii (they can be inconsistent on + and - due to float precision; add pmGrowthCurveForSources; psfMagErr is always calculated from psfModel; apply ApTrend to all source psf mags and fluxes (not just psf sources); always use the psfModel for PSF_QF,_PERFECT; use BILINEAR to interpolate for aperture mags (BIQUAD implementation is wrong; apply growth curve to apMag & apFlux for all sources; save GrowthCurve with PSF model and read from PSF model

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20110404/psModules/src/objects/pmSourcePhotometry.c

    r31340 r31361  
    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;
    104100    float SN;
    105     pmModel *model;
    106101
    107102    source->psfMag    = NAN;
    108103    source->extMag    = NAN;
    109     source->errMag    = NAN;
     104    source->psfMagErr = NAN;
    110105    source->apMag     = NAN;
    111106    source->apMagRaw  = NAN;
     
    113108    source->apFluxErr = NAN;
    114109
    115     // we must have a valid model
    116     // XXX allow aperture magnitudes for sources without a model
    117     model = pmSourceGetModel (&isPSF, source);
    118     if (model == NULL) {
    119         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");
    120119        return false;
    121120    }
    122121
    123     // XXX handle negative flux, low-significance
    124     if (model->dparams->data.F32[PM_PAR_I0] > 0) {
    125         SN = fabs(model->params->data.F32[PM_PAR_I0] / model->dparams->data.F32[PM_PAR_I0]);
    126         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;
    127126    } else {
    128127        SN = NAN;
    129         source->errMag = NAN;
    130     }
    131     x = model->params->data.F32[PM_PAR_XPOS];
    132     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];
    133133
    134134    // measure PSF model photometry
    135     // XXX TEST: do not use flux scale
    136     // XXX NOTE: turn this back on?
    137     if (0 && psf->FluxScale) {
    138         // the source peak pixel is guaranteed to be on the image, and only minimally different from the source center
    139         double fluxScale = pmTrend2DEval (psf->FluxScale, (float)source->peak->x, (float)source->peak->y);
    140         psAssert (isfinite(fluxScale), "how can the flux scale be invalid? source at %d, %d\n", source->peak->x, source->peak->y);
    141         psAssert (fluxScale > 0.0, "how can the flux scale be negative? source at %d, %d\n", source->peak->x, source->peak->y);
    142         source->psfFlux = fluxScale * source->modelPSF->params->data.F32[PM_PAR_I0];
    143         source->psfFluxErr = fluxScale * source->modelPSF->dparams->data.F32[PM_PAR_I0];
    144         source->psfMag = -2.5*log10(source->psfFlux);
    145     } else {
    146         status = pmSourcePhotometryModel (&source->psfMag, &source->psfFlux, source->modelPSF);
    147         source->psfFluxErr = source->psfFlux * (source->modelPSF->dparams->data.F32[PM_PAR_I0] / source->modelPSF->params->data.F32[PM_PAR_I0]);
    148     }
     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
    149148
    150149    if (mode == PM_SOURCE_PHOT_PSFONLY) {
     
    152151    }
    153152
     153    // get the EXT model photometry (all EXT models)
    154154    // if we have a collection of model fits, check if one of them is a pointer to modelEXT
    155155    if (source->modelFits) {
     
    172172    }
    173173
    174     // for PSFs, correct both apMag and psfMag to same system, consistent with infinite flux star in aperture RADIUS
    175     // XXX add a flag for "ap_mag is corrected?"
    176     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) {
    177176        // the source peak pixel is guaranteed to be on the image, and only minimally different from the source center
    178177        double apTrend = pmTrend2DEval (psf->ApTrend, (float)source->peak->x, (float)source->peak->y);
     
    182181    }
    183182
    184     // measure the contribution of included pixels
     183    // measure the contribution of included pixels to the PSF model fit
    185184    if (mode & PM_SOURCE_PHOT_WEIGHT) {
    186         pmSourcePixelWeight (source, model, source->maskObj, maskVal, radius);
     185        pmSourcePixelWeight (source, modelPSF, source->maskObj, maskVal, radius);
    187186    }
    188187
     
    218217        y += dy;
    219218
    220         if (!psImageShiftMask(&flux, &mask, source->pixels, source->maskObj, maskVal, dx, dy,
    221                               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)) {
    222222            // Not much we can do about it
    223223            psErrorClear();
     
    233233
    234234    // measure object aperture photometry
    235     status = pmSourcePhotometryAperSource (source, model, flux, variance, mask, maskVal);
     235    status = pmSourcePhotometryAperSource (source, modelPSF, flux, variance, mask, maskVal);
    236236    if (!status) {
    237237        psTrace ("psModules.objects", 3, "fail mag : bad Ap Mag");
     
    242242    // detection limits (esp near bright neighbors)
    243243    source->apMag = source->apMagRaw;
    244     if (isfinite (source->apMag) && isPSF && psf) {
     244    if (isfinite (source->apMag) && psf) {
    245245        if (psf->growth && (mode & PM_SOURCE_PHOT_GROWTH)) {
    246             source->apMag = source->apMagRaw + pmGrowthCurveCorrect (psf->growth, source->apRadius);
    247             // XXX correct the apFlux?
     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);
    248250        }
    249251    }
Note: See TracChangeset for help on using the changeset viewer.