IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

updates from trunk

Location:
branches/simtest_nebulous_branches
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/simtest_nebulous_branches

  • branches/simtest_nebulous_branches/ppStack/src

    • Property svn:ignore
      •  

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

    r23576 r27840  
    1010#include "ppStackLoop.h"
    1111
    12 bool ppStackLoop(pmConfig *config)
     12/// Print a summary of the inputs, and return the number of good inputs
     13static int stackSummary(const ppStackOptions *options, // Stack options, with input mask
     14                        const char *place              // Place in code
     15    )
     16{
     17    int numGood = 0;                // Number of good inputs
     18    psString summary = NULL;        // Summary of images
     19    for (int i = 0; i < options->num; i++) {
     20        psString reason = NULL;         // Reason for rejecting
     21        if (options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] == 0) {
     22            psStringAppend(&reason, " Good.");
     23            numGood++;
     24        } else {
     25            if (options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PPSTACK_MASK_CAL) {
     26                psStringAppend(&reason, " Calibration failed.");
     27            }
     28            if (options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PPSTACK_MASK_PSF) {
     29                psStringAppend(&reason, " PSF measurement failed.");
     30            }
     31            if (options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PPSTACK_MASK_MATCH) {
     32                psStringAppend(&reason, " PSF matching failed.");
     33            }
     34            if (options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PPSTACK_MASK_CHI2) {
     35                psStringAppend(&reason, " PSF matching chi^2 deviant.");
     36            }
     37            if (options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PPSTACK_MASK_REJECT) {
     38                psStringAppend(&reason, " Rejection exceeded threshold.");
     39            }
     40        }
     41        psStringAppend(&summary, "Image %d: %s\n", i, reason);
     42        psFree(reason);
     43    }
     44    psLogMsg("ppStack", PS_LOG_INFO, "Summary of images for %s:\n%s", place, summary);
     45    psFree(summary);
     46
     47    return numGood;
     48}
     49
     50
     51
     52bool ppStackLoop(pmConfig *config, ppStackOptions *options)
    1353{
    1454    assert(config);
     
    1656    psTimerStart("PPSTACK_TOTAL");
    1757    psTimerStart("PPSTACK_STEPS");
    18 
    19     ppStackOptions *options = ppStackOptionsAlloc(); // Options for stacking
    2058
    2159    // Setup
    2260    psTrace("ppStack", 1, "Setup....\n");
    2361    if (!ppStackSetup(options, config)) {
    24         psError(PS_ERR_UNKNOWN, false, "Unable to setup.");
    25         psFree(options);
     62        psError(psErrorCodeLast(), false, "Unable to setup.");
    2663        return false;
    2764    }
     
    3370    psTrace("ppStack", 1, "Preparation for stacking: merging sources, determining target PSF....\n");
    3471    if (!ppStackPrepare(options, config)) {
    35         psError(PS_ERR_UNKNOWN, false, "Unable to prepare for stacking.");
    36         psFree(options);
     72        psError(psErrorCodeLast(), false, "Unable to prepare for stacking.");
    3773        return false;
    3874    }
     
    4076             psTimerClear("PPSTACK_STEPS"));
    4177    ppStackMemDump("prepare");
    42 
     78    if (options->quality) {
     79        // Can't do anything else
     80        return true;
     81    }
    4382
    4483    // Convolve inputs
    4584    psTrace("ppStack", 1, "Convolving inputs to target PSF....\n");
    4685    if (!ppStackConvolve(options, config)) {
    47         psError(PS_ERR_UNKNOWN, false, "Unable to convolve images.");
    48         psFree(options);
     86        psError(psErrorCodeLast(), false, "Unable to convolve images.");
    4987        return false;
    5088    }
     
    5391    ppStackMemDump("convolve");
    5492
     93    // Ensure sufficient inputs
     94    {
     95        int numGood = stackSummary(options, "initial combination");
     96        psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // ppStack recipe
     97        bool safe = psMetadataLookupBool(NULL, recipe, "SAFE"); // Be safe when combining
     98        if (safe && numGood <= 1) {
     99            psError(PPSTACK_ERR_REJECTED, true, "Insufficient inputs for combination with safety on");
     100            return false;
     101        }
     102    }
    55103
    56104    // Start threading
    57105    ppStackThreadInit();
    58     ppStackThreadData *stack = ppStackThreadDataSetup(options, config);
     106    ppStackThreadData *stack = ppStackThreadDataSetup(options, config, true);
    59107    if (!stack) {
    60         psError(PS_ERR_IO, false, "Unable to initialise stack threads.");
    61         psFree(options);
    62         return false;
    63     }
    64     psFree(options->cells); options->cells = NULL;
     108        psError(psErrorCodeLast(), false, "Unable to initialise stack threads.");
     109        return false;
     110    }
    65111
    66112    // Prepare for combination
    67     if (!ppStackCombinePrepare(stack, options, config)) {
    68         psError(PS_ERR_UNKNOWN, false, "Unable to prepare for combination.");
    69         psFree(stack);
    70         psFree(options);
     113    if (!ppStackCombinePrepare("PPSTACK.OUTPUT", "PPSTACK.OUTPUT.EXP", PPSTACK_FILES_STACK,
     114                               stack, options, config)) {
     115        psError(psErrorCodeLast(), false, "Unable to prepare for combination.");
     116        psFree(stack);
    71117        return false;
    72118    }
     
    75121    psTrace("ppStack", 1, "Initial stack of convolved images....\n");
    76122    if (!ppStackCombineInitial(stack, options, config)) {
    77         psError(PS_ERR_UNKNOWN, false, "Unable to perform initial combination.");
    78         psFree(stack);
    79         psFree(options);
    80         return false;
    81     }
    82     psLogMsg("ppStack", PS_LOG_INFO, "Stage 2: Generate Convolutions and Save: %f sec",
    83              psTimerClear("PPSTACK_STEPS"));
    84     ppStackMemDump("convolve");
    85     psLogMsg("ppStack", PS_LOG_INFO, "Stage 4: Make Initial Stack: %f sec", psTimerClear("PPSTACK_STEPS"));
    86 
     123        psError(psErrorCodeLast(), false, "Unable to perform initial combination.");
     124        psFree(stack);
     125        return false;
     126    }
     127    ppStackMemDump("initial");
     128    psLogMsg("ppStack", PS_LOG_INFO, "Stage 3: Make Initial Stack: %f sec", psTimerClear("PPSTACK_STEPS"));
     129
     130    // Done with stack inputs for now
     131    for (int i = 0; i < options->num; i++) {
     132        pmCellFreeData(options->cells->data[i]);
     133    }
     134    psFree(stack);
    87135
    88136    // Pixel rejection
    89137    psTrace("ppStack", 1, "Reject pixels....\n");
    90138    if (!ppStackReject(options, config)) {
    91         psError(PS_ERR_UNKNOWN, false, "Unable to reject pixels.");
    92         psFree(stack);
    93         psFree(options);
    94         return false;
    95     }
    96     psLogMsg("ppStack", PS_LOG_INFO, "Stage 5: Pixel Rejection: %f sec", psTimerClear("PPSTACK_STEPS"));
    97     ppStackMemDump("reject");
    98 
     139        psError(psErrorCodeLast(), false, "Unable to reject pixels.");
     140        psFree(stack);
     141        return false;
     142    }
     143    psLogMsg("ppStack", PS_LOG_INFO, "Stage 4: Pixel Rejection: %f sec", psTimerClear("PPSTACK_STEPS"));
     144
     145    // Check inputs
     146    {
     147        int numGood = stackSummary(options, "final combination");
     148        if (numGood <= 0) {
     149            psError(PPSTACK_ERR_REJECTED, true, "Insufficient inputs for combination");
     150            return false;
     151        }
     152    }
     153
     154    stack = ppStackThreadDataSetup(options, config, true);
     155    if (!stack) {
     156        psError(psErrorCodeLast(), false, "Unable to initialise stack threads.");
     157        return false;
     158    }
    99159
    100160    // Final combination
    101161    psTrace("ppStack", 2, "Final stack of convolved images....\n");
    102     if (!ppStackCombineFinal(stack, options, config)) {
    103         psError(PS_ERR_UNKNOWN, false, "Unable to perform final combination.");
    104         psFree(stack);
    105         psFree(options);
    106         return false;
    107     }
    108     psLogMsg("ppStack", PS_LOG_INFO, "Stage 6: Final Stack: %f sec", psTimerClear("PPSTACK_STEPS"));
     162    if (!ppStackCombineFinal(stack, options->convCovars, options, config, false, false, true)) {
     163        psError(psErrorCodeLast(), false, "Unable to perform final combination.");
     164        psFree(stack);
     165        return false;
     166    }
     167    psLogMsg("ppStack", PS_LOG_INFO, "Stage 5: Final Stack: %f sec", psTimerClear("PPSTACK_STEPS"));
    109168    ppStackMemDump("final");
    110169
     170    // Photometry
     171    psTrace("ppStack", 1, "Photometering stacked image....\n");
     172    if (!ppStackPhotometry(options, config)) {
     173        psError(psErrorCodeLast(), false, "Unable to perform photometry.");
     174        return false;
     175    }
     176    psLogMsg("ppStack", PS_LOG_INFO, "Stage 6: Photometry Analysis: %f sec", psTimerClear("PPSTACK_STEPS"));
     177    ppStackMemDump("photometry");
    111178
    112179    // Clean up
    113180    psTrace("ppStack", 2, "Cleaning up after combination....\n");
    114181    if (!ppStackCleanup(stack, options, config)) {
    115         psError(PS_ERR_UNKNOWN, false, "Unable to clean up.");
    116         psFree(stack);
    117         psFree(options);
    118         return false;
    119     }
    120     psLogMsg("ppStack", PS_LOG_INFO, "Stage 7: WCS & JPEGS: %f sec", psTimerClear("PPSTACK_STEPS"));
     182        psError(psErrorCodeLast(), false, "Unable to clean up.");
     183        psFree(stack);
     184        return false;
     185    }
     186    for (int i = 0; i < options->num; i++) {
     187        pmCellFreeData(options->cells->data[i]);
     188    }
     189    psFree(stack);
     190    psLogMsg("ppStack", PS_LOG_INFO, "Stage 7: Cleanup, WCS & JPEGS: %f sec", psTimerClear("PPSTACK_STEPS"));
    121191    ppStackMemDump("cleanup");
    122192
    123     psFree(stack);
    124 
    125 
    126     // Photometry
    127     psTrace("ppStack", 1, "Photometering stacked image....\n");
    128     if (!ppStackPhotometry(options, config)) {
    129         psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry.");
    130         psFree(options);
    131         return false;
    132     }
    133     psLogMsg("ppStack", PS_LOG_INFO, "Stage 8: Photometry Analysis: %f sec", psTimerClear("PPSTACK_STEPS"));
    134     ppStackMemDump("photometry");
    135 
     193#if 1
     194    // Unconvolved stack --- it's cheap to calculate, compared to everything else!
     195    if (options->convolve) {
     196        // Start threading
     197        ppStackThreadData *stack = ppStackThreadDataSetup(options, config, false);
     198        if (!stack) {
     199            psError(psErrorCodeLast(), false, "Unable to initialise stack threads.");
     200            return false;
     201        }
     202
     203        // Prepare for combination
     204        if (!ppStackCombinePrepare("PPSTACK.UNCONV", "PPSTACK.UNCONV.EXP", PPSTACK_FILES_UNCONV,
     205                                   stack, options, config)) {
     206            psError(psErrorCodeLast(), false, "Unable to prepare for combination.");
     207            psFree(stack);
     208            return false;
     209        }
     210
     211        psTrace("ppStack", 2, "Stack of unconvolved images....\n");
     212        if (!ppStackCombineFinal(stack, options->origCovars, options, config,
     213                                 false, true, false)) {
     214            psError(psErrorCodeLast(), false, "Unable to perform unconvolved combination.");
     215            psFree(stack);
     216            return false;
     217        }
     218        psLogMsg("ppStack", PS_LOG_INFO, "Stage 8: Unconvolved Stack: %f sec", psTimerClear("PPSTACK_STEPS"));
     219        ppStackMemDump("unconv");
     220
     221        if (!ppStackFilesIterateUp(config)) {
     222            psError(psErrorCodeLast(), false, "Unable to close files.");
     223            psFree(stack);
     224            return false;
     225        }
     226        ppStackFileActivation(config, PPSTACK_FILES_UNCONV, false);
     227        options->outRO->data_exists = false;
     228        options->outRO->parent->data_exists = false;
     229        options->outRO->parent->parent->data_exists = false;
     230        psFree(options->outRO);
     231        options->outRO = NULL;
     232        options->expRO->data_exists = false;
     233        options->expRO->parent->data_exists = false;
     234        options->expRO->parent->parent->data_exists = false;
     235        psFree(options->expRO);
     236        options->expRO = NULL;
     237
     238        for (int i = 0; i < options->num; i++) {
     239            pmCellFreeData(options->cells->data[i]);
     240        }
     241        psFree(stack);
     242    }
     243    psFree(options->cells); options->cells = NULL;
     244#endif
    136245
    137246    // Finish up
    138247    psTrace("ppStack", 1, "Finishing up....\n");
    139248    if (!ppStackFinish(options, config)) {
    140         psError(PS_ERR_UNKNOWN, false, "Unable to finish up.");
    141         psFree(options);
    142         return false;
    143     }
    144     psLogMsg("ppStack", PS_LOG_INFO, "Stage 9: Final output: %f sec", psTimerClear("PPSTACK_STEPS"));
     249        psError(psErrorCodeLast(), false, "Unable to finish up.");
     250        return false;
     251    }
    145252    ppStackMemDump("finish");
    146253
    147     psFree(options);
    148254    return true;
    149255}
Note: See TracChangeset for help on using the changeset viewer.