IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 28, 2006, 2:50:52 PM (20 years ago)
Author:
Paul Price
Message:

Adding work in progress

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppMerge/src/ppMergeOptions.c

    r5862 r6998  
    1 # include "ppMerge.h"
     1#include <stdio.h>
     2#include <pslib.h>
     3#include <psmodules.h>
    24
    3 // XXX EAM : optionally choose the mask image based on the detrend database
     5//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     6// ppMergeOptions
     7//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    48
    5 bool ppMergeOptions (ppData *data, ppOptions *options, ppConfig *config) {
     9// Free function
     10static void mergeOptionsFree(ppMergeOptions *options // Options to free
     11    )
     12{
     13    psFree(options->combine);
     14}
    615
    7     bool status;
     16// Allocator
     17ppMergeOptions *ppMergeOptionsAlloc(void)
     18{
     19    ppMergeOptions *options = psAlloc(sizeof(ppMergeOptions)); // The options, to return
     20    psMemSetDeallocator(options, (psFreeFunc)mergeOptionsFree);
    821
    9     // at what depth is the image read?
    10     options->imageLoadDepth = PP_LOAD_NONE;
    11     char *depth = psMetadataLookupPtr(NULL, config->recipe, "LOAD.DEPTH");
    12     if (depth == NULL) {
    13         psAbort ("merge", "load depth not specified");
     22    options->rows = 0;
     23    options->minElectrons = NAN;
     24    options->zero = false;
     25    options->scale = false;
     26    options->exptime = false;
     27    options->sample = 1;
     28    options->background = PS_STAT_SAMPLE_MEDIAN;
     29    options->onOff = 0;
     30    options->combine = PS_STAT_SAMPLE_MEAN;
     31    options->ref = 3.0;
     32    options->iter = 1;
     33    options->fracHigh = 0.0;
     34    options->fracLow = 0.0;
     35    options->nKeep = 1;
     36    options->maskVal = 0xffff;
     37
     38    return options;
     39}
     40
     41//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     42// ppMergeOptionsParse
     43//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     44
     45// Parse a recipe option according to its type
     46#define OPTION_PARSE(OPTION,MD,NAME,TYPE)                                                                    \
     47{                                                                                                            \
     48    psMetadataItem *item = psMetadataLookup(MD, NAME);                                                       \
     49    if (item) {                                                                                              \
     50        OPTION = psMetadataItemParse##TYPE(item);                                                            \
     51    }                                                                                                        \
     52}
     53
     54// Parse a statistic
     55static psStatsOptions parseStat(psMetadata *source, // Source of the statistics option
     56                                const char *name // Name of the statistics option
     57    )
     58{
     59    bool mdok = true;                   // Status of MD lookup
     60    const char *stat = psMetadataLookupStr(&mdok, source, name);  // The statistic string
     61    if (!mdok || !stat || strlen(stat) == 0) {
     62        return 0;
    1463    }
    15     if (!strcasecmp(depth, "FPA")) {
    16         options->imageLoadDepth = PP_LOAD_FPA;
     64    if (strcasecmp(stat, "MEAN") == 0 || strcasecmp(stat, "SAMPLE_MEAN") == 0) {
     65        return PS_STAT_SAMPLE_MEAN;
    1766    }
    18     if (!strcasecmp(depth, "CHIP")) {
    19         options->imageLoadDepth = PP_LOAD_CHIP;
     67    if (strcasecmp(stat, "MEDIAN") == 0 || strcasecmp(stat, "SAMPLE_MEDIAN") == 0) {
     68        return PS_STAT_SAMPLE_MEDIAN;
    2069    }
    21     if (!strcasecmp(depth, "CELL")) {
    22         options->imageLoadDepth = PP_LOAD_CELL;
     70    if (strcasecmp(stat, "ROBUST") == 0 || strcasecmp(stat, "ROBUST_MEDIAN") == 0) {
     71        return PS_STAT_ROBUST_MEDIAN;
    2372    }
    24     if (options->imageLoadDepth == PP_LOAD_NONE) {
    25         psAbort ("merge", "load depth not specified");
     73    if (strcasecmp(stat, "FITTED") == 0 || strcasecmp(stat, "FITTED_MEAN") == 0) {
     74        return PS_STAT_FITTED_MEAN;
     75    }
     76    if (strcasecmp(stat, "CLIPPED") == 0 || strcasecmp(stat, "CLIPPED_MEAN") == 0) {
     77        return PS_STAT_CLIPPED_MEAN;
    2678    }
    2779
    28     // global pixel mask
    29     options->doMask = false;
    30     if (psMetadataLookupBool(NULL, config->recipe, "MASK")) {
    31         data->mask->filename = psMetadataLookupStr(NULL, config->arguments, "-mask");
    32         if (strlen(data->mask->filename) > 0) {
    33             options->doMask = true;
    34         } else {
    35             psLogMsg("merge", PS_LOG_WARN, "Masking is desired, but no mask was supplied"
    36                      " --- no masking will be performed.\n");
    37         }
     80    psError(PS_ERR_IO, true, "Unable to interpret statistic: %s\n", name);
     81    return 0;
     82}
     83
     84// Parse the options
     85ppMergeOptions *ppMergeOptionsParse(ppConfig *config // Configuration
     86    )
     87{
     88    ppMergeOptions *options = ppMergeOptionsAlloc(); // The merge options
     89
     90    // First, deal with the recipe.  These are parameters that will typically be constant for a camera.
     91    OPTION_PARSE(options->rows,         config->recipe, "ROWS",      U16 );
     92    OPTION_PARSE(options->minElectrons, config->recipe, "ELECTRONS", F32 );
     93    OPTION_PARSE(options->sample,       config->recipe, "SAMPLE",    S32 );
     94    OPTION_PARSE(options->rej,          config->recipe, "REJ",       F32 );
     95    OPTION_PARSE(options->iter,         config->recipe, "ITER",      S32 );
     96    OPTION_PARSE(options->fracHigh,     config->recipe, "FRACHIGH",  F32 );
     97    OPTION_PARSE(options->fracLow,      config->recipe, "FRACLOW",   F32 );
     98    OPTION_PARSE(options->nKeep,        config->recipe, "NKEEP",     S32 );
     99    OPTION_PARSE(options->maskVal,      config->recipe, "MASKVAL",   U8  );
     100    options->combine = parseStat(config->recipe, "COMBINE");
     101    options->background = parseStat(config->recipe, "BACKGROUND");
     102
     103    // Now the command-line options.  These are parameters that depend on what type of frame is being combined
     104
     105    // Set options based on the type of calibration frame
     106    const char *type = psMetadataLookupStr(NULL, config->arguments, "-type"); // The type of calibration frame
     107    if (strcasecmp(type, "BIAS") == 0) {
     108        options->zero = false;
     109        options->scale = false;
     110        options->exptime = false;
     111    } else if (strcasecmp(type, "DARK") == 0) {
     112        options->zero = false;
     113        options->scale = false;
     114        options->exptime = true;
     115    } else if (strcasecmp(type, "FLAT") == 0) {
     116        options->zero = false;
     117        options->scale = true;
     118        options->exptime = false;
     119    } else if (strcasecmp(type, "FRINGE") == 0) {
     120        options->zero = true;
     121        options->scale = true;
     122        options->exptime = false;
     123    } else {
     124        psLogMsg(__func__, PS_LOG_WARN, "Unrecognised image type: %s --- ignored.\n", type);
    38125    }
    39126
    40     // how do we calculate the merge stack?
    41     psStatsOptions mergeStats = 0;
    42     psString stat = psMetadataLookupStr(NULL, config->recipe, "MERGE.STAT");
    43     if (! strcasecmp(stat, "MEAN")) {
    44         mergeStats = PS_STAT_SAMPLE_MEAN;
    45     } else if (! strcasecmp(stat, "MEDIAN")) {
    46         mergeStats = PS_STAT_SAMPLE_MEDIAN;
    47     } else {
    48         psAbort ("merge", "MERGE.STAT (%s) is not one of MEAN, MEDIAN\n", stat);
    49     }
    50     options->combineParams = pmCombineParamsAlloc (mergeStats);
     127    // Or you can set them individually
     128    OPTION_PARSE(options->zero,    config->recipe, "-zero",    Bool);
     129    OPTION_PARSE(options->scale,   config->recipe, "-scale",   Bool);
     130    OPTION_PARSE(options->exptime, config->recipe, "-exptime", Bool);
    51131
    52     // other merge stack options
    53     options->applyZeroScale = psMetadataLookupBool(NULL, config->recipe, "MERGE.RESCALE");
     132    // Number of on/off images
     133    OPTION_PARSE(options->onoff, config->recipe, "-onoff", S32);
    54134
    55     int nKeep = psMetadataLookupS32(&status, config->recipe, "MERGE.NKEEP");
    56     if (status && nKeep > 0) {
    57         options->combineParams->nKeep = nKeep;
    58     }
    59 
    60     float fracHigh = psMetadataLookupF32(&status, config->recipe, "MERGE.FRAC.HIGH");
    61     if (status) {
    62         options->combineParams->fracHigh = fracHigh;
    63     }
    64 
    65     float fracLow = psMetadataLookupF32(&status, config->recipe, "MERGE.FRAC.LOW");
    66     if (status) {
    67         options->combineParams->fracLow = fracLow;
    68     }
    69 
    70     // XXX need to set the masking value somehow...
    71 
    72     // gain and readnoise come from camera parameters and depend on chip/cell
    73     // XXX drop these from the options structure?
    74     options->gain = 1.0;
    75     options->readnoise = 0.0;
    76 
    77     return true;
     135    return options;
    78136}
Note: See TracChangeset for help on using the changeset viewer.