IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 6, 2013, 10:32:51 AM (13 years ago)
Author:
eugene
Message:

remove superfulous ppStats.h includes; generate output psf model

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20130419/pswarp/src/pswarpMakePSF.c

    r35511 r35521  
    1111
    1212#include "pswarp.h"
    13 #include <ppStats.h>
    14 #include "pswarpFileNames.h"            // Lists of file rules used at different stages
    1513
    1614#define WCS_NONLIN_TOL 0.001            // Non-linear tolerance for header WCS
     
    1917// We need a new PSF model for the warped frame.  It would be good to generate this analytically, but
    2018// that's going to be tricky.  We have a list of sources, so we use those to redetermine the PSF model.
    21 bool pswarpMakePSF (pmConfig *config) {
     19
     20bool pswarpMakePSF (pmConfig *config, pmFPAfile *output, psMetadata *stats) {
     21
     22    bool status = false;
    2223
    2324    // load the recipe
     
    2829    }
    2930
    30     if (psMetadataLookupBool(&mdok, recipe, "PSF")) {
    31         pswarpFileActivation(config, photFiles, true);
    32         if (!pswarpIOChecksBefore(config)) {
    33             psError(psErrorCodeLast(), false, "Unable to read files.");
    34             goto DONE;
    35         }
     31    if (!psMetadataLookupBool(&status, recipe, "PSF")) {
     32        psLogMsg("pswarp", PS_LOG_INFO, "Skipping PSF measurement");
     33        return true;
     34    }
    3635
    37         // supply the readout and fpa of interest to psphot
    38         pmFPAfile *photFile = psMetadataLookupPtr(NULL, config->files, "PSPHOT.INPUT");
    39         pmFPACopy(photFile->fpa, outFPA);
     36    // XXX What was being read here??  skip this for now
     37    if (false && !pswarpIOChecksBefore(config)) {
     38        psError(psErrorCodeLast(), false, "Unable to read files.");
     39        return false;
     40    }
    4041
    41         pmFPAview *view = pmFPAviewAlloc(0); ///< View into skycell
    42         view->chip = view->cell = view->readout = 0;
     42    // supply the readout and fpa of interest to psphot
     43    pmFPAfile *photFile = psMetadataLookupPtr(&status, config->files, "PSPHOT.INPUT");
     44    pmFPACopy(photFile->fpa, output->fpa);
    4345
    44         // grab the sources of interest from the storage location (pmFPAfile PSPHOT.INPUT.CMF)
    45         psArray *sources = psphotLoadPSFSources (config, view);
    46         if (!sources) {
    47             psError(psErrorCodeLast(), false, "No sources supplied to measure PSF");
    48             goto DONE;
    49         }
     46    pmFPAview *view = pmFPAviewAlloc(0); ///< View into skycell
    5047
    51         pmModelClassSetLimits(PM_MODEL_LIMITS_STRICT);
     48    pmChip *chip;
     49    while ((chip = pmFPAviewNextChip (view, photFile->fpa, 1)) != NULL) {
     50        psTrace ("pswarpMakePSF", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
     51        if (!chip->process || !chip->file_exists) { continue; }
    5252
    53         // measure the PSF using these sources
    54         if (!psphotReadoutFindPSF(config, view, "PSPHOT.INPUT", sources)) {
    55             // This is likely a data quality issue
    56             // XXX Split into multiple cases using error codes?
    57             psErrorStackPrint(stderr, "Unable to determine PSF");
    58             psWarning("Unable to determine PSF --- suspect bad data quality.");
    59             if (stats && psMetadataLookupS32(NULL, stats, "QUALITY") == 0) {
    60                 psMetadataAddS32(stats, PS_LIST_TAIL, "QUALITY", PS_META_REPLACE,
    61                                  "Unable to determine PSF", psErrorCodeLast());
    62             }
    63             psErrorClear();
    64             psphotFilesActivate(config, false);
    65         }
     53        pmCell *cell;
     54        while ((cell = pmFPAviewNextCell (view, photFile->fpa, 1)) != NULL) {
     55            psTrace ("pswarpMakePSF", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
     56            if (!cell->process || !cell->file_exists) { continue; }
    6657
    67         // Ensure seeing is carried over
    68         pmChip *photChip = pmFPAviewThisChip(view, photFile->fpa);                 // Chip with seeing
    69         psMetadataItem *item = psMetadataLookup(outChip->concepts, "CHIP.SEEING"); // Concept with seeing
    70         item->data.F32 = psMetadataLookupF32(NULL, photChip->concepts, "CHIP.SEEING");
     58            // process each of the readouts
     59            pmReadout *readout;
     60            while ((readout = pmFPAviewNextReadout(view, photFile->fpa, 1)) != NULL) {
     61                if (!readout->data_exists) {
     62                    continue;
     63                }
    7164
    72 // XXX EAM : put this in a visualization function
    73 #if (TESTING)
    74         {
    75             #define PSF_SIZE 20         ///< Half-size of PSF
    76             #define PSF_FLUX 10000      ///< Central flux for PSF
    77             pmChip *photChip = pmFPAviewThisChip(view, photFile->fpa);
    78             pmPSF *psf = psMetadataLookupPtr(NULL, photChip->analysis, "PSPHOT.PSF");
    79             psImage *image = psImageAlloc(2 * PSF_SIZE + 1, 2 * PSF_SIZE + 1, PS_TYPE_F32);
    80             psImageInit(image, 0);
    81             pmModel *model = pmModelFromPSFforXY(psf, PSF_SIZE, PSF_SIZE, PSF_FLUX);
    82             pmModelAdd(image, NULL, model, PM_MODEL_OP_FULL, 0);
    83             psFree(model);
    84             psFits *fits = psFitsOpen("psf.fits", "w");
    85             psFitsWriteImage(fits, NULL, image, 0, NULL);
    86             psFitsClose(fits);
    87             psFree(image);
    88         }
    89 #endif
     65                // grab the sources of interest from the storage location (pmFPAfile PSPHOT.INPUT.CMF)
     66                psArray *sources = psphotLoadPSFSources (config, view);
     67                if (!sources) {
     68                    // psError(psErrorCodeLast(), false, "No sources supplied to measure PSF");
     69                    psLogMsg ("psphot", 3, "no psf sources for this readout (%d %d %d)", view->chip, view->cell, view->readout);
     70                    continue;
     71                }
    9072
    91         psFree(view);
     73                // XXX move above the loop
     74                pmModelClassSetLimits(PM_MODEL_LIMITS_STRICT);
     75               
     76                // measure the PSF using these sources
     77                if (!psphotReadoutFindPSF(config, view, "PSPHOT.INPUT", sources)) {
     78                    // A failure is likely a data quality issue.  raise a quality flag, but do not skip other readouts
     79                    // XXX Split into multiple cases using error codes?
     80                    psErrorStackPrint(stderr, "Unable to determine PSF for readout (%d %d %d)", view->chip, view->cell, view->readout);
     81                    psWarning("Unable to determine PSF --- suspect bad data quality : readout (%d %d %d)", view->chip, view->cell, view->readout);
     82                    if (stats) {
     83                        int currentQuality = psMetadataLookupS32(&status, stats, "QUALITY");
     84                        if (currentQuality == 0) {
     85                            psMetadataAddS32(stats, PS_LIST_TAIL, "QUALITY", PS_META_REPLACE, "Unable to determine PSF", psErrorCodeLast());
     86                        }
     87                    }
     88                    psErrorClear();
     89                }
     90            }
     91        }
     92
     93        // Ensure seeing is carried over from the PSPHOT.INPUT chip to the output chip
     94        pmChip *outChip = pmFPAviewThisChip(view, output->fpa); // Chip with seeing
     95        psMetadataItem *item = psMetadataLookup(outChip->concepts, "CHIP.SEEING"); // Concept with seeing
     96        item->data.F32 = psMetadataLookupF32(&status, chip->concepts, "CHIP.SEEING");
    9297    }
     98
     99    // XXX test function found below
     100    // pswarpMakePSF_test ();
     101
     102    psFree(view);
     103    return true;
     104}
     105
     106# if (0)
     107bool pswarpMakePSF_test () {
     108
     109#define PSF_SIZE 20         ///< Half-size of PSF
     110#define PSF_FLUX 10000      ///< Central flux for PSF
     111    pmChip *photChip = pmFPAviewThisChip(view, photFile->fpa);
     112    pmPSF *psf = psMetadataLookupPtr(NULL, photChip->analysis, "PSPHOT.PSF");
     113    psImage *image = psImageAlloc(2 * PSF_SIZE + 1, 2 * PSF_SIZE + 1, PS_TYPE_F32);
     114    psImageInit(image, 0);
     115    pmModel *model = pmModelFromPSFforXY(psf, PSF_SIZE, PSF_SIZE, PSF_FLUX);
     116    pmModelAdd(image, NULL, model, PM_MODEL_OP_FULL, 0);
     117    psFree(model);
     118    psFits *fits = psFitsOpen("psf.fits", "w");
     119    psFitsWriteImage(fits, NULL, image, 0, NULL);
     120    psFitsClose(fits);
     121    psFree(image);
    93122    return true;
    94123}
    95124# endif
    96 
Note: See TracChangeset for help on using the changeset viewer.