IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 25, 2015, 10:05:06 PM (11 years ago)
Author:
eugene
Message:

merge changes from trunk

Location:
branches/eam_branches/ipp-20150616
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20150616

  • branches/eam_branches/ipp-20150616/psphot/src/psphotMergeSources.c

    r38389 r38552  
    853853// array containing the child sources.  XXX currently, this is only used by psphotStackReadout
    854854// (sources go on allSources so that psphotChoosePSF can be called repeatedly)
    855 psArray *psphotSourceChildrenByObject (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objectsSrc, bool sourcesSubtracted) {
     855psArray *psphotSourceChildrenByObject (pmConfig *config, const pmFPAview *view, const char *fileruleOut, const char *fileruleSrc, psArray *objectsSrc, bool sourcesSubtracted) {
    856856
    857857    bool status;
    858858
    859     int nImages = psphotFileruleCount(config, filerule);
     859    int nImages = psphotFileruleCount(config, fileruleOut);
    860860
    861861    // generate look-up arrays for detections and readouts
    862862    psArray *detArrays = psArrayAlloc(nImages);
    863863    psArray *readouts = psArrayAlloc(nImages);
     864    psArray *fitOptionsArray = psArrayAlloc(nImages);
     865
     866    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
     867    assert (recipe);
     868    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT");
     869    assert (maskVal);
     870    int psfSize  = psMetadataLookupS32 (&status, recipe, "PCM_BOX_SIZE");
     871    assert (status);
    864872
    865873    for (int i = 0; i < nImages; i++) {
    866874
    867875        // find the currently selected readout
    868         pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, i); // File of interest
     876        pmFPAfile *file = pmFPAfileSelectSingle(config->files, fileruleOut, i); // File of interest
    869877        psAssert (file, "missing file?");
    870878
    871879        pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
    872880        psAssert (readout, "missing readout?");
     881
     882        pmFPAfile *fileSrc = pmFPAfileSelectSingle(config->files, fileruleSrc, i); // File of interest
     883        psAssert (file, "missing file?");
     884
     885        pmReadout *readoutSrc = pmFPAviewThisReadout(view, fileSrc->fpa);
     886        psAssert (readoutSrc, "missing readout?");
     887
    873888
    874889        // create DETECTIONS containers for each image, in case one lacks it
     
    886901            psAssert (detections, "missing detections?");
    887902        }
     903        pmSourceFitOptions *fitOptions = NULL;
     904        if (psMetadataLookupBool(&status, recipe, "EXTENDED_SOURCE_FITS")) {
     905            fitOptions = psMetadataLookupPtr (&status, readoutSrc->analysis, "PCM_FIT_OPTIONS");
     906            psAssert (fitOptions, "missing pcm fit options");
     907            psMetadataAddPtr (readout->analysis, PS_LIST_TAIL, "PCM_FIT_OPTIONS", PS_DATA_UNKNOWN | PS_META_REPLACE, "pcm fit options", fitOptions);
     908        }
    888909
    889910        // we need to save the new sources on the detection arrays of the appropriate image
    890911        detArrays->data[i] = psMemIncrRefCounter(detections);
    891912        readouts->data[i] = psMemIncrRefCounter(readout);
     913        if (fitOptions) {
     914            fitOptionsArray->data[i] = psMemIncrRefCounter(fitOptions);
     915        }
    892916    }
    893917
     
    932956            // does this copy all model data? (NO)
    933957            sourceOut->modelPSF = pmModelCopy(sourceSrc->modelPSF);
    934             sourceOut->modelEXT = pmModelCopy(sourceSrc->modelEXT);
    935 
     958
     959            bool foundModelEXT = false;
    936960            if (sourceSrc->modelFits) {
    937961                sourceOut->modelFits = psArrayAlloc(sourceSrc->modelFits->n);
    938962                for (int j = 0; j < sourceSrc->modelFits->n; j++) {
    939                     sourceOut->modelFits->data[j] = pmModelCopy(sourceSrc->modelFits->data[j]);
    940                 }
     963                    pmModel *modelSrc = sourceSrc->modelFits->data[j];
     964                    pmModel *modelOut = sourceOut->modelFits->data[j] = pmModelCopy(modelSrc);
     965                    if (modelSrc == sourceSrc->modelEXT) {
     966                        foundModelEXT = true;
     967                        sourceOut->modelEXT = psMemIncrRefCounter (modelOut);
     968                    }
     969                    modelOut->isPCM = modelSrc->isPCM;
     970                }
    941971            }
     972            if (!foundModelEXT && sourceSrc->modelEXT) {
     973                // Will this ever happen?
     974                sourceOut->modelEXT = pmModelCopy(sourceSrc->modelEXT);
     975            }
    942976
    943977            // drop the references to the original image pixels:
     
    949983            pmReadout *readout = readouts->data[index];
    950984
     985            pmSourceFitOptions *fitOptions = fitOptionsArray->data[index];
     986
    951987            // allocate image, weight, mask for the new image for each peak
    952988            if (sourceOut->modelPSF) {
    953989                pmSourceRedefinePixels (sourceOut, readout, sourceOut->peak->x, sourceOut->peak->y,
    954                                                                         sourceOut->modelPSF->fitRadius);
     990                                                                        sourceSrc->windowRadius);
    955991            } else {
    956992                // if we have no pixels we can't use it to determine the psf so make sure this bit is off
     
    9651001            if (!sourcesSubtracted) {
    9661002                sourceOut->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
    967             }
     1003            } else {
     1004                bool isPSF = false;
     1005                pmModel *model = pmSourceGetModel (&isPSF, sourceOut);
     1006                if (model && sourceSrc->modelFlux) {
     1007                    if (model->isPCM) {
     1008                        pmPCMdata *pcm = pmPCMinit (sourceOut, fitOptions, model, maskVal, psfSize);
     1009                        if (pcm) {
     1010                            // pmPCMMakeModel (sourceOut, model, pcm->nsigma, maskVal, psfSize);
     1011                            pmPCMCacheModel (sourceOut, maskVal, psfSize, pcm->nsigma);
     1012                            psFree(pcm);
     1013                        } else {
     1014                            // What to do here?
     1015                            psAssert (pcm, "pmPCMinit failed!");
     1016                        }
     1017                    } else {
     1018                        pmSourceCacheModel (sourceOut, maskVal);
     1019                    }
     1020                }
     1021            }
    9681022
    9691023            // set the output detections:
     
    9811035    psFree (detArrays);
    9821036    psFree (readouts);
     1037    psFree (fitOptionsArray);
    9831038
    9841039    return objectsOut;
Note: See TracChangeset for help on using the changeset viewer.