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/pmSourceMoments.c

    r27531 r29004  
    2222#include <strings.h>
    2323#include <pslib.h>
     24
    2425#include "pmHDU.h"
    2526#include "pmFPA.h"
    26 #include "pmFPAMaskWeight.h"
     27
     28#include "pmTrend2D.h"
     29#include "pmResiduals.h"
     30#include "pmGrowthCurve.h"
    2731#include "pmSpan.h"
     32#include "pmFootprintSpans.h"
    2833#include "pmFootprint.h"
    2934#include "pmPeaks.h"
    3035#include "pmMoments.h"
    31 #include "pmResiduals.h"
    32 #include "pmGrowthCurve.h"
    33 #include "pmTrend2D.h"
    34 #include "pmPSF.h"
     36#include "pmModelFuncs.h"
    3537#include "pmModel.h"
     38#include "pmModelUtils.h"
     39#include "pmModelClass.h"
     40#include "pmSourceMasks.h"
     41#include "pmSourceExtendedPars.h"
     42#include "pmSourceDiffStats.h"
    3643#include "pmSource.h"
    3744
     
    5461# define VALID_RADIUS(X,Y,RAD2) (((RAD2) >= (PS_SQR(X) + PS_SQR(Y))) ? 1 : 0)
    5562
     63static bool beVerbose = false;
     64void pmSourceMomentsSetVerbose(bool state){ beVerbose = state; }
     65
    5666bool pmSourceMoments(pmSource *source, psF32 radius, psF32 sigma, psF32 minSN, psImageMaskType maskVal)
    5767{
     
    6171    PS_ASSERT_FLOAT_LARGER_THAN(radius, 0.0, false);
    6272
    63     // use sky from moments if defined, 0.0 otherwise
     73    // use sky from moments if defined, 0.0 otherwise
     74
     75    // XXX this value comes from the sky model at the source center, and tends to over-estimate
     76    // the sky in the vicinity of bright sources.  we are better off assuming the model worked
     77    // well:
    6478    psF32 sky = 0.0;
    65     if (source->moments == NULL) {
    66         source->moments = pmMomentsAlloc();
    67     } else {
    68         sky = source->moments->Sky;
    69     }
     79    // XXX if (source->moments == NULL) {
     80    // XXX     source->moments = pmMomentsAlloc();
     81    // XXX } else {
     82    // XXX     sky = source->moments->Sky;
     83    // XXX }
    7084
    7185    // First Pass: calculate the first moments (these are subtracted from the coordinates below)
     
    131145            psF32 wDiff = *vWgt;
    132146
    133             // skip pixels below specified significance level.  this is allowed, but should be
    134             // avoided -- the over-weights the wings of bright stars compared to those of faint
    135             // stars.
    136             if (PS_SQR(pDiff) < minSN2*wDiff) continue;
    137             // if (pDiff < 0) continue; // XXX : MWV says I should include < 0.0 valued points...
     147            // skip pixels below specified significance level.  for a PSFs, this
     148            // over-weights the wings of bright stars compared to those of faint stars.
     149            // for the estimator used for extended source analysis (where the window
     150            // function is allowed to be arbitrarily large), we need to clip to avoid
     151            // negative second moments.
     152            if (PS_SQR(pDiff) < minSN2*wDiff) continue; //
     153            if ((minSN > 0.0) && (pDiff < 0)) continue; //
    138154
    139155            // Apply a Gaussian window function.  Be careful with the window function.  S/N
     
    197213    // Xn  = SUM (x - xc)^n * (z - sky)
    198214
     215    psF32 RF = 0.0;
     216    psF32 RH = 0.0;
     217    psF32 RS = 0.0;
    199218    psF32 XX = 0.0;
    200219    psF32 XY = 0.0;
     
    244263            if (r > radius) continue;
    245264
    246             psF32 pDiff = *vPix - sky;
     265            psF32 fDiff = *vPix - sky;
     266            psF32 pDiff = fDiff;
    247267            psF32 wDiff = *vWgt;
    248268
     
    257277            if (sigma > 0.0) {
    258278                // XXX a lot of extra flops; can we do pre-calculate?
    259                 psF32 z  = (PS_SQR(xDiff) + PS_SQR(yDiff))*rsigma2;
     279                // XXX we were re-calculating r2 (maybe the compiler caught this?)
     280                // psF32 z  = (PS_SQR(xDiff) + PS_SQR(yDiff))*rsigma2;
     281                psF32 z  = r2 * rsigma2;
    260282                assert (z >= 0.0);
    261283                psF32 weight  = exp(-z);
     
    266288
    267289            Sum += pDiff;
     290
     291# if (1)
     292# if (0)
     293            if (fDiff < 0) continue;
     294# endif
     295            psF32 rf = r * fDiff;
     296            psF32 rh = sqrt(r) * fDiff;
     297            psF32 rs = fDiff;
     298# else
     299            psF32 rf = r * pDiff;
     300            psF32 rh = sqrt(r) * pDiff;
     301            psF32 rs = pDiff;
     302# endif
    268303
    269304            psF32 x = xDiff * pDiff;
     
    284319            psF32 xyyy = xDiff * yyy / r2;
    285320            psF32 yyyy = yDiff * yyy / r2;
     321
     322            RF  += rf;
     323            RH  += rh;
     324            RS  += rs;
    286325
    287326            XX  += xx;
     
    302341    }
    303342
     343    source->moments->Mrf = RF/RS;
     344    source->moments->Mrh = RH/RS;
     345
    304346    source->moments->Mxx = XX/Sum;
    305347    source->moments->Mxy = XY/Sum;
     
    317359    source->moments->Myyyy = YYYY/Sum;
    318360
    319     // if (source->moments->Mxx < 0) {
    320     //  fprintf (stderr, "error: neg second moment??\n");
    321     // }
    322     // if (source->moments->Myy < 0) {
    323     //  fprintf (stderr, "error: neg second moment??\n");
    324     // }
    325 
    326     psTrace ("psModules.objects", 4, "Mxx: %f  Mxy: %f  Myy: %f  Mxxx: %f  Mxxy: %f  Mxyy: %f  Myyy: %f  Mxxxx: %f  Mxxxy: %f  Mxxyy: %f  Mxyyy: %f  Mxyyy: %f\n",
     361    // Calculate the Kron magnitude (make this block optional?)
     362    // float radKron = 2.5*source->moments->Mrf;
     363    float radKinner = 1.0*source->moments->Mrf;
     364    float radKron   = 2.5*source->moments->Mrf;
     365    float radKouter = 4.0*source->moments->Mrf;
     366
     367    int nKronPix = 0;
     368    Sum = Var = 0.0;
     369    float SumInner = 0.0;
     370    float SumOuter = 0.0;
     371
     372    for (psS32 row = 0; row < source->pixels->numRows ; row++) {
     373
     374        psF32 yDiff = row - yCM;
     375        if (fabs(yDiff) > radKron) continue;
     376
     377        psF32 *vPix = source->pixels->data.F32[row];
     378        psF32 *vWgt = source->variance->data.F32[row];
     379        psImageMaskType  *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[row];
     380
     381        for (psS32 col = 0; col < source->pixels->numCols ; col++, vPix++, vWgt++) {
     382            if (vMsk) {
     383                if (*vMsk & maskVal) {
     384                    vMsk++;
     385                    continue;
     386                }
     387                vMsk++;
     388            }
     389            if (isnan(*vPix)) continue;
     390
     391            psF32 xDiff = col - xCM;
     392            if (fabs(xDiff) > radKron) continue;
     393
     394            // radKron is just a function of (xDiff, yDiff)
     395            psF32 r2  = PS_SQR(xDiff) + PS_SQR(yDiff);
     396            psF32 r  = sqrt(r2);
     397
     398            psF32 pDiff = *vPix - sky;
     399            psF32 wDiff = *vWgt;
     400
     401            // skip pixels below specified significance level.  this is allowed, but should be
     402            // avoided -- the over-weights the wings of bright stars compared to those of faint
     403            // stars.
     404            if (PS_SQR(pDiff) < minSN2*wDiff) continue;
     405
     406            if (r < radKron) {
     407                Sum += pDiff;
     408                Var += wDiff;
     409                nKronPix ++;
     410                // if (beVerbose) fprintf (stderr, "mome: %d %d  %f  %f  %f\n", col, row, sky, *vPix, Sum);
     411            }
     412
     413            if ((r > radKinner) && (r < radKron)) {
     414                SumInner += pDiff;
     415            }
     416            if ((r > radKron)  && (r < radKouter)) {
     417                SumOuter += pDiff;
     418            }
     419        }
     420    }
     421    source->moments->KronFlux = Sum;
     422    source->moments->KronFinner = SumInner;
     423    source->moments->KronFouter = SumOuter;
     424    source->moments->KronFluxErr = sqrt(Var);
     425
     426    psTrace ("psModules.objects", 4, "Mrf: %f  KronFlux: %f  Mxx: %f  Mxy: %f  Myy: %f  Mxxx: %f  Mxxy: %f  Mxyy: %f  Myyy: %f  Mxxxx: %f  Mxxxy: %f  Mxxyy: %f  Mxyyy: %f  Mxyyy: %f\n",
     427             source->moments->Mrf,   source->moments->KronFlux,
    327428             source->moments->Mxx,   source->moments->Mxy,   source->moments->Myy,
    328429             source->moments->Mxxx,  source->moments->Mxxy,  source->moments->Mxyy,  source->moments->Myyy,
Note: See TracChangeset for help on using the changeset viewer.