IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 26, 2010, 9:18:39 AM (16 years ago)
Author:
Serge CHASTEL
Message:

Merging trunk in branch

Location:
branches/sc_branches/trunkTest
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/sc_branches/trunkTest

  • branches/sc_branches/trunkTest/psModules

    • Property svn:mergeinfo deleted
  • branches/sc_branches/trunkTest/psModules/src/objects/pmSourceMoments.c

    r27531 r29060  
    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;
    6579    if (source->moments == NULL) {
    66         source->moments = pmMomentsAlloc();
    67     } else {
    68         sky = source->moments->Sky;
    69     }
     80      source->moments = pmMomentsAlloc();
     81    }
     82    // XXX if (source->moments == NULL) {
     83    // XXX     source->moments = pmMomentsAlloc();
     84    // XXX } else {
     85    // XXX     sky = source->moments->Sky;
     86    // XXX }
    7087
    7188    // First Pass: calculate the first moments (these are subtracted from the coordinates below)
     
    131148            psF32 wDiff = *vWgt;
    132149
    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...
     150            // skip pixels below specified significance level.  for a PSFs, this
     151            // over-weights the wings of bright stars compared to those of faint stars.
     152            // for the estimator used for extended source analysis (where the window
     153            // function is allowed to be arbitrarily large), we need to clip to avoid
     154            // negative second moments.
     155            if (PS_SQR(pDiff) < minSN2*wDiff) continue; //
     156            if ((minSN > 0.0) && (pDiff < 0)) continue; //
    138157
    139158            // Apply a Gaussian window function.  Be careful with the window function.  S/N
     
    197216    // Xn  = SUM (x - xc)^n * (z - sky)
    198217
     218    psF32 RF = 0.0;
     219    psF32 RH = 0.0;
     220    psF32 RS = 0.0;
    199221    psF32 XX = 0.0;
    200222    psF32 XY = 0.0;
     
    244266            if (r > radius) continue;
    245267
    246             psF32 pDiff = *vPix - sky;
     268            psF32 fDiff = *vPix - sky;
     269            psF32 pDiff = fDiff;
    247270            psF32 wDiff = *vWgt;
    248271
     
    257280            if (sigma > 0.0) {
    258281                // XXX a lot of extra flops; can we do pre-calculate?
    259                 psF32 z  = (PS_SQR(xDiff) + PS_SQR(yDiff))*rsigma2;
     282                // XXX we were re-calculating r2 (maybe the compiler caught this?)
     283                // psF32 z  = (PS_SQR(xDiff) + PS_SQR(yDiff))*rsigma2;
     284                psF32 z  = r2 * rsigma2;
    260285                assert (z >= 0.0);
    261286                psF32 weight  = exp(-z);
     
    266291
    267292            Sum += pDiff;
     293
     294# if (1)
     295# if (0)
     296            if (fDiff < 0) continue;
     297# endif
     298            psF32 rf = r * fDiff;
     299            psF32 rh = sqrt(r) * fDiff;
     300            psF32 rs = fDiff;
     301# else
     302            psF32 rf = r * pDiff;
     303            psF32 rh = sqrt(r) * pDiff;
     304            psF32 rs = pDiff;
     305# endif
    268306
    269307            psF32 x = xDiff * pDiff;
     
    284322            psF32 xyyy = xDiff * yyy / r2;
    285323            psF32 yyyy = yDiff * yyy / r2;
     324
     325            RF  += rf;
     326            RH  += rh;
     327            RS  += rs;
    286328
    287329            XX  += xx;
     
    302344    }
    303345
     346    source->moments->Mrf = RF/RS;
     347    source->moments->Mrh = RH/RS;
     348
    304349    source->moments->Mxx = XX/Sum;
    305350    source->moments->Mxy = XY/Sum;
     
    317362    source->moments->Myyyy = YYYY/Sum;
    318363
    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",
     364    // Calculate the Kron magnitude (make this block optional?)
     365    // float radKron = 2.5*source->moments->Mrf;
     366    float radKinner = 1.0*source->moments->Mrf;
     367    float radKron   = 2.5*source->moments->Mrf;
     368    float radKouter = 4.0*source->moments->Mrf;
     369
     370    int nKronPix = 0;
     371    Sum = Var = 0.0;
     372    float SumInner = 0.0;
     373    float SumOuter = 0.0;
     374
     375    for (psS32 row = 0; row < source->pixels->numRows ; row++) {
     376
     377        psF32 yDiff = row - yCM;
     378        if (fabs(yDiff) > radKron) continue;
     379
     380        psF32 *vPix = source->pixels->data.F32[row];
     381        psF32 *vWgt = source->variance->data.F32[row];
     382        psImageMaskType  *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[row];
     383
     384        for (psS32 col = 0; col < source->pixels->numCols ; col++, vPix++, vWgt++) {
     385            if (vMsk) {
     386                if (*vMsk & maskVal) {
     387                    vMsk++;
     388                    continue;
     389                }
     390                vMsk++;
     391            }
     392            if (isnan(*vPix)) continue;
     393
     394            psF32 xDiff = col - xCM;
     395            if (fabs(xDiff) > radKron) continue;
     396
     397            // radKron is just a function of (xDiff, yDiff)
     398            psF32 r2  = PS_SQR(xDiff) + PS_SQR(yDiff);
     399            psF32 r  = sqrt(r2);
     400
     401            psF32 pDiff = *vPix - sky;
     402            psF32 wDiff = *vWgt;
     403
     404            // skip pixels below specified significance level.  this is allowed, but should be
     405            // avoided -- the over-weights the wings of bright stars compared to those of faint
     406            // stars.
     407            if (PS_SQR(pDiff) < minSN2*wDiff) continue;
     408
     409            if (r < radKron) {
     410                Sum += pDiff;
     411                Var += wDiff;
     412                nKronPix ++;
     413                // if (beVerbose) fprintf (stderr, "mome: %d %d  %f  %f  %f\n", col, row, sky, *vPix, Sum);
     414            }
     415
     416            if ((r > radKinner) && (r < radKron)) {
     417                SumInner += pDiff;
     418            }
     419            if ((r > radKron)  && (r < radKouter)) {
     420                SumOuter += pDiff;
     421            }
     422        }
     423    }
     424    source->moments->KronFlux = Sum;
     425    source->moments->KronFinner = SumInner;
     426    source->moments->KronFouter = SumOuter;
     427    source->moments->KronFluxErr = sqrt(Var);
     428
     429    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",
     430             source->moments->Mrf,   source->moments->KronFlux,
    327431             source->moments->Mxx,   source->moments->Mxy,   source->moments->Myy,
    328432             source->moments->Mxxx,  source->moments->Mxxy,  source->moments->Mxyy,  source->moments->Myyy,
Note: See TracChangeset for help on using the changeset viewer.