Changeset 6828
- Timestamp:
- Apr 10, 2006, 5:53:19 PM (20 years ago)
- Location:
- branches/rel10_ifa/psModules/src/astrom
- Files:
-
- 2 edited
-
pmFPACopy.c (modified) (7 diffs)
-
pmFPACopy.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/rel10_ifa/psModules/src/astrom/pmFPACopy.c
r6815 r6828 273 273 // Generate an HDU with the pixels 274 274 static bool generateHDU(pmCell *target, // The target cell 275 pmCell *source // The source cell 275 pmCell *source, // The source cell 276 int xBin, int yBin // Binning in x and y 276 277 ) 277 278 { … … 315 316 psFree(sourceCells); 316 317 318 xSize = (int)ceilf((float)xSize/(float)xBin); 319 ySize = (int)ceilf((float)ySize/(float)yBin); 320 317 321 hdu->images = psArrayAlloc(numReadouts); 318 322 for (int i = 0; i < numReadouts; i++) { … … 349 353 } 350 354 355 // Bin a region down by specified factors in x and y 356 static void binRegion(psRegion *region, // Region to be binned 357 int xBin, int yBin// Binning in x and y 358 ) 359 { 360 // Want to include the lower bound: 1 binned by 4 --> 0; 3 binned by 4 --> 0; 4 binned by 4 --> 1 361 region->x0 = (int)(region->x0 / xBin); 362 region->y0 = (int)(region->y0 / yBin); 363 // Want to exclude the upper bound: 4 binned by 4 --> 1; 5 binned by 4 --> 2; 7 binned by 4 --> 2 364 region->x1 = (int)((region->x1 + xBin - 1) / xBin); 365 region->y1 = (int)((region->y1 + yBin - 1) / yBin); 366 } 367 351 368 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 352 // Public functions 369 // File-static engine functions --- these do all the work. Actually, cellCopy does all the work; the others 370 // merely iterate on the higher-level components. 353 371 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 354 372 355 356 int pmFPACopy(pmFPA *target, // The target FPA 357 pmFPA *source // The source FPA, to be copied 358 ) 373 static int cellCopy(pmCell *target, // The target cell 374 pmCell *source, // The source cell, to be copied 375 bool pixels, // Copy the pixels? 376 int xBin, int yBin // (Relative) binning factors in x and y 377 ) 359 378 { 360 379 assert(target); 361 380 assert(source); 362 381 363 psArray *targetChips = target->chips; // The target chips364 psArray *sourceChips = source->chips; // The source chips365 if (targetChips->n != sourceChips->n) {366 psError(PS_ERR_IO, true, "Number of source chips (%d) differs from the number of target chips (%d)\n",367 sourceChips->n, targetChips->n);368 return false;369 }370 371 #if 1372 // Copy any headers373 if (target->hdu && !target->hdu->phu) {374 pmHDU *sourceHDU = pmHDUFromFPA(source);375 target->hdu->header = psMetadataCopy(target->hdu->header, sourceHDU->header);376 }377 #endif378 379 int numChips = 0; // Number of chips copied380 for (int i = 0; i < targetChips->n; i++) {381 pmChip *targetChip = targetChips->data[i]; // The target chip382 const char *chipName = psMetadataLookupStr(NULL, targetChip->concepts, "CHIP.NAME"); // Name of chip383 int chipNum = pmFPAFindChip(source, chipName); // Number of chip with that name384 if (chipNum >= 0) {385 pmChip *sourceChip = sourceChips->data[chipNum]; // The source chip386 int numCells = pmChipCopy(targetChip, sourceChip); // Number of cells copied387 psTrace(__func__, 5, "Copied %d cells for chip %s\n", numCells, chipName);388 numChips++;389 }390 }391 392 // Update the concepts393 psMetadataCopy(target->concepts, source->concepts);394 395 return numChips;396 }397 398 int pmChipCopy(pmChip *target, // The target chip399 pmChip *source // The source chip, to be copied400 )401 {402 assert(target);403 assert(source);404 405 psArray *targetCells = target->cells; // The target cells406 psArray *sourceCells = source->cells; // The source cells407 if (targetCells->n != sourceCells->n) {408 psError(PS_ERR_IO, true, "Number of source cells (%d) differs from the number of target cells (%d)\n",409 sourceCells->n, targetCells->n);410 return false;411 }412 413 #if 1414 // Copy any headers415 if (target->hdu && !target->hdu->phu) {416 pmHDU *sourceHDU = pmHDUFromChip(source);417 target->hdu->header = psMetadataCopy(target->hdu->header, sourceHDU->header);418 }419 #endif420 421 int numCells = 0; // Number of cells copied422 for (int i = 0; i < targetCells->n; i++) {423 pmCell *targetCell = targetCells->data[i]; // The target cell424 const char *cellName = psMetadataLookupStr(NULL, targetCell->concepts, "CELL.NAME"); // Name of cell425 int cellNum = pmChipFindCell(source, cellName); // Number of cell with that name426 if (cellNum >= 0) {427 pmCell *sourceCell = sourceCells->data[cellNum]; // The source cell428 int numReadouts = pmCellCopy(targetCell, sourceCell); // Number of readouts copied429 psTrace(__func__, 5, "Copied %d readouts for cell %s\n", numReadouts, cellName);430 numCells++;431 }432 }433 434 // Update the concepts435 psMetadataCopy(target->concepts, source->concepts);436 437 return numCells;438 439 }440 441 int pmCellCopy(pmCell *target, // The target cell442 pmCell *source // The source cell, to be copied443 )444 {445 assert(target);446 assert(source);447 448 382 psArray *sourceReadouts = source->readouts; // The source readouts 449 383 int numReadouts = sourceReadouts->n; // Number of readouts copied 450 384 451 #if 1452 385 // Copy any headers 453 386 if (target->hdu && !target->hdu->phu) { … … 455 388 target->hdu->header = psMetadataCopy(target->hdu->header, sourceHDU->header); 456 389 } 457 #endif458 390 459 391 pmHDU *hdu = pmHDUFromCell(target); // The target HDU; we need to fix this up 460 392 if (!hdu->images) { 461 generateHDU(target, source );393 generateHDU(target, source, xBin, yBin); 462 394 } 463 395 if (!hdu->header) { … … 496 428 psFree(trimsecString); 497 429 } else { 498 copyPixels(hdu->images->data[i], sourceImage, *trimsec, xFlip, yFlip); 430 binRegion(trimsec, xBin, yBin); 431 if (pixels) { 432 copyPixels(hdu->images->data[i], sourceImage, *trimsec, xFlip, yFlip); 433 } 499 434 targetReadout->image = psImageSubset(hdu->images->data[i], *trimsec); 500 435 } … … 519 454 psFree(biassecString); 520 455 } else { 521 copyPixels(hdu->images->data[i], bias, *biassec, xFlip, yFlip); 456 binRegion(biassec, xBin, yBin); 457 if (pixels) { 458 copyPixels(hdu->images->data[i], bias, *biassec, xFlip, yFlip); 459 } 522 460 psImage *newBias = psImageSubset(hdu->images->data[i], *biassec); 523 461 psListAdd(targetReadout->bias, PS_LIST_TAIL, newBias); … … 565 503 } 566 504 505 // Update the binning concepts 506 psMetadataItem *binItem = psMetadataLookup(target->concepts, "CELL.XBIN"); 507 binItem->data.S32 *= xBin; 508 binItem = psMetadataLookup(target->concepts, "CELL.YBIN"); 509 binItem->data.S32 *= yBin; 510 567 511 return numReadouts; 568 512 } 513 514 static int chipCopy(pmChip *target, // The target chip 515 pmChip *source, // The source chip, to be copied 516 bool pixels, // Copy the pixels? 517 int xBin, int yBin // (Relative) binning factors in x and y 518 ) 519 { 520 assert(target); 521 assert(source); 522 523 psArray *targetCells = target->cells; // The target cells 524 psArray *sourceCells = source->cells; // The source cells 525 if (targetCells->n != sourceCells->n) { 526 psError(PS_ERR_IO, true, "Number of source cells (%d) differs from the number of target cells (%d)\n", 527 sourceCells->n, targetCells->n); 528 return false; 529 } 530 531 // Copy any headers 532 if (target->hdu && !target->hdu->phu) { 533 pmHDU *sourceHDU = pmHDUFromChip(source); 534 target->hdu->header = psMetadataCopy(target->hdu->header, sourceHDU->header); 535 } 536 537 int numCells = 0; // Number of cells copied 538 for (int i = 0; i < targetCells->n; i++) { 539 pmCell *targetCell = targetCells->data[i]; // The target cell 540 const char *cellName = psMetadataLookupStr(NULL, targetCell->concepts, "CELL.NAME"); // Name of cell 541 int cellNum = pmChipFindCell(source, cellName); // Number of cell with that name 542 if (cellNum >= 0) { 543 pmCell *sourceCell = sourceCells->data[cellNum]; // The source cell 544 int numReadouts = cellCopy(targetCell, sourceCell, pixels, xBin, yBin); // Number of readouts 545 // copied 546 psTrace(__func__, 5, "Copied %d readouts for cell %s\n", numReadouts, cellName); 547 numCells++; 548 } 549 } 550 551 // Update the concepts 552 psMetadataCopy(target->concepts, source->concepts); 553 554 return numCells; 555 556 } 557 558 static int fpaCopy(pmFPA *target, // The target FPA 559 pmFPA *source, // The source FPA, to be copied 560 bool pixels, // Copy the pixels? 561 int xBin, int yBin // (Relative) binning factors in x and y 562 ) 563 { 564 assert(target); 565 assert(source); 566 567 psArray *targetChips = target->chips; // The target chips 568 psArray *sourceChips = source->chips; // The source chips 569 if (targetChips->n != sourceChips->n) { 570 psError(PS_ERR_IO, true, "Number of source chips (%d) differs from the number of target chips (%d)\n", 571 sourceChips->n, targetChips->n); 572 return false; 573 } 574 575 // Copy any headers 576 if (target->hdu && !target->hdu->phu) { 577 pmHDU *sourceHDU = pmHDUFromFPA(source); 578 target->hdu->header = psMetadataCopy(target->hdu->header, sourceHDU->header); 579 } 580 581 int numChips = 0; // Number of chips copied 582 for (int i = 0; i < targetChips->n; i++) { 583 pmChip *targetChip = targetChips->data[i]; // The target chip 584 const char *chipName = psMetadataLookupStr(NULL, targetChip->concepts, "CHIP.NAME"); // Name of chip 585 int chipNum = pmFPAFindChip(source, chipName); // Number of chip with that name 586 if (chipNum >= 0) { 587 pmChip *sourceChip = sourceChips->data[chipNum]; // The source chip 588 int numCells = chipCopy(targetChip, sourceChip, pixels, xBin, yBin); // Number of cells copied 589 psTrace(__func__, 5, "Copied %d cells for chip %s\n", numCells, chipName); 590 numChips++; 591 } 592 } 593 594 // Update the concepts 595 psMetadataCopy(target->concepts, source->concepts); 596 597 return numChips; 598 } 599 600 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 601 // Public functions 602 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 603 604 605 int pmFPACopy(pmFPA *target, // The target FPA 606 pmFPA *source // The source FPA, to be copied 607 ) 608 { 609 return fpaCopy(target, source, true, 1, 1); 610 } 611 612 int pmChipCopy(pmChip *target, // The target chip 613 pmChip *source // The source chip, to be copied 614 ) 615 { 616 return chipCopy(target, source, true, 1, 1); 617 } 618 619 int pmCellCopy(pmCell *target, // The target cell 620 pmCell *source // The source cell, to be copied 621 ) 622 { 623 return cellCopy(target, source, true, 1, 1); 624 } 625 626 627 int pmFPACopyStructure(pmFPA *target, // The target FPA 628 pmFPA *source, // The source FPA, to be copied 629 int xBin, int yBin // Binning factors in x and y 630 ) 631 { 632 return fpaCopy(target, source, false, xBin, yBin); 633 } 634 635 int pmChipCopyStructure(pmChip *target, // The target chip 636 pmChip *source, // The source chip, to be copied 637 int xBin, int yBin // Binning factors in x and y 638 ) 639 { 640 return chipCopy(target, source, false, xBin, yBin); 641 } 642 643 int pmCellCopyStructure(pmCell *target, // The target cell 644 pmCell *source, // The source cell, to be copied 645 int xBin, int yBin // Binning factors in x and y 646 ) 647 { 648 return cellCopy(target, source, false, xBin, yBin); 649 } -
branches/rel10_ifa/psModules/src/astrom/pmFPACopy.h
r6720 r6828 2 2 #define PM_FPA_COPY_H 3 3 4 // Copy the FPA components, including the pixels 4 5 int pmFPACopy(pmFPA *target, // The target FPA 5 6 pmFPA *source // The source FPA, to be copied … … 12 13 ); 13 14 15 // Versions that copy the structure and not the pixels; they also allow binning 16 int pmFPACopyStructure(pmFPA *target, // The target FPA 17 pmFPA *source, // The source FPA, to be copied 18 int xBin, int yBin // Binning factors in x and y 19 ); 20 int pmChipCopyStructure(pmChip *target, // The target chip 21 pmChip *source, // The source chip, to be copied 22 int xBin, int yBin // Binning factors in x and y 23 ); 24 int pmCellCopyStructure(pmCell *target, // The target cell 25 pmCell *source, // The source cell, to be copied 26 int xBin, int yBin // Binning factors in x and y 27 ); 28 29 14 30 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
