IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 17, 2009, 2:31:20 PM (17 years ago)
Author:
Paul Price
Message:

Cleaning up. Had trouble getting the output photometry file written out, but works now.

File:
1 edited

Legend:

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

    r21360 r21524  
    66 *
    77 *  @author IfA
    8  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2009-02-06 01:37:17 $
     8 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2009-02-18 00:31:20 $
    1010 *  Copyright 2009 Institute for Astronomy, University of Hawaii
    1111 */
    1212
     13#ifdef HAVE_CONFIG_H
     14#include <config.h>
     15#endif
     16
     17#include <stdio.h>
     18#include <pslib.h>
     19#include <psmodules.h>
     20#include <psphot.h>
     21
    1322#include "ppSub.h"
    1423
    15 /**
    16  * Photometry stage 1: measure the PSF from the minuend image
    17  */
    18 bool ppSubMakePSF (pmConfig *config, const pmFPAview *view) {
     24bool ppSubMakePSF(pmConfig *config, const pmFPAview *view)
     25{
     26    psAssert(config, "Require configuration");
     27    psAssert(view, "Require view");
    1928
    20     bool mdok = false;
    21 
    22     // Photometry is to be performed in two stages:
    23     // 1. Measure the PSF using the PSF-matched images
    24     // 2. Find and measure sources on the subtracted image
    2529    psTimerStart("PPSUB_PHOT");
    2630
    27     // Look up recipe values
    2831    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSUB_RECIPE); // Recipe for ppSub
    2932    psAssert(recipe, "We checked this earlier, so it should be here.");
    3033
    31     psMetadata *psphotRecipe = psMetadataLookupMetadata(NULL, config->recipes, PSPHOT_RECIPE); // Recipe for psphot
     34    if (!psMetadataLookupBool(NULL, recipe, "PHOTOMETRY")) {
     35        return true;
     36    }
     37
     38    psMetadata *psphotRecipe = psMetadataLookupMetadata(NULL, config->recipes, PSPHOT_RECIPE);// psphot recipe
    3239    psAssert(recipe, "We checked this earlier, so it should be here.");
    33 
    34     if (!psMetadataLookupBool(NULL, recipe, "PHOTOMETRY")) return true;
    3540
    3641    bool reverse = psMetadataLookupBool(NULL, config->arguments, "REVERSE"); // Reverse sense of subtraction?
    3742
    38     pmReadout *minuend = NULL;
    39     pmFPAfile *minuendFile = NULL;
     43    bool mdok = false;                  // Status of MD lookup
     44    pmReadout *minuend = NULL;          // Image that will be positive following subtraction
     45    pmFPAfile *minuendFile = NULL;      // File for minuend image
    4046    if (reverse) {
    41         minuend = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.CONV");
    42         minuendFile = psMetadataLookupPtr(&mdok, config->files, "PPSUB.REF.CONV");
     47        minuend = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.CONV");
     48        minuendFile = psMetadataLookupPtr(&mdok, config->files, "PPSUB.REF.CONV");
    4349    } else {
    44         minuend = pmFPAfileThisReadout(config->files, view, "PPSUB.INPUT.CONV");
    45         minuendFile = psMetadataLookupPtr(&mdok, config->files, "PPSUB.INPUT.CONV");
     50        minuend = pmFPAfileThisReadout(config->files, view, "PPSUB.INPUT.CONV");
     51        minuendFile = psMetadataLookupPtr(&mdok, config->files, "PPSUB.INPUT.CONV");
    4652    }
    4753
    48     // supply the minuend pmFPAfile to psphot as PSPHOT.INPUT:
    49     psMetadataAddPtr (config->files, PS_LIST_TAIL, "PSPHOT.INPUT", PS_DATA_UNKNOWN | PS_META_REPLACE, "psphot input : view on another pmFPAfile", minuendFile);
     54#if 1
     55    pmReadout *template = minuend;
     56    pmFPAfile *photFile = psMetadataLookupPtr(&mdok, config->files, "PSPHOT.INPUT"); // Photometry file
     57    pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout to photometer
     58    if (!photRO) {
     59        pmCell *cell = pmFPAviewThisCell(view, photFile->fpa); // Cell to photometer
     60        photRO = pmReadoutAlloc(cell); // Output readout: subtraction
     61    }
     62    photRO->image = psImageCopy(photRO->image, template->image, PS_TYPE_F32);
     63    if (template->variance) {
     64        photRO->variance = psImageCopy(photRO->variance, template->variance, PS_TYPE_F32);
     65    } else {
     66        psFree(photRO->variance);
     67        photRO->variance = NULL;
     68    }
     69    if (template->mask) {
     70        photRO->mask = psImageCopy(photRO->mask, template->mask, PS_TYPE_IMAGE_MASK);
     71    } else {
     72        psFree(photRO->mask);
     73        photRO->mask = NULL;
     74    }
     75#else
     76    // Supply the minuend pmFPAfile to psphot as PSPHOT.INPUT:
     77    psMetadataAddPtr(config->files, PS_LIST_TAIL, "PSPHOT.INPUT", PS_DATA_UNKNOWN | PS_META_REPLACE,
     78                     "psphot input: view on another pmFPAfile", minuendFile);
     79#endif
    5080
    51     // old-style variance renormalization
    52     if (!ppSubReadoutRenormPhot (config, recipe, minuend)) {
    53         psError(PS_ERR_UNKNOWN, false, "failure in renormalization");
    54         return false;
    55     }
    56 
    57     // extract the loaded sources from the associated readout
     81    // Extract the loaded sources from the associated readout, and generate PSF
     82    // Here, we assume the image is background-subtracted
    5883    pmReadout *sourcesRO = pmFPAfileThisReadout(config->files, view, "PPSUB.SOURCES");
    5984    psArray *sources = psMetadataLookupPtr(&mdok, sourcesRO->analysis, "PSPHOT.SOURCES");
    60 
    61     // generate PSF from the supplied sources (assumes image is background-subtracted)
    6285    if (!psphotReadoutFindPSF(config, view, sources)) {
    63         psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry on subtracted image.");
    64         return false;
     86        psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry on subtracted image.");
     87        return false;
    6588    }
    6689
     
    7093    psMetadataItemSupplement(hdu->header, psphotRecipe, "FWHM_MAJ");
    7194    psMetadataItemSupplement(hdu->header, psphotRecipe, "FWHM_MIN");
     95
     96    // Get rid of the generated header; it will be regenerated by the real photometry run
     97    psMetadataRemoveKey(photRO->analysis, "PSPHOT.HEADER");
    7298
    7399    return true;
     
    87113
    88114// Blow away the sources psphot found --- they're irrelevant for the subtraction
    89 // XXX is this still needed?  These are now probably not being set 
     115// XXX is this still needed?  These are now probably not being set
    90116// pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout with sources
    91117// psMetadataRemoveKey(photRO->analysis, "PSPHOT.SOURCES");
Note: See TracChangeset for help on using the changeset viewer.