Changeset 9951
- Timestamp:
- Nov 13, 2006, 12:19:52 PM (19 years ago)
- Location:
- trunk/psModules/src/detrend
- Files:
-
- 2 edited
-
pmFringeStats.c (modified) (7 diffs)
-
pmFringeStats.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/detrend/pmFringeStats.c
r9856 r9951 519 519 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 520 520 521 bool pmFringes WriteFits(psFits *fits, psMetadata *header, const psArray *fringes, const char *extname)522 { 523 PS_ASSERT_PTR_NON_NULL( fits, false);521 bool pmFringesFormat(pmCell *cell, psMetadata *header, const psArray *fringes) 522 { 523 PS_ASSERT_PTR_NON_NULL(cell, false); 524 524 PS_ASSERT_ARRAY_NON_NULL(fringes, false); 525 525 … … 568 568 psMetadataAddS32(scalars, PS_LIST_TAIL, "PSFRNGNY", PS_META_REPLACE, "Large-scale smoothing in y", 569 569 regions->nY); 570 psMetadataAdd(cell->analysis, PS_LIST_TAIL, "FRINGE.HEADER", PS_DATA_METADATA, 571 "Header for fringe data", scalars); 572 psFree(scalars); 573 570 574 571 575 psArray *table = psArrayAlloc(numRows); // The table … … 600 604 } 601 605 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 612 psArray *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"); 619 620 return NULL; 620 621 } 621 622 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"); 627 626 return NULL; 628 627 } 628 629 629 630 630 // Read the scalars from the header 631 631 #define READ_FRINGES_SCALAR(SCALAR, NAME) \ 632 int SCALAR = psMetadataLookupS32(&mdok, header Copy, NAME); \632 int SCALAR = psMetadataLookupS32(&mdok, header, NAME); \ 633 633 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"); \ 636 635 return NULL; \ 637 636 } 638 637 639 638 // 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"); 646 643 647 644 // Now the vectors: x, y, mask, f, df 648 psArray *table = psFitsReadTable(fits); // The table649 645 long numRows = table->n; // Number of rows 650 651 646 pmFringeRegions *regions = pmFringeRegionsAlloc(numRows, dX, dY, nX, nY); // The fringe regions 652 647 psVector *x = psVectorAlloc(numRows, PS_TYPE_F32); // x position … … 664 659 VECTOR->data.TYPE[i] = psMetadataLookup##TYPE(&mdok, row, NAME); \ 665 660 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); \ 667 662 goto READ_FRINGES_DONE; \ 668 663 } \ … … 674 669 psMetadataItem *item = psMetadataLookup(row, NAME); \ 675 670 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); \ 677 672 goto READ_FRINGES_DONE; \ 678 673 } \ … … 684 679 ARRAY->data[i] = vector; \ 685 680 } 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); \ 688 683 goto READ_FRINGES_DONE; \ 689 684 } \ 690 685 } 691 692 686 693 687 // Translate the table into vectors … … 719 713 720 714 READ_FRINGES_DONE: 721 psFree(table);722 715 psFree(regions); 723 716 psFree(f); -
trunk/psModules/src/detrend/pmFringeStats.h
r9855 r9951 8 8 /// @author Paul Price, IfA 9 9 /// 10 /// @version $Revision: 1.1 0$ $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 $ 12 12 /// 13 13 /// Copyright 2004-2006 Institute for Astronomy, University of Hawaii … … 78 78 ); 79 79 80 81 82 80 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 83 81 // pmFringeStats … … 147 145 /// Write an array of fringes measurements to a FITS table. 148 146 /// 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). 152 bool 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. 162 psArray *pmFringesParse(pmCell *cell ///< Cell for which to read fringes 158 163 ); 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 and163 /// the (possibly multiple) fringe statistics for that region. The current extension is used if the extension164 /// name is not provided.165 psArray *pmFringesReadFits(psMetadata *header, ///< Header to read, or NULL166 psFits *fits,///< FITS file from which to read167 const char *extname ///< Extension name to read, or NULL168 );169 164 170 165
Note:
See TracChangeset
for help on using the changeset viewer.
