IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 4, 2011, 1:12:39 PM (15 years ago)
Author:
eugene
Message:

use the smoothed image for footprint culling; use a more stringent culling for saturated stars; more tweaks to get sat stars to be fitted; various updates to psphotStack; unify psphotImageLoop varients; be a bit careful about number of stars in a PSF clump

Location:
trunk/psphot
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot

  • trunk/psphot/src/psphotStackImageLoop.c

    r30624 r31154  
    11# include "psphotStandAlone.h"
    2 #define WCS_NONLIN_TOL 0.001            // Non-linear tolerance for header WCS
    32
    43# define ESCAPE(MESSAGE) {                              \
     
    87    }
    98
    10 bool GetAstrometryFPA (pmConfig *config, pmFPAview *view);
    11 bool SetAstrometryFPA (pmConfig *config, pmFPAview *view, bool bilevelAstrometry);
    12 bool GetAstrometryChip (pmConfig *config, pmFPAview *view, bool bilevelAstrometry);
     9// XXX this implementation is not smart about multi-level astrometry headers
     10bool UpdateHeadersForFPA (pmConfig *config, pmFPAview *view);
     11bool UpdateHeadersForChip (pmConfig *config, pmFPAview *view);
    1312
    1413bool psphotStackImageLoop (pmConfig *config) {
     
    1817    pmCell *cell;
    1918    pmReadout *readout;
     19
     20    psMemDump("startloop");
    2021
    2122    pmFPAfile *inputRaw = psMetadataLookupPtr (&status, config->files, "PSPHOT.STACK.INPUT.RAW");
     
    3233    // XXX for now, just load the full set of images up front
    3334    if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for fpa in psphot.");
    34 
    35     bool bilevelAstrometry = GetAstrometryFPA(config, view);
    3635
    3736    // for psphot, we force data to be read at the chip level
     
    5150                if (! readout->data_exists) { continue; }
    5251
     52                psMemDump("load");
     53
    5354                // PSF matching
    5455                if (!psphotStackMatchPSFs (config, view)) {
     
    5758                    return false;
    5859                }
     60                psMemDump("stackmatch");
    5961
    6062                // XXX for now, we assume there is only a single chip in the PHU:
     
    6466                    return false;
    6567                }
    66 
     68                psMemDump("psphot");
    6769            }
    6870            // drop all versions of the internal files
     
    7880        }
    7981
    80         GetAstrometryChip(config, view, bilevelAstrometry);
     82        UpdateHeadersForChip(config, view);
    8183
    8284        // save output which is saved at the chip level
    8385        if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE ("failed output for Chip in psphot.");
    8486    }
     87    psMemDump("doneloop");
    8588
    86     SetAstrometryFPA(config, view, bilevelAstrometry);
    87    
     89    UpdateHeadersForFPA(config, view);
     90
    8891    // save output which is saved at the fpa level
    8992    if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE ("failed ouput for FPA in psphot.");
     
    9396
    9497    psFree (view);
     98
     99    psMemDump("doneoutput");
    95100    return true;
    96101}
    97102
    98 /*
    99    the easiest way to implement this is to assume we can pre-load the full set of images up front.
    100    with 5 filters and 6000^2 (image, mask, var = 10 byte per pixel), we need 1.8GB, which is not too bad.
    101 */
    102 
    103 # define UPDATE_HEADER 1
    104 
    105 bool GetAstrometryFPA (pmConfig *config, pmFPAview *view) {
    106 
    107     bool foundAstrometry = false;
    108     bool bilevelAstrometry = false;
     103bool UpdateHeadersForChip (pmConfig *config, pmFPAview *view) {
    109104
    110105    int num = psphotFileruleCount(config, "PSPHOT.INPUT");
     
    122117        psAssert (input, "missing input file");
    123118
    124         // find the FPA phu
    125         pmHDU *phu = pmFPAviewThisPHU(view, input->fpa);
    126         if (!phu) {
    127             psWarning("Unable to read bilevel mosaic astrometry for input FPA entry %d", i);
    128             continue;
     119        // just copy the input headers to the output headers, then update version info
     120        pmChip *inChip = pmFPAviewThisChip(view, input->fpa); ///< Chip in the input
     121        pmHDU *inHDU = pmFPAviewThisHDU (view, input->fpa);
     122
     123        pmChip *outChip = pmFPAviewThisChip(view, output->fpa); ///< Chip in the output
     124        pmHDU *outHDU = pmFPAviewThisHDU (view, output->fpa);
     125        if (!outHDU) {
     126            pmFPAAddSourceFromView(output->fpa, view, output->format);
     127            outHDU = pmFPAviewThisHDU (view, output->fpa);
     128            psAssert (outHDU, "failed to make HDU");
    129129        }
    130 
    131         char *ctype = psMetadataLookupStr(NULL, phu->header, "CTYPE1");
    132         if (!ctype) {
    133             psWarning("Error in WCS keywords for input FPA entry %d", i);
    134             continue;
     130        if (!outHDU->header) {
     131            outHDU->header = psMetadataCopy(NULL, inHDU->header);
    135132        }
    136 
    137         if (!foundAstrometry) {
    138             bilevelAstrometry = !strcmp (&ctype[4], "-DIS");
    139         } else {
    140             if (bilevelAstrometry != !strcmp (&ctype[4], "-DIS")) {
    141                 psAbort("astrometry type mis-match");
    142             }
    143         }
    144 
    145         if (bilevelAstrometry) {
    146             // update the output structures
    147             if (!pmAstromReadBilevelMosaic(output->fpa, phu->header)) {
    148                 psWarning("Unable to read bilevel mosaic astrometry for input FPA.");
    149             }
    150         }
     133        outChip->toFPA = psMemIncrRefCounter(inChip->toFPA);
     134        outChip->fromFPA = psMemIncrRefCounter(inChip->fromFPA);
    151135    }
    152     return bilevelAstrometry;
     136    return true;
    153137}
    154138
    155 bool GetAstrometryChip (pmConfig *config, pmFPAview *view, bool bilevelAstrometry) {
     139bool UpdateHeadersForFPA (pmConfig *config, pmFPAview *view) {
    156140
    157141    int num = psphotFileruleCount(config, "PSPHOT.INPUT");
     
    169153        psAssert (input, "missing input file");
    170154
    171         // Need to update the output for astrometry.  Read WCS data from the corresponding
    172         // header and save in the output fpa
    173         pmHDU *inHDU = pmFPAviewThisHDU (view, input->fpa);
    174         pmChip *outChip = pmFPAviewThisChip(view, output->fpa); ///< Chip in the output
     155        output->fpa->toTPA = psMemIncrRefCounter(input->fpa->toTPA);
     156        output->fpa->fromTPA = psMemIncrRefCounter(input->fpa->fromTPA);
     157        output->fpa->toSky = psMemIncrRefCounter(input->fpa->toSky);
    175158
    176         pmHDU *outHDU = pmFPAviewThisHDU (view, output->fpa);
    177         if (!outHDU) {
    178             pmFPAAddSourceFromView(output->fpa, view, output->format);
    179             outHDU = pmFPAviewThisHDU (view, output->fpa);
    180             psAssert (outHDU, "failed to make HDU");
    181         }
    182         if (!outHDU->header) {
    183           outHDU->header = psMetadataAlloc();
    184         }
     159        pmConceptsCopyFPA(output->fpa, input->fpa, true, true);
    185160
    186         if (bilevelAstrometry) {
    187             if (!pmAstromReadBilevelChip (outChip, inHDU->header)) {
    188                 psWarning("Unable to read bilevel chip astrometry for input FPA.");
    189                 continue;
    190             }
    191             if (!pmAstromWriteBilevelChip(outHDU->header, outChip, WCS_NONLIN_TOL)) {
    192                 psWarning("Unable to generate WCS header.");
    193                 continue;
    194             }
    195         } else {
    196             // we use a default FPA pixel scale of 1.0
    197             if (!pmAstromReadWCS (output->fpa, outChip, inHDU->header, 1.0)) {
    198                 psWarning("Unable to read WCS astrometry for input FPA.");
    199                 continue;
    200             }
    201             if (!pmAstromWriteWCS(outHDU->header, output->fpa, outChip, WCS_NONLIN_TOL)) {
    202                 psWarning("Unable to generate WCS header.");
    203                 continue;
    204             }
    205         }
     161        // XXX TEST
     162        // pmFPASetFileStatus(output->fpa, true);
     163        // pmFPASetDataStatus(output->fpa, true);
     164        // pmChip *chip = output->fpa->chips->data[0];
     165        // pmCell *cell = chip->cells->data[0];
     166        // pmReadout *readout = cell->readouts->data[0];
    206167    }
    207 
    208168    return true;
    209169}
    210170
    211 bool SetAstrometryFPA (pmConfig *config, pmFPAview *view, bool bilevelAstrometry) {
     171/*
     172   the easiest way to implement this is to assume we can pre-load the full set of images up front.
     173   with 5 filters and 6000^2 (image, mask, var = 10 byte per pixel), we need 1.8GB, which is not too bad.
     174*/
    212175
    213     if (!bilevelAstrometry) return true;
    214 
    215     int num = psphotFileruleCount(config, "PSPHOT.INPUT");
    216 
    217     // loop over the available readouts
    218     for (int i = 0; i < num; i++) {
    219 
    220         // find the currently selected readout
    221         pmFPAfile *output = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.OUTPUT.IMAGE", i); // File of interest
    222         psAssert (output, "missing file?");
    223 
    224         pmHDU *PHU = pmFPAviewThisPHU(view, output->fpa);
    225         if (!PHU) {
    226             pmFPAAddSourceFromView(output->fpa, view, output->format);
    227             PHU = pmFPAviewThisPHU (view, output->fpa);
    228             psAssert (PHU, "failed to make PHU");
    229         }
    230         if (!PHU->header) {
    231           PHU->header = psMetadataAlloc();
    232         }
    233 
    234         if (!pmAstromWriteBilevelMosaic(PHU->header, output->fpa, WCS_NONLIN_TOL)) {
    235             psWarning("Unable to generate WCS header.");
    236         }
    237     }
    238 
    239     return true;
    240 }
Note: See TracChangeset for help on using the changeset viewer.