IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 20, 2010, 1:14:11 PM (16 years ago)
Author:
eugene
Message:

Many changes:

  • psphot-related issues

1) added a new feature to psLib/src/fft/psImageFFT to allow for a pre-FFTed kernel generated for a specific image dimension which can then be applied to an arbitrary number of images for convolution -- this avoids the kernel FFT for every image convolution.
2) updated the psMinimizeLMM to include 2 levels of tolerance: minTol and maxTol: if the minimization reaches minTol, it stops. if it only reaches maxTol within maxIter, it stops and is considered successful, if it fails to reach maxTol, then it fails. This allows us to accept fits that are actually acceptable (within error) even if they are not as close as ideally possible.
3) add new stat: psfWeightNotPoor (vs psfWeightNotBad) : the first gives the fraction of psf-weighted unmasked pixels considering any mask bits (except the internal 'mark' bit), while the former considers only 'bad' mask bits -- these are written to QF_PSF and QF_PSF_PERFECT in the CMF files.
4) define user-set parameters for max and min valid flux in the linear fit analysis: Note this was the cause of the non-negative fluxes in forced photometry -- the min limit was hard-wired to 0.0.
5) significance image is now constructed as (image + (image/1000)2) / sqrt(variance) so that bright sources have well-defined peaks (other wise, they become somewhat flat-topped as image = sqrt(variance), leading to ill-defined peaks).
6) modification of the visualization functions to accept facility and level values akin to psTrace
7) modification of the source fitting APIs to allow thread- and source- independent fit options (iterations, tolerances, etc)
8) use Kron magnitude as test for source size (CR vs EXT) instead of PSF-based aperture
9) set a min systematic error in the aperture mags when used for size classification significance
10) threaded the psf-convolved model (PCM) fitting process (extended source fits)
11) for extended sources, adjust the radius based on the footprint and re-calculate moments for guess; save the psf-based moments for output in psf table
12) for Sersic fitting, choose the best index with a grid search using only a few iterations; iterate fully on the selected value.
13) same for Sersic fitting using the PCM fitting process
14) fixed a bug in which the PSF candidate stars which failed in the psf fitting were not correctly unmarked as being PSF stars
15) define galaxy fit radius based on sky stdev (global, not local)
16) move the PCM code to psModules
17) save and report the raw aperture mag in addition to the curve-of-growth corrected one (PS1_V3)
18) save and report the Kron parameters and higher-order moments
19) some psModule header reorganization for code clarity
20) fixed a bug in which the diff stats were counting 'marked' pixels (outside area of interest) as 'masked'.
21) save the radial profile aperture sizes in the headers
22) better guess for Sersic parameters based on moments (requires setting the functional form so that the scale length is right)

  • ppSub-related:

1) ensure masked pixels are NANed in output diff image
2) add code to flag detections if they have bright positive neighbors (+ output of these in PS1_DV2)
3) define separate penalties for each image (based on their fwhm values) (this requires the penalties to be calculated later in the code).
4) define separate apertures for each image for flux normalization
5) choose aperture based on curve-of-growth (was based on fixed fraction of full aperture flux, and thus noisy)
6) some fine tuning of the penalty factor (this still seems arbitrary, and results are somewhat sensitive to the right value)

