IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 26, 2009, 1:59:32 PM (17 years ago)
Author:
beaumont
Message:

merged with trunk

Location:
branches/cnb_branches/cnb_branch_20090301
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/cnb_branches/cnb_branch_20090301

  • branches/cnb_branches/cnb_branch_20090301/ppSub

  • branches/cnb_branches/cnb_branch_20090301/ppSub/src

    • Property svn:ignore
      •  

        old new  
        1010stamp-h1
        1111ppSubKernel
         12ppSubErrorCodes.h
         13ppSubErrorCodes.c
         14ppSubVersionDefinitions.h
  • branches/cnb_branches/cnb_branch_20090301/ppSub/src/ppSubReadoutPhotometry.c

    r21524 r24244  
    2222#include "ppSub.h"
    2323
    24 bool ppSubReadoutPhotometry (pmConfig *config, psMetadata *stats, const pmFPAview *view)
     24bool ppSubReadoutPhotometry(const char *name, ppSubData *data)
    2525{
     26    psAssert(data, "Require processing data");
     27    pmConfig *config = data->config;    // Configuration
    2628    psAssert(config, "Require configuration");
    27     psAssert(view, "Require view");
     29
     30    if (!data->photometry) {
     31        return true;
     32    }
    2833
    2934    // Look up recipe values
     
    3944    // The PSF (measured in ppSubMakePSF) is stored on the chip->analysis of PSPHOT.INPUT
    4045    // In order to use an incoming PSF, it must be stored on the chip->analysis of PSPHOT.PSF.LOAD
     46    pmFPAview *view = ppSubViewReadout(); // View to readout
    4147    pmChip *psfInputChip = pmFPAfileThisChip(config->files, view, "PSPHOT.INPUT"); // Chip with PSF
    4248    psAssert (psfInputChip, "should have been generated for ppSubMakePSF");
     
    4551    pmPSF *psf = psMetadataLookupPtr(NULL, psfInputChip->analysis, "PSPHOT.PSF"); // PSF for photometry
    4652    if (!psf) {
    47         psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find PSF from psphot");
    48         return false;
     53        psErrorStackPrint(stderr, "No PSF available");
     54        psWarning("No PSF available --- suspect bad data quality.");
     55        ppSubDataQuality(data, psErrorCodeLast(), PPSUB_FILES_PHOT_SUB | PPSUB_FILES_PHOT_INV);
     56        return true;
    4957    }
    5058    psMetadataAddPtr(psfLoadChip->analysis, PS_LIST_TAIL, "PSPHOT.PSF", PS_DATA_UNKNOWN | PS_META_REPLACE,
     
    5664    // around the pointers so PSPHOT.INPUT corresponds to the output image; previously, it was
    5765    // equivalent to the minuend image.
    58     pmFPAfile *outputFile = psMetadataLookupPtr(&mdok, config->files, "PPSUB.OUTPUT"); // Output file
    59     pmReadout *outRO = pmFPAviewThisReadout(view, outputFile->fpa); // Readout with the sources
     66    pmReadout *inRO = pmFPAfileThisReadout(config->files, view, name); // Readout with image and sources
    6067
    61     // XXX possibly rename this to PPSUB.RESID?
    6268    pmFPAfile *photFile = psMetadataLookupPtr(&mdok, config->files, "PSPHOT.INPUT"); // Photometry file
     69    pmFPAfile *inFile = psMetadataLookupPtr(&mdok, config->files, name); // Input file
     70    if (!pmFPACopy(photFile->fpa, inFile->fpa)) {
     71        psError(PS_ERR_UNKNOWN, false, "Unable to copy FPA for photometry");
     72        psFree(view);
     73        return false;
     74    }
    6375    pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout to photometer
    64     if (!photRO) {
    65         pmCell *cell = pmFPAviewThisCell(view, photFile->fpa); // Cell to photometer
    66         photRO = pmReadoutAlloc(cell); // Output readout: subtraction
    67     }
    68     photRO->image = psImageCopy(photRO->image, outRO->image, PS_TYPE_F32);
    69     if (outRO->variance) {
    70         photRO->variance = psImageCopy(photRO->variance, outRO->variance, PS_TYPE_F32);
    71     } else {
    72         psFree(photRO->variance);
    73         photRO->variance = NULL;
    74     }
    75     if (outRO->mask) {
    76         photRO->mask = psImageCopy(photRO->mask, outRO->mask, PS_TYPE_IMAGE_MASK);
    77     } else {
    78         psFree(photRO->mask);
    79         photRO->mask = NULL;
     76    if (psMetadataLookup(photRO->analysis, "PSPHOT.SOURCES")) {
     77        psMetadataRemoveKey(photRO->analysis, "PSPHOT.SOURCES");
    8078    }
    8179
    82 #if 0
    83     psMetadataAddPtr(config->files, PS_LIST_TAIL, "PSPHOT.INPUT", PS_DATA_UNKNOWN | PS_META_REPLACE,
    84                      "psphot input: view on another pmFPAfile", photFile);
    85 #endif
     80    psMetadataAddPtr(photRO->parent->parent->analysis, PS_LIST_TAIL, "PSPHOT.PSF",
     81                     PS_META_REPLACE | PS_DATA_UNKNOWN, "Point-spread function", data->psf);
     82
     83    psFree(photRO->analysis);
     84    photRO->analysis = psMetadataAlloc();
    8685
    8786    if (!psphotReadoutMinimal(config, view)) {
    88         psWarning("Unable to perform photometry on subtracted image.");
    89         psErrorStackPrint(stderr, "Error stack from photometry:");
    90         psErrorClear();
     87        // This is likely a data quality issue
     88        // XXX Split into multiple cases using error codes?
     89        psErrorStackPrint(stderr, "Unable to perform photometry on image");
     90        psWarning("Unable to perform photometry on image --- suspect bad data quality.");
     91        ppSubDataQuality(data, psErrorCodeLast(), PPSUB_FILES_PHOT_SUB | PPSUB_FILES_PHOT_INV);
    9192    }
    92 #if 1
    93     photRO->data_exists = true;
    94     photRO->parent->data_exists = true;
    95     photRO->parent->parent->data_exists = true;
    96 #endif
    9793
    98     if (stats) {
     94    if (data->stats) {
    9995        psArray *sources = psMetadataLookupPtr(NULL, photRO->analysis, "PSPHOT.SOURCES"); // Sources
    100         psMetadataAddS32(stats, PS_LIST_TAIL, "NUM_SOURCES", 0, "Number of sources detected",
    101                          sources ? sources->n : 0);
    102         psMetadataAddF32(stats, PS_LIST_TAIL, "TIME_PHOT", 0, "Time to do photometry",
    103                          psTimerClear("PPSUB_PHOT"));
     96        bool mdok;
     97        int numSources = psMetadataLookupS32(&mdok, data->stats, "NUM_SOURCES"); // Number of sources
     98        numSources += sources ? sources->n : 0;
     99        psMetadataAddS32(data->stats, PS_LIST_TAIL, "NUM_SOURCES", PS_META_REPLACE,
     100                         "Total number of sources detected", numSources);
     101        float newTime = psTimerClear("PPSUB_PHOT"); // Time for photometry
     102        float oldTime = psMetadataLookupF32(&mdok, data->stats, "TIME_PHOT"); // Previous time for photometry
     103        psMetadataAddF32(data->stats, PS_LIST_TAIL, "TIME_PHOT", PS_META_REPLACE, "Time to do photometry",
     104                         isfinite(oldTime) ? oldTime + newTime : newTime);
     105    }
     106
     107    if (!data->quality) {
     108        if (!psMetadataCopySingle(inRO->analysis, photRO->analysis, "PSPHOT.SOURCES")) {
     109            psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to copy PSPHOT.SOURCES");
     110            return false;
     111        }
     112        if (!psMetadataCopySingle(inRO->analysis, photRO->analysis, "PSPHOT.HEADER")) {
     113            psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to copy PSPHOT.HEADER");
     114            return false;
     115        }
    104116    }
    105117
Note: See TracChangeset for help on using the changeset viewer.