IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 9, 2010, 10:56:32 AM (16 years ago)
Author:
eugene
Message:

changed pmSourceFitModel and related APIs to pass a structure of fit options; this lets us change the options between soruces within the multithreaded context; also re-organized the include orders to avoid conflicts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20100621/psModules/src/objects/pmSourceMoments.c

    r27531 r28643  
    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)
     
    197211    // Xn  = SUM (x - xc)^n * (z - sky)
    198212
     213    psF32 RF = 0.0;
     214    psF32 RH = 0.0;
     215    psF32 RS = 0.0;
    199216    psF32 XX = 0.0;
    200217    psF32 XY = 0.0;
     
    244261            if (r > radius) continue;
    245262
    246             psF32 pDiff = *vPix - sky;
     263            psF32 fDiff = *vPix - sky;
     264            psF32 pDiff = fDiff;
    247265            psF32 wDiff = *vWgt;
    248266
     
    257275            if (sigma > 0.0) {
    258276                // XXX a lot of extra flops; can we do pre-calculate?
    259                 psF32 z  = (PS_SQR(xDiff) + PS_SQR(yDiff))*rsigma2;
     277                // XXX we were re-calculating r2 (maybe the compiler caught this?)
     278                // psF32 z  = (PS_SQR(xDiff) + PS_SQR(yDiff))*rsigma2;
     279                psF32 z  = r2 * rsigma2;
    260280                assert (z >= 0.0);
    261281                psF32 weight  = exp(-z);
     
    266286
    267287            Sum += pDiff;
     288
     289# if (1)
     290# if (0)
     291            if (fDiff < 0) continue;
     292# endif
     293            psF32 rf = r * fDiff;
     294            psF32 rh = sqrt(r) * fDiff;
     295            psF32 rs = fDiff;
     296# else
     297            psF32 rf = r * pDiff;
     298            psF32 rh = sqrt(r) * pDiff;
     299            psF32 rs = pDiff;
     300# endif
    268301
    269302            psF32 x = xDiff * pDiff;
     
    284317            psF32 xyyy = xDiff * yyy / r2;
    285318            psF32 yyyy = yDiff * yyy / r2;
     319
     320            RF  += rf;
     321            RH  += rh;
     322            RS  += rs;
    286323
    287324            XX  += xx;
     
    302339    }
    303340
     341    source->moments->Mrf = RF/RS;
     342    source->moments->Mrh = RH/RS;
     343
    304344    source->moments->Mxx = XX/Sum;
    305345    source->moments->Mxy = XY/Sum;
     
    317357    source->moments->Myyyy = YYYY/Sum;
    318358
    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",
     359    // Calculate the Kron magnitude (make this block optional?)
     360    // float radKron = 2.5*source->moments->Mrf;
     361    float radKinner = 1.0*source->moments->Mrf;
     362    float radKron   = 2.5*source->moments->Mrf;
     363    float radKouter = 4.0*source->moments->Mrf;
     364
     365    int nKronPix = 0;
     366    Sum = Var = 0.0;
     367    float SumInner = 0.0;
     368    float SumOuter = 0.0;
     369
     370    for (psS32 row = 0; row < source->pixels->numRows ; row++) {
     371
     372        psF32 yDiff = row - yCM;
     373        if (fabs(yDiff) > radKron) continue;
     374
     375        psF32 *vPix = source->pixels->data.F32[row];
     376        psF32 *vWgt = source->variance->data.F32[row];
     377        psImageMaskType  *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[row];
     378
     379        for (psS32 col = 0; col < source->pixels->numCols ; col++, vPix++, vWgt++) {
     380            if (vMsk) {
     381                if (*vMsk & maskVal) {
     382                    vMsk++;
     383                    continue;
     384                }
     385                vMsk++;
     386            }
     387            if (isnan(*vPix)) continue;
     388
     389            psF32 xDiff = col - xCM;
     390            if (fabs(xDiff) > radKron) continue;
     391
     392            // radKron is just a function of (xDiff, yDiff)
     393            psF32 r2  = PS_SQR(xDiff) + PS_SQR(yDiff);
     394            psF32 r  = sqrt(r2);
     395
     396            psF32 pDiff = *vPix - sky;
     397            psF32 wDiff = *vWgt;
     398
     399            // skip pixels below specified significance level.  this is allowed, but should be
     400            // avoided -- the over-weights the wings of bright stars compared to those of faint
     401            // stars.
     402            if (PS_SQR(pDiff) < minSN2*wDiff) continue;
     403
     404            if (r < radKron) {
     405                Sum += pDiff;
     406                Var += wDiff;
     407                nKronPix ++;
     408                // if (beVerbose) fprintf (stderr, "mome: %d %d  %f  %f  %f\n", col, row, sky, *vPix, Sum);
     409            }
     410
     411            if ((r > radKinner) && (r < radKron)) {
     412                SumInner += pDiff;
     413            }
     414            if ((r > radKron)  && (r < radKouter)) {
     415                SumOuter += pDiff;
     416            }
     417        }
     418    }
     419    source->moments->KronFlux = Sum;
     420    source->moments->KronFinner = SumInner;
     421    source->moments->KronFouter = SumOuter;
     422    source->moments->KronFluxErr = sqrt(Var);
     423
     424    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",
     425             source->moments->Mrf,   source->moments->KronFlux,
    327426             source->moments->Mxx,   source->moments->Mxy,   source->moments->Myy,
    328427             source->moments->Mxxx,  source->moments->Mxxy,  source->moments->Mxyy,  source->moments->Myyy,
Note: See TracChangeset for help on using the changeset viewer.