IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 5651


Ignore:
Timestamp:
Nov 30, 2005, 6:03:51 PM (20 years ago)
Author:
Paul Price
Message:

pmFPAMorph compiles

Location:
trunk/archive/scripts/src/phase2
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/archive/scripts/src/phase2/Makefile.am

    r5632 r5651  
    1212        pmFPAConceptsSet.c \
    1313        pmFPAConstruct.c \
     14        pmFPAMorph.c \
    1415        pmFPARead.c \
    1516        pmFPAWrite.c \
  • trunk/archive/scripts/src/phase2/ipprc.config

    r5621 r5651  
    88### Setups for each camera system
    99CAMERAS         METADATA
    10 #       MEGACAM_SINGLE  STR     megacam_single.config
    1110        MEGACAM_RAW     STR     megacam_raw.config
     11        GPC1_RAW        STR     gpc1_raw.config
    1212        MEGACAM_SPLICE  STR     megacam_splice.config
    13         GPC1_RAW        STR     gpc1_raw.config
    1413#       LRIS_BLUE       STR     lris_blue.config
    1514#       LRIS_RED        STR     lris_red.config
     
    2322TRACE           METADATA                        # Trace levels
    2423        pap                     S32     10
     24        pmFPAPrint              S32     10
    2525#       pmConfigRead            S32     10
    2626#       pmFPAWriteMask          S32     10
  • trunk/archive/scripts/src/phase2/papPhase2.c

    r5633 r5651  
    1717#include "pmSubtractBias.h"
    1818#include "pmChipMosaic.h"
     19#include "pmFPAMorph.h"
    1920
    2021// Phase 2 needs to:
     
    287288    }
    288289
     290    pmFPAPrint(input);
     291    exit(1);
     292
    289293#ifdef PRODUCTION
    290294    psFitsClose(inputFile);
     
    296300    pmFPAReadMask(input, inputFile);
    297301    pmFPAReadWeight(input, inputFile);
    298 #else
     302//#else
    299303    {
    300304        // Generate mask and weight frame
     
    827831    psLogMsg("phase2", PS_LOG_INFO, "Processing completed after %f sec.\n", psTimerMark("phase2"));
    828832
     833
     834#if 1
     835    // Testing pmFPAMorph
     836    psMetadata *newCamera = psMetadataConfigParse(NULL, NULL, "megacam_splice.config", true);
     837    pmFPA *newFPA = pmFPAConstruct(newCamera);
     838    pmFPAMorph(newFPA, input, true, 0, 0);
     839    psFits *newFile = psFitsAlloc("morph.fits");
     840    pmFPAWrite(newFile, newFPA, database);
     841    psFree(newFile);
     842    psFree(newFPA);
     843#endif
     844
     845#if 0
    829846    // Write the output
    830847    pmFPAWrite(outputFile, input, database);
    831848    pmFPAWriteMask(input, outputFile);
    832849    pmFPAWriteWeight(input, outputFile);
     850#endif
    833851
    834852    psLogMsg("phase2", PS_LOG_INFO, "Output completed after %f sec.\n", psTimerMark("phase2"));
  • trunk/archive/scripts/src/phase2/phase2.config

    r5621 r5651  
    66BIAS            BOOL    FALSE           # Bias subtraction
    77DARK            BOOL    FALSE           # Dark subtraction
    8 OVERSCAN        BOOL    TRUE            # Overscan subtraction
     8OVERSCAN        BOOL    FALSE           # Overscan subtraction
    99FLAT            BOOL    FALSE           # Flat-field normalisation
    1010FRINGE          BOOL    FALSE           # Fringe subtraction
  • trunk/archive/scripts/src/phase2/pmConfig.c

    r5633 r5651  
    283283    } // Done looking at all cameras
    284284    if (! winner) {
    285         psError(PS_ERR_IO, true, "Unable to find an camera that matches input FITS header!\n");
     285        psError(PS_ERR_IO, true, "Unable to find a camera that matches input FITS header!\n");
    286286    }
    287287
  • trunk/archive/scripts/src/phase2/pmFPA.h

    r5564 r5651  
    7575    psImage *mask;                     // Mask for image
    7676    psImage *weight;                   // Weight for image
     77#if 0
    7778    psList *bias;                      // List of bias section (sub-)images
     79#endif
    7880    psMetadata *analysis;              // Readout-level analysis metadata
    7981    pmCell *parent;                    // Parent cell
  • trunk/archive/scripts/src/phase2/pmFPAConstruct.c

    r5633 r5651  
    272272    )
    273273{
    274     psTrace(__func__, 0, "FPA:\n");
     274    psTrace(__func__, 1, "FPA:\n");
    275275    if (fpa->hdu) {
    276         psTrace(__func__, 1, "---> FPA is extension %s.\n", fpa->hdu->extname);
     276        psTrace(__func__, 2, "---> FPA is extension %s.\n", fpa->hdu->extname);
    277277        if (! fpa->hdu->images) {
    278             psTrace(__func__, 1, "---> NO PIXELS for extension %s\n", fpa->hdu->extname);
    279         }
    280     }
     278            psTrace(__func__, 2, "---> NO PIXELS for extension %s\n", fpa->hdu->extname);
     279        }
     280    }
     281    psMetadataPrint(fpa->concepts, 2);
    281282
    282283    psArray *chips = fpa->chips;        // Array of chips
    283284    // Iterate over the FPA
    284285    for (int i = 0; i < chips->n; i++) {
    285         psTrace(__func__, 1, "Chip: %d\n", i);
     286        psTrace(__func__, 3, "Chip: %d\n", i);
    286287        pmChip *chip = chips->data[i]; // The chip
    287288        if (chip->hdu) {
    288             psTrace(__func__, 2, "---> Chip is extension %s.\n", chip->hdu->extname);
     289            psTrace(__func__, 4, "---> Chip is extension %s.\n", chip->hdu->extname);
    289290            if (! chip->hdu->images) {
    290                 psTrace(__func__, 2, "---> NO PIXELS for extension %s\n", chip->hdu->extname);
    291             }
    292         }
     291                psTrace(__func__, 4, "---> NO PIXELS for extension %s\n", chip->hdu->extname);
     292            }
     293        }
     294        psMetadataPrint(chip->concepts, 4);
     295
    293296        // Iterate over the chip
    294297        psArray *cells = chip->cells;   // Array of cells
    295298        for (int j = 0; j < cells->n; j++) {
    296             psTrace(__func__, 2, "Cell: %d\n", j);
     299            psTrace(__func__, 5, "Cell: %d\n", j);
    297300            pmCell *cell = cells->data[j]; // The cell
    298301            if (cell->hdu) {
    299                 psTrace(__func__, 3, "---> Cell is extension %s.\n", cell->hdu->extname);
     302                psTrace(__func__, 6, "---> Cell is extension %s.\n", cell->hdu->extname);
    300303                if (! cell->hdu->images) {
    301                     psTrace(__func__, 3, "---> NO PIXELS for extension %s\n", cell->hdu->extname);
    302                 }
    303             }
    304             psMetadataPrint(cell->concepts, 3);
    305             psTrace(__func__, 3, "Readouts:\n");
     304                    psTrace(__func__, 6, "---> NO PIXELS for extension %s\n", cell->hdu->extname);
     305                }
     306            }
     307            psMetadataPrint(cell->concepts, 6);
     308
     309            psTrace(__func__, 7, "Readouts:\n");
    306310            psArray *readouts = cell->readouts; // Array of readouts
    307311            for (int k = 0; k < readouts->n; k++) {
    308312                pmReadout *readout = readouts->data[k]; // The readout
    309313                psImage *image = readout->image; // The image
    310                 psTrace(__func__, 4, "Image: [%d:%d,%d:%d] (%dx%d)\n", image->col0, image->col0 +
     314                psTrace(__func__, 8, "Image: [%d:%d,%d:%d] (%dx%d)\n", image->col0, image->col0 +
    311315                        image->numCols, image->row0, image->row0 + image->numRows, image->numCols,
    312316                        image->numRows);
  • trunk/archive/scripts/src/phase2/pmFPAMorph.c

    r5633 r5651  
    33#include <assert.h>
    44#include "pslib.h"
    5 #include "papmodule.h"
     5
     6#include "papStuff.h"
     7#include "pmFPA.h"
     8#include "pmFPAMorph.h"
    69
    710#define MAX(x,y) ((x) > (y) ? (x) : (y))
     
    2326        }
    2427        break;
     28      case PS_TYPE_F32:
     29        for (int y = 0; y < image->numRows; y++) {
     30            for (int x = 0; x < image->numCols; x++) {
     31                flipped->data.F32[y][size - x - 1] = image->data.F32[y][x];
     32            }
     33        }
     34        break;
    2535      default:
    2636        psError(PS_ERR_IO, true, "Image type %x not yet supported for flip.\n", image->type.type);
     
    5161}
    5262
     63
     64#if 0
    5365// Return a list of the region strings and the method for interpreting them
    5466static psList *getRegions(psString *method, // Method for evaluating the regions
     
    6779    return regionStrings;
    6880}
     81#endif
     82
     83
     84// Splice an image into another image
     85static psRegion *spliceImage(psImage *target, // Target image onto which to splice
     86                             int *x0, int *y0, // Starting coordinates to splice to
     87                             psImage *source, // Source image from which to splice
     88                             const psRegion *from, // Region to splice from
     89                             int readdir, // Read direction
     90                             bool xFlip, bool yFlip // Flip x and y axes?
     91                        )
     92{
     93    psImage *toSplice = psImageSubset(source, *from); // Subimage, to splice into target
     94    if (xFlip) {
     95        int size = 0;           // Size of flipped image
     96        if (readdir == 1) {
     97            size = toSplice->numCols;
     98        } else if (readdir == 2) {
     99            size = target->numCols;
     100        }
     101        psImage *temp = xFlipImage(toSplice, size);
     102        psFree(toSplice);
     103        toSplice = temp;
     104    }
     105    if (yFlip) {
     106        int size = 0;           // Size of flipped image
     107        if (readdir == 1) {
     108            size = target->numRows;
     109        } else if (readdir == 2) {
     110            size = toSplice->numRows;
     111        }
     112        psImage *temp = yFlipImage(toSplice, size);
     113        psFree(toSplice);
     114        toSplice = temp;
     115    }
     116
     117    (void)psImageOverlaySection(target, toSplice, *x0, *y0, "=");
     118
     119    if (readdir == 1) {
     120        *x0 += toSplice->numCols;
     121    } else if (readdir == 2) {
     122        *y0 += toSplice->numRows;
     123    }
     124
     125    // Return the region where we pasted the image
     126    psRegion *outRegion = psAlloc(sizeof(psRegion));
     127    // Addding 1 to get FITS standard
     128    outRegion->x0 = *x0 + 1;
     129    outRegion->x1 = *x0 + toSplice->numCols;
     130    outRegion->y0 = *y0 + 1;
     131    outRegion->y1 = *y0 + toSplice->numRows;
     132
     133    psFree(toSplice);
     134    return outRegion;
     135}
     136
     137// Splice bias regions (overscans)
     138static bool spliceBias(psImage *splice, // Image to which to splice
     139                       int *x0, int *y0, // Starting position for splice
     140                       const pmCell *in, // Input cell
     141                       pmCell *out,     // Output cell
     142                       int xFlip, int yFlip, // Flip the image?
     143                       int readNum,     // Number of readout
     144                       int readdir      // Read direction
     145                       )
     146{
     147    psArray *readouts = in->readouts; // The readouts;
     148    pmReadout *readout = readouts->data[readNum]; // The readout of interest
     149    psList *inBiassecs = psMetadataLookupPtr(NULL, in->concepts, "CELL.BIASSEC"); // List of input biassecs
     150    psListIterator *inBiassecsIter = psListIteratorAlloc(inBiassecs, PS_LIST_HEAD, false);
     151    psRegion *inBiassec = NULL; // BIASSEC from list
     152    psList *outBiassecs = psListAlloc(NULL); // List of biassecs for output
     153    while (inBiassec = psListGetAndIncrement(inBiassecsIter)) {
     154        psRegion *outBiassec = spliceImage(splice, x0, y0, readout->image, inBiassec, readdir, xFlip,
     155                                           yFlip);
     156        psListAdd(outBiassecs, PS_LIST_TAIL, outBiassec);
     157    }
     158    psFree(inBiassecsIter);
     159    psMetadataAdd(out->concepts, PS_LIST_TAIL, "CELL.BIASSEC", PS_DATA_LIST | PS_META_REPLACE,
     160                  "BIASSEC from pmFPAMorph", outBiassecs);
     161   
     162    return true;
     163}
     164
    69165
    70166// Splice a list of cells together
     
    79175    psTrace(__func__, 5, "Splicing together all cells in the bucket.\n");
    80176
    81     if (inCells->size != outCells->size) {
     177    if (inCells->n != outCells->n) {
    82178        psError(PS_ERR_IO, true, "Sizes of input (%d) and output (%d) lists of cells don't match.\n",
    83                 inCells->size, outCells->size);
     179                inCells->n, outCells->n);
    84180        return NULL;
    85181    }
    86182
    87     int numCells = inCells->size;       // Number of cells
     183    int numCells = inCells->n;          // Number of cells
    88184    int readdir = 0;                    // Read direction for CCD; currently unknown
    89185    int numReadouts = 0;                // Number of readouts in a cell
     
    97193    psVector *yFlip = psVectorAlloc(numCells, PS_TYPE_U8); // Do we need to flip in y?
    98194
     195
     196    // We go through the cells to make sure everything's kosher, and to get the sizes.
    99197    psListIterator *inCellsIter = psListIteratorAlloc(inCells, PS_LIST_HEAD, false); // Iterator for cells
    100     papCell *inCell = NULL;             // Cell from list of input cells
     198    pmCell *inCell = NULL;              // Cell from list of input cells
    101199    psListIterator *outCellsIter = psListIteratorAlloc(outCells, PS_LIST_HEAD, false); // Iterator for cells
    102200    int cellNum = 0;                    // Cell number;
     
    104202        psArray *readouts = inCell->readouts;   // The readouts comprising the cell
    105203
    106         // Check the read direction
     204        // Get and check the read direction
    107205        int cellReaddir = psMetadataLookupS32(NULL, inCell->concepts, "CELL.READDIR");
    108206        if (readdir == 0) {
     207            // Zero means unknown; set it.
    109208            readdir = cellReaddir;
    110209        } else if (readdir != cellReaddir) {
    111             psError(PS_ERR_IO, true, "Trying to splice cells with different read directions (%d vs %d)\n",
    112                     readdir, cellReaddir);
     210            psError(PS_ERR_IO, true, "Trying to splice cells with different read directions (%d vs %d). I "
     211                    "don't know how to do that!\n", readdir, cellReaddir);
    113212            // XXX Clean up before returning
    114213            return NULL;
    115214        }
    116         // Check the number of readouts
     215
     216        // Get and check the number of readouts
    117217        if (! spliced) {
    118218            numReadouts = readouts->n;
     
    131231        }
    132232
    133         // Get the cell parities
    134         papCell *outCell = psListGetAndIncrement(outCellsIter); // Corresponding output cell
    135         int xParityIn = psMetadataLookupS32(NULL, inCell, "CELL.XPARITY");
    136         int yParityIn = psMetadataLookupS32(NULL, inCell, "CELL.YPARITY");
    137         int xParityOut = psMetadataLookupS32(NULL, outCell, "CELL.XPARITY");
    138         int yParityOut = psMetadataLookupS32(NULL, outCell, "CELL.YPARITY");
     233        // Get and check the cell parities
     234        pmCell *outCell = psListGetAndIncrement(outCellsIter);  // Corresponding output cell
     235        int xParityIn = psMetadataLookupS32(NULL, inCell->concepts, "CELL.XPARITY");
     236        int yParityIn = psMetadataLookupS32(NULL, inCell->concepts, "CELL.YPARITY");
     237        int xParityOut = psMetadataLookupS32(NULL, outCell->concepts, "CELL.XPARITY");
     238        int yParityOut = psMetadataLookupS32(NULL, outCell->concepts, "CELL.YPARITY");
    139239        if (xParityIn == 0 || xParityOut == 0 || yParityIn == 0 || yParityOut == 0) {
    140240            psError(PS_ERR_IO, false, "Unable to determine parity of cell!\n");
     
    159259        // Calculate the sizes of the spliced images
    160260        for (int i = 0; i < numReadouts; i++) {
    161             papReadout *readout = readouts->data[i]; // The readout of interest
     261            pmReadout *readout = readouts->data[i]; // The readout of interest
    162262            psImage *image = readout->image; // The image pixels
    163             psList *overscans = readout->overscans; // The overscan regions
    164263
    165264            // Check image type
     
    173272            }
    174273
     274            psRegion *trimsec = psMetadataLookupPtr(NULL, inCell->concepts, "CELL.TRIMSEC"); // Trim section
     275            psList *biassecs = psMetadataLookupPtr(NULL, inCell->concepts, "CELL.BIASSEC"); // Bias section
     276            psListIterator *biassecsIter = psListIteratorAlloc(biassecs, PS_LIST_HEAD, false); // Iterator
     277            psRegion *biassec = NULL;   // Bias section from list iteration
     278
    175279            // Get the size of the spliced image
    176280            if (readdir == 1) {
    177                 psTrace(__func__, 9, "Image size: %dx%d\n", image->numCols, image->numRows);
    178                 xSize->data.S32[i] += image->numCols;
    179                 ySize->data.S32[i] = MAX(ySize->data.S32[i], image->numRows);
     281                xSize->data.S32[i] += trimsec->x1 - trimsec->x0;
     282                ySize->data.S32[i] = MAX(ySize->data.S32[i], trimsec->y1 - trimsec->y0);
     283                while (biassec = psListGetAndIncrement(biassecsIter)) {
     284                    xSize->data.S32[i] += biassec->x1 - biassec->x0;
     285                    ySize->data.S32[i] = MAX(ySize->data.S32[i], biassec->y1 - biassec->y0);
     286                }
    180287            } else if (readdir == 2) {
    181                 psTrace(__func__, 9, "Image size: %dx%d\n", image->numCols, image->numRows);
    182                 ySize->data.S32[i] += image->numRows;
    183                 xSize->data.S32[i] = MAX(xSize->data.S32[i], image->numCols);
     288                ySize->data.S32[i] += trimsec->y1 - trimsec->y0;
     289                xSize->data.S32[i] = MAX(xSize->data.S32[i], trimsec->x1 - trimsec->x0);
     290                while (biassec = psListGetAndIncrement(biassecsIter)) {
     291                    ySize->data.S32[i] += biassec->y1 - biassec->y0;
     292                    xSize->data.S32[i] = MAX(ySize->data.S32[i], biassec->x1 - biassec->x0);
     293                }
    184294            } else {
    185295                psError(PS_ERR_IO, true, "Invalid read direction: %d\n", readdir);
     
    187297                return NULL;
    188298            }
    189 
    190             psListIterator *overscansIter = psListIteratorAlloc(overscans, PS_LIST_HEAD, false);
    191             psImage *overscan = NULL;   // Overscan image
    192             while (overscan = psListGetAndIncrement(overscansIter)) {
    193 
    194                 // Check image type
    195                 if (type == 0) {
    196                     type = image->type.type;
    197                 } else if (image->type.type != type) {
    198                     psError(PS_ERR_IO, true, "Trying to splice readouts with different image types "
    199                             "(%d vs %d)\n", type, image->type.type);
    200                     // XXX Clean up before returning
    201                     return NULL;
    202                 }
    203 
    204                 // Get the size of the spliced image
    205                 if (readdir == 1) {
    206                     psTrace(__func__, 9, "Overscan size: %dx%d\n", image->numCols, image->numRows);
    207                     xSize->data.S32[i] += overscan->numCols;
    208                     ySize->data.S32[i] = MAX(ySize->data.S32[i], overscan->numRows);
    209                 } else if (readdir == 2) {
    210                     psTrace(__func__, 9, "Overscan size: %dx%d\n", image->numCols, image->numRows);
    211                     ySize->data.S32[i] += overscan->numRows;
    212                     xSize->data.S32[i] = MAX(xSize->data.S32[i], overscan->numCols);
    213                 }
    214             }
    215 
    216         }
     299            psFree(biassecsIter);
     300        }
     301
     302        // Copy the concepts over
     303        psMetadataCopy(outCell->concepts, inCell->concepts);
    217304    }
    218305    psFree(inCellsIter);
    219306    psFree(outCellsIter);
     307
    220308
    221309    // Make sure all the readouts have the same size
     
    234322    for (int i = 0; i < numReadouts; i++) {
    235323        psImage *splice = psImageAlloc(numCols, numRows, type); // The spliced image
    236 
     324        int x0 = 0, y0 = 0;             // Position at which the splice begins
     325
     326        // Position-dependent overscans first
     327        if (posDep) {
     328            for (int cellNum = 0; cellNum < inCells->n / 2; cellNum++) {
     329                pmCell *inCell = psListGet(inCells, cellNum); // Input cell of interest
     330                pmCell *outCell = psListGet(outCells, cellNum); // Output cell of interest
     331                spliceBias(splice, &x0, &y0, inCell, outCell, xFlip->data.U8[i], yFlip->data.U8[i], i,
     332                           readdir);
     333            }
     334        }
     335
     336        // Then the images
    237337        psListIterator *inCellsIter = psListIteratorAlloc(inCells, PS_LIST_HEAD, false);// Iterator for cells
    238         papCell *inCell = NULL;         // Cell from the list of cells
     338        pmCell *inCell = NULL;          // Cell from the list of cells
    239339        psListIterator *outCellsIter = psListIteratorAlloc(outCells, PS_LIST_HEAD, false); // Iterator
    240340        int cellNum = 0;                // Cell number
    241         int x0 = 0, y0 = 0;             // Position at which the splice begins
    242341        while (inCell = psListGetAndIncrement(inCellsIter)) {
    243342            psArray *readouts = inCell->readouts; // The readouts comprising the cell
    244             papReadout *readout = readouts->data[i]; // The specific readout of interest
    245             psImage *image = readout->image; // The image pixels
    246             psList *overscans = readout->overscans; // The overscan regions
    247             papCell *outCell = psListGetAndIncrement(outCellsIter); // Output cell
    248            
    249             psImage *toSplice = psMemIncrRefCounter(image); // Image to splice in
    250             if (xFlip->data.U8[cellNum]) {
    251                 int size = 0;           // Size of flipped image
    252                 if (readdir == 1) {
    253                     size = toSplice->numCols;
    254                 } else if (readdir == 2) {
    255                     size = numCols;
    256                 }
    257                 psImage *temp = xFlipImage(toSplice, size);
    258                 psFree(toSplice);
    259                 toSplice = temp;
    260             }
    261             if (yFlip->data.U8[cellNum]) {
    262                 int size = 0;           // Size of flipped image
    263                 if (readdir == 1) {
    264                     size = numRows;
    265                 } else if (readdir == 2) {
    266                     size = toSplice->numRows;
    267                 }
    268                 psImage *temp = yFlipImage(toSplice, size);
    269                 psFree(toSplice);
    270                 toSplice = temp;
    271             }
    272 
    273             (void)psImageOverlaySection(splice, toSplice, x0, y0, "=");
    274 
    275             if (readdir == 1) {
    276                 x0 += toSplice->numCols;
    277             } else if (readdir == 2) {
    278                 y0 += toSplice->numRows;
    279             }
    280 
    281             // Update the TRIMSEC for the output cell
    282             psString trimsecString = psMetadataLookupString(NULL, outCell, "CELL.TRIMSEC");
    283             psString trimsecMethod = NULL; // Method of determining trimsec
    284             psList *trimsecs = getRegions(&trimsecMethod, trimsecString); // List of trimsecs
    285             if (strncmp(trimsecMethod, "HEADER", 6) != 0 && strncmp(trimsecMethod, "HD", 2) != 0) {
    286                 psError(PS_ERR_IO, true, "Can only splice cells if the CELL.TRIMSEC (= %s) is determined "
    287                         "from the header.\n", trimsecString);
    288                 // XXX Clean up before returning
    289                 return NULL;
    290             }
    291             if (trimsecs->size != 1) {
    292                 psError(PS_ERR_IO, true, "Multiple headers specified for CELL.TRIMSEC: %s\n", trimsecString);
    293                 // XXX Clean up before returning
    294                 return NULL;
    295             }
    296             psString trimsecName = trimsecs->head->data; // Grab header for TRIMSEC off the list
    297             psFree(trimsecs);
    298 
    299             // TRIMSEC region; add 1 to get FITS standard
    300             psRegion trimsecRegion = {x0 + 1, x0 + toSplice->numCols, y0 + 1, y0 + toSplice->numRows};
    301             psString trimsecValue = psRegionToString(trimsecRegion);
    302             psMetadataAddStr(header, PS_LIST_TAIL, trimsecName, 0, "TRIMSEC from pmFPAMorph", trimsecValue);
    303             // XXX Does psMetadataAddStr overwrite a previous value?
    304 
    305             // Repeat the above for each overscan (flip, overlay, update BIASSEC)
    306             // Prepare the BIASSEC
    307             psString biassecString = psMetadataLookupString(NULL, outCell, "CELL.BIASSEC");
    308             psString biassecMethod = NULL; // Method of determining biassec
    309             psList *biassecs = getRegions(&biassecMethod, biassecString); // List of biassecs
    310             if (strncmp(biassecMethod, "HEADER", 6) != 0 && strncmp(biassecMethod, "HD", 2) != 0) {
    311                 psError(PS_ERR_IO, true, "Can only splice cells if the CELL.BIASSEC (= %s) is determined "
    312                         "from the header.\n", biassecString);
    313                 // XXX Clean up before returning
    314                 return NULL;
    315             }
    316             if (biassecs->size != overscans->size);
    317 
    318             psListIterator *overscansIter = psListIteratorAlloc(overscans, PS_LIST_HEAD, false);
    319             psImage *overscan = NULL;   // Overscan from list
    320             psListIterator *biassecsIter = psListIteratorAlloc(biassecs, PS_LIST_HEAD, false);
    321             psString biassecName = NULL;// FITS header keyword for biassec
    322             while ((overscan = psListGetAndIncrement(overscansIter)) &&
    323                    (biassecName = psListGetAndIncrement(biassecsIter))) {
    324                 // Splice the overscan on
    325                 psImage *toSplice = psMemIncrRefCounter(overscan); // Image to splice in
    326                 if (xFlip->data.U8[cellNum]) {
    327                     int size = 0;       // Size of flipped image
    328                     if (readdir == 1) {
    329                         size = toSplice->numCols;
    330                     } else if (readdir == 2) {
    331                         size = numCols;
    332                     }
    333                     psImage *temp = xFlipImage(toSplice, size);
    334                     psFree(toSplice);
    335                     toSplice = temp;
    336                 }
    337                 if (yFlip->data.U8[cellNum]) {
    338                     int size = 0;       // Size of flipped image
    339                     if (readdir == 1) {
    340                         size = numRows;
    341                     } else if (readdir == 2) {
    342                         size = toSplice->numRows;
    343                     }
    344                     psImage *temp = yFlipImage(toSplice, size);
    345                     psFree(toSplice);
    346                     toSplice = temp;
    347                 }
    348                
    349                 (void)psImageOverlaySection(splice, toSplice, x0, y0, "=");
    350 
    351                 if (readdir == 1) {
    352                     x0 += toSplice->numCols;
    353                 } else if (readdir == 2) {
    354                     y0 += toSplice->numRows;
    355                 }
    356 
    357                 // Update the header
    358                 psRegion biassecRegion = {x0 + 1, x0 + toSplice->numCols, y0 + 1, y0 + toSplice->numRows};
    359                 psString biassecValue = psRegionToString(biassecRegion);
    360                 psMetadataAddStr(header, PS_LIST_TAIL, biassecName, 0, "BIASSEC from pmFPAMorph",
    361                                  biassecValue);
    362             }
    363             psFree(overscansIter);
    364             psFree(biassecsIter);
    365             psFree(biassecs);
    366         } // Iterating over input cells
     343            pmReadout *readout = readouts->data[i]; // The specific readout of interest
     344            pmCell *outCell = psListGetAndIncrement(outCellsIter); // Output cell
     345            psRegion *inTrimsec = psMetadataLookupPtr(NULL, inCell->concepts, "CELL.TRIMSEC"); // TRIMSEC
     346            psRegion *outTrimsec = spliceImage(splice, &x0, &y0, readout->image, inTrimsec, readdir,
     347                                               xFlip->data.U8[cellNum], yFlip->data.U8[cellNum]);
     348
     349            // Update the output TRIMSEC
     350            psMetadataAdd(outCell->concepts, PS_LIST_TAIL, "CELL.TRIMSEC", PS_DATA_UNKNOWN | PS_META_REPLACE,
     351                             "TRIMSEC from pmFPAMorph", outTrimsec);
     352        }
     353        psFree(inCellsIter);
     354        psFree(outCellsIter);
     355
     356        // Then the biases
     357        if (! posDep) {
     358            // Need to only do half the biases
     359            for (int cellNum = inCells->n / 2; cellNum < inCells->n; cellNum++) {
     360                pmCell *inCell = psListGet(inCells, cellNum); // Input cell of interest
     361                pmCell *outCell = psListGet(outCells, cellNum); // Output cell of interest
     362                spliceBias(splice, &x0, &y0, inCell, outCell, xFlip->data.U8[i], yFlip->data.U8[i], i,
     363                           readdir);
     364            }
     365        } else {
     366            // Need to do all the biases
     367            for (int cellNum = 0; cellNum < inCells->n; cellNum++) {
     368                pmCell *inCell = psListGet(inCells, cellNum); // Input cell of interest
     369                pmCell *outCell = psListGet(outCells, cellNum); // Output cell of interest
     370                spliceBias(splice, &x0, &y0, inCell, outCell, xFlip->data.U8[i], yFlip->data.U8[i], i,
     371                           readdir);
     372            }
     373        }
    367374
    368375        spliced->data[i] = splice;
     376
    369377    } // Iterating over readouts
    370378
     
    426434            psListAdd(sourceCells, PS_LIST_TAIL, fromCell);
    427435
    428             int xParityIn = psMetadataLookupS32(NULL, fromCell, "CELL.XPARITY");
    429             int yParityIn = psMetadataLookupS32(NULL, fromCell, "CELL.YPARITY");
    430             int xParityOut = psMetadataLookupS32(NULL, toCell, "CELL.XPARITY");
    431             int yParityOut = psMetadataLookupS32(NULL, toCell, "CELL.YPARITY");
     436#if 1
     437            int xParityIn = psMetadataLookupS32(NULL, fromCell->concepts, "CELL.XPARITY");
     438            int yParityIn = psMetadataLookupS32(NULL, fromCell->concepts, "CELL.YPARITY");
     439            int xParityOut = psMetadataLookupS32(NULL, toCell->concepts, "CELL.XPARITY");
     440            int yParityOut = psMetadataLookupS32(NULL, toCell->concepts, "CELL.YPARITY");
    432441            psTrace(__func__, 3, "Chip %d, cell %d: in (%d,%d) out (%d,%d)\n", i, j, xParityIn, yParityIn,
    433442                    xParityOut, yParityOut);
     443#endif
    434444
    435445            // Copy the cell contents over
    436446            toCell->readouts = psMemIncrRefCounter(fromCell->readouts);
    437447           
    438             if (toCell->private && strlen(toCell->private->extname) > 0) {
     448            if (toCell->hdu && strlen(toCell->hdu->extname) > 0) {
    439449                // Splice the component cells
    440                 p_pmHDU *hdu = toCell->private;
     450                p_pmHDU *hdu = toCell->hdu;
    441451                if (! hdu->header) {
    442452                    hdu->header = psMetadataAlloc();
    443453                }
    444                 hdu->pixels = spliceCells(hdu->header, targetCells, sourceCells, positionDependent);
     454                hdu->images = spliceCells(targetCells, sourceCells, positionDependent);
    445455                // Purge the lists
    446456                while (psListRemove(targetCells, PS_LIST_TAIL));
     
    450460        }
    451461
    452         if (toChip->private && strlen(toChip->private->extname) > 0) {
     462        if (toChip->hdu && strlen(toChip->hdu->extname) > 0) {
    453463            // Splice the component cells
    454             p_pmHDU *hdu = toChip->private;
     464            p_pmHDU *hdu = toChip->hdu;
    455465            if (! hdu->header) {
    456466                hdu->header = psMetadataAlloc();
    457467            }
    458             hdu->pixels = spliceCells(hdu->header, targetCells, sourceCells);
     468            hdu->images = spliceCells(targetCells, sourceCells, positionDependent);
    459469            // Purge the lists
    460470            while (psListRemove(targetCells, PS_LIST_TAIL));
     
    464474    }
    465475
     476    if (toFPA->hdu && strlen(toFPA->hdu->extname) > 0) {
     477        // Splice the component cells
     478        p_pmHDU *hdu = toFPA->hdu;
     479        if (! hdu->header) {
     480            hdu->header = psMetadataAlloc();
     481        }
     482        hdu->images = spliceCells(targetCells, sourceCells, positionDependent);
     483        // Purge the lists
     484        while (psListRemove(targetCells, PS_LIST_TAIL));
     485        while (psListRemove(sourceCells, PS_LIST_TAIL));
     486    }
     487
    466488    return true;
    467489}
    468 
  • trunk/archive/scripts/src/phase2/pmFPAMorph.h

    r5106 r5651  
    33
    44// Morph one focal plane representation into another
    5 bool pmFPAMorph(papFPA *toFPA,          // FPA structure to which to morph
    6                 papFPA *fromFPA,        // FPA structure from which to morph
     5bool pmFPAMorph(pmFPA *toFPA,           // FPA structure to which to morph
     6                pmFPA *fromFPA,         // FPA structure from which to morph
     7                bool positionDependent, // Is the position of the overscan dependent on the position?
    78                int chipNum,            // Chip number, in case the scopes are different
    89                int cellNum             // Cell number, in case the scopes are different
  • trunk/archive/scripts/src/phase2/psAdditionals.c

    r5633 r5651  
    33#include "pslib.h"
    44#include "psAdditionals.h"
     5
     6
     7psMetadata *psMetadataCopy(psMetadata *out,
     8                           const psMetadata *in)
     9{
     10    PS_ASSERT_PTR_NON_NULL(in,NULL);
     11    if (out ==  NULL) {
     12        out = psMetadataAlloc();
     13    }
     14    psMetadataItem *inItem = NULL;
     15    psMetadataIterator *iter = psMetadataIteratorAlloc(*(psMetadata**)&in, PS_LIST_HEAD, NULL);
     16    unsigned long numPointers = 0;      // Number of pointers we were forced to copy
     17    while (inItem = psMetadataGetAndIncrement(iter)) {
     18        psMetadataItem *outItem = NULL;
     19
     20        // Need to look for MULTI, which won't be picked up using the iterator.
     21        psMetadataItem *multiCheckItem = psMetadataLookup(in, inItem->name);
     22        int multiFlag = 0;              // Flag to indicate MULTI or not
     23        if (multiCheckItem->type == PS_DATA_METADATA_MULTI) {
     24            multiFlag = PS_DATA_METADATA_MULTI;
     25        }
     26
     27#define PS_METADATA_COPY_CASE(NAME,TYPE) \
     28          case PS_TYPE_##NAME: \
     29            psMetadataAdd(out, PS_LIST_TAIL, inItem->name, PS_TYPE_##NAME | multiFlag, inItem->comment, \
     30                          inItem->data.TYPE); \
     31            break;
     32
     33        switch (inItem->type) {
     34            // Numerical types
     35            PS_METADATA_COPY_CASE(BOOL,B);
     36            PS_METADATA_COPY_CASE(S8, S8);
     37            PS_METADATA_COPY_CASE(S16, S16);
     38            PS_METADATA_COPY_CASE(S32, S32);
     39            PS_METADATA_COPY_CASE(U8, U8);
     40            PS_METADATA_COPY_CASE(U16, U16);
     41            PS_METADATA_COPY_CASE(U32, U32);
     42            PS_METADATA_COPY_CASE(F32, F32);
     43            PS_METADATA_COPY_CASE(F64, F64);
     44
     45            // String: relying on the fact that this will copy the string, not point at it.
     46          case PS_DATA_STRING:
     47            psMetadataAdd(out, PS_LIST_TAIL, inItem->name, PS_DATA_STRING | multiFlag, inItem->comment,
     48                          inItem->data.V);
     49            break;
     50
     51            // Metadata: copy the next level and stuff that in too
     52          case PS_DATA_METADATA:
     53            {
     54                psMetadata *metadata = psMetadataCopy(NULL, inItem->data.md);
     55                psMetadataAdd(out, PS_LIST_TAIL, inItem->name, PS_DATA_METADATA | multiFlag, inItem->comment,
     56                              metadata);
     57                break;
     58            }
     59            // Other kinds of pointers
     60          default:
     61            numPointers++;
     62            psMetadataItemAlloc(inItem->name, inItem->type, inItem->comment, inItem->data.V);
     63            break;
     64        }
     65    }
     66    psFree(iter);
     67
     68    if (numPointers > 0) {
     69        psLogMsg(__func__, PS_LOG_WARN, "Forced to copy %d pointers when copying metadata.  Updating the "
     70                 "copied psMetadata will affect the original!\n");
     71    }
     72
     73    return out;
     74}
     75
    576
    677psMetadata *psMetadataLookupMD(bool *status, const psMetadata *md, const char *key)
  • trunk/archive/scripts/src/phase2/psAdditionals.h

    r5104 r5651  
    33
    44#include "pslib.h"
     5
     6// Deep copy of metadata
     7psMetadata *psMetadataCopy(psMetadata *out, const psMetadata *in);
    58
    69// Get a value from the metadata that we believe should be metadata.
Note: See TracChangeset for help on using the changeset viewer.