IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 25, 2010, 2:54:22 PM (16 years ago)
Author:
eugene
Message:

merge changes from eam_branches/ipp-20100823

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/objects/pmSourcePhotometry.c

    r29004 r29546  
    6262
    6363/**
    64     this function is used to calculate the three defined source magnitudes:
    65     - apMag  : only if S/N > AP_MIN_SN
    66              : is optionally corrected for curve-of-growth if:
    67         - the source is a STAR (PSF)
    68         - the option is selected (mode & PM_SOURCE_PHOT_GROWTH)
    69     - psfMag : all sources with non-NULL modelPSF
    70              : is optionally corrected for aperture residual if:
    71         - the source is a STAR (PSF)
    72         - the option is selected (mode & PM_SOURCE_PHOT_APCORR)
    73 
    74     - extMag : all sources with non-NULL modelEXT
     64   this function is used to calculate the three defined source magnitudes:
     65   - apMag  : only if S/N > AP_MIN_SN
     66   : is optionally corrected for curve-of-growth if:
     67   - the source is a STAR (PSF)
     68   - the option is selected (mode & PM_SOURCE_PHOT_GROWTH)
     69   - psfMag : all sources with non-NULL modelPSF
     70   : is optionally corrected for aperture residual if:
     71   - the source is a STAR (PSF)
     72   - the option is selected (mode & PM_SOURCE_PHOT_APCORR)
     73
     74   - extMag : all sources with non-NULL modelEXT
    7575**/
    7676
    7777// XXX masked region should be (optionally) elliptical
     78// if mode is PM_SOURCE_PHOT_PSFONLY, we skip all other magnitudes
    7879bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psImageMaskType maskVal, psImageMaskType markVal)
    7980{
     
    8889    pmModel *model;
    8990
    90     source->psfMag = NAN;
    91     source->extMag = NAN;
    92     source->errMag = NAN;
    93     source->apMag  = NAN;
     91    source->psfMag    = NAN;
     92    source->extMag    = NAN;
     93    source->errMag    = NAN;
     94    source->apMag     = NAN;
     95    source->apMagRaw  = NAN;
     96    source->apFlux    = NAN;
     97    source->apFluxErr = NAN;
    9498
    9599    // we must have a valid model
     
    114118    // measure PSF model photometry
    115119    // XXX TEST: do not use flux scale
     120    // XXX NOTE: turn this back on?
    116121    if (0 && psf->FluxScale) {
    117122        // the source peak pixel is guaranteed to be on the image, and only minimally different from the source center
     
    127132    }
    128133
     134    if (mode == PM_SOURCE_PHOT_PSFONLY) {
     135        return true;
     136    }
     137
    129138    // if we have a collection of model fits, check if one of them is a pointer to modelEXT
    130139    if (source->modelFits) {
     
    148157
    149158    // for PSFs, correct both apMag and psfMag to same system, consistent with infinite flux star in aperture RADIUS
     159    // XXX add a flag for "ap_mag is corrected?"
    150160    if ((mode & PM_SOURCE_PHOT_APCORR) && isPSF && psf && psf->ApTrend) {
    151161        // the source peak pixel is guaranteed to be on the image, and only minimally different from the source center
     
    181191    // if we are measuring aperture photometry and applying the growth correction,
    182192    // we need to shift the flux in the selected pixels (but not the mask)
    183     psImage *flux = NULL, *mask = NULL; // Star flux and mask images, to photometer
     193    psImage *flux = NULL;
     194    psImage *variance = NULL;
     195    psImage *mask = NULL; // Star flux and mask images, to photometer
    184196    if (mode & PM_SOURCE_PHOT_INTERP) {
    185197        float dx = 0.5 - x + (int)x;
     
    198210    } else {
    199211        flux = source->pixels;
     212        variance = source->variance;
    200213        mask = source->maskObj;
    201214    }
    202215
    203216    // measure object aperture photometry
    204     status = pmSourcePhotometryAper  (&source->apMagRaw, model, flux, mask, maskVal);
     217    status = pmSourcePhotometryAperSource (source, model, flux, variance, mask, maskVal);
    205218    if (!status) {
    206219        psTrace ("psModules.objects", 3, "fail mag : bad Ap Mag");
     
    214227        if (psf->growth && (mode & PM_SOURCE_PHOT_GROWTH)) {
    215228            source->apMag = source->apMagRaw + pmGrowthCurveCorrect (psf->growth, source->apRadius);
     229            // XXX correct the apFlux?
    216230        }
    217231        if (mode & PM_SOURCE_PHOT_APCORR) {
     
    233247
    234248/*
    235 aprMag' - fitMag = flux*skySat + r^2*rflux*skyBias + ApTrend(x,y)
    236 (aprMag - flux*skySat - r^2*rflux*skyBias) - fitMAg = ApTrend(x,y)
    237 (aprMag - flux*skySat - r^2*rflux*skyBias) = fitMAg + ApTrend(x,y)
     249  aprMag' - fitMag = flux*skySat + r^2*rflux*skyBias + ApTrend(x,y)
     250  (aprMag - flux*skySat - r^2*rflux*skyBias) - fitMAg = ApTrend(x,y)
     251  (aprMag - flux*skySat - r^2*rflux*skyBias) = fitMAg + ApTrend(x,y)
    238252
    239253*/
     
    267281
    268282// return source aperture magnitude
    269 bool pmSourcePhotometryAper (float *apMag, pmModel *model, psImage *image, psImage *mask, psImageMaskType maskVal)
     283bool pmSourcePhotometryAperSource (pmSource *source, pmModel *model, psImage *image, psImage *variance, psImage *mask, psImageMaskType maskVal)
     284{
     285    PS_ASSERT_PTR_NON_NULL(source, false);
     286    PS_ASSERT_PTR_NON_NULL(image, false);
     287    PS_ASSERT_PTR_NON_NULL(mask, false);
     288
     289    if (DO_SKY) {
     290        PS_ASSERT_PTR_NON_NULL(model, false);
     291    }
     292
     293    bool status;
     294    status = pmSourcePhotometryAper(&source->apMagRaw, &source->apFlux, &source->apFluxErr, model, image, variance, mask, maskVal);
     295
     296    return status;
     297}
     298
     299// return source aperture magnitude
     300bool pmSourcePhotometryAper (float *apMag, float *apFluxOut, float *apFluxErr, pmModel *model, psImage *image, psImage *variance, psImage *mask, psImageMaskType maskVal)
    270301{
    271302    PS_ASSERT_PTR_NON_NULL(apMag, false);
     
    277308    }
    278309
    279     float apSum = 0;
    280310    float sky = 0;
    281     *apMag = NAN;
     311    float apFlux = 0;
     312    float apFluxVar = 0;
    282313
    283314    if (DO_SKY) {
    284315        sky = model->params->data.F32[PM_PAR_SKY];
    285     } else {
    286         sky = 0;
    287316    }
    288317
    289318    psF32 **imData = image->data.F32;
    290319    psImageMaskType **mkData = mask->data.PS_TYPE_IMAGE_MASK_DATA;
    291     int nAperPix = 0;
    292 
    293     // measure apMag
     320    psF32 **varData = (variance) ? variance->data.F32 : image->data.F32; // if variance is not supplied, assume gain of 1.0, no read noise
     321
     322    // measure apFlux and apFluxVar, save apMag if not NAN
     323    // XXX note that these fluxes/mags are uncorrected for masked pixels
     324    // XXX raise a bit if the aperture has a masked pixel (not marked)?
    294325    for (int iy = 0; iy < image->numRows; iy++) {
    295326        for (int ix = 0; ix < image->numCols; ix++) {
    296             if (mkData[iy][ix] & maskVal)
    297                 continue;
    298             apSum += imData[iy][ix] - sky;
    299             nAperPix ++;
    300             // fprintf (stderr, "aper: %d %d  %f  %f  %f\n", ix, iy, sky, imData[iy][ix], apSum);
    301         }
    302     }
    303     if (apSum <= 0) {
     327            if (mkData[iy][ix] & maskVal) continue;
     328            apFlux += imData[iy][ix] - sky;
     329            apFluxVar += varData[iy][ix];
     330        }
     331    }
     332    if (apFluxOut) *apFluxOut = apFlux;
     333    if (apFluxErr) *apFluxErr = sqrt(apFluxVar);
     334
     335    if (apFlux <= 0) {
    304336        *apMag = NAN;
    305         return true;
    306     }
    307 
    308     *apMag = -2.5*log10(apSum);
     337    } else {
     338        *apMag = -2.5*log10(apFlux);
     339    }
    309340    return true;
    310341}
     
    419450    }
    420451
     452    // NOTE: until 2010.10.01, these measurements included a 3sigma-per-pixel significance
     453    // this followed what we understood as the definition given to us
     454    // by Armin, but it always seemed a poor idea -- a faint source is unlikely to have any 3sigma pixels.
     455    // changed to remove the per-pixel filter.
     456
    421457    for (int iy = 0; iy < flux->numRows; iy++) {
    422458        for (int ix = 0; ix < flux->numCols; ix++) {
    423459            // only count up the stats in the unmarked region (ie, the aperture)
     460            // skip the marked pixels; these are not relevant
    424461            if (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & markVal) {
    425462                continue;
     
    430467            }
    431468
    432             float SN = flux->data.F32[iy][ix] / sqrt(variance->data.F32[iy][ix]);
    433 
    434             if (SN > +FLUX_LIMIT) {
     469            float value = flux->data.F32[iy][ix];
     470
     471            if (value > 0.0) {
    435472                nGood ++;
    436                 fGood += fabs(flux->data.F32[iy][ix]);
    437             }
    438 
    439             if (SN < -FLUX_LIMIT) {
     473                fGood += fabs(value);
     474            } else {
    440475                nBad ++;
    441                 fBad += fabs(flux->data.F32[iy][ix]);
     476                fBad += fabs(value);
    442477            }
    443478        }
     
    613648
    614649            switch (term) {
    615             case 0:
     650              case 0:
    616651                factor = 1;
    617652                break;
    618             case 1:
     653              case 1:
    619654                factor = xi + Pi->col0;
    620655                break;
    621             case 2:
     656              case 2:
    622657                factor = yi + Pi->row0;
    623658                break;
    624             default:
     659              default:
    625660                psAbort("invalid term for pmSourceWeight");
    626661            }
     
    691726
    692727            switch (term) {
    693             case 0:
     728              case 0:
    694729                factor = 1;
    695730                break;
    696             case 1:
     731              case 1:
    697732                factor = xi + Pi->col0;
    698733                break;
    699             case 2:
     734              case 2:
    700735                factor = yi + Pi->row0;
    701736                break;
    702             default:
     737              default:
    703738                psAbort("invalid term for pmSourceWeight");
    704739            }
Note: See TracChangeset for help on using the changeset viewer.