IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 27, 2008, 7:12:46 PM (18 years ago)
Author:
eugene
Message:

working on the photometry of fake sources

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20080511/ppSim/src/ppSimPhotomReadout.c

    r17709 r17818  
    1 # include "psphotInternal.h"
     1# include "ppSim.h"
    22
    3 bool psphotReadout(pmConfig *config, const pmFPAview *view) {
     3bool ppSimPhotomReadout(pmConfig *config, const pmFPAview *view) {
    44
    55    psTimerStart ("psphotReadout");
     
    1818    }
    1919
    20     // find the currently selected readout
    21     // XXX keep this name or go with something like PPSIM.PHOT.INPUT?
    22     pmReadout  *readout = pmFPAfileThisReadout (config->files, view, "PSPHOT.INPUT");
     20    // find the currently selected readout.
     21    // we always perform photometry on the mosaiced chip
     22    pmReadout  *readout = pmFPAfileThisReadout (config->files, view, "PPSIM.CHIP");
    2323    PS_ASSERT_PTR_NON_NULL (readout, false);
    2424
     
    2727
    2828    // load the psf model, if suppled.  FWHM_X,FWHM_Y,etc are saved in the recipe
     29    // this function uses PSPHOT.PSF.LOAD as the pmFPAfile
    2930    pmPSF *psf = psphotLoadPSF (config, view, recipe);
    3031    assert (psf);
     
    3334    // PPSIM.REAL.SOURCES carries the pmSource objects (from psphot analysis or loaded externally)
    3435    psArray *realSources = psMetadataLookupPtr (NULL, readout->analysis, "PPSIM.REAL.SOURCES");
    35     psArray *fakeSources = psMetadataLookupPtr (NULL, readout->analysis, "PSPHOT.SOURCES");
    36     forceSources = ppSimLoadForceSources (config, view);
     36    psArray *forceSources = ppSimLoadForceSources (config, view);
    3737
    38     // replace all sources
    39     psphotRemoveSources (realSources, recipe);
     38    // XXX make a copy of the fake-source parameters so these can be saved independently
     39    // from the measured fake-source parameters
     40    psArray *injectedSources = psMetadataLookupPtr (NULL, readout->analysis, "PPSIM.SOURCES");
     41    psArray *fakeSources = psArrayAlloc (injectedSources->n);
     42    for (int i = 0; i < injectedSources->n; i++) {
     43      fakeSources->data[i] = pmSourceCopy (injectedSources->data[i]);
     44    }
     45
     46    // remove all sources
     47    psphotRemoveAllSources (realSources, recipe);
    4048
    4149    // generate a background model (median, smoothed image)
    42     if (!psphotModelBackground (config, view, "PSPHOT.INPUT")) {
     50    if (!psphotModelBackground (config, view, "PPSIM.CHIP")) {
    4351        return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);
    4452    }
    45     if (!psphotSubtractBackground (config, view, "PSPHOT.INPUT")) {
     53    if (!psphotSubtractBackground (config, view, "PPSIM.CHIP")) {
    4654        return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);
    4755    }
     
    5159
    5260    // XXX fake sources should measure peak->x,y, force sources should not
     61    psMaskType maskVal = 0xff;
    5362    psImage *significance = psphotSignificanceImage (readout, recipe, 1, maskVal);
    5463    ppSimDetections (significance, recipe, fakeSources);
     
    6069
    6170    // replace all sources
    62     psphotReplaceAll (realSources, recipe);
     71    psphotReplaceAllSources (realSources, recipe);
    6372
    6473    // construct an initial model for each object
     
    6776    psphotGuessModels (readout, forceSources, recipe, psf);
    6877   
     78    psArray *sources = NULL;
     79
    6980    // linear fit to real + fake sources
    70     psArray *sources = ppSimMergeSources (realSources, fakeSources);
     81    sources = ppSimMergeSources (realSources, fakeSources);
    7182    psphotFitSourcesLinear (readout, sources, recipe, psf, FALSE); // XXX option to NOT subtract
    72     psphotReplaceAll (sources, recipe);
     83    psphotReplaceAllSources (sources, recipe);
    7384    psFree (sources); // only frees the merged references
    7485
    7586    // linear fit to real + forced sources
    76     psArray *sources = ppSimMergeSources (realSources, forceSources);
     87    sources = ppSimMergeSources (realSources, forceSources);
    7788    psphotFitSourcesLinear (readout, sources, recipe, psf, FALSE); // XXX option to NOT subtract
    78     psphotReplaceAll (sources, recipe);
     89    psphotReplaceAllSources (sources, recipe);
    7990    psFree (sources); // only frees the merged references
    8091
     
    8596    if (!psphotApResid (readout, forceSources, recipe, psf)) {
    8697        psLogMsg ("psphot", 3, "failed on psphotApResid");
    87         return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);
     98        return psphotReadoutCleanup (config, readout, recipe, NULL, psf, NULL);
    8899    }
    89100
    90     // calculate source magnitudes
     101    // calculate source magnitudes (for which set??)
    91102    pmReadout *background = psphotSelectBackground (config, view, false);
    92     psphotMagnitudes(sources, recipe, psf, background);
     103    psphotMagnitudes(fakeSources, recipe, psf, background);
     104    psphotMagnitudes(forceSources, recipe, psf, background);
    93105
    94106    // drop the references to the image pixels held by each source
    95     psphotSourceFreePixels (sources);
     107    psphotSourceFreePixels (realSources);
     108    psphotSourceFreePixels (fakeSources);
     109    psphotSourceFreePixels (forceSources);
    96110
    97111    // create the exported-metadata and free local data
    98     return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);
     112    // XXX this places the sources on readout->analysis as PSPHOT.SOURCES.  modify?
     113    // (or don't supply the sources, and do this with a different function)
     114    psphotReadoutCleanup(config, readout, recipe, NULL, psf, NULL);
     115
     116    // add forceSources to the readout (real and fake already there)
     117    psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PPSIM.FAKE.SOURCES", PS_DATA_ARRAY, "fake photometry ", fakeSources);
     118    psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PPSIM.FORCE.SOURCES", PS_DATA_ARRAY, "forced photometry ", forceSources);
     119    psFree (forceSources);
     120    return true;
    99121}
Note: See TracChangeset for help on using the changeset viewer.