Location:
trunk/psModules
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules

    • Property svn:mergeinfo deleted
  • trunk/psModules/src/objects/pmSourcePhotometry.c

    r28517 r29004  
    2222#include "pmFPA.h"
    2323#include "pmFPAMaskWeight.h"
     24
     25#include "pmTrend2D.h"
     26#include "pmResiduals.h"
     27#include "pmGrowthCurve.h"
    2428#include "pmSpan.h"
     29#include "pmFootprintSpans.h"
    2530#include "pmFootprint.h"
    2631#include "pmPeaks.h"
    2732#include "pmMoments.h"
    28 #include "pmGrowthCurve.h"
    29 #include "pmResiduals.h"
    30 #include "pmTrend2D.h"
     33#include "pmModelFuncs.h"
     34#include "pmModel.h"
     35#include "pmModelUtils.h"
     36#include "pmModelClass.h"
     37#include "pmSourceMasks.h"
     38#include "pmSourceExtendedPars.h"
     39#include "pmSourceDiffStats.h"
     40#include "pmSource.h"
     41#include "pmSourceFitModel.h"
    3142#include "pmPSF.h"
    32 #include "pmModel.h"
    33 #include "pmSource.h"
    34 #include "pmModelClass.h"
     43#include "pmPSFtry.h"
     44
    3545#include "pmSourcePhotometry.h"
    3646
     
    6676
    6777// XXX masked region should be (optionally) elliptical
    68 bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psImageMaskType maskVal)
     78bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psImageMaskType maskVal, psImageMaskType markVal)
    6979{
    7080    PS_ASSERT_PTR_NON_NULL(source, false);
     
    122132        for (int i = 0; i < source->modelFits->n; i++) {
    123133            pmModel *model = source->modelFits->data[i];
     134            if (model->flags & PM_MODEL_STATUS_BADARGS) continue;
    124135            status = pmSourcePhotometryModel (&model->mag, NULL, model);
    125136            if (model == source->modelEXT) foundEXT = true;
     
    145156    // measure the contribution of included pixels
    146157    if (mode & PM_SOURCE_PHOT_WEIGHT) {
    147         pmSourcePixelWeight (&source->pixWeight, model, source->maskObj, maskVal);
     158        pmSourcePixelWeight (&source->pixWeightNotBad, &source->pixWeightNotPoor, model, source->maskObj, maskVal, markVal);
    148159    }
    149160
    150161    // measure the contribution of included pixels
    151162    if (mode & PM_SOURCE_PHOT_DIFFSTATS) {
    152         pmSourceMeasureDiffStats (source, maskVal);
     163        pmSourceMeasureDiffStats (source, maskVal, markVal);
    153164    }
    154165
     
    191202
    192203    // measure object aperture photometry
    193     status = pmSourcePhotometryAper  (&source->apMag, model, flux, mask, maskVal);
     204    status = pmSourcePhotometryAper  (&source->apMagRaw, model, flux, mask, maskVal);
    194205    if (!status) {
    195206        psTrace ("psModules.objects", 3, "fail mag : bad Ap Mag");
     
    199210    // if the aper mag is NAN, the flux < 0.  this can happen for sources near the
    200211    // detection limits (esp near bright neighbors)
     212    source->apMag = source->apMagRaw;
    201213    if (isfinite (source->apMag) && isPSF && psf) {
    202214        if (psf->growth && (mode & PM_SOURCE_PHOT_GROWTH)) {
    203             source->apMag += pmGrowthCurveCorrect (psf->growth, source->apRadius);
     215            source->apMag = source->apMagRaw + pmGrowthCurveCorrect (psf->growth, source->apRadius);
    204216        }
    205217        if (mode & PM_SOURCE_PHOT_APCORR) {
    206218            // XXX this should be removed -- we no longer fit for the 'sky bias'
     219            // XXX is this happening???
    207220            rflux   = pow (10.0, 0.4*source->psfMag);
     221            psAssert (psf->skyBias == 0.0, "sky bias not 0");
     222            psAssert (psf->skySat == 0.0, "sky sat not 0");
    208223            source->apMag -= PS_SQR(source->apRadius)*rflux * psf->skyBias + psf->skySat / rflux;
    209224        }
     
    257272    PS_ASSERT_PTR_NON_NULL(image, false);
    258273    PS_ASSERT_PTR_NON_NULL(mask, false);
    259     PS_ASSERT_PTR_NON_NULL(model, false);
     274
     275    if (DO_SKY) {
     276        PS_ASSERT_PTR_NON_NULL(model, false);
     277    }
    260278
    261279    float apSum = 0;
     
    271289    psF32 **imData = image->data.F32;
    272290    psImageMaskType **mkData = mask->data.PS_TYPE_IMAGE_MASK_DATA;
     291    int nAperPix = 0;
    273292
    274293    // measure apMag
    275     for (int ix = 0; ix < image->numCols; ix++) {
    276         for (int iy = 0; iy < image->numRows; iy++) {
     294    for (int iy = 0; iy < image->numRows; iy++) {
     295        for (int ix = 0; ix < image->numCols; ix++) {
    277296            if (mkData[iy][ix] & maskVal)
    278297                continue;
    279298            apSum += imData[iy][ix] - sky;
     299            nAperPix ++;
     300            // fprintf (stderr, "aper: %d %d  %f  %f  %f\n", ix, iy, sky, imData[iy][ix], apSum);
    280301        }
    281302    }
     
    290311
    291312// return source aperture magnitude
    292 bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *mask, psImageMaskType maskVal)
    293 {
    294     PS_ASSERT_PTR_NON_NULL(pixWeight, false);
     313bool pmSourcePixelWeight (float *pixWeightNotBad, float *pixWeightNotPoor, pmModel *model, psImage *mask, psImageMaskType maskVal, psImageMaskType markVal)
     314{
     315    PS_ASSERT_PTR_NON_NULL(pixWeightNotBad, false);
     316    PS_ASSERT_PTR_NON_NULL(pixWeightNotPoor, false);
    295317    PS_ASSERT_PTR_NON_NULL(mask, false);
    296318    PS_ASSERT_PTR_NON_NULL(model, false);
    297319
    298320    float modelSum = 0;
    299     float validSum = 0;
     321    float notBadSum = 0;
     322    float notPoorSum = 0;
    300323    float sky = 0;
    301324    float value;
     
    305328    int dY, DY, NY;
    306329
    307     *pixWeight = 0.0;
     330    *pixWeightNotBad = 0.0;
     331    *pixWeightNotPoor = 0.0;
    308332
    309333    // we only care about the value of the object model, not the local sky
     
    345369
    346370            // for the full model, add all points
    347             value = model->modelFunc (NULL, params, coord) - sky;
     371            value = fabs(model->modelFunc (NULL, params, coord) - sky);
    348372            modelSum += value;
    349373
    350374            // include count only the unmasked pixels within the image area
    351             if (mx < 0)
    352                 continue;
    353             if (my < 0)
    354                 continue;
    355             if (mx >= NX)
    356                 continue;
    357             if (my >= NY)
    358                 continue;
    359             if (mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & maskVal)
    360                 continue;
    361 
    362             validSum += value;
     375            if (mx < 0) continue;
     376            if (my < 0) continue;
     377            if (mx >= NX) continue;
     378            if (my >= NY) continue;
     379
     380            if (!(mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & maskVal)) {
     381                notBadSum += value;
     382            }
     383            if (!(mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & ~markVal)) {
     384                notPoorSum += value;
     385            }
    363386        }
    364387    }
    365388    psFree (coord);
    366389
    367     if (validSum <= 0)
    368         return false;
    369 
    370     *pixWeight = validSum / modelSum;
     390    *pixWeightNotBad  = notBadSum  / modelSum;
     391    *pixWeightNotPoor = notPoorSum / modelSum;
     392
    371393    return (true);
    372394}
     
    374396# define FLUX_LIMIT 3.0
    375397
    376 // return source aperture magnitude
    377 bool pmSourceMeasureDiffStats (pmSource *source, psImageMaskType maskVal)
     398// measure stats that may be using in difference images for distinguishing real sources from bad residuals
     399bool pmSourceMeasureDiffStats (pmSource *source, psImageMaskType maskVal, psImageMaskType markVal)
    378400{
    379401    PS_ASSERT_PTR_NON_NULL(source, false);
     
    399421    for (int iy = 0; iy < flux->numRows; iy++) {
    400422        for (int ix = 0; ix < flux->numCols; ix++) {
     423            // only count up the stats in the unmarked region (ie, the aperture)
     424            if (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & markVal) {
     425                continue;
     426            }
    401427            if (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & maskVal) {
    402428                nMask ++;
Note: See TracChangeset for help on using the changeset viewer.