IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6828


Ignore:
Timestamp:
Apr 10, 2006, 5:53:19 PM (20 years ago)
Author:
Paul Price
Message:

Changed to allow copy with binning

Location:
branches/rel10_ifa/psModules/src/astrom
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/rel10_ifa/psModules/src/astrom/pmFPACopy.c

    r6815 r6828  
    273273// Generate an HDU with the pixels
    274274static 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
    276277                       )
    277278{
     
    315316    psFree(sourceCells);
    316317
     318    xSize = (int)ceilf((float)xSize/(float)xBin);
     319    ySize = (int)ceilf((float)ySize/(float)yBin);
     320
    317321    hdu->images = psArrayAlloc(numReadouts);
    318322    for (int i = 0; i < numReadouts; i++) {
     
    349353}
    350354
     355// Bin a region down by specified factors in x and y
     356static 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
    351368//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    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.
    353371//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    354372
    355 
    356 int pmFPACopy(pmFPA *target,            // The target FPA
    357               pmFPA *source             // The source FPA, to be copied
    358              )
     373static 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                   )
    359378{
    360379    assert(target);
    361380    assert(source);
    362381
    363     psArray *targetChips = target->chips; // The target chips
    364     psArray *sourceChips = source->chips; // The source chips
    365     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 1
    372     // Copy any headers
    373     if (target->hdu && !target->hdu->phu) {
    374         pmHDU *sourceHDU = pmHDUFromFPA(source);
    375         target->hdu->header = psMetadataCopy(target->hdu->header, sourceHDU->header);
    376     }
    377     #endif
    378 
    379     int numChips = 0;                   // Number of chips copied
    380     for (int i = 0; i < targetChips->n; i++) {
    381         pmChip *targetChip = targetChips->data[i]; // The target chip
    382         const char *chipName = psMetadataLookupStr(NULL, targetChip->concepts, "CHIP.NAME"); // Name of chip
    383         int chipNum = pmFPAFindChip(source, chipName); // Number of chip with that name
    384         if (chipNum >= 0) {
    385             pmChip *sourceChip = sourceChips->data[chipNum]; // The source chip
    386             int numCells = pmChipCopy(targetChip, sourceChip); // Number of cells copied
    387             psTrace(__func__, 5, "Copied %d cells for chip %s\n", numCells, chipName);
    388             numChips++;
    389         }
    390     }
    391 
    392     // Update the concepts
    393     psMetadataCopy(target->concepts, source->concepts);
    394 
    395     return numChips;
    396 }
    397 
    398 int pmChipCopy(pmChip *target,          // The target chip
    399                pmChip *source           // The source chip, to be copied
    400               )
    401 {
    402     assert(target);
    403     assert(source);
    404 
    405     psArray *targetCells = target->cells; // The target cells
    406     psArray *sourceCells = source->cells; // The source cells
    407     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 1
    414     // Copy any headers
    415     if (target->hdu && !target->hdu->phu) {
    416         pmHDU *sourceHDU = pmHDUFromChip(source);
    417         target->hdu->header = psMetadataCopy(target->hdu->header, sourceHDU->header);
    418     }
    419     #endif
    420 
    421     int numCells = 0;                   // Number of cells copied
    422     for (int i = 0; i < targetCells->n; i++) {
    423         pmCell *targetCell = targetCells->data[i]; // The target cell
    424         const char *cellName = psMetadataLookupStr(NULL, targetCell->concepts, "CELL.NAME"); // Name of cell
    425         int cellNum = pmChipFindCell(source, cellName); // Number of cell with that name
    426         if (cellNum >= 0) {
    427             pmCell *sourceCell = sourceCells->data[cellNum]; // The source cell
    428             int numReadouts = pmCellCopy(targetCell, sourceCell); // Number of readouts copied
    429             psTrace(__func__, 5, "Copied %d readouts for cell %s\n", numReadouts, cellName);
    430             numCells++;
    431         }
    432     }
    433 
    434     // Update the concepts
    435     psMetadataCopy(target->concepts, source->concepts);
    436 
    437     return numCells;
    438 
    439 }
    440 
    441 int pmCellCopy(pmCell *target,          // The target cell
    442                pmCell *source           // The source cell, to be copied
    443               )
    444 {
    445     assert(target);
    446     assert(source);
    447 
    448382    psArray *sourceReadouts = source->readouts; // The source readouts
    449383    int numReadouts = sourceReadouts->n; // Number of readouts copied
    450384
    451     #if 1
    452385    // Copy any headers
    453386    if (target->hdu && !target->hdu->phu) {
     
    455388        target->hdu->header = psMetadataCopy(target->hdu->header, sourceHDU->header);
    456389    }
    457     #endif
    458390
    459391    pmHDU *hdu = pmHDUFromCell(target); // The target HDU; we need to fix this up
    460392    if (!hdu->images) {
    461         generateHDU(target, source);
     393        generateHDU(target, source, xBin, yBin);
    462394    }
    463395    if (!hdu->header) {
     
    496428            psFree(trimsecString);
    497429        } 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            }
    499434            targetReadout->image = psImageSubset(hdu->images->data[i], *trimsec);
    500435        }
     
    519454                psFree(biassecString);
    520455            } 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                }
    522460                psImage *newBias = psImageSubset(hdu->images->data[i], *biassec);
    523461                psListAdd(targetReadout->bias, PS_LIST_TAIL, newBias);
     
    565503    }
    566504
     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
    567511    return numReadouts;
    568512}
     513
     514static 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
     558static 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
     605int 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
     612int 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
     619int 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
     627int 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
     635int 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
     643int 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  
    22#define PM_FPA_COPY_H
    33
     4// Copy the FPA components, including the pixels
    45int pmFPACopy(pmFPA *target,            // The target FPA
    56              pmFPA *source             // The source FPA, to be copied
     
    1213              );
    1314
     15// Versions that copy the structure and not the pixels; they also allow binning
     16int 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                      );
     20int 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                       );
     24int 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
    1430#endif
Note: See TracChangeset for help on using the changeset viewer.