Changeset 6998
- Timestamp:
- Apr 28, 2006, 2:50:52 PM (20 years ago)
- Location:
- trunk/ppMerge/src
- Files:
-
- 2 added
- 2 edited
-
ppMergeConfig.c (modified) (2 diffs)
-
ppMergeConfig.h (added)
-
ppMergeOptions.c (modified) (1 diff)
-
ppMergeOptions.h (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppMerge/src/ppMergeConfig.c
r6824 r6998 1 # include "ppMerge.h" 1 #include <stdio.h> 2 #include <pslib.h> 3 #include <psmodules.h> 2 4 3 static void usage (void) { 4 fprintf (stderr, "USAGE: ppMerge [-file INPUT.fits] [-list INPUT.txt] OUTPUT\n"); 5 exit (2); 5 #include "ppMergeConfig.h" 6 7 // Output usage information 8 static void usage(const char *programName // Name of the program 9 ) 10 { 11 printf("Merge multiple calibration frames into a master frame by stacking.\n\n" 12 "Usage:\n" 13 "\t%s OUTPUT.fits [-files FILES] [-list FILE_LIST]\n\n" 14 "where:\n" 15 "FILES is a glob to be interpreted by the program.\n" 16 "FILE_LIST is a list of files (including a glob interpreted by the shell).\n" 17 "\n", programName); 18 exit(EXIT_FAILURE); 6 19 } 7 20 8 pmConfig *ppMergeConfig (intargc, char **argv)21 pmConfig *ppMergeConfig(int *argc, char **argv) 9 22 { 10 bool status; 23 if (*argc == 1) { 24 usage(argv[0]); 25 } 11 26 12 if (argc == 1) usage (); 13 14 // load the site-wide configuration information 15 pmConfig *config = pmConfigRead(&argc, argv); 27 // Load the site-wide configuration information 28 pmConfig *config = pmConfigRead(argc, argv); 16 29 if (! config) { 17 30 psErrorStackPrint(stderr, "Can't find site configuration!\n"); 18 exit(EXIT_FAILURE);31 usage(argv[0]); 19 32 } 20 33 21 // Parse other command-line arguments 34 // Parse other command-line arguments, save for future use 22 35 config->arguments = psMetadataAlloc(); // The arguments, with default values 36 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-type", 0, "Type of calibration frame", ""); 37 psMetadataAddBool(config->arguments, PS_LIST_TAIL, "-zero", 0, "Subtract background?", false); 38 psMetadataAddBool(config->arguments, PS_LIST_TAIL, "-scale", 0, "Scale by background?", false); 39 psMetadataAddBool(config->arguments, PS_LIST_TAIL, "-exptime", 0, "Scale by the exposure time?", false); 40 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "-onoff", 0, "Number of on/off pairs", 0); 23 41 24 // the input file is a required argument; if not found, we will exit 25 status = pmConfigFileSetsMD (config->arguments, &argc, argv, "INPUT", "-file", "-list"); 26 if (!status) { usage ();} 42 // We require an input file set 43 bool status = pmConfigFileSetsMD(config->arguments, argc, argv, "INPUT", "-files", "-list"); 44 if (!status) { 45 usage(argv[0]); 46 } 27 47 28 if (! psArgumentParse(config->arguments, &argc, argv) || argc != 2) { 29 usage (); 48 // Parse other arguments 49 if (! psArgumentParse(config->arguments, argc, argv) || *argc != 2) { 50 usage(argv[0]); 30 51 } 31 52 … … 33 54 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "Name of the output image", argv[1]); 34 55 35 // the input image(s) are required arguments 36 // the first one defines the camera 56 // The input images are required. The first one defines the camera. 37 57 status = false; 38 pmFPAfileFromArgs (&status, config, "PPIMAGE.INPUT", "INPUT");58 pmFPAfileFromArgs(&status, config, "PPMERGE.INPUT", "INPUT"); 39 59 if (!status) { 40 psAbort (__func__, "missing INPUT entry");60 usage(argv[0]); 41 61 } 42 62 43 # if 0 44 // define Database handle, if used 63 64 #if 0 65 // Define database handle, if required 45 66 config->database = pmConfigDB(config->site); 46 # endif67 #endif 47 68 48 return true; 49 } 50 51 /* we require all information needed to determine the scaling 52 to be written in the header. is this reasonable? 53 */ 69 return config; 70 } -
trunk/ppMerge/src/ppMergeOptions.c
r5862 r6998 1 # include "ppMerge.h" 1 #include <stdio.h> 2 #include <pslib.h> 3 #include <psmodules.h> 2 4 3 // XXX EAM : optionally choose the mask image based on the detrend database 5 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 6 // ppMergeOptions 7 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 4 8 5 bool ppMergeOptions (ppData *data, ppOptions *options, ppConfig *config) { 9 // Free function 10 static void mergeOptionsFree(ppMergeOptions *options // Options to free 11 ) 12 { 13 psFree(options->combine); 14 } 6 15 7 bool status; 16 // Allocator 17 ppMergeOptions *ppMergeOptionsAlloc(void) 18 { 19 ppMergeOptions *options = psAlloc(sizeof(ppMergeOptions)); // The options, to return 20 psMemSetDeallocator(options, (psFreeFunc)mergeOptionsFree); 8 21 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 55 static 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; 14 63 } 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; 17 66 } 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; 20 69 } 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; 23 72 } 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; 26 78 } 27 79 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 85 ppMergeOptions *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); 38 125 } 39 126 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); 51 131 52 // other merge stack options53 options->applyZeroScale = psMetadataLookupBool(NULL, config->recipe, "MERGE.RESCALE");132 // Number of on/off images 133 OPTION_PARSE(options->onoff, config->recipe, "-onoff", S32); 54 134 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; 78 136 }
Note:
See TracChangeset
for help on using the changeset viewer.
