IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 26432


Ignore:
Timestamp:
Dec 15, 2009, 6:41:32 PM (16 years ago)
Author:
eugene
Message:

rework how the psf is passed around so that we are sure we get it from the right psphot run

Location:
branches/eam_branches/20091201/ppSub/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20091201/ppSub/src/ppSub.h

    r24862 r26432  
    160160bool psMetadataCopySingle(psMetadata *target, psMetadata *source, const char *name);
    161161
     162bool ppSubCopyPSF (pmFPAfile *output, pmFPAfile *input, pmFPAview *view);
     163
    162164///@}
    163165#endif
  • branches/eam_branches/20091201/ppSub/src/ppSubCamera.c

    r24261 r26432  
    319319        pmFPAfileActivate(config->files, false, "PSPHOT.INPUT");
    320320
    321         // Internal-ish file for getting the PSF from the minuend
    322         pmFPAfile *psf = pmFPAfileDefineOutputFromFile(config, psphot, "PSPHOT.PSF.LOAD");
     321        // Internal file for getting the PSF from the minuend
     322        pmFPAfile *psf = pmFPAfileDefineFromFPA(config, output->fpa, 1, 1, "PSPHOT.PSF.LOAD");
    323323        if (!psf) {
    324324            psError(PS_ERR_IO, false, "Failed to build FPA from PSPHOT.PSF.LOAD");
  • branches/eam_branches/20091201/ppSub/src/ppSubMakePSF.c

    r26318 r26432  
    6161        return false;
    6262    }
     63
    6364    pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout to photometer
     65
     66    // we need to remove any existing PSPHOT.SOURCES (why not do this in psphot?)
    6467    if (psMetadataLookup(photRO->analysis, "PSPHOT.SOURCES")) {
    6568        psMetadataRemoveKey(photRO->analysis, "PSPHOT.SOURCES");
    6669    }
    6770
     71# ifdef TESTING
    6872    // XXX for testing, dump these images:
    6973    psphotSaveImage (NULL, photRO->image, "findpsf.im.fits");
    7074    psphotSaveImage (NULL, photRO->variance, "findpsf.wt.fits");
    7175    psphotSaveImage (NULL, photRO->mask, "findpsf.mk.fits");
     76# endif
    7277
    7378    // Extract the loaded sources from the associated readout, and generate PSF
     
    8489    }
    8590
     91    // save the resulting PSF information on the pmFPAfile PSPHOT.PSF.LOAD
     92    pmFPAfile *psfFile = psMetadataLookupPtr(&mdok, config->files, "PSPHOT.PSF.LOAD"); // PSF file
     93    if (!ppSubCopyPSF (psfFile, photFile, view)) {
     94        psErrorStackPrint(stderr, "PSF was not generated");
     95        psWarning("PSF was not generated --- suspect bad data quality.");
     96        ppSubDataQuality(data, psErrorCodeLast(), PPSUB_FILES_PHOT_SUB | PPSUB_FILES_PHOT_INV);
     97    }
     98
    8699    // Get rid of the generated header; it will be regenerated by the real photometry run
    87100    psMetadataRemoveKey(photRO->analysis, "PSPHOT.HEADER");
    88 
    89     if (!data->quality) {
    90         data->psf = psMemIncrRefCounter(psMetadataLookupPtr(NULL, photRO->parent->parent->analysis,
    91                                                             "PSPHOT.PSF"));
    92     }
    93101
    94102    psFree(view);
     
    96104    return true;
    97105}
     106
     107bool ppSubCopyPSF (pmFPAfile *output, pmFPAfile *input, pmFPAview *view) {
     108
     109    bool mdok = false;
     110
     111    pmChip *inputChip   = pmFPAviewThisChip(view, input->fpa); // Chip with PSF info
     112    pmChip *outputChip  = pmFPAviewThisChip(view, output->fpa); // Chip to store PSF info
     113
     114    pmReadout *inputRO  = pmFPAviewThisReadout(view, input->fpa); // Readout with PSF info
     115    pmReadout *outputRO = pmFPAviewThisReadout(view, output->fpa); // Readout to store PSF info
     116
     117    if (!outputRO) {
     118        pmCell *outputCell  = pmFPAviewThisCell(view, output->fpa);
     119        outputRO = pmReadoutAlloc(outputCell);
     120        outputRO->image = psMemIncrRefCounter (inputRO->image);
     121    }
     122
     123    // copy the PSF-related data to PSPHOT.PSF.LOAD for safe-keeping
     124    psMetadata *psfRegions = psMetadataAlloc();
     125
     126    int nRegions = psMetadataLookupS32 (&mdok, inputRO->analysis, "PSF.CLUMP.NREGIONS");
     127    if (!nRegions) {
     128        psErrorStackPrint(stderr, "No PSF available");
     129        return false;
     130    }
     131    psMetadataAddS32 (psfRegions, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS",  PS_META_REPLACE, "psf clump regions", nRegions);
     132
     133    for (int i = 0; i < nRegions; i++) {
     134        char fieldName[80];
     135        snprintf (fieldName, 80, "PSF.CLUMP.REGION.%03d", i);
     136        psMetadata *regionMD = psMetadataLookupPtr (&mdok, inputRO->analysis, fieldName);
     137        if (!regionMD) {
     138            psWarning ("missing psf clump region metadata for entry %d", i);
     139            continue;
     140        }
     141        psMetadataAddMetadata (psfRegions, PS_LIST_TAIL, fieldName, PS_META_REPLACE, "psf clump region", regionMD);
     142    }
     143
     144    // XXX why am I replacing the entire analysis MD?
     145    psFree(outputRO->analysis);
     146    outputRO->analysis = psfRegions;
     147
     148    // copy the PSF model data
     149    pmPSF *psf = psMetadataLookupPtr(NULL, inputChip->analysis, "PSPHOT.PSF"); // PSF for photometry
     150    if (!psf) {
     151        psErrorStackPrint(stderr, "No PSF available");
     152        return false;
     153    }
     154    psMetadataAddPtr(outputChip->analysis, PS_LIST_TAIL, "PSPHOT.PSF", PS_DATA_UNKNOWN | PS_META_REPLACE, "PSF from ppSubMakePSF", psf);
     155
     156    return true;
     157}
  • branches/eam_branches/20091201/ppSub/src/ppSubMatchPSFs.c

    r26318 r26432  
    193193    }
    194194
     195# ifdef TESTING
    195196    // XXX for testing
    196197    psphotSaveImage (NULL, refRO->image,    "refRO.im.fits");
     
    209210    psphotSaveImage (NULL, refConv->variance, "refConv.wt.fits");
    210211    psphotSaveImage (NULL, refConv->mask,     "refConv.mk.fits");
     212# endif
    211213
    212214    psFree(optWidths);
  • branches/eam_branches/20091201/ppSub/src/ppSubReadoutPhotometry.c

    r26264 r26432  
    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.SOURCES on both of these  (why is this needed for both??)
    7861    pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout to photometer
    7962    if (psMetadataLookup(photRO->analysis, "PSPHOT.SOURCES")) {
    8063        psMetadataRemoveKey(photRO->analysis, "PSPHOT.SOURCES");
    8164    }
     65    pmReadout *inRO = pmFPAfileThisReadout(config->files, view, name); // Readout with image and sources
     66    if (psMetadataLookup(inRO->analysis, "PSPHOT.SOURCES")) {
     67        psMetadataRemoveKey(inRO->analysis, "PSPHOT.SOURCES");
     68    }
    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)) {
     
    126116            return false;
    127117        }
     118        if (!psMetadataCopySingle(inRO->analysis, photRO->analysis, PM_DETEFF_ANALYSIS)) {
     119            psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to copy Detection Efficiency");
     120            return false;
     121        }
    128122    }
    129123
     
    133127    return true;
    134128}
    135 
    136 
    137 
    138 
    139129
    140130#ifdef TESTING
Note: See TracChangeset for help on using the changeset viewer.