IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 8, 2023, 11:54:08 AM (3 years ago)
Author:
eugene
Message:

merge from eam_branches/ipp-20220316. no_warn strncpy; avoid passing NULL to sprintf %s; add code for PATTERN_DEAD_CELLS; fix error in PSF residual image evaluation; drop detailed mask analysis for binned images (not actually used)

Location:
trunk/psModules
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules

  • trunk/psModules/src/detrend/pmPatternIO.c

    r41892 r42379  
    482482}
    483483
    484 // read the set of tables, one for each chip
     484// Read the set of tables, one for each chip.  The values are saved on the cell->analysis
     485// metadata of the pmFPAfile associated with the pattern file.  Later, when this is used (e.g.,
     486// ppImageDetrendPatternRowApply), the values are transferred to the cell->analysis metadata of
     487// the pmFPAfile for the image being processed.
    485488bool pmPatternRowAmpReadChips (pmFPAfile *file) {
    486489
     
    560563    return true;
    561564}
     565
     566/**************** PatternDeadCells I/O *************************/
     567
     568bool pmPatternDeadCellsRead (const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
     569    {
     570        // read the full model in one pass: require the level to be FPA
     571        if (view->chip != -1) {
     572            psError(PS_ERR_IO, false, "Pattern Dead Cells must be read at the FPA level");
     573            return false;
     574        }
     575
     576        if (!pmPatternDeadCellsReadFPA (file)) {
     577            psError(PS_ERR_IO, false, "Failed to read Pattern Dead Cells for fpa");
     578            return false;
     579        }
     580        return true;
     581    }
     582
     583// read in all chip-level Pattern Dead Cells data for this FPA
     584bool pmPatternDeadCellsReadFPA (pmFPAfile *file) {
     585
     586    if (!pmPatternDeadCellsReadChips (file)) {
     587        psError(PS_ERR_IO, false, "Failed to read Pattern Dead Cells for chips");
     588        return false;
     589    }
     590
     591    return true;
     592}
     593
     594// Read the set of dead cell image cubes, one for each chip.  The values are saved on the
     595// chip->analysis metadata of the pmFPAfile associated with the pattern file.  Later, when this
     596// is used (e.g., ppImageDetrendPatternDeadCellsApply), the values are transferred to the
     597// chip->analysis metadata of the pmFPAfile for the image being processed.
     598bool pmPatternDeadCellsReadChips (pmFPAfile *file) {
     599
     600    bool haveData, status;
     601
     602    // loop over the extensions
     603    // for each extension, use the extname (eg, XY01.ded) to assign to a chip
     604
     605    // move to the start of the file
     606    haveData = psFitsMoveExtNum (file->fits, 1, false);
     607    if (!haveData) {
     608        psError(PS_ERR_IO, false, "Failed to read even the first extension?");
     609        return false;
     610    }
     611
     612    int nGood = 0;
     613    while (haveData) {
     614
     615        // load the header
     616        psMetadata *header = psFitsReadHeader(NULL, file->fits); // The FITS header
     617        if (!header) psAbort("cannot read dead cell header");
     618
     619        // load the full model in one shot
     620        psImage *deadCellData = psFitsReadImage(file->fits, psRegionSet(0,0,0,0), 0); // dead cell patterns
     621        if (!deadCellData) psAbort("cannot read dead cell pattern");
     622       
     623        // determine the chip (not all chips have DEAD CELL patterns)
     624        char *extname = psMetadataLookupStr (&status, header, "EXTNAME");
     625        psLogMsg ("psModules.detrend", 8, "read dead cell pattern for extname %s\n", extname);
     626
     627        // I expect to find a name of the form: chipName.ded (eg, XY01.ded)
     628        // where chipName like 'XY01'
     629        psAssert (strlen(extname) == 8, "invalid extension %s", extname);
     630        psAssert (extname[5] == 'd', "invalid extension %s", extname);
     631        psAssert (extname[6] == 'e', "invalid extension %s", extname);
     632        psAssert (extname[7] == 'd', "invalid extension %s", extname);
     633
     634        char chipName[5];
     635        strncpy (chipName, extname, 4);
     636        chipName[4] = 0;
     637
     638        pmChip *chip = pmConceptsChipFromName (file->fpa, chipName);
     639        if (!chip) psAbort ("invalid chip?");
     640
     641        psMetadataAddImage (chip->analysis, PS_LIST_TAIL, "PTN.DEAD.CELL", PS_META_REPLACE, "", deadCellData);
     642        psFree (deadCellData);
     643        psFree (header);
     644
     645        // move to the next extension
     646        haveData = psFitsMoveExtNum (file->fits, 1, true);
     647        nGood ++;
     648    }
     649    psLogMsg ("psModules.detrend", 4, "read patterns for %d chips from Pattern Dead Cells file\n", nGood);
     650
     651    return true;
     652}
Note: See TracChangeset for help on using the changeset viewer.