Changeset 5104 for trunk/archive/scripts/src/phase2/papPhase2.c
- Timestamp:
- Sep 22, 2005, 4:54:52 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/archive/scripts/src/phase2/papPhase2.c (modified) (30 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/archive/scripts/src/phase2/papPhase2.c
r4820 r5104 4 4 #include "pslib.h" 5 5 #include "psAdditionals.h" 6 7 #include "pmSubtractBias.h"8 6 9 7 #include "pmFPA.h" 10 8 #include "pmConfig.h" 11 9 #include "pmFPAConstruct.h" 10 #include "pmFPARead.h" 11 #include "pmFPAConceptsGet.h" 12 #include "pmFPAWrite.h" 13 14 #include "pmFlatField.h" 15 #include "pmMaskBadPixels.h" 16 #include "pmNonLinear.h" 17 #include "pmSubtractBias.h" 12 18 13 19 // Phase 2 needs to: … … 37 43 #define RECIPE "PHASE2" // Name of the recipe to use 38 44 39 static psMem oryId memPrintAlloc(const psMemBlock *mb)45 static psMemId memPrintAlloc(const psMemBlock *mb) 40 46 { 41 47 printf("Allocated memory block %lld (%lld):\n" … … 46 52 return 0; 47 53 } 48 static psMem oryId memPrintFree(const psMemBlock *mb)54 static psMemId memPrintFree(const psMemBlock *mb) 49 55 { 50 56 printf("Freed memory block %lld (%lld):\n" … … 69 75 #if 0 70 76 // Hunting memory leaks 71 psMemAllocateCallbackSetID( 3539);72 psMemFreeCallbackSetID( 3539);77 psMemAllocateCallbackSetID(23289); 78 psMemFreeCallbackSetID(23289); 73 79 psMemAllocateCallbackSet(memPrintAlloc); 74 80 psMemFreeCallbackSet(memPrintFree); 75 81 #endif 76 82 77 // psTraceSetLevel(".", 10);83 psTraceSetLevel("pmConfigCameraFromHeader", 10); 78 84 79 85 // Parse the configurations … … 88 94 // Parse other command-line arguments 89 95 psMetadata *arguments = psMetadataAlloc(); // The arguments, with default values 90 psMetadataAddStr(arguments, PS_LIST_TAIL, "-bias", "Name of the bias image", "");91 psMetadataAddStr(arguments, PS_LIST_TAIL, "-dark", "Name of the dark image", "");92 psMetadataAddStr(arguments, PS_LIST_TAIL, "-flat", "Name of the flat-field image", "");93 psMetadataAddStr(arguments, PS_LIST_TAIL, "-mask", "Name of the mask image", "");94 psMetadataAddS32(arguments, PS_LIST_TAIL, "-chip", "Chip number to process (if positive)", -1);96 psMetadataAddStr(arguments, PS_LIST_TAIL, "-bias", 0, "Name of the bias image", ""); 97 psMetadataAddStr(arguments, PS_LIST_TAIL, "-dark", 0, "Name of the dark image", ""); 98 psMetadataAddStr(arguments, PS_LIST_TAIL, "-flat", 0, "Name of the flat-field image", ""); 99 psMetadataAddStr(arguments, PS_LIST_TAIL, "-mask", 0, "Name of the mask image", ""); 100 psMetadataAddS32(arguments, PS_LIST_TAIL, "-chip", 0, "Chip number to process (if positive)", -1); 95 101 if (! psArgumentParse(arguments, &argc, argv) || argc != 3) { 96 102 printf("\nPan-STARRS Phase 2 processing\n\n"); … … 113 119 printf("Mask: %s\n", maskName); 114 120 printf("Chip: %d\n", chipNum); 115 psFree(arguments);116 121 117 122 // Open the input … … 132 137 #endif 133 138 134 #if 0135 139 // Open the output and output mask 136 140 // We do it here so that we don't process the whole lot and then find out we can't open the output file … … 144 148 exit(EXIT_FAILURE); 145 149 } 150 151 #if 0 146 152 psString outputMaskName = psStringCopy(outputName); 147 153 (void)psStringAppend(&outputMaskName, ".mask"); … … 158 164 #endif 159 165 160 161 166 // Get camera configuration from header if not already defined 162 167 if (! camera) { … … 176 181 177 182 // Construct camera in preparation for reading 178 pmFPA *input = pmFPAConstruct(camera , database);179 pmFPA *mask = pmFPAConstruct(camera , database);180 pmFPA *bias = pmFPAConstruct(camera , database);181 pmFPA *dark = pmFPAConstruct(camera , database);182 pmFPA *flat = pmFPAConstruct(camera , database);183 pmFPA *input = pmFPAConstruct(camera); 184 pmFPA *mask = pmFPAConstruct(camera); 185 pmFPA *bias = pmFPAConstruct(camera); 186 pmFPA *dark = pmFPAConstruct(camera); 187 pmFPA *flat = pmFPAConstruct(camera); 183 188 184 189 // Set various tasks … … 198 203 199 204 if (psMetadataLookupBool(NULL, recipe, "MASK")) { 200 if ( maskName) {205 if (strlen(maskName) > 0) { 201 206 doMask = true; 202 207 } else { … … 209 214 } 210 215 if (psMetadataLookupBool(NULL, recipe, "BIAS")) { 211 if ( biasName) {216 if (strlen(biasName) > 0) { 212 217 doBias = true; 213 218 } else { … … 217 222 } 218 223 if (psMetadataLookupBool(NULL, recipe, "DARK")) { 219 if ( darkName) {224 if (strlen(darkName) > 0) { 220 225 doDark = true; 221 226 } else { … … 260 265 } 261 266 } 267 262 268 if (psMetadataLookupBool(NULL, recipe, "FLAT")) { 263 if ( flatName) {269 if (strlen(flatName) > 0) { 264 270 doFlat = true; 265 271 } else { … … 269 275 } 270 276 271 #if 0272 277 // Chip selection 273 278 if (chipNum >= 0) { … … 282 287 283 288 // Read in the input pixels 284 if (! pmFPARead(input, inputFile )) {289 if (! pmFPARead(input, inputFile, header, database)) { 285 290 psErrorStackPrint(stderr, "Unable to populate camera from FITS file: %s\n", inputName); 286 291 exit(EXIT_FAILURE); … … 292 297 #endif 293 298 299 pmFPAPrint(input); 294 300 295 301 // Load the calibration frames, if required 296 if (biasName) { 302 if (doBias) { 303 #ifdef PRODUCTION 297 304 psFits *biasFile = psFitsOpen(biasName, "r"); // File handle for bias 305 #else 306 psFits *biasFile = psFitsAlloc(biasName); 307 #endif 298 308 psMetadata *biasHeader = psFitsReadHeader(NULL, biasFile); // FITS header for bias 299 309 if (! pmConfigValidateCamera(camera, biasHeader)) { 300 psError( "phase2", true, "Bias (%s) does not seem to be from the same camera.\n", biasName);310 psError(PS_ERR_IO, true, "Bias (%s) does not seem to be from the same camera.\n", biasName); 301 311 exit(EXIT_FAILURE); 302 312 } 303 313 psFree(biasHeader); 304 if (! pmFPARead(bias, biasFile )) {314 if (! pmFPARead(bias, biasFile, NULL, database)) { 305 315 psErrorStackPrint(stderr, "Unable to populate bias camera from fits FITS: %s\n", biasName); 306 316 exit(EXIT_FAILURE); 307 317 } 318 #ifdef PRODUCTION 308 319 psFitsClose(biasFile); 309 } 310 311 if (darkName) { 320 #else 321 psFree(biasFile); 322 #endif 323 } 324 325 if (doDark) { 326 #ifdef PRODUCTION 312 327 psFits *darkFile = psFitsOpen(darkName, "r"); // File handle for dark 328 #else 329 psFits *darkFile = psFitsAlloc(darkName); 330 #endif 313 331 psMetadata *darkHeader = psFitsReadHeader(NULL, darkFile); // FITS header for dark 314 332 if (! pmConfigValidateCamera(camera, darkHeader)) { 315 psError( "phase2", true, "Dark (%s) does not seem to be from the same camera.\n", darkName);333 psError(PS_ERR_IO, true, "Dark (%s) does not seem to be from the same camera.\n", darkName); 316 334 exit(EXIT_FAILURE); 317 335 } 318 336 psFree(darkHeader); 319 if (! pmFPARead(dark, darkFile )) {337 if (! pmFPARead(dark, darkFile, NULL, database)) { 320 338 psErrorStackPrint(stderr, "Unable to populate dark camera from fits FITS: %s\n", darkName); 321 339 exit(EXIT_FAILURE); 322 340 } 341 #ifdef PRODUCTION 323 342 psFitsClose(darkFile); 324 } 325 326 if (maskName) { 343 #else 344 psFree(darkFile); 345 #endif 346 } 347 348 if (doMask) { 349 #ifdef PRODUCTION 327 350 psFits *maskFile = psFitsOpen(maskName, "r"); // File handle for mask 351 #else 352 psFits *maskFile = psFitsAlloc(maskName); 353 #endif 328 354 psMetadata *maskHeader = psFitsReadHeader(NULL, maskFile); // FITS header for mask 329 355 if (! pmConfigValidateCamera(camera, maskHeader)) { 330 psError( "phase2", true, "Mask (%s) does not seem to be from the same camera.\n", maskName);356 psError(PS_ERR_IO, true, "Mask (%s) does not seem to be from the same camera.\n", maskName); 331 357 exit(EXIT_FAILURE); 332 358 } 333 359 psFree(maskHeader); 334 if (! pmFPARead(mask, maskFile )) {360 if (! pmFPARead(mask, maskFile, NULL, database)) { 335 361 psErrorStackPrint(stderr, "Unable to populate mask camera from fits FITS: %s\n", maskName); 336 362 exit(EXIT_FAILURE); 337 363 } 364 #ifdef PRODUCTION 338 365 psFitsClose(maskFile); 366 #else 367 psFree(maskFile); 368 #endif 339 369 } 340 370 341 if (flatName) { 371 if (doFlat) { 372 #ifdef PRODUCTION 342 373 psFits *flatFile = psFitsOpen(flatName, "r"); // File handle for flat 374 #else 375 psFits *flatFile = psFitsAlloc(flatName); 376 #endif 343 377 psMetadata *flatHeader = psFitsReadHeader(NULL, flatFile); // FITS header for flat 344 378 if (! pmConfigValidateCamera(camera, flatHeader)) { 345 psError( "phase2", true, "Flat (%s) does not seem to be from the same camera.\n", flatName);379 psError(PS_ERR_IO, true, "Flat (%s) does not seem to be from the same camera.\n", flatName); 346 380 exit(EXIT_FAILURE); 347 381 } 348 382 psFree(flatHeader); 349 if (! pmFPARead(flat, flatFile )) {383 if (! pmFPARead(flat, flatFile, NULL, database)) { 350 384 psErrorStackPrint(stderr, "Unable to populate flat camera from fits FITS: %s\n", flatName); 351 385 exit(EXIT_FAILURE); 352 386 } 387 #ifdef PRODUCTION 353 388 psFitsClose(flatFile); 389 #else 390 psFree(flatFile); 391 #endif 354 392 } 355 393 356 psArray *inputChips = input s->chips; // Array of chips in input image394 psArray *inputChips = input->chips; // Array of chips in input image 357 395 psArray *biasChips = bias->chips; // Array of chips in bias image 358 396 psArray *darkChips = dark->chips; // Array of chips in dark image … … 377 415 378 416 for (int j = 0; j < inputCells->n; j++) { 379 pmCell *inputCell = inputCells->data[ i]; // Cell of interest in input image380 pmCell *biasCell = biasCells->data[ i]; // Cell of interest in bias image381 pmCell *darkCell = darkCells->data[ i]; // Cell of interest in dark imag382 pmCell *maskCell = maskCells->data[ i]; // Cell of interest in mask image383 pmCell *flatCell = flatCells->data[ i]; // Cell of interest in flat image417 pmCell *inputCell = inputCells->data[j]; // Cell of interest in input image 418 pmCell *biasCell = biasCells->data[j]; // Cell of interest in bias image 419 pmCell *darkCell = darkCells->data[j]; // Cell of interest in dark imag 420 pmCell *maskCell = maskCells->data[j]; // Cell of interest in mask image 421 pmCell *flatCell = flatCells->data[j]; // Cell of interest in flat image 384 422 385 423 if (! inputCell->valid) { … … 388 426 389 427 psArray *inputReadouts = inputCell->readouts; // Array of readouts in input image 390 if ( biasCell->readouts->n !=1) {428 if (doBias && biasCell->readouts->n > 1) { 391 429 psLogMsg("phase2", PS_LOG_WARN, "Bias contains multiple readouts: only the first will be" 392 430 " used."); 393 431 } 394 if (d arkCell->readouts->n !=1) {432 if (doDark && darkCell->readouts->n > 1) { 395 433 psLogMsg("phase2", PS_LOG_WARN, "Dark contains multiple readouts: only the first will be" 396 434 " used."); 397 435 } 398 if ( maskCell->readouts->n !=1) {436 if (doMask && maskCell->readouts->n > 1) { 399 437 psLogMsg("phase2", PS_LOG_WARN, "Mask contains multiple readouts: only the first will be" 400 438 " used."); 401 439 } 402 if ( flatCell->readouts->n !=1) {440 if (doFlat && flatCell->readouts->n > 1) { 403 441 psLogMsg("phase2", PS_LOG_WARN, "Flat contains multiple readouts: only the first will be" 404 442 " used."); 405 443 } 406 444 445 pmReadout *biasReadout = NULL; // Bias readout 446 pmReadout *maskReadout = NULL; // Mask readout 447 pmReadout *flatReadout = NULL; // Flat readout 407 448 psImage *biasImage = NULL; // Bias pixels 408 449 psImage *darkImage = NULL; // Dark pixels 409 450 float darkTime = 1.0; // Dark time for dark image 410 411 if (biasName) { 412 pmReadout *biasReadout = biasCell->readouts->data[0]; // Readout of interest in bias image 451 psImage *maskImage = NULL; // Mask pixels 452 453 if (doBias) { 454 biasReadout = biasCell->readouts->data[0]; // Readout of interest in bias image 413 455 biasImage = biasReadout->image; 414 456 } 415 if (d arkName) {457 if (doDark) { 416 458 pmReadout *darkReadout = darkCell->readouts->data[0]; // Readout of interest in dark image 417 459 darkImage = darkReadout->image; 418 darkTime = p mReadoutGetDarkTime(darkReadout);460 darkTime = psMetadataLookupF32(NULL, darkCell->concepts, "CELL.DARKTIME"); 419 461 if (darkTime <= 0.0) { 420 462 psErrorStackPrint(stderr, "DARKTIME for dark image (%f) is non-positive.\n", darkTime); … … 422 464 } 423 465 } 424 if (maskName) { 425 pmReadout *maskReadout = maskCell->readouts->data[0]; // Readout of interest in mask image 426 } 427 if (flatName) { 428 pmReadout *flatReadout = flatCell->readouts->data[0]; // Readout of interest in mask image 466 if (doMask) { 467 maskReadout = maskCell->readouts->data[0]; // Readout of interest in mask image 468 maskImage = maskReadout->image; 469 } 470 if (doFlat) { 471 flatReadout = flatCell->readouts->data[0]; // Readout of interest in mask image 429 472 } 430 473 … … 432 475 pmReadout *inputReadout = inputReadouts->data[k]; // Readout of interest in input image 433 476 psImage *inputImage = inputReadout->image; // The actual image 434 psList *input Bias = inputReadout->bias; // List of overscan bias regions477 psList *inputOverscans = inputReadout->overscans; // List of overscan bias regions 435 478 436 479 // Mask bad pixels 437 480 if (doMask) { 481 float saturation = psMetadataLookupF32(NULL, inputCell->concepts, "CELL.SATURATION"); 482 438 483 // Need to change this later to grow the mask by the size of the convolution kernel 439 (void)pmMaskBadPixels(inputReadout, mask Readout,440 P S_MASK_TRAP | PS_MASK_BADCOL | PS_MASK_SAT, saturation,441 P S_MASK_TRAP, 0);484 (void)pmMaskBadPixels(inputReadout, maskImage, 485 PM_MASK_TRAP | PM_MASK_BADCOL | PM_MASK_SAT, saturation, 486 PM_MASK_TRAP, 0); 442 487 } 443 488 … … 450 495 } else { 451 496 switch (dataItem->type) { 452 case PS_META_VECTOR: 453 // These are the polynomial coefficients 454 psVector *coeff = dataItem->data.V; // The coefficient vector 455 if (coeff->type.type != PS_TYPE_F64) { 456 psVector *temp = psVectorCopy(NULL, coeff, PS_TYPE_F64); // F64 version 497 case PS_META_VEC: 498 { 499 // These are the polynomial coefficients 500 psVector *coeff = dataItem->data.V; // The coefficient vector 501 if (coeff->type.type != PS_TYPE_F64) { 502 psVector *temp = psVectorCopy(NULL, coeff, PS_TYPE_F64); // F64 version 503 psFree(coeff); 504 coeff = temp; 505 } 506 psPolynomial1D *correction = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, 507 coeff->n + 1); 508 for (int i = 0; i < coeff->n; i++) { 509 correction->coeff[i] = coeff->data.F64[i]; 510 } 511 (void)pmNonLinearityPolynomial(inputReadout, correction); 457 512 psFree(coeff); 458 coeff = temp;513 psFree(correction); 459 514 } 460 psPolynomial1D *correction = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD,461 coeff->n + 1);462 for (int i = 0; i < coeff->n; i++) {463 correction->coeff[i] = coeff->data.F64[i];464 }465 (void)pmNonLinearityPolynomial(inputReadout, correction);466 psFree(coeffCopy);467 psFree(coeff);468 psFree(correction);469 515 break; 470 516 case PS_META_STR: 471 // This is a filename 472 psString name = dataItem->data.V; // Filename 473 psLookupTable *table = psLookupTableAlloc(name, "%f %f", 0); 474 if (psLookupTableRead(table) <= 0) { 475 psErrorStackPrint(stderr, "Unable to read non-linearity correction file %s " 476 "--- ignored\n", tableName); 477 } else { 478 (void)pmNonLinearityLookup(inputReadout, table); 517 { 518 // This is a filename 519 psString name = dataItem->data.V; // Filename 520 psLookupTable *table = psLookupTableAlloc(name, "%f %f", 0); 521 if (psLookupTableRead(table) <= 0) { 522 psErrorStackPrint(stderr, "Unable to read non-linearity correction file " 523 "%s --- ignored\n", name); 524 } else { 525 #ifdef PRODUCTION 526 (void)pmNonLinearityLookup(inputReadout, table); 527 #else 528 printf("XXX: Non-linearity with lookup table not yet implemented.\n"); 529 #endif 530 } 531 psFree(table); 479 532 } 480 psFree(table);481 533 break; 482 534 case PS_META_META: 483 // This is a menu 484 psMetadata *options = dataItem->data.V; // Options with concept values as keys 485 bool mdok = false; // Success of MD lookup 486 psString concept = psMetadataLookupStr(&mdok, recipe, "NONLIN.SOURCE"); 487 if (! mdok || ! concept) { 488 psLogMsg("phase2", PS_LOG_WARN, "Non-linearity correction desired, but " 489 "unable to find NONLIN.SOURCE in recipe --- ignored.\n"); 490 } else { 491 psMetadataItem *conceptValueItem = pmCellGetConcept(inputCell, concept); 492 if (! conceptValueItem) { 493 psLogMsg("phase2", PS_LOG_WARN, "Unable to find value of concept %s " 494 "for non-linearity correction --- ignored.\n", concept); 495 } else if (conceptValueItem->type != PS_META_STR) { 496 psLogMsg("phase2", PS_LOG_WARN, "Type for concept %s isn't STRING, as" 497 " expected for non-linearity correction --- ignored.\n", 498 concept); 535 { 536 // This is a menu 537 psMetadata *options = dataItem->data.V; // Options with concept values as keys 538 bool mdok = false; // Success of MD lookup 539 psString concept = psMetadataLookupString(&mdok, recipe, "NONLIN.SOURCE"); 540 if (! mdok || ! concept) { 541 psLogMsg("phase2", PS_LOG_WARN, "Non-linearity correction desired, but " 542 "unable to find NONLIN.SOURCE in recipe --- ignored.\n"); 499 543 } else { 500 psString conceptValue = conceptValueItem->data.V; 501 // Get the value of the concept 502 psMetadataItem *optionItem = psMetadataLookup(options, conceptValue); 503 if (!optionItem) { 504 psLogMsg("phase2", PS_LOG_WARN, "Unable to find %s in NONLIN.DATA" 505 " --- ignored.\n", conceptValue); 506 } else if (optionItem->type == PS_META_VECTOR) { 507 // These are the polynomial coefficients 508 psVector *coeff = optionItem->data.V; // The coefficient vector 509 if (coeff->type.type != PS_TYPE_F64) { 510 psVector *temp = psVectorCopy(NULL, coeff, PS_TYPE_F64); 544 psMetadataItem *conceptValueItem = pmCellGetConcept(inputCell, concept); 545 if (! conceptValueItem) { 546 psLogMsg("phase2", PS_LOG_WARN, "Unable to find value of concept %s " 547 "for non-linearity correction --- ignored.\n", concept); 548 } else if (conceptValueItem->type != PS_META_STR) { 549 psLogMsg("phase2", PS_LOG_WARN, "Type for concept %s isn't STRING, as" 550 " expected for non-linearity correction --- ignored.\n", 551 concept); 552 } else { 553 psString conceptValue = conceptValueItem->data.V; 554 // Get the value of the concept 555 psMetadataItem *optionItem = psMetadataLookup(options, conceptValue); 556 if (!optionItem) { 557 psLogMsg("phase2", PS_LOG_WARN, "Unable to find %s in NONLIN.DATA" 558 " --- ignored.\n", conceptValue); 559 } else if (optionItem->type == PS_META_VEC) { 560 // These are the polynomial coefficients 561 psVector *coeff = optionItem->data.V; // The coefficient vector 562 if (coeff->type.type != PS_TYPE_F64) { 563 psVector *temp = psVectorCopy(NULL, coeff, PS_TYPE_F64); 564 psFree(coeff); 565 coeff = temp; 566 } 567 // Polynomial correction 568 psPolynomial1D *correction = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, 569 coeff->n + 1); 570 for (int i = 0; i < coeff->n; i++) { 571 correction->coeff[i] = coeff->data.F64[i]; 572 } 573 (void)pmNonLinearityPolynomial(inputReadout, correction); 511 574 psFree(coeff); 512 coeff = temp; 575 psFree(correction); 576 } else if (optionItem->type == PS_META_STR) { 577 // This is a filename 578 psString tableName = optionItem->data.V; // The filename 579 psLookupTable *table = psLookupTableAlloc(tableName, "%f %f", 0); 580 int numLines = 0; // Number of lines read from table 581 if ((numLines = psLookupTableRead(table)) <= 0) { 582 psErrorStackPrint(stderr, "Unable to read non-linearity " 583 "correction file %s --- ignored\n", 584 tableName); 585 } else { 586 #ifdef PRODUCTION 587 (void)pmNonLinearityLookup(inputReadout, table); 588 #else 589 printf("XXX: Non-linearity correction from lookup table not " 590 "yet implemented.\n"); 591 #endif 592 } 593 psFree(table); 594 } else { 595 psLogMsg("phase2", PS_LOG_WARN, "Non-linearity correction " 596 "desired but unable to interpret NONLIN.DATA for %s" 597 " --- ignored\n", conceptValue); 513 598 } 514 // Polynomial correction515 psPolynomial1D *correction = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD,516 coeff->n + 1);517 for (int i = 0; i < coeff->n; i++) {518 correction->coeff[i] = coeff->data.F64[i];519 }520 (void)pmNonLinearityPolynomial(inputReadout, correction);521 psFree(coeffCopy);522 psFree(coeff);523 psFree(correction);524 } else if (optionItem->type == PS_META_STR) {525 // This is a filename526 psString tableName = optionItem->data.V; // The filename527 psLookupTable *table = psLookupTableAlloc(tableName, "%f %f", 0);528 if ((int numLines = psLookupTableRead(table)) <= 0) {529 psErrorStackPrint(stderr, "Unable to read non-linearity "530 "correction file %s --- ignored\n", tableName);531 } else {532 (void)pmNonLinearityLookup(inputReadout, table);533 }534 psFree(table);535 } else {536 psLogMsg("phase2", PS_LOG_WARN, "Non-linearity correction "537 "desired but unable to interpret NONLIN.DATA for %s"538 " --- ignored\n", conceptValue);539 599 } 540 600 } … … 553 613 // it's not in there yet. Once it is, we can get rid of "pedestal". 554 614 615 #ifdef PRODUCTION 555 616 psImage *pedestal = NULL; // Pedestal image (bias + scaled dark) 556 617 if (doDark) { 557 float inputTime = pmReadoutGetDarkTime(inputReadout); // Dark time for input image 618 // Dark time for input image 619 float inputTime = psMetadataLookupF32(NULL, inputCell->concepts, "CELL.DARKTIME"); 558 620 if (inputTime <= 0) { 559 621 psErrorStackPrint(stderr, "DARKTIME for input image (%f) is non-positive.\n", … … 562 624 } 563 625 564 pedestal = psBinaryOp(NULL, darkImage, "*",565 psScalarAlloc(inputTime * darkTime, PS_TYPE_F32));626 pedestal = (psImage*)psBinaryOp(NULL, darkImage, "*", 627 psScalarAlloc(inputTime * darkTime, PS_TYPE_F32)); 566 628 } 567 629 if (doBias) { … … 569 631 if (biasImage->numRows != darkImage->numRows || 570 632 biasImage->numCols != darkImage->numCols) { 571 psError( "phase2", true, "Bias and dark images have different dimensions: "633 psError(PS_ERR_IO, true, "Bias and dark images have different dimensions: " 572 634 "%dx%d vs %dx%d\n", biasImage->numCols, biasImage->numRows, 573 635 darkImage->numCols, darkImage->numRows); … … 579 641 } 580 642 } 581 643 #endif 582 644 if (overscanMode == PM_OVERSCAN_ROWS || overscanMode == PM_OVERSCAN_COLUMNS) { 583 645 // Need to get the read direction 584 int readdir = p mCellGetReaddir(inputCell); // Read direction646 int readdir = psMetadataLookupS32(NULL, inputCell->concepts, "CELL.READDIR"); 585 647 if (readdir == 1) { 586 648 overscanMode = PM_OVERSCAN_ROWS; … … 594 656 } 595 657 596 void *overscanResult = NULL; // Result of overscan fit 597 (void)pmSubtractBias(inputImage, overscanResult, inputBias, overscanMode, overscanStat, 598 overscanBin, overscanFit, pedestal); 599 600 // Output overscan fit results, if required 601 if (doOverscan) { 602 switch (overscanFit) { 603 case PM_FIT_POLYNOMIAL: 604 psPolynomial1D *poly = (psPolynomial1D*)overscanResult; // The polynomial 605 psString coeffs = NULL; // String containing the coefficients 606 for (int i = 0; i < poly->n; i++) { 607 psStringAppend(&coeffs, "%.2f ", poly->coeffs[i]); 658 printf("mode: %d\n", overscanMode); 659 660 if (doBias || doOverscan || doDark) { 661 void *overscanResult = NULL; // Result of overscan fit 662 #ifdef PRODUCTION 663 (void)pmSubtractBias(inputReadout, overscanResult, inputOverscans, overscanMode, 664 overscanStats, overscanBins, overscanFit, pedestal); 665 #else 666 (void)pmSubtractBias(inputReadout, overscanResult, inputOverscans, overscanMode, 667 overscanStats, overscanBins, overscanFit, biasReadout); 668 #endif 669 670 // Output overscan fit results, if required 671 if (doOverscan) { 672 switch (overscanFit) { 673 case PM_FIT_POLYNOMIAL: 674 { 675 psPolynomial1D *poly = (psPolynomial1D*)overscanResult; // The polynomial 676 psString coeffs = NULL; // String containing the coefficients 677 for (int i = 0; i < poly->n; i++) { 678 psStringAppend(&coeffs, "%.2f ", poly->coeff[i]); 679 } 680 psLogMsg("phase2", PS_LOG_INFO, "Overscan polynomial coefficients:\n%s\n", 681 coeffs); 682 psFree(coeffs); 683 } 684 break; 685 case PM_FIT_SPLINE: 686 { 687 psSpline1D *spline = (psSpline1D*)overscanResult; // The spline 688 psString coeffs = NULL; // String containing the coefficients 689 for (int i = 0; i < spline->n; i++) { 690 psPolynomial1D *poly = spline->spline[i]; // i-th polynomial 691 psStringAppend(&coeffs, "%d: ", i); 692 for (int j = 0; j < poly->n; j++) { 693 psStringAppend(&coeffs, "%.2f ", poly->coeff[i]); 694 } 695 psStringAppend(&coeffs, "\n"); 696 } 697 psLogMsg("phase2", PS_LOG_INFO, "Overscan spline coefficients:\n%s\n", 698 coeffs); 699 psFree(coeffs); 700 } 701 break; 702 case PM_FIT_NONE: 703 break; 704 default: 705 psAbort(__func__, "Should never get here!!!\n"); 608 706 } 609 psLogMsg("phase2", PS_LOG_INFO, "Overscan polynomial coefficients:\n%s\n",610 coeffs);611 psFree(coeffs);612 break;613 case PM_FIT_SPLINE:614 psSpline1D *spline = (psSpline1D*)overscanResult; // The spline615 psString coeffs = NULL; // String containing the coefficients616 for (int i = 0; i < spline->n; i++) {617 psPolynomial1D *poly = spline->spline[i]; // i-th polynomial618 psStringAppend(&coeffs, "%d: ", i);619 for (int j = 0; j < poly->n; j++) {620 psStringAppend(&coeffs, "%.2f ", poly->coeffs[i]);621 }622 psStringAppend(&coeffs, "\n");623 }624 psLogMsg("phase2", PS_LOG_INFO, "Overscan spline coefficients:\n%s\n", coeffs);625 psFree(coeffs);626 break;627 case PM_FIT_NONE:628 break;629 default:630 psAbort("Should never get here!!!\n");631 707 } 632 708 } … … 634 710 // Flat-field correction 635 711 if (doFlat) { 636 (void)pmFlatField(inputReadout, maskReadout,flatReadout);712 (void)pmFlatField(inputReadout, flatReadout); 637 713 } 638 714 … … 659 735 660 736 // Write the output 661 pmFPAWrite(outputFile, input );662 pmFPAWriteMask(outputMaskFile, input);737 pmFPAWrite(outputFile, input, database); 738 // pmFPAWriteMask(outputMaskFile, input); 663 739 #ifdef PRODUCTION 664 740 psFitsClose(outputFile); 665 psFitsClose(outputMaskFile);741 // psFitsClose(outputMaskFile); 666 742 #else 667 743 psFree(outputFile); 668 psFree(outputMaskFile); 669 #endif 670 671 #endif 672 744 // psFree(outputMaskFile); 745 #endif 746 747 psFree(arguments); 673 748 psFree(site); 674 749 psFree(header); … … 681 756 psFree(flat); 682 757 psFree(overscanStats); 683 psFree(inputFile);684 758 685 759 #if 1
Note:
See TracChangeset
for help on using the changeset viewer.
