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/psphot

    • Property svn:mergeinfo deleted
  • branches/sc_branches/trunkTest/psphot/src/psphotBlendFit.c

    r28405 r29060  
    6565    assert (status && fitIter > 0);
    6666
    67     float fitTol = psMetadataLookupF32 (&status, recipe, "EXT_FIT_TOL"); // Fit tolerance
    68     assert (status && isfinite(fitTol) && fitTol > 0);
     67    float fitMinTol = psMetadataLookupF32 (&status, recipe, "EXT_FIT_MIN_TOL"); // Fit tolerance
     68    if (!status || !isfinite(fitMinTol) || fitMinTol <= 0) {
     69        fitMinTol = psMetadataLookupF32 (&status, recipe, "PSF_FIT_TOL"); // Fit tolerance
     70        if (!status || !isfinite(fitMinTol) || fitMinTol <= 0) {
     71            psAbort("PSF_FIT_MIN_TOL (and PSF_FIT_TOL) not defined or positive");
     72        }
     73    }
     74
     75    float fitMaxTol = psMetadataLookupF32 (&status, recipe, "EXT_FIT_MAX_TOL"); // Fit tolerance
     76    if (!status || !isfinite(fitMaxTol) || fitMaxTol <= 0) {
     77        fitMaxTol = 1.0;
     78    }
    6979
    7080    bool poisson = psMetadataLookupBool(&status, recipe, "POISSON.ERRORS.PHOT.LMM"); // Poisson errors?
    7181    assert (status);
    7282
     83    float maxChisqDOF = psMetadataLookupF32 (&status, recipe, "EXT_FIT_MAX_CHISQ"); // Fit tolerance
     84
    7385    float skySig = psMetadataLookupF32(&status, recipe, "SKY_SIG");
    7486    assert (status && isfinite(skySig) && skySig > 0);
    7587
    7688    // Define source fitting parameters for extended source fits
    77     pmSourceFitModelInit(fitIter, fitTol, PS_SQR(skySig), poisson);
     89    pmSourceFitOptions *fitOptions = pmSourceFitOptionsAlloc();
     90    fitOptions->nIter         = fitIter;
     91    fitOptions->minTol        = fitMinTol;
     92    fitOptions->maxTol        = fitMaxTol;
     93    fitOptions->maxChisqDOF   = maxChisqDOF;
     94    fitOptions->poissonErrors = poisson;
     95    fitOptions->weight        = PS_SQR(skySig);
     96    fitOptions->mode          = PM_SOURCE_FIT_PSF;
    7897
    7998    psphotInitLimitsPSF (recipe, readout);
    80     psphotInitLimitsEXT (recipe);
    81     psphotInitRadiusPSF (recipe, readout->analysis, psf->type);
     99    psphotInitLimitsEXT (recipe, readout);
     100    psphotInitRadiusPSF (recipe, readout);
    82101
    83102    // starts the timer, sets up the array of fitSets
     
    88107    if (!sources->n) {
    89108        psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping blend");
     109        psFree (fitOptions);
    90110        return true;
    91111    }
     
    112132            psArrayAdd(job->args, 1, psf);
    113133            psArrayAdd(job->args, 1, newSources); // return for new sources
     134            psArrayAdd(job->args, 1, fitOptions); // default fit options
    114135            psFree (newSources);
    115136
     
    121142            if (!psThreadJobAddPending(job)) {
    122143                psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
     144                psFree (fitOptions);
    123145                return NULL;
    124146            }
    125 
    126 # if (0)
    127             {
    128                 int nfit = 0;
    129                 int npsf = 0;
    130                 int next = 0;
    131                 int nfail = 0;
    132                 psArray *newSources = psArrayAllocEmpty(16);
    133 
    134                 if (!psphotBlendFit_Unthreaded (&nfit, &npsf, &next, &nfail, readout, recipe, cells->data[j], psf, newSources)) {
    135                     psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    136                     return NULL;
    137                 }
    138                 Nfit += nfit;
    139                 Npsf += npsf;
    140                 Next += next;
    141                 Nfail += nfail;
    142 
    143                 // add these back onto sources
    144                 for (int k = 0; k < newSources->n; k++) {
    145                     psArrayAdd (sources, 16, newSources->data[k]);
    146                 }
    147                 psFree (newSources);
    148             }
    149 # endif
    150147        }
    151148
     
    153150        if (!psThreadPoolWait (false)) {
    154151            psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
     152            psFree (fitOptions);
    155153            return NULL;
    156154        }
     
    163161            } else {
    164162                psScalar *scalar = NULL;
    165                 scalar = job->args->data[5];
     163                scalar = job->args->data[6];
    166164                Nfit += scalar->data.S32;
    167                 scalar = job->args->data[6];
     165                scalar = job->args->data[7];
    168166                Npsf += scalar->data.S32;
    169                 scalar = job->args->data[7];
     167                scalar = job->args->data[8];
    170168                Next += scalar->data.S32;
    171                 scalar = job->args->data[8];
     169                scalar = job->args->data[9];
    172170                Nfail += scalar->data.S32;
    173171
     
    186184      psphotSaveImage (NULL, readout->image,  "image.v2.fits");
    187185    }
     186    psFree (fitOptions);
    188187
    189188    psLogMsg ("psphot.psphotBlendFit", PS_LOG_INFO, "fit models: %f sec for %d objects (%d psf, %d ext, %d failed, %ld skipped)\n", psTimerMark ("psphot.fit.nonlinear"), Nfit, Npsf, Next, Nfail, sources->n - Nfit);
     
    204203    psScalar *scalar = NULL;
    205204
    206     pmReadout *readout  = job->args->data[0];
    207     psMetadata *recipe  = job->args->data[1];
    208     psArray *sources    = job->args->data[2];
    209     pmPSF *psf          = job->args->data[3];
    210     psArray *newSources = job->args->data[4];
     205    pmReadout *readout             = job->args->data[0];
     206    psMetadata *recipe             = job->args->data[1];
     207    psArray *sources               = job->args->data[2];
     208    pmPSF *psf                     = job->args->data[3];
     209    psArray *newSources            = job->args->data[4];
     210    pmSourceFitOptions *fitOptions = job->args->data[5];
    211211
    212212    // bit-masks to test for good/bad pixels
     
    269269        Nfit ++;
    270270
     271        if (0) {
     272            psF32 Mxx = source->moments->Mxx;
     273            psF32 Myy = source->moments->Myy;
     274            fprintf (stderr, "1: Mxx: %f, Myy: %f\n", Mxx, Myy);
     275        }
     276
    271277        // try fitting PSFs or extended sources depending on source->mode
    272278        // these functions subtract the resulting fitted source
    273279        if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) {
    274             if (psphotFitBlob (readout, source, newSources, psf, maskVal, markVal)) {
     280            if (psphotFitBlob (readout, source, newSources, psf, fitOptions, maskVal, markVal)) {
    275281                source->type = PM_SOURCE_TYPE_EXTENDED;
    276282                psTrace ("psphot", 5, "source at %7.1f, %7.1f is ext", source->peak->xf, source->peak->yf);
     
    280286            }
    281287        } else {
    282             if (psphotFitBlend (readout, source, psf, maskVal, markVal)) {
     288            if (psphotFitBlend (readout, source, psf, fitOptions, maskVal, markVal)) {
    283289                source->type = PM_SOURCE_TYPE_STAR;
    284290                psTrace ("psphot", 5, "source at %7.1f, %7.1f is psf", source->peak->xf, source->peak->yf);
     
    289295        }
    290296
     297        if (0) {
     298            psF32 Mxx = source->moments->Mxx;
     299            psF32 Myy = source->moments->Myy;
     300            fprintf (stderr, "2: Mxx: %f, Myy: %f\n", Mxx, Myy);
     301        }
     302
    291303        psTrace ("psphot", 5, "source at %7.1f, %7.1f failed", source->peak->xf, source->peak->yf);
    292304        Nfail ++;
     
    298310
    299311    // change the value of a scalar on the array (wrap this and put it in psArray.h)
    300     scalar = job->args->data[5];
     312    scalar = job->args->data[6];
    301313    scalar->data.S32 = Nfit;
    302314
    303     scalar = job->args->data[6];
     315    scalar = job->args->data[7];
    304316    scalar->data.S32 = Npsf;
    305317
    306     scalar = job->args->data[7];
     318    scalar = job->args->data[8];
    307319    scalar->data.S32 = Next;
    308320
    309     scalar = job->args->data[8];
     321    scalar = job->args->data[9];
    310322    scalar->data.S32 = Nfail;
    311323
Note: See TracChangeset for help on using the changeset viewer.