Changeset 26573
- Timestamp:
- Jan 12, 2010, 3:53:09 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionVisual.c
r26562 r26573 238 238 239 239 for (int i = 0; i < kernels->num; i++) { 240 pmSubtractionKernelPreCalc *preCalc = kernels->preCalc->data[i];241 psKernel *kernel = preCalc->kernel;242 243 int xSub = i % NXsub;244 int ySub = i / NXsub;245 246 int xPix = xSub * (2*footprint + 1 + 3) + footprint;247 int yPix = ySub * (2*footprint + 1 + 3) + footprint;248 249 double sum = 0.0;250 for (int y = -footprint; y <= footprint; y++) {251 for (int x = -footprint; x <= footprint; x++) {252 output->data.F32[y + yPix][x + xPix] = kernel->kernel[y][x];253 sum += kernel->kernel[y][x];254 }255 }256 fprintf (stderr, "kernel %d, sum %f\n", i, sum);257 } 258 240 pmSubtractionKernelPreCalc *preCalc = kernels->preCalc->data[i]; 241 psKernel *kernel = preCalc->kernel; 242 243 int xSub = i % NXsub; 244 int ySub = i / NXsub; 245 246 int xPix = xSub * (2*footprint + 1 + 3) + footprint; 247 int yPix = ySub * (2*footprint + 1 + 3) + footprint; 248 249 double sum = 0.0; 250 for (int y = -footprint; y <= footprint; y++) { 251 for (int x = -footprint; x <= footprint; x++) { 252 output->data.F32[y + yPix][x + xPix] = kernel->kernel[y][x]; 253 sum += kernel->kernel[y][x]; 254 } 255 } 256 fprintf (stderr, "kernel %d, sum %f\n", i, sum); 257 } 258 259 259 pmVisualScaleImage(kapa1, output, "Image", 0, true); 260 260 pmVisualAskUser(&plotImage); … … 276 276 float maxFlux = NAN; 277 277 for (int i = 0; i < stamps->num; i++) { 278 pmSubtractionStamp *stamp = stamps->stamps->data[i];279 if (!isfinite(stamp->flux)) continue;280 if (!stamp->convolutions1 && !stamp->convolutions2) continue;281 if (!maxStamp) {282 maxFlux = stamp->flux;283 maxStamp = stamp;284 continue;285 }286 if (stamp->flux > maxFlux) {287 maxFlux = stamp->flux;288 maxStamp = stamp;289 }278 pmSubtractionStamp *stamp = stamps->stamps->data[i]; 279 if (!isfinite(stamp->flux)) continue; 280 if (!stamp->convolutions1 && !stamp->convolutions2) continue; 281 if (!maxStamp) { 282 maxFlux = stamp->flux; 283 maxStamp = stamp; 284 continue; 285 } 286 if (stamp->flux > maxFlux) { 287 maxFlux = stamp->flux; 288 maxStamp = stamp; 289 } 290 290 } 291 291 292 292 if (!isfinite(maxStamp->flux)) { 293 fprintf (stderr, "no valid stamps?\n");293 fprintf (stderr, "no valid stamps?\n"); 294 294 } 295 295 … … 297 297 298 298 if (maxStamp->convolutions1) { 299 // output image is a grid of NXsub by NYsub sub-images300 nKernels = maxStamp->convolutions1->n;301 int NXsub = sqrt(nKernels);302 int NYsub = nKernels / NXsub;303 if (nKernels % NXsub) NYsub++;304 305 int NXpix = NXsub * (2*footprint + 1 + 3);306 int NYpix = NYsub * (2*footprint + 1 + 3);307 308 psImage *output = psImageAlloc(NXpix, NYpix, PS_TYPE_F32);309 psImageInit (output, 0.0);310 311 for (int i = 0; i < nKernels; i++) {299 // output image is a grid of NXsub by NYsub sub-images 300 nKernels = maxStamp->convolutions1->n; 301 int NXsub = sqrt(nKernels); 302 int NYsub = nKernels / NXsub; 303 if (nKernels % NXsub) NYsub++; 304 305 int NXpix = NXsub * (2*footprint + 1 + 3); 306 int NYpix = NYsub * (2*footprint + 1 + 3); 307 308 psImage *output = psImageAlloc(NXpix, NYpix, PS_TYPE_F32); 309 psImageInit (output, 0.0); 310 311 for (int i = 0; i < nKernels; i++) { 312 312 psKernel *kernel = maxStamp->convolutions1->data[i]; 313 314 int xSub = i % NXsub;315 int ySub = i / NXsub;316 317 int xPix = xSub * (2*footprint + 1 + 3) + footprint;318 int yPix = ySub * (2*footprint + 1 + 3) + footprint;319 320 double sum = 0.0;321 for (int y = -footprint; y <= footprint; y++) {322 for (int x = -footprint; x <= footprint; x++) {323 output->data.F32[y + yPix][x + xPix] = kernel->kernel[y][x];324 sum += kernel->kernel[y][x];325 }326 }327 fprintf (stderr, "kernel %d, sum %f\n", i, sum);328 } 329 pmVisualScaleImage(kapa2, output, "Image", 0, true);330 } 331 313 314 int xSub = i % NXsub; 315 int ySub = i / NXsub; 316 317 int xPix = xSub * (2*footprint + 1 + 3) + footprint; 318 int yPix = ySub * (2*footprint + 1 + 3) + footprint; 319 320 double sum = 0.0; 321 for (int y = -footprint; y <= footprint; y++) { 322 for (int x = -footprint; x <= footprint; x++) { 323 output->data.F32[y + yPix][x + xPix] = kernel->kernel[y][x]; 324 sum += kernel->kernel[y][x]; 325 } 326 } 327 fprintf (stderr, "kernel %d, sum %f\n", i, sum); 328 } 329 pmVisualScaleImage(kapa2, output, "Image", 0, true); 330 } 331 332 332 if (maxStamp->convolutions2) { 333 // output image is a grid of NXsub by NYsub sub-images334 nKernels = maxStamp->convolutions2->n;335 int NXsub = sqrt(nKernels);336 int NYsub = nKernels / NXsub;337 if (nKernels % NXsub) NYsub++;338 339 int NXpix = NXsub * (2*footprint + 1 + 3);340 int NYpix = NYsub * (2*footprint + 1 + 3);341 342 psImage *output = psImageAlloc(NXpix, NYpix, PS_TYPE_F32);343 psImageInit (output, 0.0);344 345 for (int i = 0; i < nKernels; i++) {333 // output image is a grid of NXsub by NYsub sub-images 334 nKernels = maxStamp->convolutions2->n; 335 int NXsub = sqrt(nKernels); 336 int NYsub = nKernels / NXsub; 337 if (nKernels % NXsub) NYsub++; 338 339 int NXpix = NXsub * (2*footprint + 1 + 3); 340 int NYpix = NYsub * (2*footprint + 1 + 3); 341 342 psImage *output = psImageAlloc(NXpix, NYpix, PS_TYPE_F32); 343 psImageInit (output, 0.0); 344 345 for (int i = 0; i < nKernels; i++) { 346 346 psKernel *kernel = maxStamp->convolutions2->data[i]; 347 348 int xSub = i % NXsub;349 int ySub = i / NXsub;350 351 int xPix = xSub * (2*footprint + 1 + 3) + footprint;352 int yPix = ySub * (2*footprint + 1 + 3) + footprint;353 354 double sum = 0.0;355 for (int y = -footprint; y <= footprint; y++) {356 for (int x = -footprint; x <= footprint; x++) {357 output->data.F32[y + yPix][x + xPix] = kernel->kernel[y][x];358 sum += kernel->kernel[y][x];359 }360 }361 fprintf (stderr, "kernel %d, sum %f\n", i, sum);362 } 363 pmVisualScaleImage(kapa2, output, "Image", 1, true);364 } 365 347 348 int xSub = i % NXsub; 349 int ySub = i / NXsub; 350 351 int xPix = xSub * (2*footprint + 1 + 3) + footprint; 352 int yPix = ySub * (2*footprint + 1 + 3) + footprint; 353 354 double sum = 0.0; 355 for (int y = -footprint; y <= footprint; y++) { 356 for (int x = -footprint; x <= footprint; x++) { 357 output->data.F32[y + yPix][x + xPix] = kernel->kernel[y][x]; 358 sum += kernel->kernel[y][x]; 359 } 360 } 361 fprintf (stderr, "kernel %d, sum %f\n", i, sum); 362 } 363 pmVisualScaleImage(kapa2, output, "Image", 1, true); 364 } 365 366 366 pmVisualAskUser(&plotImage); 367 367 return true; … … 390 390 391 391 overlay[Noverlay].type = KII_OVERLAY_BOX; 392 if ((stamp->x < 1.0) && (stamp->y < 1.0)) {393 // fprintf (stderr, "stamp zero: %f %f\n", stamp->x, stamp->y);394 continue;395 }396 if (!isfinite(stamp->x) && !isfinite(stamp->y)) {397 // fprintf (stderr, "stamp nan: %f %f\n", stamp->x, stamp->y);398 continue;399 }392 if ((stamp->x < 1.0) && (stamp->y < 1.0)) { 393 // fprintf (stderr, "stamp zero: %f %f\n", stamp->x, stamp->y); 394 continue; 395 } 396 if (!isfinite(stamp->x) && !isfinite(stamp->y)) { 397 // fprintf (stderr, "stamp nan: %f %f\n", stamp->x, stamp->y); 398 continue; 399 } 400 400 overlay[Noverlay].x = stamp->x; 401 401 overlay[Noverlay].y = stamp->y; … … 425 425 bool pmSubtractionVisualShowFitInit(pmSubtractionStampList *stamps) { 426 426 427 //if (!pmVisualIsVisual()) return true;427 if (!pmVisualIsVisual()) return true; 428 428 429 429 // generate 4 storage images large enough to hold the N stamps: … … 433 433 float NXf = sqrt(stamps->num); 434 434 NX = (int) NXf == NXf ? NXf : NXf + 1.0; 435 435 436 436 float NYf = stamps->num / NX; 437 437 NY = (int) NYf == NY ? NYf : NYf + 1.0; … … 449 449 differenceImage = psImageAlloc (NXpix, NYpix, PS_TYPE_F32); 450 450 convolutionImage = psImageAlloc (NXpix, NYpix, PS_TYPE_F32); 451 451 452 452 psImageInit (sourceImage, 0.0); 453 453 psImageInit (targetImage, 0.0); … … 462 462 bool pmSubtractionVisualShowFitAddStamp(psKernel *target, psKernel *source, psKernel *convolution, double background, double norm, int index) { 463 463 464 //if (!pmVisualIsVisual()) return true;464 if (!pmVisualIsVisual()) return true; 465 465 466 466 double sum; … … 475 475 sum = 0.0; 476 476 for (int y = -footprint; y <= footprint; y++) { 477 for (int x = -footprint; x <= footprint; x++) {478 targetImage->data.F32[y + NYpix][x + NXpix] = target->kernel[y][x];479 sum += targetImage->data.F32[y + NYpix][x + NXpix];480 }477 for (int x = -footprint; x <= footprint; x++) { 478 targetImage->data.F32[y + NYpix][x + NXpix] = target->kernel[y][x]; 479 sum += targetImage->data.F32[y + NYpix][x + NXpix]; 480 } 481 481 } 482 482 targetImage->data.F32[footprint + 1 + NYpix][NXpix] = sum; … … 485 485 sum = 0.0; 486 486 for (int y = -footprint; y <= footprint; y++) { 487 for (int x = -footprint; x <= footprint; x++) {488 sourceImage->data.F32[y + NYpix][x + NXpix] = source->kernel[y][x];489 sum += sourceImage->data.F32[y + NYpix][x + NXpix];490 }487 for (int x = -footprint; x <= footprint; x++) { 488 sourceImage->data.F32[y + NYpix][x + NXpix] = source->kernel[y][x]; 489 sum += sourceImage->data.F32[y + NYpix][x + NXpix]; 490 } 491 491 } 492 492 sourceImage->data.F32[footprint + 1 + NYpix][NXpix] = sum; … … 495 495 sum = 0.0; 496 496 for (int y = -footprint; y <= footprint; y++) { 497 for (int x = -footprint; x <= footprint; x++) {498 convolutionImage->data.F32[y + NYpix][x + NXpix] = -convolution->kernel[y][x];499 sum += convolutionImage->data.F32[y + NYpix][x + NXpix];500 }497 for (int x = -footprint; x <= footprint; x++) { 498 convolutionImage->data.F32[y + NYpix][x + NXpix] = -convolution->kernel[y][x]; 499 sum += convolutionImage->data.F32[y + NYpix][x + NXpix]; 500 } 501 501 } 502 502 convolutionImage->data.F32[footprint + 1 + NYpix][NXpix] = sum; 503 503 504 504 // insert the (difference) kernel into the (difference) image: 505 505 sum = 0.0; 506 506 for (int y = -footprint; y <= footprint; y++) { 507 for (int x = -footprint; x <= footprint; x++) {508 differenceImage->data.F32[y + NYpix][x + NXpix] = target->kernel[y][x] - background - source->kernel[y][x] * norm;509 sum += differenceImage->data.F32[y + NYpix][x + NXpix];510 }507 for (int x = -footprint; x <= footprint; x++) { 508 differenceImage->data.F32[y + NYpix][x + NXpix] = target->kernel[y][x] - background - source->kernel[y][x] * norm; 509 sum += differenceImage->data.F32[y + NYpix][x + NXpix]; 510 } 511 511 } 512 512 differenceImage->data.F32[footprint + 1 + NYpix][NXpix] = sum; … … 515 515 sum = 0.0; 516 516 for (int y = -footprint; y <= footprint; y++) { 517 for (int x = -footprint; x <= footprint; x++) {518 residualImage->data.F32[y + NYpix][x + NXpix] = target->kernel[y][x] - background - source->kernel[y][x] * norm +convolution->kernel[y][x];519 sum += residualImage->data.F32[y + NYpix][x + NXpix];520 }517 for (int x = -footprint; x <= footprint; x++) { 518 residualImage->data.F32[y + NYpix][x + NXpix] = target->kernel[y][x] - background - source->kernel[y][x] * norm - convolution->kernel[y][x]; 519 sum += residualImage->data.F32[y + NYpix][x + NXpix]; 520 } 521 521 } 522 522 residualImage->data.F32[footprint + 1 + NYpix][NXpix] = sum; … … 524 524 // insert the (fresidual) kernel into the (fresidual) image: 525 525 for (int y = -footprint; y <= footprint; y++) { 526 for (int x = -footprint; x <= footprint; x++) {527 fresidualImage->data.F32[y + NYpix][x + NXpix] = residualImage->data.F32[y + NYpix][x + NXpix] / sqrt(PS_MAX(target->kernel[y][x], 100.0));528 }526 for (int x = -footprint; x <= footprint; x++) { 527 fresidualImage->data.F32[y + NYpix][x + NXpix] = residualImage->data.F32[y + NYpix][x + NXpix] / sqrt(PS_MAX(target->kernel[y][x], 100.0)); 528 } 529 529 } 530 530 return true; … … 533 533 bool pmSubtractionVisualShowFit(double norm) { 534 534 535 // for testing, dump the residual image and exit 536 if (0) { 537 psMetadata *header = psMetadataAlloc(); 538 psMetadataAddF32 (header, PS_LIST_TAIL, "NORM", 0, "Normalization", norm); 539 psFits *fits = psFitsOpen("resid.fits", "w"); 540 psFitsWriteImage(fits, header, residualImage, 0, NULL); 541 psFitsClose(fits); 542 // exit (0); 543 } 544 535 545 if (!pmVisualIsVisual()) return true; 536 537 // XXX a dumb test : dump the residual image and exit538 {539 psMetadata *header = psMetadataAlloc();540 psMetadataAddF32 (header, PS_LIST_TAIL, "NORM", 0, "Normalization", norm);541 psFits *fits = psFitsOpen("resid.fits", "w");542 psFitsWriteImage(fits, header, residualImage, 0, NULL);543 psFitsClose(fits);544 exit (0);545 }546 547 546 if (!pmVisualInitWindow(&kapa1, "ppSub:Images")) return false; 548 547 if (!pmVisualInitWindow(&kapa2, "ppSub:Misc")) return false; … … 558 557 pmVisualScaleImage(kapa2, fresidualImage, "Frac Residual Stamps", 2, true); 559 558 pmVisualScaleImage(kapa2, differenceImage, "Difference Stamps", 0, true); 560 pmVisualScaleImage(kapa2, residualImage, "Residual Stamps", 1, true); 559 560 if (1) { 561 KiiImage image; 562 KapaImageData data; 563 Coords coords; 564 strcpy (coords.ctype, "RA---TAN"); 565 566 image.data2d = residualImage->data.F32; 567 image.Nx = residualImage->numCols; 568 image.Ny = residualImage->numRows; 569 strcpy (data.name, "Residual Stamps"); 570 strcpy (data.file, "Residual Stamps"); 571 572 data.zero = -300.0; 573 data.range = +600.0; 574 data.logflux = 0; 575 576 KiiSetChannel (kapa2, 1); 577 KiiNewPicture2D (kapa2, &image, &data, &coords); 578 } else { 579 pmVisualScaleImage(kapa2, residualImage, "Residual Stamps", 1, true); 580 } 581 561 582 KiiCenter (kapa2, 0.5*residualImage->numCols, 0.5*residualImage->numRows, 1); 562 583 … … 603 624 for (int i = 0; i < kernels->num; i++) { 604 625 x->data.F32[i] = i; 605 y->data.F32[i] = p_pmSubtractionSolutionCoeff(kernels, polyValues, i, false);626 y->data.F32[i] = p_pmSubtractionSolutionCoeff(kernels, polyValues, i, false); 606 627 graphdata.ymin = PS_MIN(graphdata.ymin, y->data.F32[i]); 607 628 graphdata.ymax = PS_MAX(graphdata.ymax, y->data.F32[i]);
Note:
See TracChangeset
for help on using the changeset viewer.
