IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 30620


Ignore:
Timestamp:
Feb 13, 2011, 11:52:31 AM (15 years ago)
Author:
eugene
Message:

some reorganization: create ppStackUpdateHeader, ppStackStats, ppStackJPEG functions to clean up ppStackLoop; plug some leaks; cleanup include sections; create ppStackCleanup for end of processing (renamed old ppStackCleanup to ppStackCleanupFiles); move jpeg creation from ppStackCleanupFiles to ppStackJPEG; same for stats; adjust kernel auto-scaling to take place after we have measured the source sizes; update headers with stack_id, skycell_id, tess_id (optional)

Location:
trunk/ppStack/src
Files:
29 edited
3 copied

Legend:

Unmodified
Added
Removed
  • trunk/ppStack/src/Makefile.am

    r28253 r30620  
    4949        ppStackFinish.c         \
    5050        ppStackTarget.c         \
     51        ppStackUpdateHeader.c   \
     52        ppStackJPEGs.c          \
     53        ppStackStats.c          \
    5154        ppStackErrorCodes.c
    5255
  • trunk/ppStack/src/ppStack.c

    r29552 r30620  
    1 #ifdef HAVE_CONFIG_H
    2 #include <config.h>
    3 #endif
    4 
    5 #include <stdio.h>
    6 #include <pslib.h>
    7 #include <psmodules.h>
    8 #include <psphot.h>
    9 
    101#include "ppStack.h"
    11 #include "ppStackLoop.h"
    12 
    13 #define TIMER_NAME "PPSTACK"            // Name of timer
    142
    153int main(int argc, char *argv[])
    164{
    175    psLibInit(NULL);
    18     psTimerStart(TIMER_NAME);
     6    psTimerStart("PPSTACK");
    197    psTimerStart("PPSTACK_STEPS");
    208
     
    2311    psphotErrorRegister();
    2412
     13    ppStackOptions *options = NULL;                               // Options for stacking
     14
    2515    pmConfig *config = pmConfigRead(&argc, argv, PPSTACK_RECIPE); // Configuration
    26     ppStackOptions *options = NULL;                               // Options for stacking
    2716    if (!config) {
    28         goto die;
     17        ppStackCleanup(config, options);
    2918    }
    3019
     
    3322    if (!pmModelClassInit()) {
    3423        psError(PPSTACK_ERR_PROG, false, "Unable to initialise model classes.");
    35         goto die;
     24        ppStackCleanup(config, options);
    3625    }
    3726
    3827    if (!psphotInit()) {
    3928        psError(PPSTACK_ERR_PROG, false, "Error initialising psphot.");
    40         goto die;
     29        ppStackCleanup(config, options);
    4130    }
    4231
    43     (void)psTraceSetLevel("ppStack", 5);
    44 
    4532    if (!ppStackArgumentsSetup(argc, argv, config)) {
    46         goto die;
     33        ppStackCleanup(config, options);
    4734    }
    4835
    4936    if (!ppStackCamera(config)) {
    50         goto die;
     37        ppStackCleanup(config, options);
    5138    }
    5239
    5340    if (!ppStackArgumentsParse(config)) {
    54         goto die;
     41        ppStackCleanup(config, options);
    5542    }
    5643
    5744    options = ppStackOptionsAlloc();
    5845    if (!ppStackLoop(config, options)) {
    59         goto die;
     46        ppStackCleanup(config, options);
    6047    }
    6148
    62 
    63  die:
    64     // Common code for the death.
    65     {
    66         psExit exitValue = ppStackExitCode(PS_EXIT_SUCCESS); // Exit code
    67 
    68         // Ensure everything closes
    69         if (config) {
    70             ppStackFileActivation(config, PPSTACK_FILES_PREPARE, true);
    71             ppStackFileActivation(config, PPSTACK_FILES_CONVOLVE, true);
    72             ppStackFileActivation(config, PPSTACK_FILES_STACK, true);
    73             ppStackFileActivation(config, PPSTACK_FILES_UNCONV, true);
    74             ppStackFileActivation(config, PPSTACK_FILES_PHOT, true);
    75             if (!ppStackFilesIterateUp(config)) {
    76                 psError(psErrorCodeLast(), false, "Unable to close files.");
    77                 exitValue = ppStackExitCode(exitValue);
    78                 pmFPAfileFreeSetStrict(false);
    79             }
    80         }
    81 
    82         // Write out summary statistics
    83         if (options && options->stats) {
    84 
    85             psMetadataAddS32(options->stats, PS_LIST_TAIL, "QUALITY", PS_META_REPLACE,
    86                              "Bad data quality flag", options->quality);
    87             psMetadataAddF32(options->stats, PS_LIST_TAIL, "TIME_STACK", 0,
    88                              "Total time", psTimerClear("PPSTACK_TOTAL"));
    89 
    90             const char *statsMDC = psMetadataConfigFormat(options->stats);
    91             if (!statsMDC || strlen(statsMDC) == 0) {
    92                 psError(PS_ERR_IO, false, "Unable to get statistics MDC file.");
    93                 return false;
    94             }
    95             if (fprintf(options->statsFile, "%s", statsMDC) != strlen(statsMDC)) {
    96                 psError(PS_ERR_IO, false, "Unable to write statistics MDC file.");
    97                 return false;
    98             }
    99             psFree(statsMDC);
    100             if (fclose(options->statsFile) == EOF) {
    101                 psError(PS_ERR_IO, false, "Unable to close statistics MDC file.");
    102                 return false;
    103             }
    104             options->statsFile = NULL;
    105             pmConfigRunFilenameAddWrite(config, "STATS",
    106                                         psMetadataLookupStr(NULL, config->arguments, "STATS"));
    107         }
    108         psFree(options);
    109 
    110         // Dump configuration
    111         bool mdok;                                                                    // Status of MD lookup
    112         psString dump = psMetadataLookupStr(&mdok, config->arguments, "DUMP_CONFIG"); // File for config
    113         if (dump && !pmConfigDump(config, dump)) {
    114             psError(psErrorCodeLast(), false, "Unable to dump configuration.");
    115             exitValue = ppStackExitCode(exitValue);
    116         }
    117 
    118         psTrace("ppStack", 1, "Finished at %f sec\n", psTimerMark(TIMER_NAME));
    119         psTimerStop();
    120 
    121         psFree(config);
    122         pmModelClassCleanup();
    123         pmConfigDone();
    124         psLibFinalize();
    125         pmVisualClose();
    126         pmVisualCleanup ();
    127 
    128         exitValue = ppStackExitCode(exitValue);
    129         exit(exitValue);
    130     }
     49    ppStackCleanup(config, options);
    13150}
    13251
  • trunk/ppStack/src/ppStack.h

    r28253 r30620  
     1#ifdef HAVE_CONFIG_H
     2#include <config.h>
     3#endif
     4
     5#include <stdio.h>
     6#include <pslib.h>
     7#include <psmodules.h>
     8#include <ppStats.h>
     9#include <psphot.h>
     10
    111#ifndef PPSTACK_H
    212#define PPSTACK_H
     
    717#include <pslib.h>
    818#include <psmodules.h>
    9 
    10 #include "ppStackOptions.h"
    11 #include "ppStackErrorCodes.h"
    1219
    1320// Mask values for inputs
     
    2532// List of files
    2633typedef enum {
     34    PPSTACK_FILES_NONE,                 // NOP list
    2735    PPSTACK_FILES_PREPARE,              // Files for preparation
    2836    PPSTACK_FILES_TARGET,               // Files for target generation
     
    3341} ppStackFileList;
    3442
     43#include "ppStackOptions.h"
     44#include "ppStackThread.h"
     45#include "ppStackLoop.h"
     46#include "ppStackErrorCodes.h"
    3547
    3648// Setup command-line arguments
     
    180192    );
    181193
     194bool ppStackWriteVariance(const char *name, // Name of image
     195                          psMetadata *header, // Header
     196                          const psImage *variance, // Variance
     197                          const psImage *covariance, // Variance
     198                          pmConfig *config // Configuration
     199    );
     200
    182201/// Return an appropriate exit code based on the error code
    183202psExit ppStackExitCode(psExit exitValue);
    184203
     204bool ppStackCleanup(pmConfig *config, ppStackOptions *options) PS_ATTR_NORETURN;
     205
    185206#endif
  • trunk/ppStack/src/ppStackArguments.c

    r28617 r30620  
    1 #ifdef HAVE_CONFIG_H
    2 #include <config.h>
    3 #endif
    4 
    5 #include <stdio.h>
    6 #include <string.h>
    7 #include <pslib.h>
    8 #include <psmodules.h>
    9 
    101#include "ppStack.h"
    112
     
    189180    psMetadataAddStr(arguments, PS_LIST_TAIL, "-temp-mask", 0, "Suffix for temporary masks", NULL);
    190181    psMetadataAddStr(arguments, PS_LIST_TAIL, "-temp-variance", 0, "Suffix for temporary variance maps", NULL);
    191     psMetadataAddBool(arguments, PS_LIST_TAIL, "-temp-delete", 0,
    192                       "Delete temporary files on completion?", false);
     182    psMetadataAddBool(arguments, PS_LIST_TAIL, "-temp-delete", 0, "Delete temporary files on completion?", false);
    193183    psMetadataAddS32(arguments, PS_LIST_TAIL, "-threads", 0, "Number of threads to use", 0);
    194184    psMetadataAddBool(arguments, PS_LIST_TAIL, "-visual", 0, "visualisation", false);
    195185
     186    psMetadataAddStr(arguments, PS_LIST_TAIL, "-stack_id",   0, "stack ID",        NULL);
     187    psMetadataAddStr(arguments, PS_LIST_TAIL, "-skycell_id", 0, "skycell ID",      NULL);
     188    psMetadataAddStr(arguments, PS_LIST_TAIL, "-tess_id",    0, "tessellation ID", NULL);
     189
    196190    if (argc == 1) {
    197191        usage(argv[0], arguments, config);
     192    }
     193
     194    // stack-type : used to define the stack for PSPS
     195    if ((argNum = psArgumentGet (argc, argv, "-stack-type"))) {
     196        if (argc <= argNum+1) {
     197            psErrorStackPrint(stderr, "Expected to see an argument for -stack-type");
     198            exit(PS_EXIT_CONFIG_ERROR);
     199        }
     200        psArgumentRemove (argNum, &argc, argv);
     201        if (strcasecmp(argv[argNum], "NIGHTLY") && strcasecmp(argv[argNum], "DEEP") && strcasecmp(argv[argNum], "BEST_IQ")) {
     202            psErrorStackPrint(stderr, "Invalid option for -stack-type %s (must be one of NIGHTLY_STACK, DEEP_STACK, IQ_STACK)", argv[argNum]);
     203            exit(PS_EXIT_CONFIG_ERROR);
     204        }
     205        psMetadataAddStr (arguments, PS_LIST_TAIL, "STACK_TYPE", PS_META_REPLACE, "Stack Type", argv[argNum]);
     206        psArgumentRemove (argNum, &argc, argv);
     207    } else {
     208        psMetadataAddStr (arguments, PS_LIST_TAIL, "STACK_TYPE", PS_META_REPLACE, "Stack Type", "DEEP_STACK");
    198209    }
    199210
  • trunk/ppStack/src/ppStackCamera.c

    r27989 r30620  
    1 #ifdef HAVE_CONFIG_H
    2 #include <config.h>
    3 #endif
    4 
    5 #include <stdio.h>
    6 #include <string.h>
    7 #include <pslib.h>
    8 #include <psmodules.h>
    9 #include <psphot.h>
    10 
    111#include "ppStack.h"
    122
  • trunk/ppStack/src/ppStackCleanup.c

    r27427 r30620  
    1 #ifdef HAVE_CONFIG_H
    2 #include <config.h>
    3 #endif
     1#include "ppStack.h"
    42
    5 #include <stdio.h>
    6 #include <pslib.h>
    7 #include <psmodules.h>
    8 #include <ppStats.h>
    9 
    10 #include "ppStack.h"
    11 #include "ppStackLoop.h"
    12 
    13 
    14 bool ppStackCleanup(ppStackThreadData *stack, ppStackOptions *options, pmConfig *config)
     3// ppStackCleanupFiles
     4bool ppStackCleanupFiles(ppStackThreadData *stack, ppStackOptions *options, pmConfig *config, ppStackFileList stackFiles, ppStackFileList photFiles, bool closeJPEGs)
    155{
    166    psAssert(stack, "Require stack");
     
    188    psAssert(config, "Require configuration");
    199
    20     psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // ppStack recipe
    21     psAssert(recipe, "We've thrown an error on this before.");
    22 
    23 #if 0
    24     // Ensure masked regions really look masked
    25     {
    26         psString maskBadStr = psMetadataLookupStr(NULL, recipe, "MASK.BAD"); // Name of bits for bad
    27         psImageMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels
    28         if (!pmReadoutMaskApply(options->outRO, maskBad)) {
    29             psWarning("Unable to apply mask");
    30         }
    31     }
    32 #endif
    33 
    34     // Generate binned JPEGs
    35     {
    36         int bin1 = psMetadataLookupS32(NULL, recipe, "BIN1"); // First binning level
    37         int bin2 = psMetadataLookupS32(NULL, recipe, "BIN2"); // Second binning level
    38 
    39         // Target cells
    40         pmFPAview *view = pmFPAviewAlloc(0); // View to cells of interest
    41         view->chip = view->cell = 0;
    42         pmCell *cell1 = pmFPAfileThisCell(config->files, view, "PPSTACK.OUTPUT.JPEG1");
    43         pmCell *cell2 = pmFPAfileThisCell(config->files, view, "PPSTACK.OUTPUT.JPEG2");
    44         psImageMaskType maskValue = pmConfigMaskGet("BLANK", config); // Bits to mask
    45         psFree(view);
    46 
    47         pmReadout *ro1 = pmReadoutAlloc(cell1), *ro2 = pmReadoutAlloc(cell2); // Binned readouts
    48         if (!pmReadoutRebin(ro1, options->outRO, maskValue, bin1, bin1) ||
    49             !pmReadoutRebin(ro2, ro1, 0, bin2, bin2)) {
    50             psError(PPSTACK_ERR_DATA, false, "Unable to bin output.");
    51             psFree(ro1);
    52             psFree(ro2);
    53             return false;
    54         }
    55         psFree(ro1);
    56         psFree(ro2);
    57     }
    58 
    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 
    7310    if (!ppStackFilesIterateUp(config)) {
    7411        psError(psErrorCodeLast(), false, "Unable to close files.");
    7512        return false;
    7613    }
    77     ppStackFileActivation(config, PPSTACK_FILES_STACK, false);
    78     ppStackFileActivation(config, PPSTACK_FILES_PHOT, false);
     14    ppStackFileActivation(config, stackFiles, false);
     15    ppStackFileActivation(config, photFiles, false);
    7916
    8017    // 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;
     18    options->outRO->data_exists = false;
     19    options->outRO->parent->data_exists = false;
     20    options->outRO->parent->parent->data_exists = false;
     21    psFree(options->outRO);
     22    options->outRO = NULL;
    8723
    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;
     24    options->expRO->data_exists = false;
     25    options->expRO->parent->data_exists = false;
     26    options->expRO->parent->parent->data_exists = false;
     27    psFree(options->expRO);
     28    options->expRO = NULL;
    9329
     30    for (int i = 0; i < options->num; i++) {
     31        pmCellFreeData(options->cells->data[i]);
     32    }
     33
     34    if (closeJPEGs) {
     35        // XXX move these close / free operations to the jpeg creation function
    9436        pmFPAview *view = pmFPAviewAlloc(0);// Pointer into FPA hierarchy
    9537        view->chip = view->cell = 0;        // pmFPAviewFreeData doesn't want to deal with readouts
     
    11860    return true;
    11961}
     62
     63bool ppStackCleanup (pmConfig *config, ppStackOptions *options) {
     64
     65    psExit exitValue = ppStackExitCode(PS_EXIT_SUCCESS); // Exit code
     66
     67    // Ensure everything closes
     68    if (config) {
     69        ppStackFileActivation(config, PPSTACK_FILES_PREPARE, true);
     70        ppStackFileActivation(config, PPSTACK_FILES_CONVOLVE, true);
     71        ppStackFileActivation(config, PPSTACK_FILES_STACK, true);
     72        ppStackFileActivation(config, PPSTACK_FILES_UNCONV, true);
     73        ppStackFileActivation(config, PPSTACK_FILES_PHOT, true);
     74        if (!ppStackFilesIterateUp(config)) {
     75            psError(psErrorCodeLast(), false, "Unable to close files.");
     76            exitValue = ppStackExitCode(exitValue);
     77            pmFPAfileFreeSetStrict(false);
     78        }
     79    }
     80
     81    // Write out summary statistics
     82    if (options && options->stats) {
     83
     84        psMetadataAddS32(options->stats, PS_LIST_TAIL, "QUALITY", PS_META_REPLACE, "Bad data quality flag", options->quality);
     85        psMetadataAddF32(options->stats, PS_LIST_TAIL, "TIME_STACK", 0, "Total time", psTimerClear("PPSTACK_TOTAL"));
     86
     87        const char *statsMDC = psMetadataConfigFormat(options->stats);
     88        if (!statsMDC || strlen(statsMDC) == 0) {
     89            psError(PS_ERR_IO, false, "Unable to get statistics MDC file.");
     90            exitValue = ppStackExitCode(exitValue);
     91            exit(exitValue);
     92        }
     93        if (fprintf(options->statsFile, "%s", statsMDC) != strlen(statsMDC)) {
     94            psError(PS_ERR_IO, false, "Unable to write statistics MDC file.");
     95            exitValue = ppStackExitCode(exitValue);
     96            exit(exitValue);
     97        }
     98        psFree(statsMDC);
     99        if (fclose(options->statsFile) == EOF) {
     100            psError(PS_ERR_IO, false, "Unable to close statistics MDC file.");
     101            exitValue = ppStackExitCode(exitValue);
     102            exit(exitValue);
     103        }
     104        options->statsFile = NULL;
     105        pmConfigRunFilenameAddWrite(config, "STATS", psMetadataLookupStr(NULL, config->arguments, "STATS"));
     106    }
     107    psFree(options);
     108
     109    // Dump configuration
     110    bool mdok;                                                                    // Status of MD lookup
     111    psString dump = psMetadataLookupStr(&mdok, config->arguments, "DUMP_CONFIG"); // File for config
     112    if (dump && !pmConfigDump(config, dump)) {
     113        psError(psErrorCodeLast(), false, "Unable to dump configuration.");
     114        exitValue = ppStackExitCode(exitValue);
     115    }
     116
     117    psTrace("ppStack", 1, "Finished at %f sec\n", psTimerMark("PPSTACK"));
     118    psTimerStop();
     119
     120    psFree(config);
     121    pmModelClassCleanup();
     122    pmConfigDone();
     123    psLibFinalize();
     124    pmVisualClose();
     125    pmVisualCleanup ();
     126
     127    exitValue = ppStackExitCode(exitValue);
     128    exit(exitValue);
     129}
  • trunk/ppStack/src/ppStackCombineFinal.c

    r29552 r30620  
    1 #ifdef HAVE_CONFIG_H
    2 #include <config.h>
    3 #endif
    4 
    5 #include <stdio.h>
    6 #include <pslib.h>
    7 #include <psmodules.h>
    8 
    91#include "ppStack.h"
    10 #include "ppStackLoop.h"
    11 
    12 #define WCS_TOLERANCE 0.001             // Tolerance for WCS
    132
    143//#define TESTING                         // Enable test output
     
    10796    }
    10897
    109     // Propagate WCS
    110     bool wcsDone = false;           // Have we done the WCS?
    111     for (int i = 0; i < options->num && !wcsDone; i++) {
    112         if (options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) {
    113             continue;
    114         }
    115 
    116         ppStackThread *thread = stack->threads->data[0]; // Representative stack
    117         pmReadout *inRO = thread->readouts->data[i]; // Template readout
    118         if (inRO && !wcsDone) {
    119             // Copy astrometry over
    120             wcsDone = true;
    121             pmHDU *inHDU = pmHDUFromCell(inRO->parent); // Template HDU
    122             pmHDU *outHDU = pmHDUFromCell(outRO->parent); // Output HDU
    123             pmChip *outChip = outRO->parent->parent; // Output chip
    124             pmFPA *outFPA = outChip->parent; // Output FPA
    125             if (!outHDU || !inHDU) {
    126                 psWarning("Unable to find HDU at FPA level to copy astrometry.");
    127             } else {
    128                 if (!pmAstromReadWCS(outFPA, outChip, inHDU->header, 1.0)) {
    129                     psErrorClear();
    130                     psWarning("Unable to read WCS astrometry from input FPA.");
    131                     wcsDone = false;
    132                 } else {
    133                     if (!outHDU->header) {
    134                         outHDU->header = psMetadataAlloc();
    135                     }
    136                     if (!pmAstromWriteWCS(outHDU->header, outFPA, outChip, WCS_TOLERANCE)) {
    137                         psErrorClear();
    138                         psWarning("Unable to write WCS astrometry to output FPA.");
    139                         wcsDone = false;
    140                     }
    141                 }
    142             }
    143         }
    144     }
    145 
    146     // Put version information into the header
    147     pmHDU *hdu = pmHDUFromCell(outRO->parent);
    148     if (!hdu) {
    149         psError(PPSTACK_ERR_PROG, false, "Unable to find HDU for output.");
    150         return false;
    151     }
    152     if (!hdu->header) {
    153         hdu->header = psMetadataAlloc();
    154     }
    155     ppStackVersionHeader(hdu->header);
    156 
    157 
    15898#ifdef TESTING
    15999    static int pass = 0;                // Pass through
  • trunk/ppStack/src/ppStackCombineInitial.c

    r28405 r30620  
    1 #ifdef HAVE_CONFIG_H
    2 #include <config.h>
    3 #endif
    4 
    5 #include <stdio.h>
    6 #include <pslib.h>
    7 #include <psmodules.h>
    8 
    91#include "ppStack.h"
    10 #include "ppStackLoop.h"
    112
    123//#define TESTING                         // Enable test output
  • trunk/ppStack/src/ppStackCombinePrepare.c

    r27427 r30620  
    1 #ifdef HAVE_CONFIG_H
    2 #include <config.h>
    3 #endif
    4 
    5 #include <stdio.h>
    6 #include <pslib.h>
    7 #include <psmodules.h>
    8 
    91#include "ppStack.h"
    10 #include "ppStackLoop.h"
    112
    123bool ppStackCombinePrepare(const char *outName, const char *expName,
  • trunk/ppStack/src/ppStackConvolve.c

    r30394 r30620  
    1 #ifdef HAVE_CONFIG_H
    2 #include <config.h>
    3 #endif
    4 
    5 #include <stdio.h>
    6 #include <pslib.h>
    7 #include <psmodules.h>
    8 
    91#include "ppStack.h"
    10 #include "ppStackLoop.h"
    112
    123//#define TESTING
    13 
    144
    155// Update the value of a concept
     
    2010    item->data.F32 = VALUE; \
    2111}
    22 
    23 
    2412
    2513bool ppStackConvolve(ppStackOptions *options, pmConfig *config)
     
    6957        ppStackFileActivationSingle(config, PPSTACK_FILES_CONVOLVE, true, i);
    7058        if (options->convolve) {
    71             // XXX PPSTACK.CONV.KERNEL not defined unless convolve
    72             // pmFPAfileActivate(config->files, true, "PPSTACK.CONV.KERNEL");
     59            // PPSTACK.CONV.KERNEL not defined unless convolve
    7360            pmFPAfileActivateSingle(config->files, true, "PPSTACK.CONV.KERNEL", i); // Activated file
    7461        }
     
    191178        }
    192179        psFree(maskHeader);
    193         if (!ppStackWriteImage(options->convVariances->data[i], hdu->header, readout->variance, config)) {
     180        if (!ppStackWriteVariance(options->convVariances->data[i], hdu->header, readout->variance, readout->covariance->image, config)) {
    194181            psError(PPSTACK_ERR_IO, false, "Unable to write convolved variance %d", i);
    195182            psFree(fpaList);
  • trunk/ppStack/src/ppStackErrorCodes.c.in

    r27004 r30620  
     1#include "ppStack.h"
     2
    13/** @file ppStackErrorCodes.c.in
    24 *
     
    1012 *  Copyright 2009 Institute for Astronomy, University of Hawaii
    1113 */
    12 
    13 #include "pslib.h"
    14 #include "ppStackErrorCodes.h"
    1514
    1615/*
  • trunk/ppStack/src/ppStackFiles.c

    r28253 r30620  
    1 #ifdef HAVE_CONFIG_H
    2 #include <config.h>
    3 #endif
    4 
    5 #include <stdio.h>
    6 #include <unistd.h>
    7 #include <pslib.h>
    8 #include <psmodules.h>
    9 
    101#include "ppStack.h"
    112
    12 
    133// Here follows lists of files for activation/deactivation at various stages.  Each must be NULL-terminated.
     4
     5/// NOP list
     6static char *filesNOP[] = { NULL };
    147
    158/// Files required in preparation for convolution
     
    4134{
    4235    switch (list) {
     36      case PPSTACK_FILES_NONE:     return filesNOP;
    4337      case PPSTACK_FILES_PREPARE:  return filesPrepare;
    4438      case PPSTACK_FILES_TARGET:   return filesTarget;
     
    206200    return true;
    207201}
     202
     203// Write an image to a FITS file
     204bool ppStackWriteVariance(const char *name, // Name of image
     205                          psMetadata *header, // Header
     206                          const psImage *variance, // Variance
     207                          const psImage *covariance, // Variance
     208                          pmConfig *config // Configuration
     209    )
     210{
     211    assert(name);
     212    assert(variance);
     213
     214    psString resolved = pmConfigConvertFilename(name, config, true, true); // Resolved file name
     215    psFits *fits = psFitsOpen(resolved, "w");
     216    if (!fits) {
     217        psError(PPSTACK_ERR_IO, false, "Unable to open FITS file %s to write image.", resolved);
     218        psFree(resolved);
     219        return false;
     220    }
     221    if (!psFitsWriteImage(fits, header, variance, 0, NULL)) {
     222        psError(PPSTACK_ERR_IO, false, "Unable to write FITS image %s.", resolved);
     223        psFitsClose(fits);
     224        psFree(resolved);
     225        return false;
     226    }
     227    if (covariance) {
     228        psMetadata *tmphead = psMetadataAlloc();
     229        psMetadataAddS32(tmphead, PS_LIST_TAIL, "COVARIANCE.CENTRE.X", PS_META_REPLACE, "center", (int)(covariance->numCols / 2));
     230        psMetadataAddS32(tmphead, PS_LIST_TAIL, "COVARIANCE.CENTRE.Y", PS_META_REPLACE, "center", (int)(covariance->numRows / 2));
     231        if (!psFitsWriteImage(fits, tmphead, covariance, 0, "COVAR_SkyChip_SkyCell")) {
     232            psError(PPSTACK_ERR_IO, false, "Unable to write FITS image %s.", resolved);
     233            psFitsClose(fits);
     234            psFree(resolved);
     235            return false;
     236        }
     237    }
     238    if (!psFitsClose(fits)) {
     239        psError(PPSTACK_ERR_IO, false, "Unable to close FITS image %s.", resolved);
     240        psFree(resolved);
     241        return false;
     242    }
     243    psFree(resolved);
     244    return true;
     245}
  • trunk/ppStack/src/ppStackFinish.c

    r27906 r30620  
    1 #ifdef HAVE_CONFIG_H
    2 #include <config.h>
    3 #endif
     1#include "ppStack.h"
    42
    5 #include <stdio.h>
    6 #include <unistd.h>
    7 #include <pslib.h>
    8 #include <psmodules.h>
    9 #include <psphot.h>
    10 
    11 #include "ppStack.h"
    12 #include "ppStackLoop.h"
    13 
     3// this function unlinks the temporary files (if desired)
    144bool ppStackFinish(ppStackOptions *options, pmConfig *config)
    155{
     
    3222            }
    3323
    34             psString imageResolved = pmConfigConvertFilename(options->convImages->data[i],
    35                                                              config, false, false);
    36             psString maskResolved = pmConfigConvertFilename(options->convMasks->data[i],
    37                                                             config, false, false);
    38             psString varianceResolved = pmConfigConvertFilename(options->convVariances->data[i],
    39                                                                 config, false, false);
     24            // XXX careful about repeatative resolution of nebulous names (though these are probably not neb names)
     25            psString imageResolved = pmConfigConvertFilename(options->convImages->data[i], config, false, false);
     26            psString maskResolved = pmConfigConvertFilename(options->convMasks->data[i], config, false, false);
     27            psString varianceResolved = pmConfigConvertFilename(options->convVariances->data[i], config, false, false);
    4028            if (unlink(imageResolved) == -1 || unlink(maskResolved) == -1 ||
    4129                unlink(varianceResolved) == -1) {
     
    4735        }
    4836    }
    49 
    50 
    5137    return true;
    5238}
     
    6046
    6147    psErrorCode errorCode = psErrorCodeLast(); // Error code
    62     if (errorCode != PS_ERR_NONE) {
    63         psErrorStackPrint(stderr, "Unable to perform stack.");
    64         pmFPAfileFreeSetStrict(false);
    65         switch (errorCode) {
    66           case PPSTACK_ERR_UNKNOWN:
    67           case PS_ERR_UNKNOWN:
    68             psLogMsg("ppStack", PS_LOG_WARN, "Unknown error code: %x", errorCode);
    69             exitValue = PS_EXIT_UNKNOWN_ERROR;
    70             break;
    71           case PS_ERR_IO:
    72           case PS_ERR_DB_CLIENT:
    73           case PS_ERR_DB_SERVER:
    74           case PS_ERR_BAD_FITS:
    75           case PS_ERR_OS_CALL_FAILED:
    76           case PM_ERR_SYS:
    77           case PPSTACK_ERR_IO:
    78             psLogMsg("ppStack", PS_LOG_WARN, "I/O error code: %x", errorCode);
    79             exitValue = PS_EXIT_SYS_ERROR;
    80             break;
    81           case PS_ERR_BAD_PARAMETER_VALUE:
    82           case PS_ERR_BAD_PARAMETER_TYPE:
    83           case PS_ERR_BAD_PARAMETER_NULL:
    84           case PS_ERR_BAD_PARAMETER_SIZE:
    85           case PPSTACK_ERR_ARGUMENTS:
    86           case PPSTACK_ERR_CONFIG:
    87             psLogMsg("ppStack", PS_LOG_WARN, "Configuration error code: %x", errorCode);
    88             exitValue = PS_EXIT_CONFIG_ERROR;
    89             break;
    90           case PPSTACK_ERR_PSF:
    91           case PSPHOT_ERR_PSF:
    92           case PM_ERR_STAMPS:
    93           case PM_ERR_SMALL_AREA:
    94           case PPSTACK_ERR_REJECTED:
    95           case PPSTACK_ERR_DATA:
    96             psLogMsg("ppStack", PS_LOG_WARN, "Data error code: %x", errorCode);
    97             exitValue = PS_EXIT_DATA_ERROR;
    98             break;
    99           case PS_ERR_UNEXPECTED_NULL:
    100           case PS_ERR_PROGRAMMING:
    101           case PPSTACK_ERR_NOT_IMPLEMENTED:
    102           case PPSTACK_ERR_PROG:
    103             psLogMsg("ppStack", PS_LOG_WARN, "Programming error code: %x", errorCode);
    104             exitValue = PS_EXIT_PROG_ERROR;
    105             break;
    106           default:
    107             // It's a programming error if we're not dealing with the error correctly
    108             psLogMsg("ppStack", PS_LOG_WARN, "Unrecognised error code: %x", errorCode);
    109             exitValue = PS_EXIT_PROG_ERROR;
    110             break;
    111         }
     48    if (errorCode == PS_ERR_NONE) {
     49        return exitValue;
     50    }
     51
     52    psErrorStackPrint(stderr, "Unable to perform stack.");
     53    pmFPAfileFreeSetStrict(false);
     54    switch (errorCode) {
     55      case PPSTACK_ERR_UNKNOWN:
     56      case PS_ERR_UNKNOWN:
     57        psLogMsg("ppStack", PS_LOG_WARN, "Unknown error code: %x", errorCode);
     58        exitValue = PS_EXIT_UNKNOWN_ERROR;
     59        break;
     60      case PS_ERR_IO:
     61      case PS_ERR_DB_CLIENT:
     62      case PS_ERR_DB_SERVER:
     63      case PS_ERR_BAD_FITS:
     64      case PS_ERR_OS_CALL_FAILED:
     65      case PM_ERR_SYS:
     66      case PPSTACK_ERR_IO:
     67        psLogMsg("ppStack", PS_LOG_WARN, "I/O error code: %x", errorCode);
     68        exitValue = PS_EXIT_SYS_ERROR;
     69        break;
     70      case PS_ERR_BAD_PARAMETER_VALUE:
     71      case PS_ERR_BAD_PARAMETER_TYPE:
     72      case PS_ERR_BAD_PARAMETER_NULL:
     73      case PS_ERR_BAD_PARAMETER_SIZE:
     74      case PPSTACK_ERR_ARGUMENTS:
     75      case PPSTACK_ERR_CONFIG:
     76        psLogMsg("ppStack", PS_LOG_WARN, "Configuration error code: %x", errorCode);
     77        exitValue = PS_EXIT_CONFIG_ERROR;
     78        break;
     79      case PPSTACK_ERR_PSF:
     80      case PSPHOT_ERR_PSF:
     81      case PM_ERR_STAMPS:
     82      case PM_ERR_SMALL_AREA:
     83      case PPSTACK_ERR_REJECTED:
     84      case PPSTACK_ERR_DATA:
     85        psLogMsg("ppStack", PS_LOG_WARN, "Data error code: %x", errorCode);
     86        exitValue = PS_EXIT_DATA_ERROR;
     87        break;
     88      case PS_ERR_UNEXPECTED_NULL:
     89      case PS_ERR_PROGRAMMING:
     90      case PPSTACK_ERR_NOT_IMPLEMENTED:
     91      case PPSTACK_ERR_PROG:
     92        psLogMsg("ppStack", PS_LOG_WARN, "Programming error code: %x", errorCode);
     93        exitValue = PS_EXIT_PROG_ERROR;
     94        break;
     95      default:
     96        // It's a programming error if we're not dealing with the error correctly
     97        psLogMsg("ppStack", PS_LOG_WARN, "Unrecognised error code: %x", errorCode);
     98        exitValue = PS_EXIT_PROG_ERROR;
     99        break;
    112100    }
    113101    return exitValue;
  • trunk/ppStack/src/ppStackLoop.c

    r29552 r30620  
    1 #ifdef HAVE_CONFIG_H
    2 #include <config.h>
    3 #endif
    4 
    5 #include <stdio.h>
    6 #include <pslib.h>
    7 #include <psmodules.h>
    8 
    91#include "ppStack.h"
    10 #include "ppStackLoop.h"
     2
     3// static functions are defined below
     4static int stackSummary(const ppStackOptions *options, const char *place);
     5
     6bool ppStackLoop(pmConfig *config, ppStackOptions *options)
     7{
     8    assert(config);
     9
     10    psTimerStart("PPSTACK_TOTAL");
     11    psTimerStart("PPSTACK_STEPS");
     12
     13    // Setup
     14    psTrace("ppStack", 1, "Setup....\n");
     15    if (!ppStackSetup(options, config)) {
     16        psError(psErrorCodeLast(), false, "Unable to setup.");
     17        return false;
     18    }
     19    psLogMsg("ppStack", PS_LOG_INFO, "Stage 0: Setup: %f sec", psTimerClear("PPSTACK_STEPS"));
     20    ppStackMemDump("setup");
     21
     22    // Preparation for stacking
     23    psTrace("ppStack", 1, "Preparation for stacking: merging sources, determining target PSF....\n");
     24
     25    if (!ppStackPrepare(options, config)) {
     26        psError(psErrorCodeLast(), false, "Unable to prepare for stacking.");
     27        return false;
     28    }
     29    psLogMsg("ppStack", PS_LOG_INFO, "Stage 1: Load Sources and Generate Target PSF: %f sec", psTimerClear("PPSTACK_STEPS"));
     30    ppStackMemDump("prepare");
     31    if (options->quality) return true; // Can't do anything else
     32
     33    // Convolve inputs
     34    psTrace("ppStack", 1, "Convolving inputs to target PSF....\n");
     35    if (!ppStackConvolve(options, config)) {
     36        psError(psErrorCodeLast(), false, "Unable to convolve images.");
     37        return false;
     38    }
     39    psLogMsg("ppStack", PS_LOG_INFO, "Stage 2: Generate Convolutions and Save: %f sec", psTimerClear("PPSTACK_STEPS"));
     40    ppStackMemDump("convolve");
     41    if (options->quality) return true; // Can't do anything else
     42
     43    // Ensure sufficient inputs
     44    {
     45        int numGood = stackSummary(options, "initial combination");
     46        psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // ppStack recipe
     47        bool safe = psMetadataLookupBool(NULL, recipe, "SAFE"); // Be safe when combining
     48        if (safe && numGood <= 1) {
     49            options->quality = PPSTACK_ERR_REJECTED;
     50            psErrorStackPrint(stderr, "Insufficient inputs for combination with safety on");
     51            psErrorClear();
     52            psWarning("Insufficient inputs for combination with safety on");
     53            return true;
     54        }
     55    }
     56
     57    // Start threading
     58    ppStackThreadInit();
     59    ppStackThreadData *stack = ppStackThreadDataSetup(options, config, true);
     60    if (!stack) {
     61        psError(psErrorCodeLast(), false, "Unable to initialise stack threads.");
     62        return false;
     63    }
     64
     65    // Prepare for combination
     66    if (!ppStackCombinePrepare("PPSTACK.OUTPUT", "PPSTACK.OUTPUT.EXP", PPSTACK_FILES_STACK, stack, options, config)) {
     67        psError(psErrorCodeLast(), false, "Unable to prepare for combination.");
     68        psFree(stack);
     69        return false;
     70    }
     71
     72    // Initial combination
     73    psTrace("ppStack", 1, "Initial stack of convolved images....\n");
     74    if (!ppStackCombineInitial(stack, options, config)) {
     75        psError(psErrorCodeLast(), false, "Unable to perform initial combination.");
     76        psFree(stack);
     77        return false;
     78    }
     79    ppStackMemDump("initial");
     80    psLogMsg("ppStack", PS_LOG_INFO, "Stage 3: Make Initial Stack: %f sec", psTimerClear("PPSTACK_STEPS"));
     81
     82    // Done with stack inputs for now
     83    // XXX is this where we are leaking??
     84    for (int i = 0; i < options->num; i++) {
     85        pmCellFreeData(options->cells->data[i]);
     86    }
     87    psFree(stack);
     88
     89    // Pixel rejection
     90    psTrace("ppStack", 1, "Reject pixels....\n");
     91    if (!ppStackReject(options, config)) {
     92        psError(psErrorCodeLast(), false, "Unable to reject pixels.");
     93        psFree(stack);
     94        return false;
     95    }
     96    psLogMsg("ppStack", PS_LOG_INFO, "Stage 4: Pixel Rejection: %f sec", psTimerClear("PPSTACK_STEPS"));
     97
     98    // Check inputs
     99    {
     100        int numGood = stackSummary(options, "final combination");
     101        if (numGood <= 0) {
     102            options->quality = PPSTACK_ERR_REJECTED;
     103            psErrorStackPrint(stderr, "Insufficient inputs survived rejection stage");
     104            psErrorClear();
     105            psWarning("Insufficient inputs survived rejection stage");
     106            return true;
     107        }
     108    }
     109
     110    stack = ppStackThreadDataSetup(options, config, true);
     111    if (!stack) {
     112        psError(psErrorCodeLast(), false, "Unable to initialise stack threads.");
     113        return false;
     114    }
     115
     116    // Final combination
     117    psTrace("ppStack", 2, "Final stack of convolved images....\n");
     118    if (!ppStackCombineFinal(stack, options->convCovars, options, config, false, false, true)) {
     119        psError(psErrorCodeLast(), false, "Unable to perform final combination.");
     120        psFree(stack);
     121        return false;
     122    }
     123    psLogMsg("ppStack", PS_LOG_INFO, "Stage 5: Final Stack: %f sec", psTimerClear("PPSTACK_STEPS"));
     124    ppStackMemDump("final");
     125
     126    // Photometry
     127    psTrace("ppStack", 1, "Photometering stacked image....\n");
     128    if (!ppStackPhotometry(options, config)) {
     129        psError(psErrorCodeLast(), false, "Unable to perform photometry.");
     130        return false;
     131    }
     132    psLogMsg("ppStack", PS_LOG_INFO, "Stage 6: Photometry Analysis: %f sec", psTimerClear("PPSTACK_STEPS"));
     133    ppStackMemDump("photometry");
     134
     135    // Update Header
     136    if (!ppStackUpdateHeader(stack, options, config)) {
     137        psError(psErrorCodeLast(), false, "Unable to update header.");
     138        psFree(stack);
     139        return false;
     140    }
     141    // Create JPEGS
     142    if (!ppStackJPEGs(stack, options, config)) {
     143        psError(psErrorCodeLast(), false, "Unable to make jpegs.");
     144        psFree(stack);
     145        return false;
     146    }
     147    // Assemble Stats
     148    if (!ppStackStats(stack, options, config)) {
     149        psError(psErrorCodeLast(), false, "Unable to assemble statistics.");
     150        psFree(stack);
     151        return false;
     152    }
     153
     154   // Clean up
     155    psTrace("ppStack", 2, "Cleaning up after combination....\n");
     156    if (!ppStackCleanupFiles(stack, options, config, PPSTACK_FILES_STACK, PPSTACK_FILES_PHOT, true)) {
     157        psError(psErrorCodeLast(), false, "Unable to clean up.");
     158        psFree(stack);
     159        return false;
     160    }
     161    psFree(stack);
     162    psLogMsg("ppStack", PS_LOG_INFO, "Stage 7: Cleanup, WCS & JPEGS: %f sec", psTimerClear("PPSTACK_STEPS"));
     163    ppStackMemDump("cleanup");
     164
     165    // Unconvolved stack --- it's cheap to calculate, compared to everything else!
     166    // XXX unconvolved stack is currently using the convolved mask!  oops!
     167    if (options->convolve) {
     168        // Start threading
     169        ppStackThreadData *stack = ppStackThreadDataSetup(options, config, false);
     170        if (!stack) {
     171            psError(psErrorCodeLast(), false, "Unable to initialise stack threads.");
     172            return false;
     173        }
     174
     175        // Prepare for combination
     176        if (!ppStackCombinePrepare("PPSTACK.UNCONV", "PPSTACK.UNCONV.EXP", PPSTACK_FILES_UNCONV,
     177                                   stack, options, config)) {
     178            psError(psErrorCodeLast(), false, "Unable to prepare for combination.");
     179            psFree(stack);
     180            return false;
     181        }
     182
     183        // generate the unconvolved stack
     184        psTrace("ppStack", 2, "Stack of unconvolved images....\n");
     185        if (!ppStackCombineFinal(stack, options->origCovars, options, config,
     186                                 false, true, false)) {
     187            psError(psErrorCodeLast(), false, "Unable to perform unconvolved combination.");
     188            psFree(stack);
     189            return false;
     190        }
     191        psLogMsg("ppStack", PS_LOG_INFO, "Stage 8: Unconvolved Stack: %f sec", psTimerClear("PPSTACK_STEPS"));
     192        ppStackMemDump("unconv");
     193
     194        // Clean up unconvolved stack
     195        psTrace("ppStack", 2, "Cleaning up after unconvolved stack....\n");
     196        if (!ppStackCleanupFiles(stack, options, config, PPSTACK_FILES_UNCONV, PPSTACK_FILES_NONE, false)) {
     197            psError(psErrorCodeLast(), false, "Unable to clean up.");
     198            psFree(stack);
     199            return false;
     200        }
     201        psFree(stack);
     202    }
     203    psFree(options->cells); options->cells = NULL;
     204
     205    // Finish up
     206    psTrace("ppStack", 1, "Finishing up....\n");
     207    if (!ppStackFinish(options, config)) {
     208        psError(psErrorCodeLast(), false, "Unable to finish up.");
     209        return false;
     210    }
     211    ppStackMemDump("finish");
     212
     213    return true;
     214}
    11215
    12216/// Print a summary of the inputs, and return the number of good inputs
    13 static int stackSummary(const ppStackOptions *options, // Stack options, with input mask
    14                         const char *place              // Place in code
    15     )
     217static int stackSummary(const ppStackOptions *options, const char *place)
    16218{
    17219    int numGood = 0;                // Number of good inputs
     
    47249    return numGood;
    48250}
    49 
    50 
    51 
    52 bool ppStackLoop(pmConfig *config, ppStackOptions *options)
    53 {
    54     assert(config);
    55 
    56     psTimerStart("PPSTACK_TOTAL");
    57     psTimerStart("PPSTACK_STEPS");
    58 
    59     // Setup
    60     psTrace("ppStack", 1, "Setup....\n");
    61     if (!ppStackSetup(options, config)) {
    62         psError(psErrorCodeLast(), false, "Unable to setup.");
    63         return false;
    64     }
    65     psLogMsg("ppStack", PS_LOG_INFO, "Stage 0: Setup: %f sec", psTimerClear("PPSTACK_STEPS"));
    66     ppStackMemDump("setup");
    67 
    68 
    69     // Preparation for stacking
    70     psTrace("ppStack", 1, "Preparation for stacking: merging sources, determining target PSF....\n");
    71     if (!ppStackPrepare(options, config)) {
    72         psError(psErrorCodeLast(), false, "Unable to prepare for stacking.");
    73         return false;
    74     }
    75     psLogMsg("ppStack", PS_LOG_INFO, "Stage 1: Load Sources and Generate Target PSF: %f sec",
    76              psTimerClear("PPSTACK_STEPS"));
    77     ppStackMemDump("prepare");
    78     if (options->quality) {
    79         // Can't do anything else
    80         return true;
    81     }
    82 
    83     // Convolve inputs
    84     psTrace("ppStack", 1, "Convolving inputs to target PSF....\n");
    85     if (!ppStackConvolve(options, config)) {
    86         psError(psErrorCodeLast(), false, "Unable to convolve images.");
    87         return false;
    88     }
    89     psLogMsg("ppStack", PS_LOG_INFO, "Stage 2: Generate Convolutions and Save: %f sec",
    90              psTimerClear("PPSTACK_STEPS"));
    91     ppStackMemDump("convolve");
    92 
    93     if (options->quality) {
    94         // Can't do anything else
    95         return true;
    96     }
    97 
    98     // Ensure sufficient inputs
    99     {
    100         int numGood = stackSummary(options, "initial combination");
    101         psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // ppStack recipe
    102         bool safe = psMetadataLookupBool(NULL, recipe, "SAFE"); // Be safe when combining
    103         if (safe && numGood <= 1) {
    104             options->quality = PPSTACK_ERR_REJECTED;
    105             psErrorStackPrint(stderr, "Insufficient inputs for combination with safety on");
    106             psErrorClear();
    107             psWarning("Insufficient inputs for combination with safety on");
    108             return true;
    109         }
    110     }
    111 
    112     // Start threading
    113     ppStackThreadInit();
    114     ppStackThreadData *stack = ppStackThreadDataSetup(options, config, true);
    115     if (!stack) {
    116         psError(psErrorCodeLast(), false, "Unable to initialise stack threads.");
    117         return false;
    118     }
    119 
    120     // Prepare for combination
    121     if (!ppStackCombinePrepare("PPSTACK.OUTPUT", "PPSTACK.OUTPUT.EXP", PPSTACK_FILES_STACK,
    122                                stack, options, config)) {
    123         psError(psErrorCodeLast(), false, "Unable to prepare for combination.");
    124         psFree(stack);
    125         return false;
    126     }
    127 
    128     // Initial combination
    129     psTrace("ppStack", 1, "Initial stack of convolved images....\n");
    130     if (!ppStackCombineInitial(stack, options, config)) {
    131         psError(psErrorCodeLast(), false, "Unable to perform initial combination.");
    132         psFree(stack);
    133         return false;
    134     }
    135     ppStackMemDump("initial");
    136     psLogMsg("ppStack", PS_LOG_INFO, "Stage 3: Make Initial Stack: %f sec", psTimerClear("PPSTACK_STEPS"));
    137 
    138     // Done with stack inputs for now
    139     for (int i = 0; i < options->num; i++) {
    140         pmCellFreeData(options->cells->data[i]);
    141     }
    142     psFree(stack);
    143 
    144     // Pixel rejection
    145     psTrace("ppStack", 1, "Reject pixels....\n");
    146     if (!ppStackReject(options, config)) {
    147         psError(psErrorCodeLast(), false, "Unable to reject pixels.");
    148         psFree(stack);
    149         return false;
    150     }
    151     psLogMsg("ppStack", PS_LOG_INFO, "Stage 4: Pixel Rejection: %f sec", psTimerClear("PPSTACK_STEPS"));
    152 
    153     // Check inputs
    154     {
    155         int numGood = stackSummary(options, "final combination");
    156         if (numGood <= 0) {
    157             options->quality = PPSTACK_ERR_REJECTED;
    158             psErrorStackPrint(stderr, "Insufficient inputs survived rejection stage");
    159             psErrorClear();
    160             psWarning("Insufficient inputs survived rejection stage");
    161             return true;
    162         }
    163     }
    164 
    165     stack = ppStackThreadDataSetup(options, config, true);
    166     if (!stack) {
    167         psError(psErrorCodeLast(), false, "Unable to initialise stack threads.");
    168         return false;
    169     }
    170 
    171     // Final combination
    172     psTrace("ppStack", 2, "Final stack of convolved images....\n");
    173     if (!ppStackCombineFinal(stack, options->convCovars, options, config, false, false, true)) {
    174         psError(psErrorCodeLast(), false, "Unable to perform final combination.");
    175         psFree(stack);
    176         return false;
    177     }
    178     psLogMsg("ppStack", PS_LOG_INFO, "Stage 5: Final Stack: %f sec", psTimerClear("PPSTACK_STEPS"));
    179     ppStackMemDump("final");
    180 
    181     // Photometry
    182     psTrace("ppStack", 1, "Photometering stacked image....\n");
    183     if (!ppStackPhotometry(options, config)) {
    184         psError(psErrorCodeLast(), false, "Unable to perform photometry.");
    185         return false;
    186     }
    187     psLogMsg("ppStack", PS_LOG_INFO, "Stage 6: Photometry Analysis: %f sec", psTimerClear("PPSTACK_STEPS"));
    188     ppStackMemDump("photometry");
    189 
    190     // Clean up
    191     psTrace("ppStack", 2, "Cleaning up after combination....\n");
    192     if (!ppStackCleanup(stack, options, config)) {
    193         psError(psErrorCodeLast(), false, "Unable to clean up.");
    194         psFree(stack);
    195         return false;
    196     }
    197     for (int i = 0; i < options->num; i++) {
    198         pmCellFreeData(options->cells->data[i]);
    199     }
    200     psFree(stack);
    201     psLogMsg("ppStack", PS_LOG_INFO, "Stage 7: Cleanup, WCS & JPEGS: %f sec", psTimerClear("PPSTACK_STEPS"));
    202     ppStackMemDump("cleanup");
    203 
    204 #if 1
    205     // Unconvolved stack --- it's cheap to calculate, compared to everything else!
    206     // XXX unconvolved stack is currently using the convolved mask!  oops!
    207     if (options->convolve) {
    208         // Start threading
    209         ppStackThreadData *stack = ppStackThreadDataSetup(options, config, false);
    210         if (!stack) {
    211             psError(psErrorCodeLast(), false, "Unable to initialise stack threads.");
    212             return false;
    213         }
    214 
    215         // Prepare for combination
    216         if (!ppStackCombinePrepare("PPSTACK.UNCONV", "PPSTACK.UNCONV.EXP", PPSTACK_FILES_UNCONV,
    217                                    stack, options, config)) {
    218             psError(psErrorCodeLast(), false, "Unable to prepare for combination.");
    219             psFree(stack);
    220             return false;
    221         }
    222 
    223         psTrace("ppStack", 2, "Stack of unconvolved images....\n");
    224         if (!ppStackCombineFinal(stack, options->origCovars, options, config,
    225                                  false, true, false)) {
    226             psError(psErrorCodeLast(), false, "Unable to perform unconvolved combination.");
    227             psFree(stack);
    228             return false;
    229         }
    230         psLogMsg("ppStack", PS_LOG_INFO, "Stage 8: Unconvolved Stack: %f sec", psTimerClear("PPSTACK_STEPS"));
    231         ppStackMemDump("unconv");
    232 
    233         if (!ppStackFilesIterateUp(config)) {
    234             psError(psErrorCodeLast(), false, "Unable to close files.");
    235             psFree(stack);
    236             return false;
    237         }
    238         ppStackFileActivation(config, PPSTACK_FILES_UNCONV, false);
    239         options->outRO->data_exists = false;
    240         options->outRO->parent->data_exists = false;
    241         options->outRO->parent->parent->data_exists = false;
    242         psFree(options->outRO);
    243         options->outRO = NULL;
    244         options->expRO->data_exists = false;
    245         options->expRO->parent->data_exists = false;
    246         options->expRO->parent->parent->data_exists = false;
    247         psFree(options->expRO);
    248         options->expRO = NULL;
    249 
    250         for (int i = 0; i < options->num; i++) {
    251             pmCellFreeData(options->cells->data[i]);
    252         }
    253         psFree(stack);
    254     }
    255     psFree(options->cells); options->cells = NULL;
    256 #endif
    257 
    258     // Finish up
    259     psTrace("ppStack", 1, "Finishing up....\n");
    260     if (!ppStackFinish(options, config)) {
    261         psError(psErrorCodeLast(), false, "Unable to finish up.");
    262         return false;
    263     }
    264     ppStackMemDump("finish");
    265 
    266     return true;
    267 }
  • trunk/ppStack/src/ppStackLoop.h

    r27427 r30620  
    11#ifndef PPSTACK_LOOP_H
    22#define PPSTACK_LOOP_H
    3 
    4 #include <pslib.h>
    5 #include <psmodules.h>
    6 
    7 #include "ppStackOptions.h"
    8 #include "ppStackThread.h"
    9 #include "ppStack.h"
    10 
    113
    124// Loop over the inputs, doing the combination
     
    7163
    7264// Cleanup following combination
    73 bool ppStackCleanup(
     65bool ppStackCleanupFiles(
    7466    ppStackThreadData *stack,           // Stack
    7567    ppStackOptions *options,            // Options
    76     pmConfig *config                    // Configuration
    77     );
     68    pmConfig *config,                   // Configuration
     69    ppStackFileList stackFiles,         // cleanup these stack files
     70    ppStackFileList photFiles,          // cleanup these phot files (PHOT or NOP)
     71    bool closeJPEGs                     // close the jpeg files?
     72);
    7873
    7974// Photometry
     
    8984    );
    9085
     86
     87bool ppStackUpdateHeader(ppStackThreadData *stack, ppStackOptions *options, pmConfig *config);
     88bool ppStackJPEGs(ppStackThreadData *stack, ppStackOptions *options, pmConfig *config);
     89bool ppStackStats(ppStackThreadData *stack, ppStackOptions *options, pmConfig *config);
     90
    9191#endif
  • trunk/ppStack/src/ppStackMatch.c

    r29552 r30620  
    1 #ifdef HAVE_CONFIG_H
    2 #include <config.h>
    3 #endif
    4 
    5 #include <stdio.h>
    6 #include <pslib.h>
    7 #include <psmodules.h>
    8 #include <psphot.h>
    9 
    101#include "ppStack.h"
    112
     
    325316                // Scale the input parameters
    326317                psVector *widthsCopy = psVectorCopy(NULL, widths, PS_TYPE_F32); // Copy of kernel widths
    327                 if (scale && !pmSubtractionParamsScale(&size, &footprint, widthsCopy, scaleRef, scaleMin, scaleMax)) {
    328                     psError(psErrorCodeLast(), false, "Unable to scale kernel parameters");
    329                     psFree(fake);
    330                     psFree(optWidths);
    331                     psFree(conv);
    332                     psFree(widthsCopy);
    333                     if (threads > 0) {
    334                         pmSubtractionThreadsFinalize();
    335                     }
    336                     return false;
    337                 }
     318
     319                pmSubtractionParamScaleOptions(scale, scaleRef, scaleMin, scaleMax);
     320
     321                // XXX EAM : the kernel scaling process has changed: the scale is now set
     322                // inside pmSubtractionMatch after the normalization window is measured
     323
     324                // if (scale && !pmSubtractionParamsScale(&size, &footprint, widthsCopy, scaleRef, scaleMin, scaleMax)) {
     325                //     psError(psErrorCodeLast(), false, "Unable to scale kernel parameters");
     326                //     psFree(fake);
     327                //     psFree(optWidths);
     328                //     psFree(conv);
     329                //     psFree(widthsCopy);
     330                //     if (threads > 0) {
     331                //         pmSubtractionThreadsFinalize();
     332                //     }
     333                //     return false;
     334                // }
    338335
    339336                if (!pmSubtractionMatch(NULL, conv, fake, readout, footprint, stride, regionSize, spacing,
  • trunk/ppStack/src/ppStackOptions.c

    r27427 r30620  
    1 #ifdef HAVE_CONFIG_H
    2 #include <config.h>
    3 #endif
    4 
    5 #include <pslib.h>
    6 #include "ppStackLoop.h"
     1#include "ppStack.h"
    72
    83static void stackOptionsFree(ppStackOptions *options)
     
    3631    psFree(options->inspect);
    3732    psFree(options->rejected);
     33
    3834    return;
    3935}
  • trunk/ppStack/src/ppStackOptions.h

    r27427 r30620  
    11#ifndef PPSTACK_OPTIONS_H
    22#define PPSTACK_OPTIONS_H
    3 
    4 #include <pslib.h>
    5 #include <psmodules.h>
    63
    74/// Options for stacking process
  • trunk/ppStack/src/ppStackPSF.c

    r29552 r30620  
    1 #ifdef HAVE_CONFIG_H
    2 #include <config.h>
    3 #endif
    4 
    5 #include <stdio.h>
    6 #include <pslib.h>
    7 #include <psmodules.h>
    8 
    91#include "ppStack.h"
    102
  • trunk/ppStack/src/ppStackPhotometry.c

    r29927 r30620  
    1 #ifdef HAVE_CONFIG_H
    2 #include <config.h>
    3 #endif
    4 
    5 #include <stdio.h>
    6 #include <pslib.h>
    7 #include <psmodules.h>
    8 #include <psphot.h>
    9 
    101#include "ppStack.h"
    11 #include "ppStackLoop.h"
    122
    133bool ppStackPhotometry(ppStackOptions *options, pmConfig *config)
  • trunk/ppStack/src/ppStackPrepare.c

    r27446 r30620  
    1 #ifdef HAVE_CONFIG_H
    2 #include <config.h>
    3 #endif
    4 
    5 #include <stdio.h>
    6 #include <pslib.h>
    7 #include <psmodules.h>
    8 
    91#include "ppStack.h"
    10 #include "ppStackLoop.h"
    112
    123#define PHOT_SOURCE_MASK (PM_SOURCE_MODE_FAIL | PM_SOURCE_MODE_SATSTAR | PM_SOURCE_MODE_BLEND | \
  • trunk/ppStack/src/ppStackReadout.c

    r29552 r30620  
    1 #ifdef HAVE_CONFIG_H
    2 #include <config.h>
    3 #endif
    4 
    5 #include <stdio.h>
    6 #include <pslib.h>
    7 #include <psmodules.h>
    8 #include <psphot.h>
    9 
    10 #include "ppStackThread.h"
    111#include "ppStack.h"
    122
  • trunk/ppStack/src/ppStackReject.c

    r28405 r30620  
    1 #ifdef HAVE_CONFIG_H
    2 #include <config.h>
    3 #endif
    4 
    5 #include <stdio.h>
    6 #include <pslib.h>
    7 #include <psmodules.h>
    8 
    91#include "ppStack.h"
    10 #include "ppStackLoop.h"
    112
    123// #define TESTING
  • trunk/ppStack/src/ppStackSetup.c

    r27158 r30620  
    1 #ifdef HAVE_CONFIG_H
    2 #include <config.h>
    3 #endif
    4 
    5 #include <stdio.h>
    6 #include <libgen.h>
    7 #include <pslib.h>
    8 #include <psmodules.h>
    9 
    101#include "ppStack.h"
    11 #include "ppStackLoop.h"
    122
    133#define BUFFER 16                       // Buffer for name array
    14 
    154
    165bool ppStackSetup(ppStackOptions *options, pmConfig *config)
  • trunk/ppStack/src/ppStackSources.c

    r28144 r30620  
    1 #include <stdio.h>
    2 #include <math.h>
    3 #include <string.h>
    4 #include <pslib.h>
    5 #include <psmodules.h>
    6 
    71#include "ppStack.h"
    82
  • trunk/ppStack/src/ppStackTarget.c

    r28302 r30620  
    1 #include <stdio.h>
    2 #include <pslib.h>
    3 #include <psmodules.h>
    4 
    51#include "ppStack.h"
    62
     
    3733        return psMemIncrRefCounter(sources);
    3834    }
     35    exclusion = 2;
    3936
    4037    int num = sources->n;               // Number of sources
  • trunk/ppStack/src/ppStackThread.c

    r27427 r30620  
    1 #ifdef HAVE_CONFIG_H
    2 #include <config.h>
    3 #endif
    4 
    5 #include <stdio.h>
    6 #include <unistd.h>
    7 #include <pslib.h>
    8 #include <psmodules.h>
    9 
    101#include "ppStack.h"
    11 #include "ppStackOptions.h"
    12 #include "ppStackThread.h"
    13 
    142
    153#define THREAD_WAIT 10000               // Microseconds to wait if thread is not available
    16 
    174
    185static void stackThreadFree(ppStackThread *thread)
  • trunk/ppStack/src/ppStackThread.h

    r26076 r30620  
    11#ifndef PPSTACK_THREAD_H
    22#define PPSTACK_THREAD_H
    3 
    4 #include <pslib.h>
    5 #include <psmodules.h>
    6 
    7 #include "ppStackOptions.h"
    83
    94// Thread for stacking chunks
  • trunk/ppStack/src/ppStackVersion.c

    r28043 r30620  
    1 #ifdef HAVE_CONFIG_H
    2 #include <config.h>
    3 #endif
    4 
    5 #include <stdio.h>
    6 #include <pslib.h>
    7 #include <psmodules.h>
    8 #include <ppStats.h>
    9 #include <psphot.h>
    10 
    111#include "ppStack.h"
    122#include "ppStackVersionDefinitions.h"
Note: See TracChangeset for help on using the changeset viewer.