IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 21, 2010, 3:01:12 PM (16 years ago)
Author:
eugene
Message:

for psf-matched images: re-determine the psf; re-generate the models with the new psf; re-fit the fluxes; subtract all sources; as radial aperture fluxes are measured only replace the current source of interest; replace all sources before convolving to the next psf

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20101205/psphot/src/psphotReplaceUnfit.c

    r29936 r30141  
    7575      pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
    7676    }
     77
     78    psphotVisualShowImage(readout);
    7779    psLogMsg ("psphot.replace", PS_LOG_INFO, "replaced models for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot.replace"));
    7880    return true;
     
    101103    return true;
    102104}
     105
     106// modify the sources to point at the corresponding pixels for the given filerule
     107bool psphotRedefinePixels (pmConfig *config, const pmFPAview *view, const char *filerule)
     108{
     109    bool status = true;
     110
     111    // select the appropriate recipe information
     112    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
     113    psAssert (recipe, "missing recipe?");
     114
     115    int num = psphotFileruleCount(config, filerule);
     116
     117    // loop over the available readouts
     118    for (int i = 0; i < num; i++) {
     119        if (!psphotRedefinePixelsReadout (config, view, filerule, i, recipe)) {
     120            psError (PSPHOT_ERR_CONFIG, false, "failed to replace all sources for %s entry %d", filerule, i);
     121            return false;
     122        }
     123    }
     124    return true;
     125}
     126
     127bool psphotRedefinePixelsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe) {
     128
     129    bool status;
     130    pmSource *source;
     131
     132    psTimerStart ("psphot.replace");
     133
     134    // find the currently selected readout
     135    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest
     136    psAssert (file, "missing file?");
     137
     138    pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
     139    psAssert (readout, "missing readout?");
     140
     141    // XXX the sources have already been copied (merge into here?)
     142    pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
     143    psAssert (detections, "missing detections?");
     144
     145    psArray *sources = detections->allSources;
     146    psAssert (sources, "missing sources?");
     147
     148    // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
     149    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
     150    psAssert (maskVal, "missing mask value?");
     151
     152    for (int i = 0; i < sources->n; i++) {
     153      source = sources->data[i];
     154
     155      // sources have not yet been subtracted in this image (but this flag may be raised)
     156      source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
     157
     158      float Xo = source->modelPSF->params->data.F32[PM_PAR_XPOS];
     159      float Yo = source->modelPSF->params->data.F32[PM_PAR_YPOS];
     160      float radius = source->modelPSF->fitRadius;
     161      if (radius < 1) {
     162          fprintf (stderr, "!");
     163      }
     164
     165      pmSourceRedefinePixels (source, readout, Xo, Yo, radius, true);
     166    }
     167    return true;
     168}
     169
     170// for now, let's store the detections on the readout->analysis for each readout
     171bool psphotResetModels (pmConfig *config, const pmFPAview *view, const char *filerule)
     172{
     173    bool status = true;
     174
     175    // select the appropriate recipe information
     176    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
     177    psAssert (recipe, "missing recipe?");
     178
     179    int num = psphotFileruleCount(config, filerule);
     180
     181    // loop over the available readouts
     182    for (int i = 0; i < num; i++) {
     183        if (!psphotResetModelsReadout (config, view, filerule, i, recipe)) {
     184            psError (PSPHOT_ERR_CONFIG, false, "failed to replace all sources for %s entry %d", filerule, i);
     185            return false;
     186        }
     187    }
     188    return true;
     189}
     190
     191bool psphotResetModelsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe) {
     192
     193    bool status;
     194    pmSource *source;
     195
     196    psTimerStart ("psphot.replace");
     197
     198    // find the currently selected readout
     199    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest
     200    psAssert (file, "missing file?");
     201
     202    pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
     203    psAssert (readout, "missing readout?");
     204
     205    // XXX the sources have already been copied (merge into here?)
     206    pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
     207    psAssert (detections, "missing detections?");
     208
     209    psArray *sources = detections->allSources;
     210    psAssert (sources, "missing sources?");
     211
     212    // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
     213    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
     214    psAssert (maskVal, "missing mask value?");
     215
     216    pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");
     217    psAssert (psf, "missing psf?");
     218
     219    for (int i = 0; i < sources->n; i++) {
     220      source = sources->data[i];
     221
     222      // sources have not yet been subtracted in this image (but this flag may be raised)
     223      source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
     224
     225      // the guess central intensity comes from the peak:
     226      float Io = source->peak->flux;
     227      float Xo = source->modelPSF->params->data.F32[PM_PAR_XPOS];
     228      float Yo = source->modelPSF->params->data.F32[PM_PAR_YPOS];
     229      float radius = source->modelPSF->fitRadius;
     230
     231      // generate a model for this object with Io = 1.0
     232      pmModel *modelPSF = pmModelFromPSFforXY(psf, Xo, Yo, Io);
     233      if (modelPSF == NULL) {
     234          psWarning ("Failed to determine PSF model for source at (%f,%f), skipping", Xo, Yo);
     235          continue;
     236      }
     237
     238      // set the source PSF model
     239      psFree (source->modelPSF);
     240      source->modelPSF = modelPSF;
     241      source->modelPSF->fitRadius = radius;
     242
     243      pmSourceCacheModel (source, maskVal);  // ALLOC x14 (!)
     244    }
     245
     246    // psphotSaveImage(NULL, readoutIn->image, "image.in.fits");
     247    // psphotSaveImage(NULL, readoutOut->image, "image.out.sub.fits");
     248    // psphotVisualShowImage (readout);
     249
     250    psLogMsg ("psphot.replace", PS_LOG_INFO, "subtracted models for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot.replace"));
     251    return true;
     252}
     253
Note: See TracChangeset for help on using the changeset viewer.