IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 27494


Ignore:
Timestamp:
Mar 28, 2010, 11:02:04 AM (16 years ago)
Author:
eugene
Message:

measuring diff stats; adding diff stats and flux in output

Location:
branches/eam_branches/20100225/psModules/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20100225/psModules/src/objects/Makefile.am

    r26162 r27494  
    2222        pmSourceMasks.c \
    2323        pmSourceMoments.c \
     24        pmSourceDiffStats.c \
    2425        pmSourceExtendedPars.c \
    2526        pmSourceUtils.c \
     
    4041        pmSourceIO_CMF_PS1_V1.c \
    4142        pmSourceIO_CMF_PS1_V2.c \
     43        pmSourceIO_CMF_PS1_DV1.c \
    4244        pmSourceIO_MatchedRefs.c \
    4345        pmSourcePlots.c \
     
    7981        pmSource.h \
    8082        pmSourceMasks.h \
     83        pmSourceDiffStats.h \
    8184        pmSourceExtendedPars.h \
    8285        pmSourceUtils.h \
  • branches/eam_branches/20100225/psModules/src/objects/pmGrowthCurveGenerate.c

    r25754 r27494  
    157157
    158158    // measure the fitMag for this model
    159     pmSourcePhotometryModel (&fitMag, model);
     159    pmSourcePhotometryModel (&fitMag, NULL, model);
    160160    growth->fitMag = fitMag;
    161161
  • branches/eam_branches/20100225/psModules/src/objects/pmSource.c

    r26893 r27494  
    4646    psFree(tmp->maskView);
    4747    psFree(tmp->modelFlux);
    48     psFree(tmp->psfFlux);
     48    psFree(tmp->psfImage);
    4949    psFree(tmp->moments);
    5050    psFree(tmp->modelPSF);
     
    5252    psFree(tmp->modelFits);
    5353    psFree(tmp->extpars);
    54     psFree(tmp->blends);
     54    psFree(tmp->moments);
     55    psFree(tmp->diffStats);
    5556    psTrace("psModules.objects", 10, "---- end ----\n");
    5657}
     
    6869    psFree (source->maskView);
    6970    psFree (source->modelFlux);
    70     psFree (source->psfFlux);
     71    psFree (source->psfImage);
    7172
    7273    source->pixels = NULL;
     
    7576    source->maskView = NULL;
    7677    source->modelFlux = NULL;
    77     source->psfFlux = NULL;
     78    source->psfImage = NULL;
    7879    return;
    7980}
     
    103104    source->maskView = NULL;
    104105    source->modelFlux = NULL;
    105     source->psfFlux = NULL;
     106    source->psfImage = NULL;
    106107    source->moments = NULL;
    107108    source->blends = NULL;
     
    113114    source->tmpFlags = 0;
    114115    source->extpars = NULL;
     116    source->diffStats = NULL;
     117
    115118    source->region = psRegionSet(NAN, NAN, NAN, NAN);
    116119    psMemSetDeallocator(source, (psFreeFunc) sourceFree);
    117120
    118121    // default values are NAN
    119     source->psfMag = NAN;
     122    source->psfMag     = NAN;
     123    source->psfFlux    = NAN;
     124    source->psfFluxErr = NAN;
    120125    source->extMag = NAN;
    121126    source->errMag = NAN;
     
    259264        mySource->modelFlux = NULL;
    260265
    261         // drop the old psfFlux pixels and force the user to re-create
    262         psFree (mySource->psfFlux);
    263         mySource->psfFlux = NULL;
     266        // drop the old psfImage pixels and force the user to re-create
     267        psFree (mySource->psfImage);
     268        mySource->psfImage = NULL;
    264269    }
    265270    return extend;
     
    873878
    874879    // if we already have a cached image, re-use that memory
    875     source->psfFlux = psImageCopy (source->psfFlux, source->pixels, PS_TYPE_F32);
    876     psImageInit (source->psfFlux, 0.0);
     880    source->psfImage = psImageCopy (source->psfImage, source->pixels, PS_TYPE_F32);
     881    psImageInit (source->psfImage, 0.0);
    877882
    878883    // in some places (psphotEnsemble), we need a normalized version
    879884    // in others, we just want the model.  which is more commonly used?
    880     // psfFlux always has unity normalization (I0 = 1.0)
    881     pmModelAdd (source->psfFlux, source->maskObj, source->modelPSF, PM_MODEL_OP_FULL | PM_MODEL_OP_NORM, maskVal);
     885    // psfImage always has unity normalization (I0 = 1.0)
     886    pmModelAdd (source->psfImage, source->maskObj, source->modelPSF, PM_MODEL_OP_FULL | PM_MODEL_OP_NORM, maskVal);
    882887    return true;
    883888}
  • branches/eam_branches/20100225/psModules/src/objects/pmSource.h

    r27265 r27494  
    1616#include "pmMoments.h"
    1717#include "pmSourceExtendedPars.h"
     18#include "pmSourceDiffStats.h"
    1819
    1920/// @addtogroup Objects Object Detection / Analysis Functions
     
    6566    psImage *maskView;                  ///< view into global image mask for this object region
    6667    psImage *modelFlux;                 ///< cached copy of the best model for this source
    67     psImage *psfFlux;                   ///< cached copy of the psf model for this source
     68    psImage *psfImage;                   ///< cached copy of the psf model for this source
    6869    pmMoments *moments;                 ///< Basic moments measured for the object.
    6970    pmModel *modelPSF;                  ///< PSF Model fit (parameters and type)
     
    7576    psArray *blends;                    ///< collection of sources thought to be confused with object
    7677    float psfMag;                       ///< calculated from flux in modelPSF
     78    float psfFlux;                      ///< calculated from flux in modelPSF
     79    float psfFluxErr;                   ///< calculated from flux in modelPSF
    7780    float extMag;                       ///< calculated from flux in modelEXT
    7881    float errMag;                       ///< error in psfMag OR extMag (depending on type)
     
    8689    psRegion region;                    ///< area on image covered by selected pixels
    8790    pmSourceExtendedPars *extpars;      ///< extended source parameters
     91    pmSourceDiffStats *diffStats;       ///< extra parameters for difference detections
    8892};
    8993
  • branches/eam_branches/20100225/psModules/src/objects/pmSourceIO.c

    r26893 r27494  
    539539                status &= pmSourcesWrite_CMF_PS1_V2 (file->fits, readout, sources, file->header, outhead, dataname);
    540540            }
     541            if (!strcmp (exttype, "PS1_DV1")) {
     542                status &= pmSourcesWrite_CMF_PS1_DV1 (file->fits, readout, sources, file->header, outhead, dataname);
     543            }
    541544
    542545            if (xsrcname) {
     
    553556                    status &= pmSourcesWrite_CMF_PS1_V2_XSRC (file->fits, sources, xsrcname, recipe);
    554557                }
     558                if (!strcmp (exttype, "PS1_DV1")) {
     559                    status &= pmSourcesWrite_CMF_PS1_DV1_XSRC (file->fits, sources, xsrcname, recipe);
     560                }
    555561            }
    556562            if (xfitname) {
     
    567573                    status &= pmSourcesWrite_CMF_PS1_V2_XFIT (file->fits, sources, xfitname);
    568574                }
     575                if (!strcmp (exttype, "PS1_DV1")) {
     576                    status &= pmSourcesWrite_CMF_PS1_DV1_XFIT (file->fits, sources, xfitname);
     577                }
    569578            }
    570579            psFree (outhead);
     
    10151024                sources = pmSourcesRead_CMF_PS1_V2 (file->fits, hdu->header);
    10161025            }
     1026            if (!strcmp (exttype, "PS1_DV1")) {
     1027                sources = pmSourcesRead_CMF_PS1_DV1 (file->fits, hdu->header);
     1028            }
    10171029
    10181030            if (!pmReadoutReadDetEff(file->fits, readout, deteffname)) {
  • branches/eam_branches/20100225/psModules/src/objects/pmSourceIO.h

    r24694 r27494  
    4343bool pmSourcesWrite_CMF_PS1_V2_XFIT (psFits *fits, psArray *sources, char *extname);
    4444
     45bool pmSourcesWrite_CMF_PS1_DV1 (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname);
     46bool pmSourcesWrite_CMF_PS1_DV1_XSRC (psFits *fits, psArray *sources, char *extname, psMetadata *recipe);
     47bool pmSourcesWrite_CMF_PS1_DV1_XFIT (psFits *fits, psArray *sources, char *extname);
     48
    4549bool pmSource_CMF_WritePHU (const pmFPAview *view, pmFPAfile *file, pmConfig *config);
    4650
     
    5357psArray *pmSourcesRead_CMF_PS1_V1 (psFits *fits, psMetadata *header);
    5458psArray *pmSourcesRead_CMF_PS1_V2 (psFits *fits, psMetadata *header);
     59psArray *pmSourcesRead_CMF_PS1_DV1 (psFits *fits, psMetadata *header);
    5560
    5661bool pmSourcesWritePSFs (psArray *sources, char *filename);
  • branches/eam_branches/20100225/psModules/src/objects/pmSourcePhotometry.c

    r25980 r27494  
    109109        psAssert (isfinite(fluxScale), "how can the flux scale be invalid? source at %d, %d\n", source->peak->x, source->peak->y);
    110110        psAssert (fluxScale > 0.0, "how can the flux scale be negative? source at %d, %d\n", source->peak->x, source->peak->y);
    111         source->psfMag = -2.5*log10(fluxScale * source->modelPSF->params->data.F32[PM_PAR_I0]);
     111        source->psfFlux = fluxScale * source->modelPSF->params->data.F32[PM_PAR_I0];
     112        source->psfFluxErr = fluxScale * source->modelPSF->dparams->data.F32[PM_PAR_I0];
     113        source->psfMag = -2.5*log10(source->psfFlux);
    112114    } else {
    113         status = pmSourcePhotometryModel (&source->psfMag, source->modelPSF);
     115        status = pmSourcePhotometryModel (&source->psfMag, &source->psfFlux, source->modelPSF);
     116        source->psfFluxErr = source->psfFlux * (source->modelPSF->dparams->data.F32[PM_PAR_I0] / source->modelPSF->params->data.F32[PM_PAR_I0]);
    114117    }
    115118
     
    119122        for (int i = 0; i < source->modelFits->n; i++) {
    120123            pmModel *model = source->modelFits->data[i];
    121             status = pmSourcePhotometryModel (&model->mag, model);
     124            status = pmSourcePhotometryModel (&model->mag, NULL, model);
    122125            if (model == source->modelEXT) foundEXT = true;
    123126        }
     
    125128            source->extMag = source->modelEXT->mag;
    126129        } else {
    127             status = pmSourcePhotometryModel (&source->extMag, source->modelEXT);
     130            status = pmSourcePhotometryModel (&source->extMag, NULL, source->modelEXT);
    128131        }
    129132    } else {
    130133        if (source->modelEXT) {
    131             status = pmSourcePhotometryModel (&source->extMag, source->modelEXT);
     134            status = pmSourcePhotometryModel (&source->extMag, NULL, source->modelEXT);
    132135        }
    133136    }
     
    143146    if (mode & PM_SOURCE_PHOT_WEIGHT) {
    144147        pmSourcePixelWeight (&source->pixWeight, model, source->maskObj, maskVal);
     148    }
     149
     150    // measure the contribution of included pixels
     151    if (mode & PM_SOURCE_PHOT_DIFFSTATS) {
     152        pmSourceMeasureDiffStats (source, maskVal);
    145153    }
    146154
     
    217225
    218226// return source model magnitude
    219 bool pmSourcePhotometryModel (float *fitMag, pmModel *model)
    220 {
    221     PS_ASSERT_PTR_NON_NULL(fitMag, false);
    222     if (model == NULL) {
    223         return false;
    224     }
    225 
    226     float fitSum = 0;
    227     *fitMag = NAN;
     227bool pmSourcePhotometryModel (float *fitMag, float *fitFlux, pmModel *model)
     228{
     229    psAssert (fitMag || fitFlux, "at least one of magnitude or flux must be requested (not NULL)");
     230    if (model == NULL) return false;
     231
     232    float mag  = NAN;
     233    float flux = NAN;
    228234
    229235    // measure fitMag
    230     fitSum = model->modelFlux (model->params);
    231     if (fitSum <= 0)
    232         return false;
    233     if (!isfinite(fitSum))
    234         return false;
    235     *fitMag = -2.5*log10(fitSum);
     236    flux = model->modelFlux (model->params);
     237    if (flux > 0) {
     238        mag = -2.5*log10(flux);
     239    }
     240    if (fitMag) {
     241        *fitMag = mag;
     242    }
     243    if (fitFlux) {
     244        *fitFlux = flux;
     245    }
     246
     247    if (flux <= 0) return false;
     248    if (!isfinite(flux)) return false;
    236249
    237250    return (true);
     
    356369
    357370    *pixWeight = validSum / modelSum;
     371    return (true);
     372}
     373
     374# define FLUX_LIMIT 3.0
     375
     376// return source aperture magnitude
     377bool pmSourceMeasureDiffStats (pmSource *source, psImageMaskType maskVal)
     378{
     379    PS_ASSERT_PTR_NON_NULL(source, false);
     380
     381    if (source->diffStats == NULL) {
     382        source->diffStats = pmSourceDiffStatsAlloc();
     383    }
     384
     385    float fGood = 0.0;
     386    float fBad  = 0.0;
     387    int   nGood = 0;
     388    int   nMask = 0;
     389    int   nBad  = 0;
     390   
     391    psImage *flux     = source->pixels;
     392    psImage *variance = source->variance;
     393    psImage *mask     = source->maskObj;
     394
     395    for (int iy = 0; iy < flux->numRows; iy++) {
     396        for (int ix = 0; ix < flux->numCols; ix++) {
     397            if (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & maskVal) {
     398                nMask ++;
     399                continue;
     400            }
     401
     402            float SN = flux->data.F32[iy][ix] / sqrt(variance->data.F32[iy][ix]);
     403
     404            if (SN > +FLUX_LIMIT) {
     405                nGood ++;
     406                fGood += flux->data.F32[iy][ix];
     407            }
     408
     409            if (SN < -FLUX_LIMIT) {
     410                nBad ++;
     411                fBad += flux->data.F32[iy][ix];
     412            }
     413        }
     414    }
     415
     416    source->diffStats->fRatio     = fGood / (fGood + fBad);       
     417    source->diffStats->nRatioBad  = nGood / (nGood + nBad);       
     418    source->diffStats->nRatioMask = nGood / (nGood + nMask);       
     419    source->diffStats->nRatioAll  = nGood / (nGood + nMask + nBad);
     420    source->diffStats->nGood      = nGood;
     421
    358422    return (true);
    359423}
  • branches/eam_branches/20100225/psModules/src/objects/pmSourcePhotometry.h

    r25980 r27494  
    2929
    3030typedef enum {
    31     PM_SOURCE_PHOT_NONE   = 0x0000,
    32     PM_SOURCE_PHOT_GROWTH = 0x0001,
    33     PM_SOURCE_PHOT_APCORR = 0x0002,
    34     PM_SOURCE_PHOT_WEIGHT = 0x0004,
    35     PM_SOURCE_PHOT_INTERP = 0x0008,
     31    PM_SOURCE_PHOT_NONE      = 0x0000,
     32    PM_SOURCE_PHOT_GROWTH    = 0x0001,
     33    PM_SOURCE_PHOT_APCORR    = 0x0002,
     34    PM_SOURCE_PHOT_WEIGHT    = 0x0004,
     35    PM_SOURCE_PHOT_INTERP    = 0x0008,
     36    PM_SOURCE_PHOT_DIFFSTATS = 0x0010,
    3637} pmSourcePhotometryMode;
    3738
    3839bool pmSourcePhotometryModel(
    3940    float *fitMag,                      ///< integrated fit magnitude
     41    float *fitFlux,                     ///< integrated fit magnitude
    4042    pmModel *model                      ///< model used for photometry
    4143);
     
    5456bool pmSourceChisq (pmModel *model, psImage *image, psImage *mask, psImage *weight, psImageMaskType maskVal, const float covarFactor);
    5557
     58bool pmSourceMeasureDiffStats (pmSource *source, psImageMaskType maskVal);
    5659
    5760double pmSourceDataDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor);
  • branches/eam_branches/20100225/psModules/src/psmodules.h

    r26893 r27494  
    115115#include <pmDetections.h>
    116116#include <pmMoments.h>
     117#include <pmSourceExtendedPars.h>
     118#include <pmSourceDiffPars.h>
    117119#include <pmResiduals.h>
    118120#include <pmGrowthCurve.h>
Note: See TracChangeset for help on using the changeset viewer.