Changeset 23704 for branches/pap/ppSub
- Timestamp:
- Apr 3, 2009, 11:58:24 AM (17 years ago)
- Location:
- branches/pap/ppSub
- Files:
-
- 4 added
- 10 edited
-
configure.ac (modified) (1 diff)
-
src/Makefile.am (modified) (2 diffs)
-
src/ppSub.c (modified) (3 diffs)
-
src/ppSub.h (modified) (1 diff)
-
src/ppSubArguments.c (modified) (5 diffs)
-
src/ppSubCamera.c (modified) (4 diffs)
-
src/ppSubData.c (modified) (2 diffs)
-
src/ppSubDefineOutput.c (modified) (4 diffs)
-
src/ppSubErrorCodes.c.in (added)
-
src/ppSubErrorCodes.dat (added)
-
src/ppSubErrorCodes.h.in (added)
-
src/ppSubFiles.c (added)
-
src/ppSubLoop.c (modified) (3 diffs)
-
src/ppSubReadout.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/pap/ppSub/configure.ac
r21038 r23704 23 23 PKG_CHECK_MODULES([PSPHOT], [psphot >= 0.9.0]) 24 24 25 AC_PATH_PROG([ERRORCODES], [psParseErrorCodes], [missing]) 26 if test "$ERRORCODES" = "missing" ; then 27 AC_MSG_ERROR([psParseErrorCodes is required]) 28 fi 29 25 30 dnl Set CFLAGS for build 26 31 IPP_STDOPTS -
branches/pap/ppSub/src/Makefile.am
r23688 r23704 42 42 ppSub.h 43 43 44 45 ### Error codes. 46 BUILT_SOURCES = ppSubErrorCodes.h ppSubErrorCodes.c 47 CLEANFILES = ppSubErrorCodes.h ppSubErrorCodes.c 48 49 ppSubErrorCodes.h : ppSubErrorCodes.dat ppSubErrorCodes.h.in 50 $(ERRORCODES) --data=ppSubErrorCodes.dat --outdir=. ppSubErrorCodes.h 51 52 ppSubErrorCodes.c : ppSubErrorCodes.dat ppSubErrorCodes.c.in ppSubErrorCodes.h 53 $(ERRORCODES) --data=ppSubErrorCodes.dat --outdir=. ppSubErrorCodes.c 54 55 44 56 clean-local: 45 57 -rm -f TAGS … … 48 60 tags: 49 61 etags `find . -name \*.[ch] -print` 50 -
branches/pap/ppSub/src/ppSub.c
r23242 r23704 49 49 } 50 50 51 if (!ppSubArgumentsSetup(argc, argv, config)) { 51 ppSubData *data = ppSubDataAlloc(); // Processing data 52 53 if (!ppSubArgumentsSetup(argc, argv, config, data)) { 52 54 psErrorStackPrint(stderr, "Error reading arguments.\n"); 53 55 exitValue = PS_EXIT_CONFIG_ERROR; … … 55 57 } 56 58 57 if (!ppSubCamera(config )) {59 if (!ppSubCamera(config, data)) { 58 60 psErrorStackPrint(stderr, "Error setting up camera.\n"); 59 61 exitValue = PS_EXIT_CONFIG_ERROR; … … 61 63 } 62 64 63 if (!ppSubArgumentsParse(config)) { 64 psErrorStackPrint(stderr, "Error reading arguments.\n"); 65 exitValue = PS_EXIT_CONFIG_ERROR; 66 goto die; 67 } 68 69 if (!ppSubLoop(config)) { 65 if (!ppSubLoop(config, data)) { 70 66 psErrorStackPrint(stderr, "Error performing subtraction.\n"); 71 67 exitValue = PS_EXIT_SYS_ERROR; -
branches/pap/ppSub/src/ppSub.h
r23688 r23704 24 24 // Output files, for activation/deactivation 25 25 typedef enum { 26 PPSUB_FILES_IMAGE = 0x01, // Image files 27 PPSUB_FILES_PHOT = 0x02, // Photometry files 28 PPSUB_FILES_ALL = 0xFF, // All files 26 PPSUB_FILES_INPUT = 0x01, // Input files 27 PPSUB_FILES_CONV = 0x02, // Convolved files (output) 28 PPSUB_FILES_SUB = 0x04, // Subtracted files (output) 29 PPSUB_FILES_INV = 0x08, // Inverse subtracted files (output) 30 PPSUB_FILES_PHOT_SUB = 0x10, // Photometry files (output) 31 PPSUB_FILES_PHOT_INV = 0x20, // Photometry files ( 32 PPSUB_FILES_ALL = 0xFF, // All files 29 33 } ppSubFiles; 30 34 31 35 /// Data for processing 32 36 typedef struct { 33 psErrorCode quality; /// Quality code; 0 for no problem 34 psMetadata *stats; /// Statistics 37 psErrorCode quality; // Quality code; 0 for no problem 38 bool photometry; // Perform photometry? 39 bool inverse; // Output inverse subtraction as well? 40 const char *statsFile; // Statistics file 41 psMetadata *stats; // Statistics 35 42 } ppSubData; 36 43 -
branches/pap/ppSub/src/ppSubArguments.c
r23402 r23704 189 189 } 190 190 191 bool ppSubArgumentsSetup(int argc, char *argv[], pmConfig *config) 192 { 193 // int argnum; // Argument Number 191 bool ppSubArguments(int argc, char *argv[], pmConfig *config, ppSubData *data) 192 { 194 193 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 194 203 195 psMetadata *arguments = config->arguments; // Command-line arguments … … 212 204 psMetadataAddStr(arguments, PS_LIST_TAIL, "-kernel", 0, "Precalculated kernel to apply", NULL); 213 205 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); 206 psMetadataAddStr(arguments, PS_LIST_TAIL, "-stamps", 0, "Stamps filename; x,y on each line", NULL); 252 207 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 208 psMetadataAddStr(arguments, PS_LIST_TAIL, "-dumpconfig", 0, "file to dump configuration to", NULL); 256 209 psMetadataAddBool(arguments, PS_LIST_TAIL, "-visual", 0, "Show diagnostic plots", NULL); … … 302 255 } 303 256 304 if (psMetadataLookupBool(NULL, arguments, "-photometry")) { 305 psMetadataAddBool(recipe, PS_LIST_TAIL, "PHOTOMETRY", PS_META_REPLACE, "Perform photometry?", true); 306 } 307 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); 257 data->stamps = psMetadataLookupStr(NULL, arguments, "-stamps"); 258 259 const char *statsName = psMetadataLookupStr(NULL, arguments, "-stats"); // Filename for statistics 260 if (statsName && strlen(statsName) > 0) { 261 psString resolved = pmConfigConvertFilename(statsName, config, true, true); // Resolved filename 262 data->statsFile = fopen(resolved, "w"); 263 if (!data->statsFile) { 264 psError(PS_ERR_IO, true, "Unable to open statistics file %s for writing.\n", resolved); 265 psFree(resolved); 266 return false; 267 } 268 psFree(resolved); 380 269 } 381 270 … … 384 273 } 385 274 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 275 int threads = psMetadataLookupS32(NULL, arguments, "-threads"); // Number of threads 401 276 if (threads > 0) { 402 277 if (!psThreadPoolInit(threads)) { … … 407 282 408 283 return true; 409 410 ERROR: 411 return false; 412 } 284 } 285 286 287 288 psTrace("ppSub", 1, "Done reading command-line arguments\n"); 289 290 return true; 291 } -
branches/pap/ppSub/src/ppSubCamera.c
r23688 r23704 161 161 162 162 163 // Now that the camera has been determined, we can read the recipe 164 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSUB_RECIPE); // Recipe for ppSim 165 if (!recipe) { 166 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find recipe %s", PPSUB_RECIPE); 167 return false; 168 } 169 data->invert = psMetadataLookupBool(NULL, recipe, "INVERSE"); 170 data->photometry = psMetadataLookupBool(NULL, recipe, "PHOTOMETRY"); 171 172 163 173 // Output image 164 174 pmFPAfile *output = defineOutputFile(config, input, true, "PPSUB.OUTPUT", PM_FPA_FILE_IMAGE); … … 170 180 output->save = true; 171 181 outMask->save = true; 172 pmFPAfile *outVar = NULL;173 182 if (inVar && refVar) { 174 outVar = defineOutputFile(config, output, false, "PPSUB.OUTPUT.VARIANCE", PM_FPA_FILE_VARIANCE); 183 pmFPAfile *outVar = defineOutputFile(config, output, false, "PPSUB.OUTPUT.VARIANCE", 184 PM_FPA_FILE_VARIANCE); 175 185 if (!outVar) { 176 186 psError(PS_ERR_UNKNOWN, false, "Unable to define output files"); … … 180 190 } 181 191 192 if (data->inverse) { 193 // Inverse output image 194 pmFPAfile *outinv = defineOutputFile(config, input, true, "PPSUB.OUTINV", PM_FPA_FILE_IMAGE); 195 pmFPAfile *outinvMask = defineOutputFile(config, outinv, false, "PPSUB.OUTINV.MASK", 196 PM_FPA_FILE_MASK); 197 if (!outinv || !outinvMask) { 198 psError(PS_ERR_UNKNOWN, false, "Unable to define output files"); 199 return false; 200 } 201 outinv->save = true; 202 outinvMask->save = true; 203 if (inVar && refVar) { 204 pmFPAfile *outinvVar = defineOutputFile(config, outinv, false, "PPSUB.OUTINV.VARIANCE", 205 PM_FPA_FILE_VARIANCE); 206 if (!outinvVar) { 207 psError(PS_ERR_UNKNOWN, false, "Unable to define output files"); 208 return false; 209 } 210 outinvVar->save = true; 211 } 212 } 182 213 183 214 // Convolved input image … … 252 283 253 284 // psPhot input 254 if ( psMetadataLookupBool(NULL, recipe, "PHOTOMETRY")) {285 if (data->photometry) { 255 286 psphotModelClassInit(); // load implementation-specific models 256 287 -
branches/pap/ppSub/src/ppSubData.c
r23688 r23704 20 20 21 21 22 static void sub OptionsFree(ppSubData *options)22 static void subDataFree(ppSubData *data) 23 23 { 24 psFree(options->stats); 24 if (data->statsFile) { 25 psString stats = psMetadataConfigFormat(data->stats); // Statistics to output 26 if (!stats || strlen(stats) == 0) { 27 psWarning("Unable to generate statistics file."); 28 } else { 29 fprintf(data->statsFile, "%s", stats); 30 } 31 psFree(stats); 32 fclose(data->statsFile); 33 } 34 psFree(data->stats); 25 35 return; 26 36 } … … 28 38 ppSubData *ppSubDataAlloc(void) 29 39 { 30 ppSubData * options= psAlloc(sizeof(ppSubData)); // Processing data, to return31 psMemSetDeallocator( options, (psFreeFunc)subOptionsFree);40 ppSubData *data = psAlloc(sizeof(ppSubData)); // Processing data, to return 41 psMemSetDeallocator(data, (psFreeFunc)subDataFree); 32 42 33 options->quality = 0; 34 options->stats = psMetadataAlloc(); 35 psMetadataAddS32(options->stats, PS_LIST_TAIL, "QUALITY", 0, "Data quality", 0); 43 data->quality = 0; 44 data->photometry = false; 45 data->inverse = false; 46 data->statsFile = NULL; 47 data->stats = psMetadataAlloc(); 48 psMetadataAddS32(data->stats, PS_LIST_TAIL, "QUALITY", 0, "Data quality", 0); 36 49 37 50 return options; -
branches/pap/ppSub/src/ppSubDefineOutput.c
r23403 r23704 21 21 #include "ppSub.h" 22 22 23 bool ppSubDefineOutput( pmConfig *config, const pmFPAview *view)23 bool ppSubDefineOutput(const char *name, pmConfig *config, const ppSubData *data, const pmFPAview *view) 24 24 { 25 psAssert(name, "Require name"); 25 26 psAssert(config, "Require configuration"); 26 27 psAssert(view, "Require view"); 27 28 28 pmCell *outCell = pmFPAfileThisCell(config->files, view, "PPSUB.OUTPUT"); // Output cell29 pmCell *outCell = pmFPAfileThisCell(config->files, view, name); // Output cell 29 30 pmFPA *outFPA = outCell->parent->parent; // Output FPA 30 31 pmHDU *outHDU = outFPA->hdu; // Output HDU … … 33 34 } 34 35 35 // generate an output readout (first check if it's already there by virtue of kernels) 36 pmReadout *outRO = pmFPAfileThisReadout(config->files, view, "PPSUB.OUTPUT.KERNELS"); // RO with kernel 37 if (!outRO) { 38 outRO = pmReadoutAlloc(outCell); // Output readout: subtraction 36 pmReadout *outRO = NULL; // Output readout 37 if (outCell->readouts && outCell->readouts->n > 0 && outCell->readouts->data[0]) { 38 outRO = psMemIncrRefCounter(outCell->readouts->data[0]); 39 } else { 40 outRO = pmReadoutAlloc(outCell); 39 41 } 40 42 … … 55 57 if (!kernels) { 56 58 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find SUBTRACTION.KERNEL"); 57 psFree(inConv);58 psFree(refConv);59 59 psFree(outRO); 60 60 return false; … … 65 65 outRO->analysis = psMetadataCopy(outRO->analysis, analysis); 66 66 67 #ifdef TESTING 68 { 69 psImage *kernelImage = psMetadataLookupPtr(&mdok, analysis, 70 "SUBTRACTION.KERNEL.IMAGE"); // Image of kernel 71 psFits *fits = psFitsOpen("kernel.fits", "w"); 72 psFitsWriteImage(fits, NULL, kernelImage, 0, NULL); 73 psFitsClose(fits); 74 } 75 #endif 67 psFree(outRO); 76 68 77 69 return true; -
branches/pap/ppSub/src/ppSubLoop.c
r23688 r23704 21 21 #include "ppSub.h" 22 22 23 bool ppSubLoop(pmConfig *config )23 bool ppSubLoop(pmConfig *config, ppSubData *data) 24 24 { 25 25 psAssert(config, "Require configuration."); … … 28 28 pmConfigRecipesCull(config, "PPSUB,PPSTATS,PSPHOT,MASKS,JPEG"); 29 29 30 ppSubData *data = ppSubDataAlloc(); // Processing data31 30 32 bool mdok; // Status of MD lookup 33 const char *statsName = psMetadataLookupStr(&mdok, config->arguments, "STATS"); // Filename for statistics 34 FILE *statsFile = NULL; // File stream for statistics 35 if (statsName && strlen(statsName) > 0) { 36 psString resolved = pmConfigConvertFilename(statsName, config, true, true); // Resolved filename 37 statsFile = fopen(resolved, "w"); 38 if (!statsFile) { 39 psError(PS_ERR_IO, true, "Unable to open statistics file %s for writing.\n", resolved); 40 psFree(resolved); 31 pmFPAfile *input = psMetadataLookupPtr(NULL, config->files, "PPSUB.INPUT"); 32 pmFPAfile *reference = psMetadataLookupPtr(NULL, config->files, "PPSUB.REF"); 33 pmFPAfile *output = psMetadataLookupPtr(NULL, config->files, "PPSUB.OUTPUT"); 34 psAssert(input && reference && output, "Require files"); 35 36 if (!ppSubFilesIterateDown(config, PPSUB_FILES_INPUT | PPSUB_FILES_CONV)) { 37 psError(PPSUB_ERR_IO, false, "Unable to load files."); 38 return false; 39 } 40 41 psTimerStart("PPSUB_MATCH"); 42 43 if (!ppSubSetMasks(config)) { 44 psError(PS_ERR_UNKNOWN, false, "Unable to set masks."); 45 return false; 46 } 47 48 if (!ppSubMatchPSFs(config, data)) { 49 psError(PS_ERR_UNKNOWN, false, "Unable to match PSFs."); 50 return false; 51 } 52 if (data->quality) { 53 // Can't do anything at all 54 return true; 55 } 56 57 // Close input files 58 if (!ppSubFilesIterateUp(config, PPSUB_FILES_INPUT)) { 59 psError(PPSUB_ERR_IO, false, "Unable to close input files."); 60 return false; 61 } 62 63 // Set up subtraction files 64 if (!ppSubFilesIterateDown(config, PPSUB_FILES_SUB)) { 65 psError(PPSUB_ERR_IO, false, "Unable to set up subtraction files."); 66 return false; 67 } 68 69 if (!ppSubDefineOutput("PPSUB.OUTPUT", config, data, view)) { 70 psError(PS_ERR_UNKNOWN, false, "Unable to define output."); 71 return false; 72 } 73 74 if (data->inverse && !ppSubDefineOutput("PPSUB.OUTINV", config, data, view)) { 75 psError(PS_ERR_UNKNOWN, false, "Unable to define inverse."); 76 return false; 77 } 78 79 if (!data->quality && !ppSubMakePSF("PPSUB.OUTPUT", "PPSUB.OUTINV", config, data, view)) { 80 psError(PS_ERR_UNKNOWN, false, "Unable to generate PSF."); 81 return false; 82 } 83 84 // Close convolved files 85 if (!ppSubFilesIterateUp(config, PPSUB_FILES_CONV)) { 86 psError(PPSUB_ERR_IO, false, "Unable to close input files."); 87 return false; 88 } 89 90 if (!ppSubReadoutSubtract("PPSUB.OUTPUT", config, view)) { 91 psError(PS_ERR_UNKNOWN, false, "Unable to subtract images."); 92 return false; 93 } 94 95 // Higher order background subtraction using psphot 96 if (!ppSubBackground("PPSUB.OUTPUT", config, view)) { 97 psError(PS_ERR_UNKNOWN, false, "Unable to subtract background."); 98 return false; 99 } 100 101 if (!data->quality && data->!ppSubReadoutPhotometry("PPSUB.OUTPUT", config, data, view)) { 102 psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry."); 103 return false; 104 } 105 106 if (!ppSubReadoutUpdate("PPSUB.OUTPUT", config, data, view)) { 107 psError(PS_ERR_UNKNOWN, false, "Unable to update."); 108 return false; 109 } 110 111 // Perform statistics on the cell 112 if (statsFile) { 113 pmFPAfile *output = psMetadataLookupPtr(NULL, config->files, "PPSUB.OUTPUT"); // Output file 114 if (!output) { 115 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find file PPSUB.OUTPUT.\n"); 41 116 goto ERROR; 42 117 } 43 psFree(resolved); 118 psImageMaskType maskValue = pmConfigMaskGet("MASK.VALUE", config); 119 ppStatsFPA(data->stats, output->fpa, view, maskValue, config); 44 120 } 45 121 46 pmFPAfile *input = psMetadataLookupPtr(NULL, config->files, "PPSUB.INPUT"); 47 if (!input) { 48 psError(PS_ERR_UNEXPECTED_NULL, false, "Can't find input data!\n"); 49 goto ERROR; 50 } 51 52 pmFPAfile *reference = psMetadataLookupPtr(NULL, config->files, "PPSUB.REF"); 53 if (!reference) { 54 psError(PS_ERR_UNEXPECTED_NULL, false, "Can't find reference data!\n"); 55 goto ERROR; 56 } 57 58 pmFPAfile *output = psMetadataLookupPtr(NULL, config->files, "PPSUB.OUTPUT"); 59 if (!output) { 60 psError(PS_ERR_UNEXPECTED_NULL, false, "Can't find output data!\n"); 61 goto ERROR; 62 } 63 64 pmFPAview *view = pmFPAviewAlloc(0); // Pointer into FPA hierarchy 65 66 // Iterate over the FPA hierarchy 67 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 68 goto ERROR; 69 } 70 71 pmChip *inChip; // Input chip of interest 72 while ((inChip = pmFPAviewNextChip(view, input->fpa, 1)) != NULL) { 73 pmChip *refChip = pmFPAviewThisChip(view, reference->fpa); // Reference chip of interest 74 if ((!inChip->file_exists && refChip->file_exists) || 75 (inChip->file_exists && !refChip->file_exists)) { 76 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "FPA format discrepency between input and reference"); 77 psFree(view); 78 goto ERROR; 122 if (data->inverse) { 123 // Set up inverse subtraction files 124 if (!ppSubFilesIterateDown(config, PPSUB_FILES_INV)) { 125 psError(PPSUB_ERR_IO, false, "Unable to set up inverse files."); 126 return false; 79 127 } 80 128 81 if (!inChip->file_exists) { 82 continue; 129 if (!ppSubReadoutInverse("PPSUB.OUTINV", "PPSUB.OUTPUT", config, view)) { 130 psError(PS_ERR_UNKNOWN, false, "Unable to invert images."); 131 return false; 83 132 } 84 133 85 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 86 goto ERROR; 134 // Close subtraction files and open inverse photometry files 135 if (!ppSubFilesIterateUp(config, PPSUB_FILES_SUB)) { 136 psError(PPSUB_ERR_IO, false, "Unable to close subtraction files."); 137 return false; 87 138 } 88 139 89 pmCell *inCell; // Cell of interest 90 while ((inCell = pmFPAviewNextCell(view, input->fpa, 1)) != NULL) { 91 pmCell *refCell = pmFPAviewThisCell(view, reference->fpa); // Reference cell of interest 92 if ((!inCell->file_exists && refCell->file_exists) || 93 (inCell->file_exists && !refCell->file_exists)) { 94 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 95 "FPA format discrepency between input and reference"); 96 psFree(view); 97 goto ERROR; 98 } 99 if (!inCell->file_exists) { 100 continue; 101 } 102 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 103 goto ERROR; 104 } 105 106 pmReadout *inRO; // Readin of interest 107 while ((inRO = pmFPAviewNextReadout(view, input->fpa, 1))) { 108 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 109 goto ERROR; 110 } 111 pmReadout *refRO = pmFPAviewThisReadout(view, reference->fpa);// Reference readout of interest 112 if (!refRO || (!inRO->data_exists && refRO->data_exists) || 113 (inRO->data_exists && !refRO->data_exists)) { 114 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 115 "FPA format discrepency between input and reference"); 116 psFree(view); 117 goto ERROR; 118 } 119 if (!inRO->data_exists) { 120 continue; 121 } 122 123 // Perform the analysis 124 if (!ppSubReadout(config, data, view)) { 125 psError(PS_ERR_UNKNOWN, false, "Unable to subtract images.\n"); 126 goto ERROR; 127 } 128 129 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 130 goto ERROR; 131 } 132 } 133 134 // Perform statistics on the cell 135 if (statsFile) { 136 pmFPAfile *output = psMetadataLookupPtr(NULL, config->files, "PPSUB.OUTPUT"); // Output file 137 if (!output) { 138 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find file PPSUB.OUTPUT.\n"); 139 goto ERROR; 140 } 141 psImageMaskType maskValue = pmConfigMaskGet("MASK.VALUE", config); 142 ppStatsFPA(data->stats, output->fpa, view, maskValue, config); 143 } 144 145 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 146 goto ERROR; 147 } 140 if (!data->quality && data->!ppSubReadoutPhotometry("PPSUB.OUTINV", config, data, view)) { 141 psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry."); 142 return false; 148 143 } 149 150 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 151 goto ERROR; 144 } else { 145 // Close subtraction files 146 if (!ppSubFilesIterateUp(config, PPSUB_FILES_SUB)) { 147 psError(PPSUB_ERR_IO, false, "Unable to close subtraction files."); 148 return false; 152 149 } 153 150 } 154 151 155 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 156 goto ERROR; 152 153 if (!ppSubReadoutUpdate("PPSUB.OUTPUT", config, data, view)) { 154 psError(PS_ERR_UNKNOWN, false, "Unable to update."); 155 return false; 157 156 } 158 157 158 159 159 psFree(view); 160 161 // Write out summary statistics162 if (statsFile) {163 psMetadataAddF32(data->stats, PS_LIST_TAIL, "TIME_SUB", 0, "Time for subtraction completion",164 psTimerMark("ppSub"));165 166 const char *statsMDC = psMetadataConfigFormat(data->stats);167 if (!statsMDC || strlen(statsMDC) == 0) {168 psWarning("Unable to generate statistics MDC file.\n");169 } else {170 fprintf(statsFile, "%s", statsMDC);171 }172 psFree((void *)statsMDC);173 fclose(statsFile);174 }175 160 176 161 psString dump_file = psMetadataLookupStr(&mdok, config->arguments, "-dumpconfig"); … … 180 165 } 181 166 182 psFree(data);183 167 return true; 184 168 185 169 ERROR: 186 psFree(data);187 170 return false; 188 171 } -
branches/pap/ppSub/src/ppSubReadout.c
r23688 r23704 21 21 #include "ppSub.h" 22 22 23 bool ppSubReadout( pmConfig *config, ppSubData *data, const pmFPAview *view)23 bool ppSubReadout(const char *name, bool reverse, pmConfig *config, ppSubData *data, const pmFPAview *view) 24 24 { 25 psTimerStart("PPSUB_MATCH"); 25 psAssert(name, "Require name"); 26 psAssert(config, "Require configuration"); 27 psAssert(data, "Require data"); 28 psAssert(view, "Require view"); 26 29 27 if (!ppSubSetMasks(config, view)) { 28 psError(PS_ERR_UNKNOWN, false, "Unable to set masks."); 29 return false; 30 } 31 32 if (!ppSubMatchPSFs(config, data, view)) { 33 psError(PS_ERR_UNKNOWN, false, "Unable to match PSFs."); 34 return false; 35 } else if (data->quality) { 36 // Can't do anything at all 37 return true; 38 } 39 40 if (!ppSubDefineOutput(config, view)) { 30 if (!ppSubDefineOutput(name, config, data, view)) { 41 31 psError(PS_ERR_UNKNOWN, false, "Unable to define output."); 42 32 return false; 43 33 } 44 34 45 if (!data->quality && !ppSubMakePSF( config, data, view)) {35 if (!data->quality && !ppSubMakePSF(name, config, data, view)) { 46 36 psError(PS_ERR_UNKNOWN, false, "Unable to generate PSF."); 47 37 return false; 48 38 } 49 39 50 if (!ppSubReadoutSubtract( config, view)) {40 if (!ppSubReadoutSubtract(name, reverse, config, view)) { 51 41 psError(PS_ERR_UNKNOWN, false, "Unable to subtract images."); 52 42 return false; … … 54 44 55 45 // Higher order background subtraction using psphot 56 if (!ppSubBackground( config, view)) {46 if (!ppSubBackground(name, config, view)) { 57 47 psError(PS_ERR_UNKNOWN, false, "Unable to subtract background."); 58 48 return false; 59 49 } 60 50 61 if (!data->quality && !ppSubReadoutPhotometry(config, data, view)) {51 if (!data->quality && data->!ppSubReadoutPhotometry(name, config, data, view)) { 62 52 psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry."); 63 53 return false; 64 54 } 65 55 66 if (!ppSubReadoutUpdate( config, data, view)) {56 if (!ppSubReadoutUpdate(name, config, data, view)) { 67 57 psError(PS_ERR_UNKNOWN, false, "Unable to update."); 68 58 return false; 69 59 } 70 60 61 62 63 71 64 return true; 72 65 }
Note:
See TracChangeset
for help on using the changeset viewer.
