IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 4, 2021, 6:05:18 PM (5 years ago)
Author:
eugene
Message:

merge changes from eam_branches/ipp-dev-20210817 (pmPattern updates, new inverse transform extra orders api, forward transform uses ORD, pmSourceIO_CMF.c.in conversion to pmFitsTableNew)

Location:
trunk/psModules
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules

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

    r26923 r41892  
    88#include "pmFPAview.h"
    99#include "pmFPAfile.h"
     10#include "pmFPAUtils.h"
    1011#include "pmFPAfileFitsIO.h"
    1112#include "pmFPAHeader.h"
     
    452453    return pmReadoutReadPattern(readout, file->fits);
    453454}
     455
     456/**************** PatternRowAmp(litude) I/O *************************/
     457
     458bool pmPatternRowAmpRead (const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
     459    {
     460        // read the full model in one pass: require the level to be FPA
     461        if (view->chip != -1) {
     462            psError(PS_ERR_IO, false, "Pattern Row Amplitude must be read at the FPA level");
     463            return false;
     464        }
     465
     466        if (!pmPatternRowAmpReadFPA (file)) {
     467            psError(PS_ERR_IO, false, "Failed to read Pattern Row Amplitude for fpa");
     468            return false;
     469        }
     470        return true;
     471    }
     472
     473// read in all chip-level Pattern Row Amplitude data for this FPA
     474bool pmPatternRowAmpReadFPA (pmFPAfile *file) {
     475
     476    if (!pmPatternRowAmpReadChips (file)) {
     477        psError(PS_ERR_IO, false, "Failed to read Pattern Row Amplitude for chips");
     478        return false;
     479    }
     480
     481    return true;
     482}
     483
     484// read the set of tables, one for each chip
     485bool pmPatternRowAmpReadChips (pmFPAfile *file) {
     486
     487    bool haveData, status;
     488
     489    // loop over the extensions
     490    // for each extension, use the extname (eg, XY01.ptn) to assign to a chip
     491
     492    // move to the start of the file
     493    haveData = psFitsMoveExtNum (file->fits, 1, false);
     494    if (!haveData) {
     495        psError(PS_ERR_IO, false, "Failed to read even the first extension?");
     496        return false;
     497    }
     498
     499    int nGood = 0;
     500    int nTotal = 0;
     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", 8, "read %ld rows from Pattern Row Amplitude file, extname %s\n", model->n, extname);
     514        nTotal += model->n;
     515
     516        // I expect to find a name of the form: chipName.ptn (eg, XY01.ptn)
     517        // where chipName like 'XY01'
     518        psAssert (strlen(extname) == 8, "invalid extension %s", extname);
     519        psAssert (extname[5] == 'p', "invalid extension %s", extname);
     520        psAssert (extname[6] == 't', "invalid extension %s", extname);
     521        psAssert (extname[7] == 'n', "invalid extension %s", extname);
     522
     523        char chipName[5];
     524        strncpy (chipName, extname, 4);
     525        chipName[4] = 0;
     526
     527        pmChip *chip = pmConceptsChipFromName (file->fpa, chipName);
     528        if (!chip) psAbort ("invalid chip?");
     529
     530        // parse the model entries
     531        for (int i = 0; i < model->n; i++) {
     532            psMetadata *row = model->data[i];
     533            psAssert (row, "missing model row");
     534
     535            char *cellName = psMetadataLookupStr(&status, row, "CELL_NAME");
     536            if (!cellName) continue;
     537
     538            float amplitude = psMetadataLookupF32(&status, row, "VALUE_MEDIAN");
     539
     540            int cellNumber = pmChipFindCell (chip, cellName);
     541            psAssert ((cellNumber >=0) && (cellNumber < chip->cells->n), "invalid cell number");
     542
     543            pmCell *cell = chip->cells->data[cellNumber];
     544            if (!cell) continue;
     545
     546            psAssert (cell->analysis, "oops");
     547
     548            psMetadataAddF32 (cell->analysis, PS_LIST_TAIL, "PTN.ROW.AMP", PS_META_REPLACE, "", amplitude);
     549            nGood ++;
     550        }
     551
     552        psFree (model);
     553        psFree (header);
     554
     555        // move to the next extension
     556        haveData = psFitsMoveExtNum (file->fits, 1, true);
     557    }
     558    psLogMsg ("psModules.detrend", 4, "read %d of %d rows from Pattern Row Amplitude file\n", nGood, nTotal);
     559
     560    return true;
     561}
Note: See TracChangeset for help on using the changeset viewer.