IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 13, 2006, 3:53:11 PM (20 years ago)
Author:
Paul Price
Message:

Adding function to read mask and weight images.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/camera/pmFPARead.c

    r7469 r7555  
    2121// Carve a readout from the image pixels
    2222static bool readoutCarve(pmReadout *readout, // Readout to be carved up
     23                         psImage **target, // Target pointer for the carved image
    2324                         psImage *image, // Image that will be carved
    2425                         const psRegion *trimsec, // Trim section
     
    4748        psFree(readout->image);         // Make way!
    4849    }
    49     readout->image = psMemIncrRefCounter(psImageSubset(image, region));
     50    *target = psMemIncrRefCounter(psImageSubset(image, region));
    5051
    5152    // Get the list of overscans
     
    346347        }
    347348
    348         pmReadout *readout = pmReadoutAlloc(cell);
    349         if (!readoutCarve(readout, image, trimsec, biassecs)) {
     349        pmReadout *readout;             // Readout into which to read
     350        if (cell->readouts->n > i && cell->readouts->data[i]) {
     351            readout = psMemIncrRefCounter(cell->readouts->data[i]);
     352        } else {
     353            readout = pmReadoutAlloc(cell);
     354        }
     355        if (!readoutCarve(readout, &readout->image, image, trimsec, biassecs)) {
    350356            psError(PS_ERR_UNEXPECTED_NULL, false,
    351357                    "Unable to carve readout into image and bias sections for %d the plane.", i);
    352358            return NULL;
    353359        }
    354         readout->mask = NULL;
    355         readout->weight = NULL;
    356360        psFree(readout);                // Drop reference
    357361    }
     
    415419}
    416420
     421
     422//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     423// Reading the mask
     424//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     425
     426// Read the mask into the cell, and allocate the readouts
     427bool pmCellReadMask(pmCell *cell,           // Cell to read into
     428                    psFits *fits,           // FITS file from which to read
     429                    psDB *db                // Database handle, for "concepts" ingest
     430                   )
     431{
     432    PS_ASSERT_PTR_NON_NULL(cell, false);
     433    PS_ASSERT_PTR_NON_NULL(fits, false);
     434
     435    pmHDU *hdu = pmHDUFromCell(cell);   // The HDU
     436    if (!hdu) {
     437        return false;                    // Nothing to see here; move along
     438    }
     439    if (!hdu->images && !pmHDURead(hdu, fits)) {
     440        psError(PS_ERR_UNKNOWN, false, "Unable to read HDU for cell.\n");
     441        return false;
     442    }
     443
     444    if (!pmConceptsReadCell(cell, PM_CONCEPT_SOURCE_HEADER, true, NULL)) {
     445        psError(PS_ERR_UNKNOWN, false, "Failed to read concepts for cell");
     446        return false;
     447    }
     448
     449    // Having read the cell, we now have to cut it up
     450    psRegion *trimsec = psMetadataLookupPtr(NULL, cell->concepts, "CELL.TRIMSEC");
     451
     452    // Iterate over each of the image planes
     453    for (int i = 0; i < hdu->images->n; i++) {
     454        psImage *image = hdu->images->data[i]; // The i-th plane
     455
     456        if (image->type.type != PS_TYPE_U8) {
     457            psImage *temp = psImageCopy(NULL, image, PS_TYPE_U8); // Temporary image
     458            psFree(hdu->images->data[i]);
     459            hdu->images->data[i] = temp;
     460            image = temp;
     461        }
     462
     463        pmReadout *readout;             // Readout into which to read
     464        if (cell->readouts->n > i && cell->readouts->data[i]) {
     465            readout = psMemIncrRefCounter(cell->readouts->data[i]);
     466        } else {
     467            readout = pmReadoutAlloc(cell);
     468        }
     469        if (!readoutCarve(readout, &readout->mask, image, trimsec, NULL)) {
     470            psError(PS_ERR_UNEXPECTED_NULL, false,
     471                    "Unable to carve readout into image and bias sections for %d the plane.", i);
     472            return NULL;
     473        }
     474        psFree(readout);                // Drop reference
     475    }
     476
     477    pmCellSetDataStatus(cell, true);
     478    return true;
     479}
     480
     481// Read the mask into the component cells
     482bool pmChipReadMask(pmChip *chip,           // Chip to read into
     483                    psFits *fits,           // FITS file from which to read
     484                    psDB *db                // Database handle, for "concepts" ingest
     485                   )
     486{
     487    PS_ASSERT_PTR_NON_NULL(chip, false);
     488    PS_ASSERT_PTR_NON_NULL(fits, false);
     489
     490    bool success = false;               // Were we able to read at least one HDU?
     491    psArray *cells = chip->cells;       // Array of cells
     492    for (int i = 0; i < cells->n; i++) {
     493        pmCell *cell = cells->data[i];  // The cell of interest
     494        success |= pmCellReadMask(cell, fits, db);
     495    }
     496    if (success) {
     497        if (!pmConceptsReadChip(chip, PM_CONCEPT_SOURCE_HEADER, true, true, NULL)) {
     498            psError(PS_ERR_IO, false, "Failed to read concepts for FPA.\n");
     499            return false;
     500        }
     501        // XXX probably could just use chip->data_exists
     502        pmChipSetDataStatus(chip, true);
     503    }
     504
     505    return success;
     506}
     507
     508// Read the mask into the component chips
     509bool pmFPAReadMask(pmFPA *fpa,              // FPA to read into
     510                   psFits *fits,            // FITS file from which to read
     511                   psDB *db                 // Database handle, for "concepts" ingest
     512                  )
     513{
     514    PS_ASSERT_PTR_NON_NULL(fpa, false);
     515    PS_ASSERT_PTR_NON_NULL(fits, false);
     516
     517    bool success = false;               // Were we able to read at least one HDU?
     518    psArray *chips = fpa->chips;        // Array of chips
     519    for (int i = 0; i < chips->n; i++) {
     520        pmChip *chip = chips->data[i];  // The cell of interest
     521        success |= pmChipReadMask(chip, fits, db);
     522    }
     523    if (success) {
     524        if (!pmConceptsReadFPA(fpa, PM_CONCEPT_SOURCE_HEADER, true, NULL)) {
     525            psError(PS_ERR_IO, false, "Failed to read concepts for FPA.\n");
     526            return false;
     527        }
     528    } else {
     529        psError(PS_ERR_UNKNOWN, false, "Unable to read any chips in FPA");
     530    }
     531
     532    return success;
     533}
     534
     535//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     536// Reading the weight map
     537//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     538
     539// Read the weight map into the cell, and allocate the readouts
     540bool pmCellReadWeight(pmCell *cell,           // Cell to read into
     541                      psFits *fits,           // FITS file from which to read
     542                      psDB *db                // Database handle, for "concepts" ingest
     543                     )
     544{
     545    PS_ASSERT_PTR_NON_NULL(cell, false);
     546    PS_ASSERT_PTR_NON_NULL(fits, false);
     547
     548    pmHDU *hdu = pmHDUFromCell(cell);   // The HDU
     549    if (!hdu) {
     550        return false;                    // Nothing to see here; move along
     551    }
     552    if (!hdu->images && !pmHDURead(hdu, fits)) {
     553        psError(PS_ERR_UNKNOWN, false, "Unable to read HDU for cell.\n");
     554        return false;
     555    }
     556
     557    if (!pmConceptsReadCell(cell, PM_CONCEPT_SOURCE_HEADER, true, NULL)) {
     558        psError(PS_ERR_UNKNOWN, false, "Failed to read concepts for cell");
     559        return false;
     560    }
     561
     562    // Having read the cell, we now have to cut it up
     563    psRegion *trimsec = psMetadataLookupPtr(NULL, cell->concepts, "CELL.TRIMSEC");
     564
     565    // Iterate over each of the image planes
     566    for (int i = 0; i < hdu->images->n; i++) {
     567        psImage *image = hdu->images->data[i]; // The i-th plane
     568
     569        if (image->type.type != PS_TYPE_F32) {
     570            psImage *temp = psImageCopy(NULL, image, PS_TYPE_F32); // Temporary image
     571            psFree(hdu->images->data[i]);
     572            hdu->images->data[i] = temp;
     573            image = temp;
     574        }
     575
     576        pmReadout *readout;             // Readout into which to read
     577        if (cell->readouts->n > i && cell->readouts->data[i]) {
     578            readout = psMemIncrRefCounter(cell->readouts->data[i]);
     579        } else {
     580            readout = pmReadoutAlloc(cell);
     581        }
     582        if (!readoutCarve(readout, &readout->weight, image, trimsec, NULL)) {
     583            psError(PS_ERR_UNEXPECTED_NULL, false,
     584                    "Unable to carve readout into image and bias sections for %d the plane.", i);
     585            return NULL;
     586        }
     587        psFree(readout);                // Drop reference
     588    }
     589
     590    pmCellSetDataStatus(cell, true);
     591    return true;
     592}
     593
     594// Read the weight map into the component cells
     595bool pmChipReadWeight(pmChip *chip,           // Chip to read into
     596                      psFits *fits,           // FITS file from which to read
     597                      psDB *db                // Database handle, for "concepts" ingest
     598                     )
     599{
     600    PS_ASSERT_PTR_NON_NULL(chip, false);
     601    PS_ASSERT_PTR_NON_NULL(fits, false);
     602
     603    bool success = false;               // Were we able to read at least one HDU?
     604    psArray *cells = chip->cells;       // Array of cells
     605    for (int i = 0; i < cells->n; i++) {
     606        pmCell *cell = cells->data[i];  // The cell of interest
     607        success |= pmCellReadWeight(cell, fits, db);
     608    }
     609    if (success) {
     610        if (!pmConceptsReadChip(chip, PM_CONCEPT_SOURCE_HEADER, true, true, NULL)) {
     611            psError(PS_ERR_IO, false, "Failed to read concepts for FPA.\n");
     612            return false;
     613        }
     614        // XXX probably could just use chip->data_exists
     615        pmChipSetDataStatus(chip, true);
     616    }
     617
     618    return success;
     619}
     620
     621// Read the weight map into the component chips
     622bool pmFPAReadWeight(pmFPA *fpa,              // FPA to read into
     623                     psFits *fits,            // FITS file from which to read
     624                     psDB *db                 // Database handle, for "concepts" ingest
     625                    )
     626{
     627    PS_ASSERT_PTR_NON_NULL(fpa, false);
     628    PS_ASSERT_PTR_NON_NULL(fits, false);
     629
     630    bool success = false;               // Were we able to read at least one HDU?
     631    psArray *chips = fpa->chips;        // Array of chips
     632    for (int i = 0; i < chips->n; i++) {
     633        pmChip *chip = chips->data[i];  // The cell of interest
     634        success |= pmChipReadWeight(chip, fits, db);
     635    }
     636    if (success) {
     637        if (!pmConceptsReadFPA(fpa, PM_CONCEPT_SOURCE_HEADER, true, NULL)) {
     638            psError(PS_ERR_IO, false, "Failed to read concepts for FPA.\n");
     639            return false;
     640        }
     641    } else {
     642        psError(PS_ERR_UNKNOWN, false, "Unable to read any chips in FPA");
     643    }
     644
     645    return success;
     646}
     647
Note: See TracChangeset for help on using the changeset viewer.