IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 3, 2010, 8:50:52 AM (16 years ago)
Author:
eugene
Message:

updates from trunk

Location:
branches/simtest_nebulous_branches
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/simtest_nebulous_branches

  • branches/simtest_nebulous_branches/psModules

  • branches/simtest_nebulous_branches/psModules/src/camera/pmFPAMosaic.c

    r21363 r27840  
    626626    bool good = true;                   // Is everything good?
    627627
     628    const char *cellName = psMetadataLookupStr(NULL, cell->concepts, "CELL.NAME"); // Name of cell
     629    const char *chipName = psMetadataLookupStr(NULL, cell->parent->concepts, "CHIP.NAME"); // Name of chip
     630
    628631    // Offset of the cell on the chip
    629632    int x0Cell = psMetadataLookupS32(&mdok, cell->concepts, "CELL.X0");
    630633    if (!mdok) {
    631         psError(PS_ERR_UNKNOWN, true, "CELL.X0 for cell is not set.\n");
     634        psError(PS_ERR_UNKNOWN, true, "CELL.X0 for cell %s,%s is not set.\n", chipName, cellName);
    632635        good = false;
    633636    }
    634637    int y0Cell = psMetadataLookupS32(&mdok, cell->concepts, "CELL.Y0");
    635638    if (!mdok) {
    636         psError(PS_ERR_UNKNOWN, true, "CELL.Y0 for cell is not set.\n");
     639        psError(PS_ERR_UNKNOWN, true, "CELL.Y0 for cell %s,%s is not set.\n", chipName, cellName);
    637640        good = false;
    638641    }
    639     psTrace("psModules.camera", 5, "Cell %ld: x0=%d y0=%d\n", index, x0Cell, y0Cell);
     642    psTrace("psModules.camera", 5, "Cell %s,%s (%ld): x0=%d y0=%d\n",
     643            chipName, cellName, index, x0Cell, y0Cell);
    640644
    641645    // Offset of the chip on the FPA
     
    649653        x0Chip = psMetadataLookupS32(&mdok, chip->concepts, "CHIP.X0");
    650654        if (!mdok) {
    651             psError(PS_ERR_UNKNOWN, true, "CHIP.X0 for chip is not set.\n");
     655            psError(PS_ERR_UNKNOWN, true, "CHIP.X0 for chip %s is not set.\n", chipName);
    652656            good = false;
    653657        }
    654658        y0Chip = psMetadataLookupS32(&mdok, chip->concepts, "CHIP.Y0");
    655659        if (!mdok) {
    656             psError(PS_ERR_UNKNOWN, true, "CHIP.Y0 for chip is not set.\n");
     660            psError(PS_ERR_UNKNOWN, true, "CHIP.Y0 for chip %s is not set.\n", chipName);
    657661            good = false;
    658662        }
     
    662666    xBin->data.S32[index] = psMetadataLookupS32(&mdok, cell->concepts, "CELL.XBIN");
    663667    if (!mdok || xBin->data.S32[index] == 0) {
    664         psError(PS_ERR_UNKNOWN, true, "CELL.XBIN for cell is not set.\n");
     668        psError(PS_ERR_UNKNOWN, true, "CELL.XBIN for cell %s,%s is not set.\n", chipName, cellName);
    665669        return false;
    666670    } else if (xBin->data.S32[index] < *xBinMin) {
     
    669673    yBin->data.S32[index] = psMetadataLookupS32(&mdok, cell->concepts, "CELL.YBIN");
    670674    if (!mdok || yBin->data.S32[index] == 0) {
    671         psError(PS_ERR_UNKNOWN, true, "CELL.YBIN for cell is not set.\n");
     675        psError(PS_ERR_UNKNOWN, true, "CELL.YBIN for cell %s,%s is not set.\n", chipName, cellName);
    672676        return false;
    673677    } else if (yBin->data.S32[index] < *yBinMin) {
     
    678682    int xParityCell = psMetadataLookupS32(&mdok, cell->concepts, "CELL.XPARITY");
    679683    if (!mdok || (xParityCell != 1 && xParityCell != -1)) {
    680         psError(PS_ERR_UNKNOWN, true, "CELL.XPARITY for cell is not set.\n");
     684        psError(PS_ERR_UNKNOWN, true, "CELL.XPARITY for cell %s,%s is not set.\n", chipName, cellName);
    681685        return false;
    682686    }
    683687    int yParityCell = psMetadataLookupS32(&mdok, cell->concepts, "CELL.YPARITY");
    684688    if (!mdok || (yParityCell != 1 && yParityCell != -1)) {
    685         psError(PS_ERR_UNKNOWN, true, "CELL.YPARITY for cell is not set.\n");
     689        psError(PS_ERR_UNKNOWN, true, "CELL.YPARITY for cell %s,%s is not set.\n", chipName, cellName);
    686690        return false;
    687691    }
     
    693697        xParityChip = psMetadataLookupS32(&mdok, chip->concepts, "CHIP.XPARITY");
    694698        if (!mdok || (xParityChip != 1 && xParityChip != -1)) {
    695             psError(PS_ERR_UNKNOWN, true, "CHIP.XPARITY for chip is not set.\n");
     699            psError(PS_ERR_UNKNOWN, true, "CHIP.XPARITY for chip %s is not set.\n", chipName);
    696700            return false;
    697701        }
    698702        yParityChip = psMetadataLookupS32(&mdok, chip->concepts, "CHIP.YPARITY");
    699703        if (!mdok || (yParityChip != 1 && yParityChip != -1)) {
    700             psError(PS_ERR_UNKNOWN, true, "CHIP.YPARITY for chip is not set.\n");
     704            psError(PS_ERR_UNKNOWN, true, "CHIP.YPARITY for chip %s is not set.\n", chipName);
    701705            return false;
    702706        }
     
    740744static bool chipMosaic(psImage **mosaicImage, // The mosaic image, to be returned
    741745                       psImage **mosaicMask, // The mosaic mask, to be returned
    742                        psImage **mosaicVariances, // The mosaic variances, to be returned
     746                       psImage **mosaicVariance, // The mosaic variance, to be returned
    743747                       int *xBinChip, int *yBinChip, // The binning in x and y, to be returned
    744748                       const pmChip *chip, // Chip to mosaic
     
    749753    assert(mosaicImage);
    750754    assert(mosaicMask);
    751     assert(mosaicVariances);
     755    assert(mosaicVariance);
    752756    assert(xBinChip);
    753757    assert(yBinChip);
     
    826830    if (allGood) {
    827831        *mosaicImage = imageMosaic(images, xFlip, yFlip, xBin, yBin, *xBinChip, *yBinChip, x0, y0, BLANK_VALUE);
    828         *mosaicVariances = imageMosaic(variances, xFlip, yFlip, xBin, yBin, *xBinChip, *yBinChip, x0, y0, BLANK_VALUE);
     832        *mosaicVariance = imageMosaic(variances, xFlip, yFlip, xBin, yBin, *xBinChip, *yBinChip, x0, y0, BLANK_VALUE);
    829833        *mosaicMask = imageMosaic(masks, xFlip, yFlip, xBin, yBin, *xBinChip, *yBinChip, x0, y0, blank);
    830834    }
     
    847851static bool fpaMosaic(psImage **mosaicImage, // The mosaic image, to be returned
    848852                      psImage **mosaicMask, // The mosaic mask, to be returned
    849                       psImage **mosaicVariances, // The mosaic variances, to be returned
     853                      psImage **mosaicVariance, // The mosaic variance, to be returned
    850854                      int *xBinFPA, int *yBinFPA, // The binning in x and y, to be returned
    851855                      const pmFPA *fpa,  // FPA to mosaic
     
    857861    assert(mosaicImage);
    858862    assert(mosaicMask);
    859     assert(mosaicVariances);
     863    assert(mosaicVariance);
    860864    assert(xBinFPA);
    861865    assert(yBinFPA);
     
    960964    if (allGood) {
    961965        *mosaicImage = imageMosaic(images, xFlip, yFlip, xBin, yBin, *xBinFPA, *yBinFPA, x0, y0, BLANK_VALUE);
    962         *mosaicVariances = imageMosaic(variances, xFlip, yFlip, xBin, yBin, *xBinFPA, *yBinFPA, x0, y0, BLANK_VALUE);
     966        *mosaicVariance = imageMosaic(variances, xFlip, yFlip, xBin, yBin, *xBinFPA, *yBinFPA, x0, y0, BLANK_VALUE);
    963967        *mosaicMask = imageMosaic(masks, xFlip, yFlip, xBin, yBin, *xBinFPA, *yBinFPA, x0, y0, blank);
    964968    }
     
    10251029    psImage *mosaicImage   = NULL;      // The mosaic image
    10261030    psImage *mosaicMask    = NULL;      // The mosaic mask
    1027     psImage *mosaicVariances = NULL;      // The mosaic variances
     1031    psImage *mosaicVariance = NULL;      // The mosaic variances
    10281032
    10291033    // Find the HDU
     
    10521056        }
    10531057        if (hdu->variances) {
    1054             mosaicVariances = psImageSubset(hdu->variances->data[0], bounds);
    1055             if (!mosaicVariances) {
     1058            mosaicVariance = psImageSubset(hdu->variances->data[0], bounds);
     1059            if (!mosaicVariance) {
    10561060                psError(PS_ERR_UNKNOWN, false, "Unable to select variance pixels.\n");
    10571061                return false;
     
    10611065        // Case 2 --- we need to mosaic by cut and paste
    10621066        psTrace("psModules.camera", 1, "Case 2 mosaicking: cut and paste.\n");
    1063         if (!chipMosaic(&mosaicImage, &mosaicMask, &mosaicVariances, &xBin, &yBin, source, targetCell, blank)) {
     1067        if (!chipMosaic(&mosaicImage, &mosaicMask, &mosaicVariance, &xBin, &yBin, source, targetCell, blank)) {
    10641068            psError(PS_ERR_UNKNOWN, false, "Unable to mosaic cells.\n");
    10651069            return false;
     
    10691073    }
    10701074    psTrace("psModules.camera", 1, "xBin,yBin: %d,%d\n", xBin, yBin);
     1075
    10711076
    10721077    // Set the concepts for the target cell
     
    10901095    target->parent->concepts = psMetadataCopy(target->parent->concepts, source->parent->concepts); // FPA lvl
    10911096
     1097    // Average the covariances
     1098    psList *covariances = psListAlloc(NULL); // Input covariance matrices
     1099    for (int i = 0; i < source->cells->n; i++) {
     1100        pmCell *cell = source->cells->data[i]; // Cell of interest
     1101        if (!cell || !cell->data_exists) {
     1102            continue;
     1103        }
     1104        pmReadout *ro = cell->readouts->data[0]; // Readout of interest
     1105        if (!ro || !ro->covariance) {
     1106            continue;
     1107        }
     1108        psListAdd(covariances, PS_LIST_TAIL, ro->covariance);
     1109    }
     1110    psKernel *mosaicCovariance = NULL;  // Covariance for mosaic
     1111    if (psListLength(covariances) > 0) {
     1112        psArray *covarArray = psListToArray(covariances); // Array with covariances
     1113        mosaicCovariance = psImageCovarianceAverage(covarArray);
     1114        psFree(covarArray);
     1115    }
     1116    psFree(covariances);
     1117
    10921118    // Now make a new readout to go in the target cell
    10931119    pmReadout *newReadout = pmReadoutAlloc(targetCell); // New readout
    10941120    newReadout->image  = mosaicImage;
    10951121    newReadout->mask   = mosaicMask;
    1096     newReadout->variance = mosaicVariances;
     1122    newReadout->variance = mosaicVariance;
     1123    newReadout->covariance = mosaicCovariance;
    10971124    psFree(newReadout);                 // Drop reference
    10981125
     
    13341361    target->concepts = psMetadataCopy(target->concepts, source->concepts);
    13351362
     1363    // Average the covariances
     1364    psList *covariances = psListAlloc(NULL); // Input covariance matrices
     1365    for (int i = 0; i < covariances->n; i++) {
     1366        pmChip *chip = chips->data[i];  // Chip of interest
     1367        if (!chip || !chip->data_exists) {
     1368            continue;
     1369        }
     1370        psArray *cells = chip->cells;   // Cells in chip
     1371        for (long j = 0; j < cells->n; j++) {
     1372            pmCell *cell = cells->data[i]; // Cell of interest
     1373            if (!cell || !cell->data_exists) {
     1374                continue;
     1375            }
     1376            pmReadout *ro = cell->readouts->data[0]; // Readout of interest
     1377            if (!ro || !ro->covariance) {
     1378                continue;
     1379            }
     1380            psListAdd(covariances, PS_LIST_TAIL, ro->covariance);
     1381        }
     1382    }
     1383    psKernel *mosaicCovariances = NULL; // Covariance for mosaic
     1384    if (psListLength(covariances) > 0) {
     1385        psArray *covarArray = psListToArray(covariances); // Array with covariances
     1386        mosaicCovariances = psImageCovarianceAverage(covarArray);
     1387        psFree(covarArray);
     1388    }
     1389    psFree(covariances);
     1390
    13361391    // Now make a new readout to go in the new cell
    13371392    pmReadout *newReadout = pmReadoutAlloc(targetCell); // New readout
     
    13391394    newReadout->mask   = mosaicMask;
    13401395    newReadout->variance = mosaicVariances;
     1396    newReadout->covariance = mosaicCovariances;
    13411397    psFree(newReadout);                 // Drop reference
    13421398
Note: See TracChangeset for help on using the changeset viewer.