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/psphot/src/psphotBlendFit.c

    r28405 r28643  
    7575
    7676    // Define source fitting parameters for extended source fits
    77     pmSourceFitModelInit(fitIter, fitTol, PS_SQR(skySig), poisson);
     77    pmSourceFitOptions *fitOptions = pmSourceFitOptionsAlloc();
     78    fitOptions->nIter         = fitIter;
     79    fitOptions->tol           = fitTol;
     80    fitOptions->poissonErrors = poisson;
     81    fitOptions->weight        = PS_SQR(skySig);
     82    fitOptions->mode          = PM_SOURCE_FIT_PSF;
    7883
    7984    psphotInitLimitsPSF (recipe, readout);
     
    8893    if (!sources->n) {
    8994        psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping blend");
     95        psFree (fitOptions);
    9096        return true;
    9197    }
     
    112118            psArrayAdd(job->args, 1, psf);
    113119            psArrayAdd(job->args, 1, newSources); // return for new sources
     120            psArrayAdd(job->args, 1, fitOptions); // default fit options
    114121            psFree (newSources);
    115122
     
    121128            if (!psThreadJobAddPending(job)) {
    122129                psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
     130                psFree (fitOptions);
    123131                return NULL;
    124132            }
    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
    150133        }
    151134
     
    153136        if (!psThreadPoolWait (false)) {
    154137            psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
     138            psFree (fitOptions);
    155139            return NULL;
    156140        }
     
    163147            } else {
    164148                psScalar *scalar = NULL;
    165                 scalar = job->args->data[5];
     149                scalar = job->args->data[6];
    166150                Nfit += scalar->data.S32;
    167                 scalar = job->args->data[6];
     151                scalar = job->args->data[7];
    168152                Npsf += scalar->data.S32;
    169                 scalar = job->args->data[7];
     153                scalar = job->args->data[8];
    170154                Next += scalar->data.S32;
    171                 scalar = job->args->data[8];
     155                scalar = job->args->data[9];
    172156                Nfail += scalar->data.S32;
    173157
     
    186170      psphotSaveImage (NULL, readout->image,  "image.v2.fits");
    187171    }
     172    psFree (fitOptions);
    188173
    189174    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);
     
    204189    psScalar *scalar = NULL;
    205190
    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];
     191    pmReadout *readout             = job->args->data[0];
     192    psMetadata *recipe             = job->args->data[1];
     193    psArray *sources               = job->args->data[2];
     194    pmPSF *psf                     = job->args->data[3];
     195    psArray *newSources            = job->args->data[4];
     196    pmSourceFitOptions *fitOptions = job->args->data[5];
    211197
    212198    // bit-masks to test for good/bad pixels
     
    269255        Nfit ++;
    270256
     257        if (0) {
     258            psF32 Mxx = source->moments->Mxx;
     259            psF32 Myy = source->moments->Myy;
     260            fprintf (stderr, "1: Mxx: %f, Myy: %f\n", Mxx, Myy);
     261        }
     262
    271263        // try fitting PSFs or extended sources depending on source->mode
    272264        // these functions subtract the resulting fitted source
    273265        if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) {
    274             if (psphotFitBlob (readout, source, newSources, psf, maskVal, markVal)) {
     266            if (psphotFitBlob (readout, source, newSources, psf, fitOptions, maskVal, markVal)) {
    275267                source->type = PM_SOURCE_TYPE_EXTENDED;
    276268                psTrace ("psphot", 5, "source at %7.1f, %7.1f is ext", source->peak->xf, source->peak->yf);
     
    280272            }
    281273        } else {
    282             if (psphotFitBlend (readout, source, psf, maskVal, markVal)) {
     274            if (psphotFitBlend (readout, source, psf, fitOptions, maskVal, markVal)) {
    283275                source->type = PM_SOURCE_TYPE_STAR;
    284276                psTrace ("psphot", 5, "source at %7.1f, %7.1f is psf", source->peak->xf, source->peak->yf);
     
    289281        }
    290282
     283        if (0) {
     284            psF32 Mxx = source->moments->Mxx;
     285            psF32 Myy = source->moments->Myy;
     286            fprintf (stderr, "2: Mxx: %f, Myy: %f\n", Mxx, Myy);
     287        }
     288
    291289        psTrace ("psphot", 5, "source at %7.1f, %7.1f failed", source->peak->xf, source->peak->yf);
    292290        Nfail ++;
     
    298296
    299297    // change the value of a scalar on the array (wrap this and put it in psArray.h)
    300     scalar = job->args->data[5];
     298    scalar = job->args->data[6];
    301299    scalar->data.S32 = Nfit;
    302300
    303     scalar = job->args->data[6];
     301    scalar = job->args->data[7];
    304302    scalar->data.S32 = Npsf;
    305303
    306     scalar = job->args->data[7];
     304    scalar = job->args->data[8];
    307305    scalar->data.S32 = Next;
    308306
    309     scalar = job->args->data[8];
     307    scalar = job->args->data[9];
    310308    scalar->data.S32 = Nfail;
    311309
Note: See TracChangeset for help on using the changeset viewer.