IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 19, 2021, 4:53:35 PM (5 years ago)
Author:
eugene
Message:

adding pmPattern amplitude I/O

Location:
branches/eam_branches/ipp-dev-20210817/psModules/src/detrend
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-dev-20210817/psModules/src/detrend/pmPattern.c

    r41838 r41851  
    476476    psImage *mask = ro->mask;           // Mask for image
    477477    int numCols = image->numCols, numRows = image->numRows; // Size of image
     478
     479    // use the background and typical amplitude value to choose to correct or not
     480    // pmCell *cell = ro->parent;
    478481
    479482    psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);
  • branches/eam_branches/ipp-dev-20210817/psModules/src/detrend/pmPatternIO.c

    r26923 r41851  
    452452    return pmReadoutReadPattern(readout, file->fits);
    453453}
     454
     455/**************** PatternRowAmp(litude) I/O *************************/
     456
     457# if (0)
     458/********************* Read Data functions *****************************/
     459
     460bool pmPatternRowAmpReadForView (const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
     461    {
     462        // read the full model in one pass: require the level to be FPA
     463        if (view->chip != -1) {
     464            psError(PS_ERR_IO, false, "Pattern Row Amplitude must be read at the FPA level");
     465            return false;
     466        }
     467
     468        if (!pmPatternRowAmpReadFPA (file)) {
     469            psError(PS_ERR_IO, false, "Failed to read Pattern Row Amplitude for fpa");
     470            return false;
     471        }
     472        return true;
     473    }
     474
     475// read in all chip-level Pattern Row Amplitude data for this FPA
     476bool pmPatternRowAmpReadFPA (pmFPAfile *file) {
     477
     478    if (!pmPatternRowAmpReadChips (file)) {
     479        psError(PS_ERR_IO, false, "Failed to read Pattern Row Amplitude for chips");
     480        return false;
     481    }
     482
     483    return true;
     484}
     485
     486// read the set of tables, one for each chip
     487bool pmPatternRowAmpReadChips (pmFPAfile *file) {
     488
     489    bool haveData, status;
     490
     491    // loop over the extensions
     492    // for each extension, use the extname (eg, XY01.ptn) to assign to a chip
     493
     494    // move to the start of the file
     495    haveData = psFitsMoveExtNum (file->fits, 1, false);
     496    if (!haveData) {
     497        psError(PS_ERR_IO, false, "Failed to read even the first extension?");
     498        return false;
     499    }
     500
     501    while (haveData) {
     502
     503        // load the header
     504        psMetadata *header = psFitsReadHeader(NULL, file->fits); // The FITS header
     505        if (!header) psAbort("cannot read model header");
     506
     507        // load the full model in one shot
     508        psArray *model = psFitsReadTable (file->fits);
     509        if (!model) psAbort("cannot read model");
     510       
     511        // determine the chip:
     512        char *extname = psMetadataLookupStr (&status, header, "EXTNAME");
     513        psLogMsg ("psModules.detrend", 4, "read %ld rows from Pattern Row Amplitude file, extname %s\n", model->n, extname);
     514
     515        // I expect to find a name of the form: chipName.ptn (eg, XY01.ptn)
     516        // where chipName like 'XY01'
     517        psAssert (strlen(extname) == 10, "invalid extension %s", extname);
     518        psAssert (extname[5] == 'p', "invalid extension %s", extname);
     519        psAssert (extname[6] == 't', "invalid extension %s", extname);
     520        psAssert (extname[7] == 'n', "invalid extension %s", extname);
     521
     522        char chipName[5];
     523        strncpy (chipName, extname, 4);
     524        chipName[4] = 0;
     525
     526        pmChip *chip = pmConceptsChipFromName (file->fpa, chipName);
     527        if (!chip) psAbort ("invalid chip?");
     528
     529        // parse the model entries
     530        for (int i = 0; i < model->n; i++) {
     531            psMetadata *row = model->data[i];
     532            char *cellName = psMetadataLookupStr(&status, row, "cellname");
     533            float *amplitude = psMetadataLookupF32(&status, row, "medianValue");
     534
     535            int cellNumber = pmChipFindCell (chip, cellName);
     536            pmCell *cell = chip->data[cellNumber];
     537
     538            psMetadataAddF32 (cell->analysis, PS_LIST_TAIL, "PTN.ROW.AMP", PS_META_REPLACE, "", amplitude);
     539        }
     540        psFree (model);
     541        psFree (header);
     542
     543        // move to the next extension
     544        haveData = psFitsMoveExtNum (file->fits, 1, true);
     545    }
     546
     547    return true;
     548}
     549# endif
Note: See TracChangeset for help on using the changeset viewer.