IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 30, 2006, 10:08:30 AM (20 years ago)
Author:
Paul Price
Message:

pmFPACopy now working

File:
1 edited

Legend:

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

    r6720 r6734  
    117117            *xSize = MAX(trimsec->x1, *xSize);
    118118            *ySize = MAX(trimsec->y1, *ySize);
     119        } else {
     120            psFree(cellsIter);
     121            return false;
    119122        }
    120123        psList *biassecs = psMetadataLookupPtr(&mdok, cell->concepts, "CELL.BIASSEC"); // Bias sections
     
    126129                    *xSize = MAX(biassec->x1, *xSize);
    127130                    *ySize = MAX(biassec->y1, *ySize);
     131                } else {
     132                    psFree(biassecsIter);
     133                    psFree(cellsIter);
     134                    return false;
    128135                }
    129136            }
     
    133140    psFree(cellsIter);
    134141
    135     return (*xSize == 0 || *ySize == 0);
     142    return (*xSize != 0 && *ySize != 0);
    136143}
    137144
     
    145152    switch (readdir) {
    146153    case 1:                           // Read direction is rows
    147         region = psRegionSet(*position, image->row0, *position + image->numCols,
     154        region = psRegionSet(*position, *position + image->numCols, image->row0,
    148155                             image->row0 + image->numRows);
    149156        *position += image->numCols;
    150157        break;
    151158    case 2:                           // Read direction is columns
    152         region = psRegionSet(image->col0, *position, image->col0 + image->numCols,
     159        region = psRegionSet(image->col0, image->col0 + image->numCols, *position,
    153160                             *position + image->numRows);
    154161        *position += image->numRows;
     
    209216    int numCells = targets->n;          // Number of cells
    210217    int cellNum = 0;                    // The cell number
    211     int position;                       // Position on the image
     218    int position = 0;                   // Position on the image
    212219    bool mdok = true;                   // Status of MD lookup
    213220
     
    218225    while ((target = psListGetAndIncrement(targetsIter)) && (source = psListGetAndIncrement(sourcesIter)) &&
    219226            !done) {
    220         if (cellNum < numCells/2) {
     227        if (cellNum <= numCells/2 - 1) {
    221228            doBiasSections(&position, target, source);
     229            cellNum++;
    222230        } else {
    223231            done = true;
     
    249257
    250258    // A final run through to do the RHS biases
    251     psListIteratorSet(targetsIter, numCells/2);
    252     psListIteratorSet(sourcesIter, numCells/2);
     259    psListIteratorSet(targetsIter, cellNum);
     260    psListIteratorSet(sourcesIter, cellNum);
    253261    while ((target = psListGetAndIncrement(targetsIter)) && (source = psListGetAndIncrement(sourcesIter))) {
    254262        doBiasSections(&position, target, source);
     
    299307    // Get the size of the HDU, either from existing trimsec and biassec, or generate these and try again
    300308    int xSize = 0, ySize = 0;           // Size of HDU
    301     if (!sizeHDU(&xSize, &ySize, targetCells) || !(generateTrimBias(targetCells, sourceCells) &&
     309    #if 1
     310
     311    if (!sizeHDU(&xSize, &ySize, targetCells) && !(generateTrimBias(targetCells, sourceCells) &&
    302312            sizeHDU(&xSize, &ySize, targetCells))) {
    303313        psError(PS_ERR_IO, true, "Unable to determine size of HDU!\n");
    304314        return false;
    305315    }
     316    #else
     317    if (!sizeHDU(&xSize, &ySize, targetCells)) {
     318        if (generateTrimBias(targetCells, sourceCells)) {
     319            if (!sizeHDU(&xSize, &ySize, targetCells)) {
     320                psError(PS_ERR_IO, true, "Unable to determine size of HDU!\n");
     321                return false;
     322            }
     323        } else {
     324            psError(PS_ERR_IO, true, "Unable to determine size of HDU!\n");
     325            return false;
     326        }
     327    }
     328    #endif
    306329
    307330    hdu->images = psArrayAlloc(numReadouts);
     
    314337    return true;
    315338}
    316 
    317 
    318 #define UPDATE_CASE(TYPENAME,TYPE) \
    319 case TYPENAME: targetItem->data.TYPE = sourceItem->data.TYPE; \
    320 break;
    321 
    322 // Update a particular "concept" for the target cell from the source cell
    323 static bool updateConcept(pmCell *target, // Target cell
    324                           const pmCell *source, // Source cell
    325                           const char *concept // Concept name
    326                          )
    327 {
    328     psMetadataItem *targetItem = psMetadataLookup(target->concepts, concept); // Concept from the target
    329     psMetadataItem *sourceItem = psMetadataLookup(source->concepts, concept); // Concept from the source
    330 
    331     switch (targetItem->type) {
    332         UPDATE_CASE(PS_TYPE_S32, S32);
    333         UPDATE_CASE(PS_TYPE_F32, F32);
    334         UPDATE_CASE(PS_TYPE_F64, F64);
    335         UPDATE_CASE(PS_DATA_STRING, V);
    336     default:
    337         psLogMsg(__func__, PS_LOG_WARN, "Unsupported type (%x) for concept %s --- ignored.\n",
    338                  targetItem->type, concept);
    339         return false;
    340     }
    341     return true;
    342 }
    343 
    344339
    345340// Copy pixels from a target image to a source image, with flips
     
    386381        return false;
    387382    }
     383
     384    #if 1
     385    // Copy any headers
     386    if (target->hdu && !target->hdu->phu) {
     387        pmHDU *sourceHDU = pmHDUFromFPA(source);
     388        target->hdu->header = psMetadataCopy(target->hdu->header, sourceHDU->header);
     389    }
     390    #endif
    388391
    389392    int numChips = 0;                   // Number of chips copied
     
    400403    }
    401404
     405    // Update the concepts
     406    psMetadataCopy(target->concepts, source->concepts);
     407
    402408    return numChips;
    403409}
     
    417423        return false;
    418424    }
     425
     426    #if 1
     427    // Copy any headers
     428    if (target->hdu && !target->hdu->phu) {
     429        pmHDU *sourceHDU = pmHDUFromChip(source);
     430        target->hdu->header = psMetadataCopy(target->hdu->header, sourceHDU->header);
     431    }
     432    #endif
    419433
    420434    int numCells = 0;                   // Number of cells copied
     
    431445    }
    432446
     447    // Update the concepts
     448    psMetadataCopy(target->concepts, source->concepts);
     449
    433450    return numCells;
    434451
     
    442459    assert(source);
    443460
    444     psArray *targetReadouts = target->readouts; // The target readouts
    445461    psArray *sourceReadouts = source->readouts; // The source readouts
    446     if (targetReadouts->n != sourceReadouts->n) {
    447         psError(PS_ERR_IO, true, "Number of source readouts (%d) differs from the number of target readouts "
    448                 "(%d)\n", sourceReadouts->n, targetReadouts->n);
    449         return false;
    450     }
    451     int numReadouts = targetReadouts->n; // Number of readouts copied
     462    int numReadouts = sourceReadouts->n; // Number of readouts copied
     463
     464    #if 1
     465    // Copy any headers
     466    if (target->hdu && !target->hdu->phu) {
     467        pmHDU *sourceHDU = pmHDUFromCell(source);
     468        target->hdu->header = psMetadataCopy(target->hdu->header, sourceHDU->header);
     469    }
     470    #endif
    452471
    453472    pmHDU *hdu = pmHDUFromCell(target); // The target HDU; we need to fix this up
    454     if (! hdu->images) {
     473    if (!hdu->images) {
    455474        generateHDU(target, source);
    456475    }
    457 
    458     // Need to check CELL.X0, CELL.Y0, CELL.XBIN, CELL.YBIN should be unchanged; we can check this by
    459     // setting the values and leaving it to the pmConceptWrite functions to do the checking against the
    460     // camera configuration when it comes time to write them out.
    461     updateConcept(target, source, "CELL.X0");
    462     updateConcept(target, source, "CELL.Y0");
    463     updateConcept(target, source, "CELL.XBIN");
    464     updateConcept(target, source, "CELL.YBIN");
     476    if (!hdu->header) {
     477        hdu->header = psMetadataAlloc();
     478    }
    465479
    466480    // Need to check/change CELL.XPARITY and CELL.YPARITY
    467481    bool xFlip = (psMetadataLookupS32(NULL, target->concepts, "CELL.XPARITY") !=
    468                   psMetadataLookupS32(NULL, target->concepts, "CELL.XPARITY")); // Switch parity in x?
     482                  psMetadataLookupS32(NULL, source->concepts, "CELL.XPARITY")); // Switch parity in x?
    469483    bool yFlip = (psMetadataLookupS32(NULL, target->concepts, "CELL.YPARITY") !=
    470                   psMetadataLookupS32(NULL, target->concepts, "CELL.YPARITY")); // Switch parity in y?
     484                  psMetadataLookupS32(NULL, source->concepts, "CELL.YPARITY")); // Switch parity in y?
    471485
    472486    bool mdok = true;                   // Status of MD lookup
     
    482496    }
    483497
    484     for (int i = 0; i < targetReadouts->n; i++) {
     498    for (int i = 0; i < numReadouts; i++) {
    485499        pmReadout *sourceReadout = sourceReadouts->data[i]; // The source readout
    486500        psImage *sourceImage = sourceReadout->image; // The source image
    487         pmReadout *targetReadout = targetReadouts->data[i]; // The target readout
     501        pmReadout *targetReadout = pmReadoutAlloc(target); // The target readout; this adds it to the cell
    488502        if (sourceImage->numCols != trimsec->x1 - trimsec->x0 ||
    489503                sourceImage->numRows != trimsec->y1 - trimsec->y0) {
     
    500514        psListIterator *biassecsIter = psListIteratorAlloc(biassecs, PS_LIST_HEAD, false); // Iterator
    501515        psRegion *biassec = NULL;       // Bias section from iteration
    502         while ((biassec = psListGetAndIncrement(biassecsIter))) {
     516        psListIterator *biasIter = psListIteratorAlloc(sourceReadout->bias, PS_LIST_HEAD, false); // Iterator
     517        psImage *bias = NULL;           // Bias image from iteration
     518        while ((biassec = psListGetAndIncrement(biassecsIter)) && (bias = psListGetAndIncrement(biasIter))) {
    503519            if (psRegionIsBad(*biassec)) {
    504520                psString biassecString = psRegionToString(*biassec); // String for bias section
     
    507523                continue;
    508524            }
    509             if (sourceImage->numCols != biassec->x1 - biassec->x0 ||
    510                     sourceImage->numRows != biassec->y1 - biassec->y0) {
     525            if (bias->numCols != biassec->x1 - biassec->x0 ||
     526                    bias->numRows != biassec->y1 - biassec->y0) {
    511527                psString biassecString = psRegionToString(*biassec); // String with the bias section
    512528                psLogMsg(__func__, PS_LOG_WARN, "Source image size (%dx%d) for readout %d doesn't match "
    513                          "CELL.BIASSEC for target (%s) -- ignored.\n", sourceImage->numCols,
    514                          sourceImage->numRows, i, biassecString);
     529                         "CELL.BIASSEC for target (%s) -- ignored.\n", bias->numCols, bias->numRows, i,
     530                         biassecString);
    515531                psFree(biassecString);
    516532            } else {
    517                 copyPixels(hdu->images->data[i], sourceImage, *biassec, xFlip, yFlip);
    518                 psImage *bias = psMemIncrRefCounter(psImageSubset(hdu->images->data[i], *biassec));
    519                 psListAdd(targetReadout->bias, PS_LIST_TAIL, bias);
    520                 psFree(bias);           // Drop reference
     533                copyPixels(hdu->images->data[i], bias, *biassec, xFlip, yFlip);
     534                psImage *newBias = psMemIncrRefCounter(psImageSubset(hdu->images->data[i], *biassec));
     535                psListAdd(targetReadout->bias, PS_LIST_TAIL, newBias);
     536                psFree(newBias);        // Drop reference
    521537            }
    522538        }
    523539        psFree(biassecsIter);
    524 
     540        psFree(biasIter);
     541    }
     542
     543    // Copy the remaining "concepts" over
     544    psMetadataIterator *conceptsIter = psMetadataIteratorAlloc(source->concepts, PS_LIST_HEAD, NULL);
     545    psMetadataItem *conceptItem = NULL; // Item from iteration
     546    while ((conceptItem = psMetadataGetAndIncrement(conceptsIter))) {
     547        psString name = conceptItem->name; // Name of concept
     548        if (strcmp(name, "CELL.TRIMSEC") != 0 && strcmp(name, "CELL.BIASSEC") != 0 &&
     549                strcmp(name, "CELL.XPARITY") != 0 && strcmp(name, "CELL.YPARITY") != 0) {
     550            psMetadataAddItem(target->concepts, conceptItem, PS_LIST_TAIL, PS_META_REPLACE);
     551        }
     552    }
     553
     554    // Need to update CELL.X0 and CELL.Y0 if we flipped
     555    if (xFlip) {
     556        psMetadataItem *xZero = psMetadataLookup(target->concepts, "CELL.X0"); // CELL.X0
     557        pmReadout *readout = target->readouts->data[0]; // A representative readout
     558        xZero->data.S32 -= readout->image->numCols - 1;
     559    }
     560    if (yFlip) {
     561        psMetadataItem *yZero = psMetadataLookup(target->concepts, "CELL.Y0"); // CELL.Y0
     562        pmReadout *readout = target->readouts->data[0]; // A representative readout
     563        yZero->data.S32 -= readout->image->numRows - 1;
    525564    }
    526565
Note: See TracChangeset for help on using the changeset viewer.