IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 33640


Ignore:
Timestamp:
Mar 30, 2012, 2:54:17 PM (14 years ago)
Author:
eugene
Message:

merge changes from trunk

Location:
branches/eam_branches/ipp-20111122/psphot
Files:
23 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20111122/psphot

  • branches/eam_branches/ipp-20111122/psphot/src

  • branches/eam_branches/ipp-20111122/psphot/src/psphotApResid.c

    r32348 r33640  
    154154
    155155        // wait for the threads to finish and manage results
    156         if (!psThreadPoolWait (false)) {
     156        if (!psThreadPoolWait (false, true)) {
    157157            psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
     158            psFree(cellGroups);
    158159            return false;
    159160        }
  • branches/eam_branches/ipp-20111122/psphot/src/psphotBlendFit.c

    r32695 r33640  
    151151
    152152        // wait for the threads to finish and manage results
    153         if (!psThreadPoolWait (false)) {
     153        if (!psThreadPoolWait (false, true)) {
    154154            psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    155155            psFree (fitOptions);
  • branches/eam_branches/ipp-20111122/psphot/src/psphotExtendedSourceAnalysis.c

    r32633 r33640  
    134134
    135135        // wait for the threads to finish and manage results
    136         if (!psThreadPoolWait (false)) {
     136        if (!psThreadPoolWait (false, true)) {
    137137            psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    138138            psFree(AnalysisRegion);
  • branches/eam_branches/ipp-20111122/psphot/src/psphotExtendedSourceFits.c

    r32744 r33640  
    218218
    219219        // wait for the threads to finish and manage results
    220         if (!psThreadPoolWait (false)) {
     220        if (!psThreadPoolWait (false, true)) {
    221221            psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    222222            psFree(AnalysisRegion);
  • branches/eam_branches/ipp-20111122/psphot/src/psphotFindFootprints.c

    r32348 r33640  
    3535        psArray *tmp = pmFootprintArrayGrow(footprints, growRadius);
    3636        psImageConvolveSetThreads(oldThreads);
    37         psLogMsg ("psphot", PS_LOG_MINUTIA, "grow footprint coverage by %d pixels, %ld footprints become %ld footprints: %f sec\n", growRadius, footprints->n, tmp->n, psTimerMark ("psphot.footprints"));
    38         psFree(footprints);
    39         footprints = tmp;
     37        psLogMsg ("psphot", PS_LOG_MINUTIA, "grow footprint coverage by %d pixels, %ld footprints become %ld footprints: %f sec\n", growRadius, footprints->n, tmp ? tmp->n : 0, psTimerMark ("psphot.footprints"));
     38        if (tmp) {
     39            psFree(footprints);
     40            footprints = tmp;
     41        } else {
     42            psLogMsg ("psphot", PS_LOG_WARN, "pmFootprintArray grow returned NULL\n");
     43        }
     44           
    4045    }
    4146
  • branches/eam_branches/ipp-20111122/psphot/src/psphotFitSourcesLinear.c

    r33094 r33640  
    280280    psLogMsg ("psphot.ensemble", PS_LOG_MINUTIA, "built fitSources: %f sec (%ld objects)\n", psTimerMark ("psphot.linear"), sources->n);
    281281
    282     // fprintf (stderr, "****** Nsat : %d ********\n", Nsat);
    283 
    284282    if (fitSources->n == 0) {
    285283        psFree(fitSources);
  • branches/eam_branches/ipp-20111122/psphot/src/psphotForcedReadout.c

    r32924 r33640  
    5555    psphotLoadExtSources (config, view, filerule);
    5656
     57    // merge the newly selected sources into the existing list
     58    // NOTE: merge OLD and NEW
     59    psphotMergeSources (config, view, filerule);
     60
    5761    // Construct an initial model for each object, set the radius to fitRadius, set circular
    5862    // fit mask.  NOTE: only applied to sources without guess models
    5963    psphotGuessModels (config, view, filerule);
    60 
    61     // merge the newly selected sources into the existing list
    62     // NOTE: merge OLD and NEW
    63     psphotMergeSources (config, view, filerule);
    6464
    6565    // linear PSF fit to source peaks, subtract the models from the image (in PSF mask)
  • branches/eam_branches/ipp-20111122/psphot/src/psphotGuessModels.c

    r32924 r33640  
    112112        // wait here for the threaded jobs to finish
    113113        // fprintf (stderr, "wait for threads (%d, %d)\n", jx, jy);
    114         if (!psThreadPoolWait (false)) {
     114        if (!psThreadPoolWait (false, true)) {
     115            // harvest our jobs
     116            psFree(cellGroups);
    115117            psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    116118            return false;
  • branches/eam_branches/ipp-20111122/psphot/src/psphotKronIterate.c

    r33612 r33640  
    163163
    164164        // wait for the threads to finish and manage results
    165         if (!psThreadPoolWait (false)) {
     165        if (!psThreadPoolWait (false, true)) {
    166166            psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    167167            return false;
  • branches/eam_branches/ipp-20111122/psphot/src/psphotMagnitudes.c

    r32348 r33640  
    129129
    130130        // wait for the threads to finish and manage results
    131         if (!psThreadPoolWait (false)) {
     131        if (!psThreadPoolWait (false, true)) {
    132132            psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    133133            return false;
     
    309309
    310310        // wait for the threads to finish and manage results
    311         if (!psThreadPoolWait (false)) {
     311        if (!psThreadPoolWait (false, true)) {
    312312            psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    313313            return false;
  • branches/eam_branches/ipp-20111122/psphot/src/psphotMergeSources.c

    r32695 r33640  
    677677      if (sourceOut->modelPSF) {
    678678        pmSourceRedefinePixels (sourceOut, readoutOut, sourceOut->peak->x, sourceOut->peak->y, sourceOut->modelPSF->fitRadius);
    679       }
     679      } else {
     680        // if we have no pixels we can't use it to determine the psf so make sure this bit is off
     681        sourceOut->tmpFlags &= ~PM_SOURCE_TMPF_CANDIDATE_PSFSTAR;
     682       }
    680683
    681684      // child sources have not been subtracted in this image, but this flag may be raised if
     
    900903            // allocate image, weight, mask for the new image for each peak
    901904            if (sourceOut->modelPSF) {
    902               pmSourceRedefinePixels (sourceOut, readout, sourceOut->peak->x, sourceOut->peak->y, sourceOut->modelPSF->fitRadius);
    903             }
     905                pmSourceRedefinePixels (sourceOut, readout, sourceOut->peak->x, sourceOut->peak->y,
     906                                                                        sourceOut->modelPSF->fitRadius);
     907            } else {
     908                // if we have no pixels we can't use it to determine the psf so make sure this bit is off
     909                sourceOut->tmpFlags &= ~PM_SOURCE_TMPF_CANDIDATE_PSFSTAR;
     910            }
    904911
    905912            // child sources have not been subtracted in this image, but this flag may be raised if
  • branches/eam_branches/ipp-20111122/psphot/src/psphotRadialApertures.c

    r32633 r33640  
    176176
    177177        // wait for the threads to finish and manage results
    178         if (!psThreadPoolWait (false)) {
     178        if (!psThreadPoolWait (false, true)) {
    179179            psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    180180            psFree(AnalysisRegion);
  • branches/eam_branches/ipp-20111122/psphot/src/psphotRadialProfileWings.c

    r32850 r33640  
    147147
    148148        // wait for the threads to finish and manage results
    149         if (!psThreadPoolWait (false)) {
     149        if (!psThreadPoolWait (false, true)) {
    150150            psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    151151            return false;
     
    307307            // linearly interpolate to the radius at which we hit the sky, using the last flux and the limiting slope
    308308            if (isfinite(lastFlux)) {
    309                 limitRadius = lastRadius + lastFlux / 3.0;
     309                float interpolatedRadius = lastRadius + lastFlux / 3.0;
     310                if (interpolatedRadius < MAX_RADIUS) {
     311                    limitRadius = interpolatedRadius;
     312                } else {
     313                    // XXX should we keep going in this case?
     314                    limitRadius = meanRadius;
     315                }
    310316            } else {
    311317                limitRadius = meanRadius;
  • branches/eam_branches/ipp-20111122/psphot/src/psphotReadout.c

    r32924 r33640  
    133133    // Construct an initial model for each object, set the radius to fitRadius, set circular
    134134    // fit mask.  NOTE: only applied to sources without guess models
    135     psphotGuessModels (config, view, filerule); // pass 1
     135    // pass 1
     136    if (!psphotGuessModels (config, view, filerule)) {
     137        psLogMsg ("psphot", 3, "failure to Guess Model - pass 1");
     138        return psphotReadoutCleanup (config, view, filerule);
     139    }
    136140
    137141    // linear PSF fit to source peaks, subtract the models from the image (in PSF mask)
     
    155159    // non-linear PSF and EXT fit to brighter sources
    156160    // replace model flux, adjust mask as needed, fit, subtract the models (full stamp)
     161    // XXX: can leave faulted job in done queue
    157162    psphotBlendFit (config, view, filerule); // pass 1 (detections->allSources)
    158163
  • branches/eam_branches/ipp-20111122/psphot/src/psphotSersicModelClass.c

    r32348 r33640  
    546546    // set the normalization by linear fit between model and data
    547547    psphotSersicModelNorm (pcm, source);
     548    if (!isfinite(PAR[PM_PAR_I0])) {
     549        fprintf(stderr, "psphotSersicModelClassGuessPCM: psphotSerisicModelNorm set PM_PAR_I0 to NAN\n");
     550        return false;
     551    }
    548552
    549553    if (TIMING) { t5 = psTimerMark ("SersicGuess"); }
  • branches/eam_branches/ipp-20111122/psphot/src/psphotSourceMatch.c

    r32924 r33640  
    33bool psphotMatchSourcesAddMissing (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objects);
    44bool psphotMatchSourcesSetIDs (psArray *objects);
     5
     6static psArray     *psphotMatchFootprintCacheAlloc (int nImages);
     7static pmFootprint *psphotMatchLookupFootprint (psArray *cache, int footprintID, int imageID);
     8static pmFootprint *psphotMatchCopyFootprint (psArray *cache, pmFootprint *footprint, int imageID, psImage *image, psArray *footprints);
    59 
    610psArray *psphotMatchSources (pmConfig *config, const pmFPAview *view, const char *filerule)
     
    193197    // vector to track if source for an image is found
    194198    psVector *found = psVectorAlloc(nImages, PS_TYPE_U8);
     199    psArray *footprintCache = psphotMatchFootprintCacheAlloc(nImages);
    195200
    196201    for (int i = 0; i < objects->n; i++) {
     
    219224
    220225        // we make a copy of the largest footprint; this will be used for all new sources associated with this object
    221         pmFootprint *footprint = NULL;
     226        pmFootprint *largestFootprint = NULL;
    222227        if (iSpansMax != -1) { // copy the footprint info
    223228            pmSource *src = obj->sources->data[iSpansMax];
     
    226231            psAssert(src->peak->footprint->nspans == nSpansMax, "wrong footprint?");
    227232           
    228             // we only care about the spans, do not worry about the image of this footprint
    229             footprint = pmFootprintCopyData(src->peak->footprint, NULL);
     233            largestFootprint = src->peak->footprint;
    230234        }
    231235
     
    248252           
    249253            // assign to a footprint on this readout->image
    250             if (footprint) {
    251                 peak->footprint = pmFootprintCopyData(footprint, readout->image);
    252 
    253                 // the peak does not claim ownership of the footprint (it does not free it). save a copy of this
    254                 // footprint on detections->footprints so we can free it later
    255                 psArrayAdd(detections->footprints, 100, peak->footprint);
    256                 psFree (peak->footprint);
     254            if (largestFootprint) {
     255                // we save the copies that we make of the of the footprints in a hash so that we can reuse them
     256                // for all sources that share the fooprint. Without this we had serious memory explosion in
     257                // dense fields with lots of footprints (spans are small but when you have enough of them ...)
     258                peak->footprint = psphotMatchLookupFootprint(footprintCache, largestFootprint->id, index);
     259                if (!peak->footprint) {
     260                    // the peak does not claim ownership of the footprint (it does not free it).
     261                    // psphotMatchCopyFootprint saves a copy of this
     262                    // footprint on detections->footprints so we can free it later
     263                    peak->footprint = psphotMatchCopyFootprint(footprintCache, largestFootprint,
     264                                            index, readout->image, detections->footprints);
     265                }
    257266            }
    258267           
     
    272281            pmSourceDefinePixels (source, readout, source->peak->x, source->peak->y, OUTER);
    273282
     283#if (0)
     284            fprintf(stderr, "Add mising source for obj: %5d %5d image: %d flux: %f size: %4d %4d\n",
     285                                                      i, obj->id, index, peakFlux, source->pixels->numRows, source->pixels->numCols);
     286#endif
     287
    274288            peak->assigned = true;
    275289            pmPhotObjAddSource(obj, source);
     
    277291            psFree (source);
    278292        }
    279         psFree (footprint);
    280     }
     293    }
     294    psFree(footprintCache);
    281295
    282296    // how many sources do we have now?
     
    309323    return true;
    310324}
     325
     326// Cache of footprints created for unmatched sources.
     327static psArray * psphotMatchFootprintCacheAlloc (int nImages) {
     328    psArray *cache = psArrayAlloc(nImages);
     329    for (int i = 0; i < nImages; i++) {
     330        psHash *hash = psHashAlloc(5000);
     331        cache->data[i] = hash;
     332    }
     333    return cache;
     334}
     335
     336// Find copy of footprint with given ID made for a given image
     337static pmFootprint *psphotMatchLookupFootprint (psArray *cache, int footprintID, int imageID) {
     338    psHash *hash = (psHash *) cache->data[imageID];
     339
     340    psAssert(hash != NULL, "missing hash for image %d", imageID);
     341
     342    // footprintID is the id of the original footprint.
     343    char key[32];
     344    sprintf(key, "%d", footprintID);
     345
     346    // The footprints in our hashes are the copies of that footprint for the respective images
     347    pmFootprint *copy = psHashLookup(hash, key);
     348
     349    return copy;
     350}
     351
     352// Create a copy of a given footprint for a given image
     353static pmFootprint *psphotMatchCopyFootprint (psArray *cache, pmFootprint *footprint, int imageID, psImage *image, psArray *footprints) {
     354
     355    psAssert((imageID >= 0 && imageID < cache->n), "invalid imageID %d", imageID);
     356
     357    psHash *hash = (psHash *) cache->data[imageID];
     358
     359    psAssert(hash != NULL, "missing hash for image %d", imageID);
     360
     361    char key[32];
     362    sprintf(key, "%d", footprint->id);
     363
     364    pmFootprint *copy = pmFootprintCopyData (footprint, image);
     365
     366    // save a copy in this image's hash
     367    psHashAdd(hash, key, copy);
     368
     369    // save a copy of this footprint on the passed in footprints Array so we can free it later
     370    psArrayAdd(footprints, 100, copy);
     371
     372    // drop our ref
     373    psFree(copy);
     374
     375    return copy;
     376}
  • branches/eam_branches/ipp-20111122/psphot/src/psphotSourceStats.c

    r32699 r33640  
    216216
    217217        // wait for the threads to finish and manage results
    218         if (!psThreadPoolWait (false)) {
     218        if (!psThreadPoolWait (false, true)) {
    219219            psError(PS_ERR_UNKNOWN, false, "Failure in thread job PSPHOT_SOURCE_STATS");
    220220            psFree(detections->newSources);
     
    347347
    348348        // wait for the threads to finish and manage results
    349         if (!psThreadPoolWait (false)) {
     349        if (!psThreadPoolWait (false, true)) {
    350350            psError(PS_ERR_UNKNOWN, false, "Failure in thread job PSPHOT_SOURCE_STATS");
    351351            return NULL;
  • branches/eam_branches/ipp-20111122/psphot/src/psphotStackImageLoop.c

  • branches/eam_branches/ipp-20111122/psphot/src/psphotStackMatchPSFs.c

    r32348 r33640  
    101101    // Image Matching (PSFs or just flux)
    102102    if (options->convolve) {
    103         matchKernel(config, readoutOut, readoutSrc, options, index);
     103        if (!matchKernel(config, readoutOut, readoutSrc, options, index)){
     104            psError(psErrorCodeLast(), false, "Unable to match image PSF in readout.");
     105            return false;
     106        }
    104107        saveMatchData(readoutOut, options, index);
    105108    }
  • branches/eam_branches/ipp-20111122/psphot/src/psphotStackMatchPSFsPrepare.c

    r32348 r33640  
    3232        pmDetections *detections = psMetadataLookupPtr(NULL, readout->analysis, "PSPHOT.DETECTIONS"); // Sources
    3333        if (!detections || !detections->allSources) {
    34             psWarning("No detections found for image %d --- rejecting.", index);
    35             options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[index] = 0x01;
    36             return true;  // XXX not an error: we continue processing other images
     34            // An input must have sources. If we got here without any the input file was likely corrupt
     35            psError(PSPHOT_ERR_IO, true, "Input %d has no sources.\n\tCheck all instances of: %s", index, inputSrc->origname);
     36            return false;
    3737        }
    3838        psAssert (detections->allSources, "missing sources?");
  • branches/eam_branches/ipp-20111122/psphot/src/psphotTest.c

    r33086 r33640  
    8585
    8686    // wait for the threads to finish and manage results
    87     if (!psThreadPoolWait (true)) {
     87    if (!psThreadPoolWait (true, true)) {
    8888        fprintf (stderr, "failure to run FillImage (2)");
    8989        exit (1);
Note: See TracChangeset for help on using the changeset viewer.