Changeset 23740 for trunk/ppSub/src/ppSubArguments.c
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/pap merged: 23690,23704,23711,23719,23723,23730-23735
- Property svn:mergeinfo changed
-
trunk/ppSub
- Property svn:mergeinfo changed
/branches/pap/ppSub merged: 23704,23711,23719,23723,23730,23732-23734
- Property svn:mergeinfo changed
-
trunk/ppSub/src
- Property svn:ignore
-
old new 10 10 stamp-h1 11 11 ppSubKernel 12 ppSubErrorCodes.h 13 ppSubErrorCodes.c
-
- Property svn:ignore
-
trunk/ppSub/src/ppSubArguments.c
r23402 r23740 41 41 } 42 42 43 // Get a float-point value from the command-line or recipe, and add it to the arguments44 #define VALUE_ARG_RECIPE_FLOAT(ARGNAME, RECIPENAME, TYPE) { \45 ps##TYPE value = psMetadataLookup##TYPE(NULL, config->arguments, ARGNAME); \46 if (isnan(value)) { \47 bool mdok; \48 value = psMetadataLookup##TYPE(&mdok, recipe, RECIPENAME); \49 if (!mdok) { \50 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to find %s in recipe %s", \51 RECIPENAME, PPSUB_RECIPE); \52 goto ERROR; \53 } \54 } \55 psMetadataAdd##TYPE(recipe, PS_LIST_TAIL, RECIPENAME, PS_META_REPLACE, NULL, value); \56 }57 58 // Get an integer value from the command-line or recipe, and add it to the arguments59 #define VALUE_ARG_RECIPE_INT(ARGNAME, RECIPENAME, TYPE, UNSET) { \60 ps##TYPE value = psMetadataLookup##TYPE(NULL, config->arguments, ARGNAME); \61 if (value == UNSET) { \62 bool mdok; \63 value = psMetadataLookup##TYPE(&mdok, recipe, RECIPENAME); \64 if (!mdok) { \65 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to find %s in recipe %s", \66 RECIPENAME, PPSUB_RECIPE); \67 goto ERROR; \68 } \69 } \70 psMetadataAdd##TYPE(recipe, PS_LIST_TAIL, RECIPENAME, PS_META_REPLACE, NULL, value); \71 }72 73 /**74 * Get a string value from the command-line and add it to the target75 */76 static bool valueArgStr(psMetadata *arguments, // Command-line arguments77 const char *argName, // Argument name in the command-line arguments78 const char *mdName, // Name for value in the metadata79 psMetadata *target // Target metadata to which to add value80 )81 {82 psString value = psMetadataLookupStr(NULL, arguments, argName); // Value of interest83 if (value && strlen(value) > 0) {84 return psMetadataAddStr(target, PS_LIST_TAIL, mdName, PS_META_REPLACE, NULL, value);85 }86 return false;87 }88 89 /**90 * Get a string value from the command-line or recipe and add it to the target91 */92 static bool valueArgRecipeStr(psMetadata *arguments, // Command-line arguments93 psMetadata *recipe, // Recipe94 const char *argName, // Argument name in the command-line arguments95 const char *mdName, // Name for value in the metadata and recipe96 psMetadata *target // Target metadata to which to add value97 )98 {99 bool mdok; // Status of MD lookup100 psString value = psMetadataLookupStr(&mdok, arguments, argName); // Value of interest101 if (!value) {102 value = psMetadataLookupStr(&mdok, recipe, mdName);103 if (!value) {104 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to find %s in recipe %s",105 mdName, PPSUB_RECIPE);106 return false;107 }108 }109 return psMetadataAddStr(target, PS_LIST_TAIL, mdName, PS_META_REPLACE, NULL, value);110 }111 112 /**113 * Get a vector from the command-line or recipe, and add it to the target114 */115 static bool vectorArgRecipe(psMetadata *arguments, // Command-line arguments116 const char *argName, // Argument name in the command-line arguments117 const psMetadata *recipe, // Recipe118 const char *recipeName, // Name for value in the recipe119 psMetadata *target, // Target to which to add value120 psElemType type // Type for vector121 )122 {123 psVector *vector; // Vector124 psString string = psMetadataLookupStr(NULL, arguments, argName); // String from arguments125 if (string) {126 psArray *array = psStringSplitArray(string, ", ", false); // Array of strings127 vector = psVectorAlloc(array->n, type);128 for (int i = 0; i < array->n; i++) {129 const char *subString = array->data[i]; // String with a value130 char *end; // Ptr to end of string parsed131 132 switch (type) {133 case PS_TYPE_F32:134 vector->data.F32[i] = strtof(subString, &end);135 break;136 case PS_TYPE_S32: {137 long value = strtol(subString, &end, 10);138 if (value > PS_MAX_S32 || value < PS_MIN_S32) {139 psError(PS_ERR_BAD_PARAMETER_VALUE, true,140 "%s list includes value beyond S32 representation: %s",141 argName, string);142 psFree(vector);143 return false;144 }145 vector->data.S32[i] = value;146 break;147 }148 default:149 psAbort("Unsupported type: %x\n", type);150 }151 if (end == subString) {152 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to decipher %s list: %s",153 argName, string);154 psFree(vector);155 return false;156 }157 }158 psFree(array);159 } else {160 vector = psMetadataLookupPtr(NULL, recipe, recipeName);161 if (!psMemCheckVector(vector) || vector->type.type != type) {162 psError(PS_ERR_BAD_PARAMETER_TYPE, false, "%s in recipe %s is not a vector of type F32.",163 recipeName, PPSUB_RECIPE);164 return false;165 }166 psMemIncrRefCounter(vector);167 }168 169 psMetadataAddVector(target, PS_LIST_TAIL, recipeName, PS_META_REPLACE, NULL, vector);170 psFree(vector); // Drop reference171 172 return true;173 }174 175 43 /** 176 44 * Add a single filename to the arguments as an array, so that it can be used with pmFPAfileBindFromArgs, etc … … 189 57 } 190 58 191 bool ppSubArguments Setup(int argc, char *argv[], pmConfig *config)59 bool ppSubArguments(int argc, char *argv[], pmConfig *config, ppSubData *data) 192 60 { 193 // int argnum; // Argument Number194 61 assert(config); 195 196 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSUB_RECIPE); // Recipe for ppSim197 if (!recipe) {198 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find recipe %s", PPSUB_RECIPE);199 return false;200 }201 202 62 203 63 psMetadata *arguments = config->arguments; // Command-line arguments … … 212 72 psMetadataAddStr(arguments, PS_LIST_TAIL, "-kernel", 0, "Precalculated kernel to apply", NULL); 213 73 psMetadataAddStr(arguments, PS_LIST_TAIL, "-stats", 0, "Statistics file", NULL); 214 psMetadataAddF32(arguments, PS_LIST_TAIL, "-region", 0, "Size of iso-kernel region", NAN); 215 psMetadataAddS32(arguments, PS_LIST_TAIL, "-size", 0, "Kernel half-size (pixels)", 0); 216 psMetadataAddS32(arguments, PS_LIST_TAIL, "-order", 0, "Spatial polynomial order", -1); 217 psMetadataAddStr(arguments, PS_LIST_TAIL, "-type", 0, 218 "Kernel type (ISIS|POIS|SPAM|FRIES|GUNK|RINGS)", NULL); 219 psMetadataAddF32(arguments, PS_LIST_TAIL, "-penalty", 0, "Penalty for wideness", NAN); 220 psMetadataAddStr(arguments, PS_LIST_TAIL, "-isis-widths", 0, 221 "ISIS Gaussian FWHMs (comma-separated)", NULL); 222 psMetadataAddStr(arguments, PS_LIST_TAIL, "-isis-orders", 0, 223 "ISIS polynomial orders (comma-separated)", NULL); 224 psMetadataAddS32(arguments, PS_LIST_TAIL, "-rings-order", 0, "RINGS polynomial order", -1); 225 psMetadataAddS32(arguments, PS_LIST_TAIL, "-inner", 0, "SPAM and FRIES inner radius", -1); 226 psMetadataAddS32(arguments, PS_LIST_TAIL, "-spam-binning", 0, "SPAM kernel binning", 0); 227 psMetadataAddF32(arguments, PS_LIST_TAIL, "-spacing", 0, "Typical stamp spacing (pixels)", NAN); 228 psMetadataAddS32(arguments, PS_LIST_TAIL, "-footprint", 0, "Stamp footprint half-size (pixels)", -1); 229 psMetadataAddF32(arguments, PS_LIST_TAIL, "-source-radius", 0, "Source matching radius (pixels)", NAN); 230 psMetadataAddS32(arguments, PS_LIST_TAIL, "-stride", 0, "Size of convolution patches (pixels)", -1); 231 psMetadataAddF32(arguments, PS_LIST_TAIL, "-threshold", 0, "Minimum threshold for stamps (ADU)", NAN); 232 psMetadataAddS32(arguments, PS_LIST_TAIL, "-iter", 0, "Number of rejection iterations", -1); 233 psMetadataAddF32(arguments, PS_LIST_TAIL, "-rej", 0, "Rejection thresold (sigma)", NAN); 234 psMetadataAddF32(arguments, PS_LIST_TAIL, "-sys", 0, "Relative systematic error in kernel", NAN); 235 psMetadataAddImageMask(arguments, PS_LIST_TAIL, "-mask-bad", 0, "Mask value for bad pixels", 0); 236 psMetadataAddImageMask(arguments, PS_LIST_TAIL, "-mask-poor", 0, "Mask value for poor pixels", 0); 237 psMetadataAddF32(arguments, PS_LIST_TAIL, "-poor-frac", 0, "Fraction of variance for poor pixels", NAN); 238 psMetadataAddF32(arguments, PS_LIST_TAIL, "-badfrac", 0, "Maximum fraction of bad pixels to accept", 1.0); 239 psMetadataAddBool(arguments, PS_LIST_TAIL, "-reverse", 0, "Reverse sense of subtraction?", false); 240 psMetadataAddBool(arguments, PS_LIST_TAIL, "-generate-mask", 0, "Generate mask if not supplied?", false); 241 psMetadataAddStr(arguments, PS_LIST_TAIL, "-stamps", 0, 242 "Stamps filename; file has x,y on each line", NULL); 243 psMetadataAddBool(arguments, PS_LIST_TAIL, "-opt", 0, 244 "Derive optimum parameters for ISIS kernels?", false); 245 psMetadataAddF32(arguments, PS_LIST_TAIL, "-opt-min", 0, "Minimum value for optimum kernel search", NAN); 246 psMetadataAddF32(arguments, PS_LIST_TAIL, "-opt-max", 0, "Minimum value for optimum kernel search", NAN); 247 psMetadataAddF32(arguments, PS_LIST_TAIL, "-opt-step", 0, "Step value for optimum kernel search", NAN); 248 psMetadataAddF32(arguments, PS_LIST_TAIL, "-opt-tol", 0, "Tolerance for optimum kernel search", NAN); 249 psMetadataAddS32(arguments, PS_LIST_TAIL, "-opt-order", 0, "Maximum order for optimum kernel search", -1); 250 psMetadataAddBool(arguments, PS_LIST_TAIL, "-dual", 0, "Dual convolution", false); 251 psMetadataAddBool(arguments, PS_LIST_TAIL, "-photometry", 0, "Perform photometry?", false); 74 psMetadataAddStr(arguments, PS_LIST_TAIL, "-stamps", 0, "Stamps filename; x,y on each line", NULL); 252 75 psMetadataAddS32(arguments, PS_LIST_TAIL, "-threads", 0, "Number of threads", 0); 253 psMetadataAddS32(arguments, PS_LIST_TAIL, "-bin1", 0, "Binning factor for first level", 0);254 psMetadataAddS32(arguments, PS_LIST_TAIL, "-bin2", 0, "Binning factor for second level", 0);255 76 psMetadataAddStr(arguments, PS_LIST_TAIL, "-dumpconfig", 0, "file to dump configuration to", NULL); 77 psMetadataAddBool(arguments, PS_LIST_TAIL, "-photometry", 0, "Perform photometry?", NULL); 78 psMetadataAddBool(arguments, PS_LIST_TAIL, "-inverse", 0, "Generate inverse subtractions?", NULL); 256 79 psMetadataAddBool(arguments, PS_LIST_TAIL, "-visual", 0, "Show diagnostic plots", NULL); 257 80 … … 302 125 } 303 126 304 if (psMetadataLookupBool(NULL, arguments, "-photometry")) { 305 psMetadataAddBool(recipe, PS_LIST_TAIL, "PHOTOMETRY", PS_META_REPLACE, "Perform photometry?", true); 306 } 127 data->stamps = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-stamps")); 307 128 308 return true; 309 } 310 311 bool ppSubArgumentsParse(pmConfig *config) 312 { 313 assert(config); 314 315 psMetadata *arguments = config->arguments; // Command-line arguments 316 317 valueArgStr(arguments, "-stats", "STATS", arguments); 318 valueArgStr(arguments, "-stamps", "STAMPS", arguments); 319 320 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSUB_RECIPE); // Recipe for ppSim 321 if (!recipe) { 322 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find recipe %s", PPSUB_RECIPE); 323 goto ERROR; 324 } 325 326 VALUE_ARG_RECIPE_FLOAT("-region", "REGION.SIZE", F32); 327 VALUE_ARG_RECIPE_INT("-size", "KERNEL.SIZE", S32, 0); 328 VALUE_ARG_RECIPE_INT("-order", "SPATIAL.ORDER", S32, -1); 329 VALUE_ARG_RECIPE_FLOAT("-spacing", "STAMP.SPACING", F32); 330 VALUE_ARG_RECIPE_INT("-rings-order", "RINGS.ORDER", S32, -1); 331 VALUE_ARG_RECIPE_INT("-inner", "INNER", S32, -1); 332 VALUE_ARG_RECIPE_INT("-spam-binning", "SPAM.BINNING", S32, 0); 333 VALUE_ARG_RECIPE_INT("-footprint", "STAMP.FOOTPRINT", S32, -1); 334 VALUE_ARG_RECIPE_FLOAT("-source-radius", "SOURCE.RADIUS", F32); 335 VALUE_ARG_RECIPE_INT("-stride", "STRIDE", S32, -1); 336 VALUE_ARG_RECIPE_FLOAT("-threshold", "STAMP.THRESHOLD", F32); 337 VALUE_ARG_RECIPE_INT("-iter", "ITER", S32, -1); 338 VALUE_ARG_RECIPE_FLOAT("-rej", "REJ", F32); 339 VALUE_ARG_RECIPE_FLOAT("-sys", "SYS", F32); 340 VALUE_ARG_RECIPE_FLOAT("-badfrac", "BADFRAC", F32); 341 VALUE_ARG_RECIPE_FLOAT("-penalty", "PENALTY", F32); 342 VALUE_ARG_RECIPE_FLOAT("-poor-frac", "POOR.FRACTION", F32); 343 VALUE_ARG_RECIPE_INT("-bin1", "BIN1", S32, 0); 344 VALUE_ARG_RECIPE_INT("-bin2", "BIN2", S32, 0); 345 346 valueArgRecipeStr(arguments, recipe, "-mask-in", "MASK.IN", recipe); 347 valueArgRecipeStr(arguments, recipe, "-mask-bad", "MASK.BAD", recipe); 348 valueArgRecipeStr(arguments, recipe, "-mask-poor", "MASK.POOR", recipe); 349 350 vectorArgRecipe(arguments, "-isis-widths", recipe, "ISIS.WIDTHS", recipe, PS_TYPE_F32); 351 vectorArgRecipe(arguments, "-isis-orders", recipe, "ISIS.ORDERS", recipe, PS_TYPE_S32); 352 353 psVector *widths = psMetadataLookupPtr(NULL, recipe, "ISIS.WIDTHS"); // ISIS Gaussian widths 354 psVector *orders = psMetadataLookupPtr(NULL, recipe, "ISIS.ORDERS"); // ISIS Polynomial orders 355 if (widths->n != orders->n) { 356 psError(PS_ERR_BAD_PARAMETER_SIZE, true, "Size of vectors for ISIS widths and orders do not match."); 357 goto ERROR; 358 } 359 360 if (psMetadataLookupBool(NULL, arguments, "-opt") || psMetadataLookupBool(NULL, recipe, "OPTIMUM")) { 361 psMetadataAddBool(recipe, PS_LIST_TAIL, "OPTIMUM", PS_META_REPLACE, 362 "Derive optimum parameters for ISIS kernels?", true); 363 VALUE_ARG_RECIPE_FLOAT("-opt-min", "OPTIMUM.MIN", F32); 364 VALUE_ARG_RECIPE_FLOAT("-opt-max", "OPTIMUM.MAX", F32); 365 VALUE_ARG_RECIPE_FLOAT("-opt-step","OPTIMUM.STEP", F32); 366 VALUE_ARG_RECIPE_FLOAT("-opt-tol", "OPTIMUM.TOL", F32); 367 VALUE_ARG_RECIPE_INT("-opt-order", "OPTIMUM.ORDER", S32, -1); 368 } 369 370 psMetadataAddBool(arguments, PS_LIST_TAIL, "REVERSE", 0, "Reverse sense of subtraction", 371 psMetadataLookupBool(NULL, arguments, "-reverse")); 372 psMetadataAddBool(recipe, PS_LIST_TAIL, "MASK.GENERATE", PS_META_REPLACE, "Generate mask if not supplied", 373 psMetadataLookupBool(NULL, arguments, "-generate-mask")); 374 psMetadataAddBool(recipe, PS_LIST_TAIL, "DUAL", PS_META_REPLACE, "Dual convolution?", 375 psMetadataLookupBool(NULL, arguments, "-dual")); 376 377 // Need to update this because it could have been overwritten by the camera's own recipe 378 if (psMetadataLookupBool(NULL, arguments, "-photometry")) { 379 psMetadataAddBool(recipe, PS_LIST_TAIL, "PHOTOMETRY", PS_META_REPLACE, "Perform photometry?", true); 129 const char *statsName = psMetadataLookupStr(NULL, arguments, "-stats"); // Filename for statistics 130 if (statsName && strlen(statsName) > 0) { 131 psString resolved = pmConfigConvertFilename(statsName, config, true, true); // Resolved filename 132 data->statsFile = fopen(resolved, "w"); 133 if (!data->statsFile) { 134 psError(PS_ERR_IO, true, "Unable to open statistics file %s for writing.\n", resolved); 135 psFree(resolved); 136 return false; 137 } 138 psFree(resolved); 380 139 } 381 140 … … 384 143 } 385 144 386 // Translate the kernel type 387 psString type = psMetadataLookupStr(NULL, arguments, "-type"); // Name of kernel type 388 if (!type || strlen(type) == 0) { 389 type = psMetadataLookupStr(NULL, recipe, "KERNEL.TYPE"); 390 if (!type || strlen(type) == 0) { 391 psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Unable to find KERNEL.TYPE specified."); 392 goto ERROR; 393 } 394 } 395 psMetadataAddStr(recipe, PS_LIST_TAIL, "KERNEL.TYPE", PS_META_REPLACE, "Type of kernel", type); 396 397 psTrace("ppSub", 1, "Done reading command-line arguments\n"); 398 399 // XXX move this to ppSubArguments 400 int threads = psMetadataLookupS32(NULL, config->arguments, "-threads"); // Number of threads 145 int threads = psMetadataLookupS32(NULL, arguments, "-threads"); // Number of threads 401 146 if (threads > 0) { 402 147 if (!psThreadPoolInit(threads)) { … … 406 151 } 407 152 153 psTrace("ppSub", 1, "Done reading command-line arguments\n"); 154 408 155 return true; 409 410 ERROR:411 return false;412 156 }
Note:
See TracChangeset
for help on using the changeset viewer.
