IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 9951


Ignore:
Timestamp:
Nov 13, 2006, 12:19:52 PM (19 years ago)
Author:
Paul Price
Message:

Changing pmFringesReadFits and pmFringesWriteFits into pmFringesFormat and pmFringesParse. Fringe data is read from FITS file, placed into the analysis metadata as FRINGE and FRINGE.HEADER using the pmFPAfile framework. pmFringeParse parses this into an array of pmFringeStats. pmFringeFormat formats the array of pmFringeStats into the analysis metadata for writing out by the pmFPAfile framework.

Location:
trunk/psModules/src/detrend
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/detrend/pmFringeStats.c

    r9856 r9951  
    519519//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    520520
    521 bool pmFringesWriteFits(psFits *fits, psMetadata *header, const psArray *fringes, const char *extname)
    522 {
    523     PS_ASSERT_PTR_NON_NULL(fits, false);
     521bool pmFringesFormat(pmCell *cell, psMetadata *header, const psArray *fringes)
     522{
     523    PS_ASSERT_PTR_NON_NULL(cell, false);
    524524    PS_ASSERT_ARRAY_NON_NULL(fringes, false);
    525525
     
    568568    psMetadataAddS32(scalars, PS_LIST_TAIL, "PSFRNGNY", PS_META_REPLACE, "Large-scale smoothing in y",
    569569                     regions->nY);
     570    psMetadataAdd(cell->analysis, PS_LIST_TAIL, "FRINGE.HEADER", PS_DATA_METADATA,
     571                  "Header for fringe data", scalars);
     572    psFree(scalars);
     573
    570574
    571575    psArray *table = psArrayAlloc(numRows); // The table
     
    600604    }
    601605
    602     bool success;                       // Success of operation
    603     if (!(success = psFitsWriteTable(fits, scalars, table, extname))) {
    604         psError(PS_ERR_IO, false, "Unable to write fringe data to extension %s\n", extname);
    605     }
    606     psFree(scalars);
    607     psFree(table);
    608 
    609     return success;
    610 }
    611 
    612 
    613 psArray *pmFringesReadFits(psMetadata *header, psFits *fits, const char *extname)
    614 {
    615     PS_ASSERT_PTR_NON_NULL(fits, NULL);
    616 
    617     if (extname && strlen(extname) > 0 && !psFitsMoveExtName(fits, extname)) {
    618         psError(PS_ERR_IO, false, "Unable to move to extension %s\n", extname);
     606    psMetadataAdd(cell->analysis, PS_LIST_TAIL, "FRINGE", PS_DATA_ARRAY, "Fringe data", table);
     607
     608    return true;
     609}
     610
     611
     612psArray *pmFringesParse(pmCell *cell)
     613{
     614    PS_ASSERT_PTR_NON_NULL(cell, NULL);
     615
     616    bool mdok;                          // Status of MD lookup
     617    psMetadata *header = psMetadataLookupMetadata(&mdok, cell->analysis, "FRINGE.HEADER"); // Header
     618    if (!mdok || !header) {
     619        psError(PS_ERR_UNKNOWN, false, "Unable to find header for fringe data.\n");
    619620        return NULL;
    620621    }
    621622
    622     psMetadata *headerCopy = psMemIncrRefCounter(header); // Copy of the header, or NULL
    623     headerCopy = psFitsReadHeader(headerCopy, fits); // The FITS header
    624     if (!headerCopy) {
    625         psError(PS_ERR_IO, false, "Unable to read header for extension %s\n", extname);
    626         psFree(headerCopy);
     623    psArray *table = psMetadataLookupPtr(NULL, cell->analysis, "FRINGE"); // FITS table
     624    if (!table) {
     625        psError(PS_ERR_UNKNOWN, false, "Unable to find table for fringe data.\n");
    627626        return NULL;
    628627    }
     628
    629629
    630630    // Read the scalars from the header
    631631    #define READ_FRINGES_SCALAR(SCALAR, NAME) \
    632     int SCALAR = psMetadataLookupS32(&mdok, headerCopy, NAME); \
     632    int SCALAR = psMetadataLookupS32(&mdok, header, NAME); \
    633633    if (!mdok || SCALAR <= 0) { \
    634         psError(PS_ERR_IO, true, "Unable to find " NAME " in header of extension %s\n", extname); \
    635         psFree(headerCopy); \
     634        psError(PS_ERR_IO, true, "Unable to find " NAME " in fringe header.\n"); \
    636635        return NULL; \
    637636    }
    638637
    639638    // Need to retrieve the scalars: dX, dY, nX, nY
    640     bool mdok = true;                   // Status of MD lookup
    641     READ_SCALAR(dX, "PSFRNGDX");
    642     READ_SCALAR(dY, "PSFRNGDY");
    643     READ_SCALAR(nX, "PSFRNGNX");
    644     READ_SCALAR(nY, "PSFRNGNY");
    645     psFree(headerCopy);
     639    READ_FRINGES_SCALAR(dX, "PSFRNGDX");
     640    READ_FRINGES_SCALAR(dY, "PSFRNGDY");
     641    READ_FRINGES_SCALAR(nX, "PSFRNGNX");
     642    READ_FRINGES_SCALAR(nY, "PSFRNGNY");
    646643
    647644    // Now the vectors: x, y, mask, f, df
    648     psArray *table = psFitsReadTable(fits); // The table
    649645    long numRows = table->n;            // Number of rows
    650 
    651646    pmFringeRegions *regions = pmFringeRegionsAlloc(numRows, dX, dY, nX, nY); // The fringe regions
    652647    psVector *x = psVectorAlloc(numRows, PS_TYPE_F32); // x position
     
    664659        VECTOR->data.TYPE[i] = psMetadataLookup##TYPE(&mdok, row, NAME); \
    665660        if (!mdok) { \
    666             psError(PS_ERR_IO, true, "Unable to find " #DESCRIPTION " .\n"); \
     661            psError(PS_ERR_IO, true, "Unable to find " #DESCRIPTION " for row %ld.\n", i); \
    667662            goto READ_FRINGES_DONE; \
    668663        } \
     
    674669        psMetadataItem *item = psMetadataLookup(row, NAME); \
    675670        if (!item) { \
    676             psError(PS_ERR_IO, true, "Unable to find " #DESCRIPTION " .\n"); \
     671            psError(PS_ERR_IO, true, "Unable to find " #DESCRIPTION " for row %ld.\n", i); \
    677672            goto READ_FRINGES_DONE; \
    678673        } \
     
    684679            ARRAY->data[i] = vector; \
    685680        } else { \
    686             psError(PS_ERR_IO, true, "Found " #DESCRIPTION ", but it's of an unsupported type (%x).\n", \
    687                     item->type); \
     681            psError(PS_ERR_IO, true, "Found " #DESCRIPTION " for row %ld, but it's of an " \
     682                    "unsupported type (%x).\n", i, item->type); \
    688683            goto READ_FRINGES_DONE; \
    689684        } \
    690685    }
    691 
    692686
    693687    // Translate the table into vectors
     
    719713
    720714READ_FRINGES_DONE:
    721     psFree(table);
    722715    psFree(regions);
    723716    psFree(f);
  • trunk/psModules/src/detrend/pmFringeStats.h

    r9855 r9951  
    88/// @author Paul Price, IfA
    99///
    10 /// @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    11 /// @date $Date: 2006-11-04 02:34:30 $
     10/// @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
     11/// @date $Date: 2006-11-13 22:19:52 $
    1212///
    1313/// Copyright 2004-2006 Institute for Astronomy, University of Hawaii
     
    7878                                        );
    7979
    80 
    81 
    8280//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    8381// pmFringeStats
     
    147145/// Write an array of fringes measurements to a FITS table.
    148146///
    149 /// Writes an array of fringe measurements for the same FPA component as a FITS table.  The array of fringe
    150 /// statistics must all use the same fringe regions (or there is no point in storing them all together).  The
    151 /// header is supplemented with scalar values dX, dY, nX and nY (as PSFRNGDX, PSFRNGDY, PSFRNGNX, PSFRNGNY)
    152 /// from the fringe regions, while the fringe coordinates and mask are written as a FITS table (as x, y,
    153 /// mask, f, df; f and df are vectors).
    154 bool pmFringesWriteFits(psFits *fits,    ///< FITS file to which to write
    155                         psMetadata *header, ///< Header, or NULL
    156                         const psArray *fringes, ///< Array of pmFringeStats, all for the same pmFringeRegion
    157                         const char *extname ///< Extension name for table
     147/// Writes an array of fringe measurements for a cell as a FITS table in the analysis metadata.  The array of
     148/// fringe statistics must all use the same fringe regions (or there is no point in storing them all
     149/// together).  The header is supplemented with scalar values dX, dY, nX and nY (as PSFRNGDX, PSFRNGDY,
     150/// PSFRNGNX, PSFRNGNY) from the fringe regions, while the fringe coordinates and mask are written as a FITS
     151/// table (as x, y, mask, f, df; f and df are vectors).
     152bool pmFringesFormat(pmCell *cell,   ///< Cell for which to write
     153                     psMetadata *header, ///< Header, or NULL
     154                     const psArray *fringes ///< Array of pmFringeStats, all for the same pmFringeRegion
     155                    );
     156
     157/// Parses an array of fringes measurements from a FITS table.
     158///
     159/// The fringes for the cell are read from the FITS table in the analysis metadata.  The table provides the
     160/// region and the (possibly multiple) fringe statistics for that region.  The current extension is used if
     161/// the extension name is not provided.
     162psArray *pmFringesParse(pmCell *cell ///< Cell for which to read fringes
    158163                       );
    159 
    160 /// Reads an array of fringes measurements from a FITS table.
    161 ///
    162 /// The fringes are read from the FITS file, at the given extension name.  The table provides the region and
    163 /// the (possibly multiple) fringe statistics for that region.  The current extension is used if the extension
    164 /// name is not provided.
    165 psArray *pmFringesReadFits(psMetadata *header, ///< Header to read, or NULL
    166                            psFits *fits,///< FITS file from which to read
    167                            const char *extname ///< Extension name to read, or NULL
    168                           );
    169164
    170165
Note: See TracChangeset for help on using the changeset viewer.