IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 29230


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

Location:
branches/eam_branches/ipp-20100823
Files:
9 edited

Legend:

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

    r29004 r29230  
    197197        // mask the given aperture and measure the apMag
    198198        psImageKeepCircle (mask, xc, yc, radius, "OR", markVal);
    199         if (!pmSourcePhotometryAper (&apMag, model, pixels, mask, maskVal)) {
     199        if (!pmSourcePhotometryAper (&apMag, NULL, NULL, model, pixels, NULL, mask, maskVal)) {
    200200            psFree (growth);
    201201            psFree (view);
  • branches/eam_branches/ipp-20100823/psModules/src/objects/pmPSFtryFitPSF.c

    r29004 r29230  
    4141#include "pmSourcePhotometry.h"
    4242#include "pmSourceVisual.h"
     43
     44# define DEBUG 1
    4345
    4446// stage 3: Refit with fixed shape parameters.  This function uses the LMM fitting, but could
  • branches/eam_branches/ipp-20100823/psModules/src/objects/pmSource.c

    r29004 r29230  
    132132
    133133    // default values are NAN
    134     source->psfMag     = NAN;
    135     source->psfFlux    = NAN;
    136     source->psfFluxErr = NAN;
    137     source->extMag = NAN;
    138     source->errMag = NAN;
    139     source->apMag  = NAN;
    140     source->sky    = NAN;
    141     source->skyErr = NAN;
    142     source->pixWeightNotBad = NAN;
     134    source->psfMag           = NAN;
     135    source->psfFlux          = NAN;
     136    source->psfFluxErr       = NAN;
     137    source->extMag           = NAN;   
     138    source->errMag           = NAN;
     139    source->apMag            = NAN;
     140    source->apMagRaw         = NAN;
     141    source->apRadius         = NAN;
     142    source->apFlux           = NAN;
     143    source->apFluxErr        = NAN;
     144    source->sky              = NAN;
     145    source->skyErr           = NAN;   
     146    source->pixWeightNotBad  = NAN;
    143147    source->pixWeightNotPoor = NAN;
    144148
    145     source->psfChisq = NAN;
    146     source->crNsigma = NAN;
    147     source->extNsigma = NAN;
     149    source->psfChisq         = NAN;
     150    source->crNsigma         = NAN;
     151    source->extNsigma        = NAN;
    148152
    149153    psTrace("psModules.objects", 10, "---- end ----\n");
  • branches/eam_branches/ipp-20100823/psModules/src/objects/pmSource.h

    r29004 r29230  
    7676    float apMagRaw;                     ///< raw mag in given aperture
    7777    float apRadius;                     ///< radius for aperture magnitude
     78    float apFlux;                       ///< apFlux corresponding to psfMag or extMag (depending on type)
     79    float apFluxErr;                    ///< apFluxErr corresponding to psfMag or extMag (depending on type)
    7880
    7981    float pixWeightNotBad;              ///< PSF-weighted coverage of unmasked (not BAD) pixels
  • branches/eam_branches/ipp-20100823/psModules/src/objects/pmSourceIO_CMF_PS1_DV2.c

    r29124 r29230  
    185185        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_FLUX",    PS_DATA_F32, "PSF fit instrumental magnitude",             source->psfFlux);
    186186        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_FLUX_SIG",PS_DATA_F32, "Sigma of PSF instrumental magnitude",        source->psfFluxErr);
     187
    187188        psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG",           PS_DATA_F32, "magnitude in standard aperture",             source->apMag);
    188         // XXX replace with AP_FLUX (& ERR)? psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG",           PS_DATA_F32, "magnitude in standard aperture",             source->apMag);
    189 
     189        psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG_RAW",       PS_DATA_F32, "magnitude in real aperture",                 source->apMagRaw);
    190190        psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG_RADIUS",    PS_DATA_F32, "radius used for aperture mags",              apRadius);
     191        psMetadataAdd (row, PS_LIST_TAIL, "AP_FLUX",          PS_DATA_F32, "instrumental flux in standard aperture",     source->apFlux);
     192        psMetadataAdd (row, PS_LIST_TAIL, "AP_FLUX_SIG",      PS_DATA_F32, "aperture flux error",                        source->apFluxErr);
     193
    191194        psMetadataAdd (row, PS_LIST_TAIL, "PEAK_FLUX_AS_MAG", PS_DATA_F32, "Peak flux expressed as magnitude",           peakMag);
    192195        psMetadataAdd (row, PS_LIST_TAIL, "CAL_PSF_MAG",      PS_DATA_F32, "PSF Magnitude using supplied calibration",   calMag);
  • 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            }
  • branches/eam_branches/ipp-20100823/psModules/src/objects/pmSourcePhotometry.h

    r29004 r29230  
    4444
    4545bool pmSourcePhotometryAper(
    46     float   *apMag,                     ///< aperture flux magnitude
     46    float *apMag,
     47    float *apFluxOut,
     48    float *apFluxErr,
    4749    pmModel *model,                     ///< model used for photometry
    4850    psImage *image,                     ///< image pixels to be used
     51    psImage *variance,                  ///< variance pixels to be used
     52    psImage *mask,                      ///< mask of pixels to ignore
     53    psImageMaskType maskVal             ///< Value to mask
     54);
     55
     56bool pmSourcePhotometryAperSource(
     57    pmSource *source,                   ///< aperture flux magnitude
     58    pmModel *model,                     ///< model used for photometry
     59    psImage *image,                     ///< image pixels to be used
     60    psImage *variance,                  ///< variance pixels to be used
    4961    psImage *mask,                      ///< mask of pixels to ignore
    5062    psImageMaskType maskVal             ///< Value to mask
  • branches/eam_branches/ipp-20100823/psphot/src/psphotModelTest.c

    r28013 r29230  
    226226    // measure the source mags
    227227    pmSourcePhotometryModel (&fitMag, model);
    228     pmSourcePhotometryAper  (&obsMag, model, source->pixels, source->maskObj, maskVal);
     228    pmSourcePhotometryAper  (&obsMag, NULL, NULL, model, source->pixels, source->variance, source->maskObj, maskVal);
    229229    fprintf (stderr, "ap: %f, fit: %f, apmifit: %f, nIter: %d\n", obsMag, fitMag, obsMag - fitMag, model->nIter);
    230230
  • branches/eam_branches/ipp-20100823/psphot/src/psphotSourceStats.c

    r29004 r29230  
    418418           
    419419            float apMag = NAN;
    420             pmSourcePhotometryAper (&apMag, NULL, source->pixels, source->maskObj, maskVal);
     420            pmSourcePhotometryAper (&apMag, NULL, NULL, NULL, source->pixels, source->variance, source->maskObj, maskVal);
    421421            fprintf (stderr, "apMag: %f, kronMag: %f\n", apMag, -2.5*log10(source->moments->KronFlux));
    422422
Note: See TracChangeset for help on using the changeset viewer.