IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 3, 2010, 8:41:49 AM (16 years ago)
Author:
eugene
Message:

updates from trunk

Location:
branches/tap_branches
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/tap_branches

  • branches/tap_branches/ppStack/src

    • Property svn:ignore
      •  

        old new  
        1010stamp-h1
        1111ppStackVersionDefinitions.h
         12ppStackErrorCodes.c
         13ppStackErrorCodes.h
  • branches/tap_branches/ppStack/src/ppStackCleanup.c

    r23341 r27838  
    44
    55#include <stdio.h>
    6 #include <unistd.h>
    76#include <pslib.h>
    87#include <psmodules.h>
     8#include <ppStats.h>
    99
    1010#include "ppStack.h"
    1111#include "ppStackLoop.h"
    12 
    13 #define WCS_TOLERANCE 0.001             // Tolerance for WCS
    1412
    1513
     
    2220    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // ppStack recipe
    2321    psAssert(recipe, "We've thrown an error on this before.");
    24 
    25     bool mdok;                          // Status of MD lookup
    26     bool tempDelete = psMetadataLookupBool(&mdok, recipe, "TEMP.DELETE"); // Delete temporary files?
    2722
    2823#if 0
     
    3732#endif
    3833
    39     // Close up
    40     bool wcsDone = false;           // Have we done the WCS?
    41     for (int i = 0; i < options->num; i++) {
    42         if (options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) {
    43             continue;
    44         }
    45 
    46         ppStackThread *thread = stack->threads->data[0]; // Representative stack
    47         pmReadout *inRO = thread->readouts->data[i]; // Template readout
    48         if (inRO && !wcsDone) {
    49             // Copy astrometry over
    50             wcsDone = true;
    51             pmHDU *inHDU = pmHDUFromCell(inRO->parent); // Template HDU
    52             pmHDU *outHDU = pmHDUFromCell(options->outRO->parent); // Output HDU
    53             pmChip *outChip = options->outRO->parent->parent; // Output chip
    54             pmFPA *outFPA = outChip->parent; // Output FPA
    55             if (!outHDU || !inHDU) {
    56                 psWarning("Unable to find HDU at FPA level to copy astrometry.");
    57             } else {
    58                 if (!pmAstromReadWCS(outFPA, outChip, inHDU->header, 1.0)) {
    59                     psErrorClear();
    60                     psWarning("Unable to read WCS astrometry from input FPA.");
    61                     wcsDone = false;
    62                 } else {
    63                     if (!outHDU->header) {
    64                         outHDU->header = psMetadataAlloc();
    65                     }
    66                     if (!pmAstromWriteWCS(outHDU->header, outFPA, outChip, WCS_TOLERANCE)) {
    67                         psErrorClear();
    68                         psWarning("Unable to write WCS astrometry to output FPA.");
    69                         wcsDone = false;
    70                     }
    71                 }
    72             }
    73         }
    74 
    75         if (tempDelete) {
    76             psString imageResolved = pmConfigConvertFilename(options->imageNames->data[i],
    77                                                              config, false, false);
    78             psString maskResolved = pmConfigConvertFilename(options->maskNames->data[i],
    79                                                             config, false, false);
    80             psString varianceResolved = pmConfigConvertFilename(options->varianceNames->data[i],
    81                                                                 config, false, false);
    82             if (unlink(imageResolved) == -1 || unlink(maskResolved) == -1 ||
    83                 unlink(varianceResolved) == -1) {
    84                 psWarning("Unable to delete temporary files for image %d", i);
    85             }
    86             psFree(imageResolved);
    87             psFree(maskResolved);
    88             psFree(varianceResolved);
    89         }
    90     }
    91 
    92     ppStackMemDump("cleanup");
    93 
    9434    // Generate binned JPEGs
    9535    {
     
    10343        pmCell *cell2 = pmFPAfileThisCell(config->files, view, "PPSTACK.OUTPUT.JPEG2");
    10444        psImageMaskType maskValue = pmConfigMaskGet("BLANK", config); // Bits to mask
     45        psFree(view);
    10546
    10647        pmReadout *ro1 = pmReadoutAlloc(cell1), *ro2 = pmReadoutAlloc(cell2); // Binned readouts
    10748        if (!pmReadoutRebin(ro1, options->outRO, maskValue, bin1, bin1) ||
    10849            !pmReadoutRebin(ro2, ro1, 0, bin2, bin2)) {
    109             psError(PS_ERR_UNKNOWN, false, "Unable to bin output.");
     50            psError(PPSTACK_ERR_DATA, false, "Unable to bin output.");
    11051            psFree(ro1);
    11152            psFree(ro2);
     
    11657    }
    11758
    118     // Put version information into the header
    119     pmHDU *hdu = pmHDUFromCell(options->outRO->parent);
    120     if (!hdu) {
    121         psError(PS_ERR_UNKNOWN, false, "Unable to find HDU for output.");
     59    // Statistics on output
     60    if (options->stats) {
     61        psTrace("ppStack", 1, "Gathering statistics on stacked image....\n");
     62        psString maskBadStr = psMetadataLookupStr(NULL, recipe, "MASK.BAD"); // Name of bits for bad
     63        psImageMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels
     64
     65        pmFPAview *view = pmFPAviewAlloc(0); // View to readout
     66        view->chip = view->cell = view->readout = 0;
     67
     68        ppStatsFPA(options->stats, options->outRO->parent->parent->parent, view, maskBad, config);
     69
     70        psFree(view);
     71    }
     72
     73    if (!ppStackFilesIterateUp(config)) {
     74        psError(psErrorCodeLast(), false, "Unable to close files.");
    12275        return false;
    12376    }
    124     if (!hdu->header) {
    125         hdu->header = psMetadataAlloc();
     77    ppStackFileActivation(config, PPSTACK_FILES_STACK, false);
     78    ppStackFileActivation(config, PPSTACK_FILES_PHOT, false);
     79
     80    // Ensure files are freed
     81    {
     82        options->outRO->data_exists = false;
     83        options->outRO->parent->data_exists = false;
     84        options->outRO->parent->parent->data_exists = false;
     85        psFree(options->outRO);
     86        options->outRO = NULL;
     87
     88        options->expRO->data_exists = false;
     89        options->expRO->parent->data_exists = false;
     90        options->expRO->parent->parent->data_exists = false;
     91        psFree(options->expRO);
     92        options->expRO = NULL;
     93
     94        pmFPAview *view = pmFPAviewAlloc(0);// Pointer into FPA hierarchy
     95        view->chip = view->cell = 0;        // pmFPAviewFreeData doesn't want to deal with readouts
     96        pmFPAfile *jpeg1 = pmFPAfileSelectSingle(config->files, "PPSTACK.OUTPUT.JPEG1", 0); // JPEG file
     97        pmFPAviewFreeData(view, jpeg1);
     98        pmFPAfile *jpeg2 = pmFPAfileSelectSingle(config->files, "PPSTACK.OUTPUT.JPEG2", 0); // JPEG file
     99        pmFPAviewFreeData(view, jpeg2);
     100        pmFPAfile *phot = NULL;         // Photometry file
     101        if (options->photometry) {
     102            phot = pmFPAfileSelectSingle(config->files, "PSPHOT.INPUT", 0); // Photometry file
     103            pmFPAviewFreeData(view, phot);
     104        }
     105
     106        view->readout = 0;
     107        pmReadout *ro1 = pmFPAviewThisReadout(view, jpeg1->fpa); // JPEG readout
     108        ro1->data_exists = ro1->parent->data_exists = ro1->parent->parent->data_exists = false;
     109        pmReadout *ro2 = pmFPAviewThisReadout(view, jpeg2->fpa); // JPEG readout
     110        ro2->data_exists = ro2->parent->data_exists = ro2->parent->parent->data_exists = false;
     111        if (options->photometry) {
     112            pmReadout *ro = pmFPAviewThisReadout(view, phot->fpa); // Photometry readout
     113            ro->data_exists = ro->parent->data_exists = ro->parent->parent->data_exists = false;
     114        }
     115        psFree(view);
    126116    }
    127     ppStackVersionHeader(hdu->header);
    128117
    129118    return true;
Note: See TracChangeset for help on using the changeset viewer.