IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 10, 2010, 7:42:02 PM (16 years ago)
Author:
eugene
Message:

updates from eam_branches/20091201

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppSub/src/ppSubReadoutPhotometry.c

    r26264 r26899  
    2424bool ppSubReadoutPhotometry(const char *name, ppSubData *data)
    2525{
     26    bool mdok = false;
     27
    2628    psAssert(data, "Require processing data");
    2729    pmConfig *config = data->config;    // Configuration
     
    4244    }
    4345
    44     // The PSF (measured in ppSubMakePSF) is stored on the chip->analysis of PSPHOT.INPUT
    45     // In order to use an incoming PSF, it must be stored on the chip->analysis of PSPHOT.PSF.LOAD
     46    // select the view of interest
    4647    pmFPAview *view = ppSubViewReadout(); // View to readout
    47     pmChip *psfInputChip = pmFPAfileThisChip(config->files, view, "PSPHOT.INPUT"); // Chip with PSF
    48     psAssert (psfInputChip, "should have been generated for ppSubMakePSF");
    49     pmChip *psfLoadChip = pmFPAfileThisChip(config->files, view, "PSPHOT.PSF.LOAD"); // Chip to have PSF
    50     psAssert (psfLoadChip, "PSPHOT.PSF.LOAD should have been defined in ppSubCamera");
    51     pmPSF *psf = psMetadataLookupPtr(NULL, psfInputChip->analysis, "PSPHOT.PSF"); // PSF for photometry
    52     if (!psf) {
    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;
    57     }
    58     psMetadataAddPtr(psfLoadChip->analysis, PS_LIST_TAIL, "PSPHOT.PSF", PS_DATA_UNKNOWN | PS_META_REPLACE,
    59                      "PSF from ppSubMakePSF", psf);
    60 
    61     bool mdok = false;
    6248
    6349    // psphotReadoutMinimal performs the photometry analysis on PSPHOT.INPUT; we need to move
    64     // around the pointers so PSPHOT.INPUT corresponds to the output image; previously, it was
    65     // equivalent to the minuend image.
    66     pmReadout *inRO = pmFPAfileThisReadout(config->files, view, name); // Readout with image and sources
    67     if (psMetadataLookup(inRO->analysis, "PSPHOT.SOURCES")) {
    68         psMetadataRemoveKey(inRO->analysis, "PSPHOT.SOURCES");
    69     }
    70 
     50    // around the pointers so PSPHOT.INPUT corresponds to the output image of interest (on one
     51    // pass this is the subtraction image, in another it is negative of the subtraction
    7152    pmFPAfile *photFile = psMetadataLookupPtr(&mdok, config->files, "PSPHOT.INPUT"); // Photometry file
    7253    pmFPAfile *inFile = psMetadataLookupPtr(&mdok, config->files, name); // Input file
     
    7657        return false;
    7758    }
     59
     60    // drop references to PSPHOT.DETECTIONS on both of these  (why is this needed for both??)
    7861    pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout to photometer
    79     if (psMetadataLookup(photRO->analysis, "PSPHOT.SOURCES")) {
    80         psMetadataRemoveKey(photRO->analysis, "PSPHOT.SOURCES");
     62    if (psMetadataLookup(photRO->analysis, "PSPHOT.DETECTIONS")) {
     63        psMetadataRemoveKey(photRO->analysis, "PSPHOT.DETECTIONS");
     64    }
     65    pmReadout *inRO = pmFPAfileThisReadout(config->files, view, name); // Readout with image and sources
     66    if (psMetadataLookup(inRO->analysis, "PSPHOT.DETECTIONS")) {
     67        psMetadataRemoveKey(inRO->analysis, "PSPHOT.DETECTIONS");
    8168    }
    8269
    83     psMetadataAddPtr(photRO->parent->parent->analysis, PS_LIST_TAIL, "PSPHOT.PSF",
    84                      PS_META_REPLACE | PS_DATA_UNKNOWN, "Point-spread function", data->psf);
    85 
    86     psFree(photRO->analysis);
    87     photRO->analysis = psMetadataAlloc();
     70    // grab the PSF information from the pmFPAfile PSPHOT.PSF.LOAD
     71    pmFPAfile *psfFile = psMetadataLookupPtr(&mdok, config->files, "PSPHOT.PSF.LOAD"); // PSF file
     72    ppSubCopyPSF (photFile, psfFile, view);
    8873
    8974    // psphotSaveImage (photFile->fpa->hdu->header, photRO->image, "findsrc.im.fits");
    9075    // psphotSaveImage (photFile->fpa->hdu->header, photRO->variance, "findsrc.wt.fits");
    9176    // psphotSaveImage (photFile->fpa->hdu->header, photRO->mask, "findsrc.mk.fits");
     77
     78    // erase the overlays from a previous psphot-related step
     79    if (pmVisualIsVisual()) {
     80        //      psphotVisualEraseOverlays (1, "all");
     81    }
    9282
    9383    if (!psphotReadoutMinimal(config, view)) {
     
    10090
    10191    // If no sources were found, there's no error,  but we want to trigger 'bad quality'
    102     psArray *sources = psMetadataLookupPtr(NULL, photRO->analysis, "PSPHOT.SOURCES"); // Sources
    103     if (!sources) {
     92    pmDetections *detections = psMetadataLookupPtr(NULL, photRO->analysis, "PSPHOT.DETECTIONS"); // Sources
     93    if (!detections) {
    10494        ppSubDataQuality(data, PSPHOT_ERR_DATA, PPSUB_FILES_PHOT_SUB | PPSUB_FILES_PHOT_INV);
    10595    }
     96    psArray *sources = detections->allSources;
     97    psAssert (sources, "missing sources?");
    10698
    10799    if (data->stats) {
     
    118110
    119111    if (!data->quality) {
    120         if (!psMetadataCopySingle(inRO->analysis, photRO->analysis, "PSPHOT.SOURCES")) {
    121             psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to copy PSPHOT.SOURCES");
     112        if (!psMetadataCopySingle(inRO->analysis, photRO->analysis, "PSPHOT.DETECTIONS")) {
     113            psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to copy PSPHOT.DETECTIONS");
    122114            return false;
    123115        }
     
    125117            psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to copy PSPHOT.HEADER");
    126118            return false;
     119        }
     120        if (!psMetadataCopySingle(inRO->analysis, photRO->analysis, PM_DETEFF_ANALYSIS)) {
     121            psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to copy Detection Efficiency");
     122            return false;
     123        }
     124
     125        // Ensure photometry information is put in the header
     126        pmHDU *hdu = pmHDUFromReadout(inRO); // HDU for readout
     127        if (hdu) {
     128            psMetadata *photHeader = psMetadataLookupMetadata(NULL, inRO->analysis, "PSPHOT.HEADER"); // Header
     129            hdu->header = psMetadataCopy(hdu->header, photHeader);
    127130        }
    128131    }
     
    134137}
    135138
    136 
    137 
    138 
    139 
    140139#ifdef TESTING
    141140    // Record data about sources: not everything gets into the output CMF files
    142141    {
    143142        pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout with the sources
    144         psArray *sources = psMetadataLookupPtr(NULL, photRO->analysis, "PSPHOT.SOURCES"); // Sources
     143        pmDetections *detections = psMetadataLookupPtr(NULL, photRO->analysis, "PSPHOT.DETECTIONS"); // Sources
     144        psArray *sources = detections->allSources;
    145145        FILE *sourceFile = fopen("sources.dat", "w"); // File for sources
    146146        fprintf(sourceFile,
Note: See TracChangeset for help on using the changeset viewer.