IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 36633 for trunk/psphot/src


Ignore:
Timestamp:
Apr 2, 2014, 10:50:14 AM (12 years ago)
Author:
bills
Message:

Merge with ipp-20140401 (The staticsky tag)

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/psphot/src

  • trunk/psphot/src/psphotFullForce.SourceStats.c

    r36375 r36633  
    8585    psAssert (markVal, "missing MARK.PSPHOT");
    8686
    87     psArray *sources = detections->allSources;
     87    // psArray *sources = detections->allSources;
     88    psArray *sources = detections->newSources ? detections->newSources : detections->allSources;
    8889
    8990    // generate the array of sources, define the associated pixel
  • trunk/psphot/src/psphotFullForceReadout.c

    r36630 r36633  
    5252    psphotLoadExtSources (config, view, filerule);
    5353
     54#ifdef notmoved
     55    // XXX: moved down below
    5456    // merge the newly selected sources into the existing list (detections->allSources)
    5557    // NOTE: merge OLD and NEW
    5658    psphotMergeSources (config, view, filerule);
     59#endif
    5760
    5861    // construct sources and measure moments and other basic stats (saved on detections->allSources)
     
    6366        return psphotReadoutCleanup (config, view, filerule);
    6467    }
     68   
     69    // classify sources based on moments, brightness.  if a PSF model has been loaded, the PSF
     70    // clump defined for it is used not measured (detections->newSources)
     71    if (!psphotRoughClass (config, view, filerule)) { // pass 1
     72        psError (PSPHOT_ERR_UNKNOWN, false, "failed to determine rough classifications");
     73        return psphotReadoutCleanup (config, view, filerule);
     74    }
     75
     76    // merge the newly selected sources into the existing list (detections->allSources)
     77    // NOTE: merge OLD and NEW
     78    psphotMergeSources (config, view, filerule);
     79
    6580
    6681    // generate a psf model for any readouts which need one
  • trunk/psphot/src/psphotFullForceSummary.c

    r36441 r36633  
    7878        usage();
    7979    }
     80    if ((N = psArgumentGet(argc, argv, "-cff"))) {
     81        if (argc <= N+1) {
     82          psErrorStackPrint(stderr, "Expected to see 1 more argument; saw %d", argc - 1);
     83          usage();
     84        }
     85        psArgumentRemove(N, &argc, argv);
     86
     87        // We read CFF file as table not as sources. All we want are the nominal parameters input to psphotFullForce
     88        psMetadataAddStr(config->arguments, PS_LIST_TAIL, "CFF_FILE", 0, "CFF file with nominal parameters", argv[N]);
     89        psArgumentRemove(N, &argc, argv);
     90    } else {
     91        psErrorStackPrint(stderr, "-cff must be supplied.");
     92        usage();
     93    }
    8094 
    8195    if (argc < 2) {
     
    148162    }
    149163    output->save = true;
     164
     165    // We read cff file as a table not as sources
     166    psString cffName = psMetadataLookupStr(NULL, config->arguments, "CFF_FILE");
     167    if (!cffName) {
     168        psError(PSPHOT_ERR_CONFIG, true, "CFF_FILE is missing from arguments");
     169        return false;
     170    }
     171    psString resolvedName = pmConfigConvertFilename(cffName, config, false, false);
     172    if (!resolvedName) {
     173        psError(PSPHOT_ERR_CONFIG, false, "failed to resolve CFF_FILE %s", cffName);
     174        return false;
     175    }
     176    psFits *fits = psFitsOpen(resolvedName, "r");
     177    if (!fits) {
     178        psError(PSPHOT_ERR_CONFIG, false, "failed to open fits CFF_FILE %s", resolvedName);
     179        return false;
     180    }
     181    psArray *inTable = psFitsReadTable(fits);
     182    if (!inTable) {
     183        psError(PSPHOT_ERR_CONFIG, false, "failed to read cff fits table from CFF_FILE %s", resolvedName);
     184        return false;
     185    }
     186    psFitsClose(fits);
     187
     188    // Convert to an array indexed by ID
     189    psArray *sortedTable = psArrayAlloc(4*inTable->n);
     190    for (int i=0; i<inTable->n; i++) {
     191        psMetadata *row = inTable->data[i];
     192        psS32 ID = psMetadataLookupS32(&status, row, "ID");
     193        if (ID >= sortedTable->n) {
     194            sortedTable = psArrayRealloc(sortedTable, 2*ID);
     195        }
     196        if (sortedTable->data[ID]) {
     197            psError(PSPHOT_ERR_CONFIG, true, "Duplicate row with ID %d", ID);
     198            return false;
     199        }
     200        sortedTable->data[ID] = psMemIncrRefCounter(row);
     201    }
     202    psMetadataAddArray(config->arguments, PS_LIST_TAIL, "CFF_TABLE", PS_META_REPLACE, "cff table", sortedTable);
     203    psFree(inTable);
     204    psFree(sortedTable);
    150205
    151206    return true;
  • trunk/psphot/src/psphotFullForceSummaryReadout.c

    r36441 r36633  
    1414    psArray *zeroPt;
    1515    psArray *exptime;
     16    psArray *cffTable;
    1617} galaxyShapeOptions;
    1718
     
    6970            if (!setOptions(&options, readout, recipe, true)) {
    7071                psError (PS_ERR_UNKNOWN, false, "problem determining galaxy shape options.");
     72                return false;
     73            }
     74            options.cffTable = psMetadataLookupPtr(NULL, config->arguments, "CFF_TABLE");
     75            if (!options.cffTable) {
     76                psError (PS_ERR_UNKNOWN, true, "Cannot find cff table in arguments.");
    7177                return false;
    7278            }
     
    309315                // copy the best fit params to the model
    310316                psEllipseAxes axes = pmPSF_ModelToAxes(outSrc->modelEXT->params->data.F32, outSrc->modelEXT->type);
    311                 axes.major *= options->rMajor->data.F32[min_j];
    312                 axes.minor *= options->rMinor->data.F32[min_j];
     317                if (outSrc->seq >= options->cffTable->n) {
     318                    psError(PS_ERR_PROGRAMMING, true, "object sequence number %d is larger than cff table length %ld",
     319                        outSrc->seq, options->cffTable->n);
     320                    return NULL;
     321                }
     322                psMetadata *row = options->cffTable->data[outSrc->seq];
     323                if (!row) {
     324                    psError (PS_ERR_PROGRAMMING, true, "NO cff data for object %d", outSrc->seq);
     325                    psFree(outSrc);
     326                    return NULL;
     327                }
     328                bool mdok;
     329                psF32 rMajor = psMetadataLookupF32(&mdok, row, "R_MAJOR");
     330                if (!mdok) {
     331                    psError (PS_ERR_PROGRAMMING, true, "can't find R_MAJOR for object %d", outSrc->seq);
     332                    psFree(outSrc);
     333                    return NULL;
     334                }
     335                psF32 rMinor = psMetadataLookupF32(&mdok, row, "R_MINOR");
     336                if (!mdok) {
     337                    psError (PS_ERR_PROGRAMMING, true, "can't find R_MINOR for object %d", outSrc->seq);
     338                    psFree(outSrc);
     339                    return NULL;
     340                }
     341                axes.major = rMajor * options->rMajor->data.F32[min_j];
     342                axes.minor = rMinor * options->rMinor->data.F32[min_j];
    313343                pmPSF_AxesToModel (outSrc->modelEXT->params->data.F32, axes, outSrc->modelEXT->type);
    314344                outSrc->modelEXT->chisq = minChisq;
  • trunk/psphot/src/psphotGalaxyShape.c

    r36441 r36633  
    205205        if (!(source->tmpFlags & PM_SOURCE_TMPF_MOMENTS_MEASURED)) continue;
    206206        if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) continue;
     207        if (!source->modelPSF) continue;
    207208
    208209        // psphotSetRadiusMomentsExact sets the radius based on Mrf
     
    274275
    275276            int i = source->galaxyFits->chisq->n - 1;
    276             float thisChisq = source->galaxyFits->chisq->data.F32[i];
    277             if (isfinite(thisChisq) && (!isfinite(chisqBest) || thisChisq < chisqBest)) {
    278                 chisqBest = thisChisq;
    279                 fRmajorBest = fRmajor;
    280                 fRminorBest = fRminor;
     277            float flux = source->galaxyFits->Flux->data.F32[i];
     278            if (isfinite(flux)) {
     279                float thisChisq = source->galaxyFits->chisq->data.F32[i];
     280                if (isfinite(thisChisq) && isfinite(flux) && (!isfinite(chisqBest) || thisChisq < chisqBest)) {
     281                    chisqBest = thisChisq;
     282                    fRmajorBest = fRmajor;
     283                    fRminorBest = fRminor;
     284                }
    281285            }
     286            // reset I0 to avoid potential problems on the next iteration
     287            PAR[PM_PAR_I0] = 1.0;
    282288        }
    283289    }
    284290
     291#define SAVE_BEST_MODEL
    285292#ifdef SAVE_BEST_MODEL
    286293    // Save model with smallest chisq
     
    301308        psphotGalaxyShapeSource (pcm, source, maskVal, psfSize, false);
    302309
    303         // Replace modelEXT with this model
    304         // XXX: only do this if the model is good
    305         psFree (source->modelEXT);
    306 
    307         source->modelEXT = psMemIncrRefCounter (pcm->modelConv);
    308         source->type = PM_SOURCE_TYPE_EXTENDED;
    309         source->mode |= PM_SOURCE_MODE_EXTMODEL;
    310         source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT;
    311 
    312         // cache the model flux
    313         pmPCMCacheModel (source, maskVal, psfSize, fitOptions->nsigma);
     310        // Replace modelEXT with this model, if the model is good
     311        if (isfinite(PAR[PM_PAR_I0])) {
     312            psFree (source->modelEXT);
     313
     314            source->modelEXT = psMemIncrRefCounter (pcm->modelConv);
     315            source->type = PM_SOURCE_TYPE_EXTENDED;
     316            source->mode |= PM_SOURCE_MODE_EXTMODEL;
     317            source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT;
     318
     319            // cache the model flux
     320            pmPCMCacheModel (source, maskVal, psfSize, fitOptions->nsigma);
     321        }
    314322    }
    315323
  • trunk/psphot/src/psphotStackImageLoop.c

    • Property svn:mergeinfo changed (with no actual effect on merging)
Note: See TracChangeset for help on using the changeset viewer.