IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 24, 2010, 2:49:53 PM (16 years ago)
Author:
eugene
Message:

added apFlux and apFluxErr to pmSource; added AP_FLUX, AP_FLUX_SIG to output in CMF_DV2

File:
1 edited

Legend:

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

    r29124 r29230  
    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
     
    8888    pmModel *model;
    8989
    90     source->psfMag = NAN;
    91     source->extMag = NAN;
    92     source->errMag = NAN;
    93     source->apMag  = NAN;
     90    source->psfMag    = NAN;
     91    source->extMag    = NAN;
     92    source->errMag    = NAN;
     93    source->apMag     = NAN;
     94    source->apMagRaw  = NAN;
     95    source->apRadius  = NAN;
     96    source->apFlux    = NAN;
     97    source->apFluxErr = NAN;
    9498
    9599    // we must have a valid model
     
    182186    // if we are measuring aperture photometry and applying the growth correction,
    183187    // we need to shift the flux in the selected pixels (but not the mask)
    184     psImage *flux = NULL, *mask = NULL; // Star flux and mask images, to photometer
     188    psImage *flux = NULL;
     189    psImage *variance = NULL;
     190    psImage *mask = NULL; // Star flux and mask images, to photometer
    185191    if (mode & PM_SOURCE_PHOT_INTERP) {
    186192        float dx = 0.5 - x + (int)x;
     
    199205    } else {
    200206        flux = source->pixels;
     207        variance = source->variance;
    201208        mask = source->maskObj;
    202209    }
    203210
    204211    // measure object aperture photometry
    205     status = pmSourcePhotometryAper  (&source->apMagRaw, model, flux, mask, maskVal);
     212    status = pmSourcePhotometryAperSource (source, model, flux, variance, mask, maskVal);
    206213    if (!status) {
    207214        psTrace ("psModules.objects", 3, "fail mag : bad Ap Mag");
     
    215222        if (psf->growth && (mode & PM_SOURCE_PHOT_GROWTH)) {
    216223            source->apMag = source->apMagRaw + pmGrowthCurveCorrect (psf->growth, source->apRadius);
     224            // XXX correct the apFlux?
    217225        }
    218226        if (mode & PM_SOURCE_PHOT_APCORR) {
     
    234242
    235243/*
    236 aprMag' - fitMag = flux*skySat + r^2*rflux*skyBias + ApTrend(x,y)
    237 (aprMag - flux*skySat - r^2*rflux*skyBias) - fitMAg = ApTrend(x,y)
    238 (aprMag - flux*skySat - r^2*rflux*skyBias) = fitMAg + ApTrend(x,y)
     244  aprMag' - fitMag = flux*skySat + r^2*rflux*skyBias + ApTrend(x,y)
     245  (aprMag - flux*skySat - r^2*rflux*skyBias) - fitMAg = ApTrend(x,y)
     246  (aprMag - flux*skySat - r^2*rflux*skyBias) = fitMAg + ApTrend(x,y)
    239247
    240248*/
     
    268276
    269277// return source aperture magnitude
    270 bool pmSourcePhotometryAper (float *apMag, pmModel *model, psImage *image, psImage *mask, psImageMaskType maskVal)
     278bool pmSourcePhotometryAperSource (pmSource *source, pmModel *model, psImage *image, psImage *variance, psImage *mask, psImageMaskType maskVal)
     279{
     280    PS_ASSERT_PTR_NON_NULL(source, false);
     281    PS_ASSERT_PTR_NON_NULL(image, false);
     282    PS_ASSERT_PTR_NON_NULL(mask, false);
     283
     284    if (DO_SKY) {
     285        PS_ASSERT_PTR_NON_NULL(model, false);
     286    }
     287
     288    bool status;
     289    status = pmSourcePhotometryAper(&source->apMagRaw, &source->apFlux, &source->apFluxErr, model, image, variance, mask, maskVal);
     290
     291    return status;
     292}
     293
     294// return source aperture magnitude
     295bool pmSourcePhotometryAper (float *apMag, float *apFluxOut, float *apFluxErr, pmModel *model, psImage *image, psImage *variance, psImage *mask, psImageMaskType maskVal)
    271296{
    272297    PS_ASSERT_PTR_NON_NULL(apMag, false);
     
    278303    }
    279304
    280     float apSum = 0;
    281305    float sky = 0;
    282     *apMag = NAN;
     306    float apFlux = 0;
     307    float apFluxVar = 0;
    283308
    284309    if (DO_SKY) {
    285310        sky = model->params->data.F32[PM_PAR_SKY];
    286     } else {
    287         sky = 0;
    288311    }
    289312
    290313    psF32 **imData = image->data.F32;
    291314    psImageMaskType **mkData = mask->data.PS_TYPE_IMAGE_MASK_DATA;
    292     int nAperPix = 0;
    293 
    294     // measure apMag
    295     // XXX save the apFlux and apFluxErr
     315    psF32 **varData = (variance) ? variance->data.F32 : image->data.F32; // if variance is not supplied, assume gain of 1.0, no read noise
     316
     317    // measure apFlux and apFluxVar, save apMag if not NAN
    296318    // XXX note that these fluxes/mags are uncorrected for masked pixels
    297319    // XXX raise a bit if the aperture has a masked pixel (not marked)?
    298320    for (int iy = 0; iy < image->numRows; iy++) {
    299321        for (int ix = 0; ix < image->numCols; ix++) {
    300             if (mkData[iy][ix] & maskVal)
    301                 continue;
    302             apSum += imData[iy][ix] - sky;
    303             nAperPix ++;
    304             // fprintf (stderr, "aper: %d %d  %f  %f  %f\n", ix, iy, sky, imData[iy][ix], apSum);
    305         }
    306     }
    307     if (apSum <= 0) {
     322            if (mkData[iy][ix] & maskVal) continue;
     323            apFlux += imData[iy][ix] - sky;
     324            apFluxVar += varData[iy][ix];
     325        }
     326    }
     327    if (apFluxOut) *apFluxOut = apFlux;
     328    if (apFluxErr) *apFluxErr = sqrt(apFluxVar);
     329
     330    if (apFlux <= 0) {
    308331        *apMag = NAN;
    309         return true;
    310     }
    311 
    312     *apMag = -2.5*log10(apSum);
     332    } else {
     333        *apMag = -2.5*log10(apFlux);
     334    }
    313335    return true;
    314336}
     
    617639
    618640            switch (term) {
    619             case 0:
     641              case 0:
    620642                factor = 1;
    621643                break;
    622             case 1:
     644              case 1:
    623645                factor = xi + Pi->col0;
    624646                break;
    625             case 2:
     647              case 2:
    626648                factor = yi + Pi->row0;
    627649                break;
    628             default:
     650              default:
    629651                psAbort("invalid term for pmSourceWeight");
    630652            }
     
    695717
    696718            switch (term) {
    697             case 0:
     719              case 0:
    698720                factor = 1;
    699721                break;
    700             case 1:
     722              case 1:
    701723                factor = xi + Pi->col0;
    702724                break;
    703             case 2:
     725              case 2:
    704726                factor = yi + Pi->row0;
    705727                break;
    706             default:
     728              default:
    707729                psAbort("invalid term for pmSourceWeight");
    708730            }
Note: See TracChangeset for help on using the changeset viewer.