LSST Applications g0265f82a02+c6dfa2ddaf,g1162b98a3f+b2075782a9,g2079a07aa2+1b2e822518,g2bbee38e9b+c6dfa2ddaf,g337abbeb29+c6dfa2ddaf,g3ddfee87b4+a60788ef87,g50ff169b8f+2eb0e556e8,g52b1c1532d+90ebb246c7,g555ede804d+a60788ef87,g591dd9f2cf+ba8caea58f,g5ec818987f+864ee9cddb,g858d7b2824+9ee1ab4172,g876c692160+a40945ebb7,g8a8a8dda67+90ebb246c7,g8cdfe0ae6a+4fd9e222a8,g99cad8db69+5e309b7bc6,g9ddcbc5298+a1346535a5,ga1e77700b3+df8f93165b,ga8c6da7877+aa12a14d27,gae46bcf261+c6dfa2ddaf,gb0e22166c9+8634eb87fb,gb3f2274832+d0da15e3be,gba4ed39666+1ac82b564f,gbb8dafda3b+5dfd9c994b,gbeb006f7da+97157f9740,gc28159a63d+c6dfa2ddaf,gc86a011abf+9ee1ab4172,gcf0d15dbbd+a60788ef87,gdaeeff99f8+1cafcb7cd4,gdc0c513512+9ee1ab4172,ge79ae78c31+c6dfa2ddaf,geb67518f79+ba1859f325,geb961e4c1e+f9439d1e6f,gee10cc3b42+90ebb246c7,gf1cff7945b+9ee1ab4172,w.2024.12
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
lsst::afw::table::io::FitsReader Class Reference

A utility class for reading FITS binary tables. More...

#include <FitsReader.h>

Public Member Functions

 FitsReader (std::string const &persistedClassName)
 Construct a FitsReader, registering it to be used for all persisted tables with the given tag.
 
 FitsReader (FitsReader const &)=default
 
 FitsReader (FitsReader &&)=default
 
FitsReaderoperator= (FitsReader const &)=default
 
FitsReaderoperator= (FitsReader &&)=default
 
virtual std::shared_ptr< BaseTablemakeTable (FitsSchemaInputMapper &mapper, std::shared_ptr< daf::base::PropertyList > metadata, int ioFlags, bool stripMetadata) const
 Callback to create a Table object from a FITS binary table schema.
 
virtual bool usesArchive (int ioFlags) const
 Callback that should return true if the FitsReader subclass makes use of an InputArchive to read first-class objects from additional FITS HDUs.
 
virtual ~FitsReader ()=default
 

Static Public Member Functions

template<typename ContainerT >
static ContainerT apply (afw::fits::Fits &fits, int ioFlags, std::shared_ptr< InputArchive > archive=std::shared_ptr< InputArchive >())
 Create a new Catalog by reading a FITS binary table.
 
template<typename ContainerT , typename SourceT >
static ContainerT apply (SourceT &source, int hdu, int ioFlags, std::shared_ptr< InputArchive > archive=std::shared_ptr< InputArchive >())
 Create a new Catalog by reading a FITS file.
 

Detailed Description

A utility class for reading FITS binary tables.

FitsReader itself provides the implementation for reading standard FITS binary tables (with a limited subset of FITS column types), but it also allows subclasses to be used instead, depending on what's actually in the FITS file. If the FITS header has the key "AFW_TABLE" with a value other than "BASE", FitsReader::apply consults a registry of subclasses to retreive one corresponding to that key. This means the type of records/tables loaded correctly depends on the file itself, rather than the caller. For instance, if you load a FITS table corresponding to a saved SourceCatalog using BaseCatalog::readFits, you'll actually get a BaseCatalog whose record are actually SourceRecords and whose table is actually a SourceTable. On the other hand, if you try to load a non-Source FITS table into a SourceCatalog, you'll get an exception when it tries to dynamic_cast the table to a SourceTable.

Definition at line 34 of file FitsReader.h.

Constructor & Destructor Documentation

◆ FitsReader() [1/3]

lsst::afw::table::io::FitsReader::FitsReader ( std::string const & persistedClassName)
explicit

Construct a FitsReader, registering it to be used for all persisted tables with the given tag.

Because they need to live in the static registry, each distinct subclass of FitsReader should be constructed only once, in a static-scope variable. The FitsReader constructor will add a pointer to that variable to the registry.

Definition at line 32 of file FitsReader.cc.

32{ getRegistry()[name] = this; }
table::Key< std::string > name
Definition Amplifier.cc:116

◆ FitsReader() [2/3]

lsst::afw::table::io::FitsReader::FitsReader ( FitsReader const & )
default

◆ FitsReader() [3/3]

lsst::afw::table::io::FitsReader::FitsReader ( FitsReader && )
default

◆ ~FitsReader()

virtual lsst::afw::table::io::FitsReader::~FitsReader ( )
virtualdefault

Member Function Documentation

◆ apply() [1/2]

template<typename ContainerT >
static ContainerT lsst::afw::table::io::FitsReader::apply ( afw::fits::Fits & fits,
int ioFlags,
std::shared_ptr< InputArchive > archive = std::shared_ptr<InputArchive>() )
inlinestatic

Create a new Catalog by reading a FITS binary table.

This is the lower-level implementation delegated to by all Catalog::readFits() methods. It creates a new Catalog of type ContainerT, creates a FitsReader according to the tag found in the file, then reads the schema and adds records to the Catalog.

Parameters
[in]fitsAn afw::fits::Fits helper that points to a FITS binary table HDU.
[in]ioFlagsA set of subclass-dependent bitflags that control optional aspects of FITS persistence. For instance, SourceFitsFlags are used by SourceCatalog to control how to read and write Footprints.
[in]archiveAn archive of Persistables containing objects that may be associated with table records. For record subclasses that have associated Persistables (e.g. SourceRecord Footprints, or ExposureRecord Psfs), this archive is usually persisted in additional HDUs in the FITS file after the main binary table, and will be loaded automatically if the passed archive is null. The explicit archive argument is provided only for cases in which the catalog itself is part of a larger object, and does not "own" its own archive (e.g. CoaddPsf persistence).

Definition at line 71 of file FitsReader.h.

72 {
73 std::shared_ptr<daf::base::PropertyList> metadata = std::make_shared<daf::base::PropertyList>();
74 fits.readMetadata(*metadata, true);
75 FitsReader const* reader = _lookupFitsReader(*metadata);
76 FitsSchemaInputMapper mapper(*metadata, true);
77 reader->_setupArchive(fits, mapper, archive, ioFlags);
78 std::shared_ptr<BaseTable> table = reader->makeTable(mapper, metadata, ioFlags, true);
79 ContainerT container(std::dynamic_pointer_cast<typename ContainerT::Table>(table));
80 if (!container.getTable()) {
81 throw LSST_EXCEPT(pex::exceptions::RuntimeError, "Invalid table class for catalog.");
82 }
83 std::size_t nRows = fits.countRows();
84 container.reserve(nRows);
85 for (std::size_t row = 0; row < nRows; ++row) {
86 mapper.readRecord(
87 // We need to be able to support reading Catalog<T const>, since it shares the same
88 // template
89 // as Catalog<T> (which invokes this method in readFits).
91 *container.addNew()),
92 fits, row);
93 }
94 return container;
95 }
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
SchemaMapper * mapper
FitsReader(std::string const &persistedClassName)
Construct a FitsReader, registering it to be used for all persisted tables with the given tag.
Definition FitsReader.cc:32
int row
Definition CR.cc:145

◆ apply() [2/2]

template<typename ContainerT , typename SourceT >
static ContainerT lsst::afw::table::io::FitsReader::apply ( SourceT & source,
int hdu,
int ioFlags,
std::shared_ptr< InputArchive > archive = std::shared_ptr<InputArchive>() )
inlinestatic

Create a new Catalog by reading a FITS file.

This is a simply a convenience function that creates an afw::fits::Fits object from either a string filename or a afw::fits::MemFileManager, then calls the other apply() overload.

Definition at line 104 of file FitsReader.h.

105 {
106 afw::fits::Fits fits(source, "r", afw::fits::Fits::AUTO_CLOSE | afw::fits::Fits::AUTO_CHECK);
107 fits.setHdu(hdu);
108 return apply<ContainerT>(fits, ioFlags, archive);
109 }

◆ makeTable()

std::shared_ptr< BaseTable > lsst::afw::table::io::FitsReader::makeTable ( FitsSchemaInputMapper & mapper,
std::shared_ptr< daf::base::PropertyList > metadata,
int ioFlags,
bool stripMetadata ) const
virtual

Callback to create a Table object from a FITS binary table schema.

Subclass readers must override to return the appropriate Table subclass. Most implementations can simply call mapper.finalize() to create the Schema, then construct a new Table and set its metadata to the given PropertyList. Readers for record classes that have first-class objects in addition to regular fields should call mapper.customize() with a custom FitsColumnReader before calling finalize().

Parameters
[in]mapperA representation of the FITS binary table schema, capable of producing an afw::table::Schema from it while allowing customization of the mapping beforehand.
[in]metadataEntries from the FITS header, which should usually be attached to the returned table object via its setMetadata method.
[in]ioFlagsSubclass-dependent bitflags that control optional persistence behaavior (see e.g. SourceFitsFlags).
[in]stripMetadataIf True, remove entries from the metadata that were added by the persistence code.

Definition at line 24 of file FitsReader.cc.

26 {
28 result->setMetadata(metadata);
29 return result;
30}
py::object result
Definition _schema.cc:429
static std::shared_ptr< BaseTable > make(Schema const &schema)
Construct a new table.
Definition BaseTable.cc:120

◆ operator=() [1/2]

FitsReader & lsst::afw::table::io::FitsReader::operator= ( FitsReader && )
default

◆ operator=() [2/2]

FitsReader & lsst::afw::table::io::FitsReader::operator= ( FitsReader const & )
default

◆ usesArchive()

virtual bool lsst::afw::table::io::FitsReader::usesArchive ( int ioFlags) const
inlinevirtual

Callback that should return true if the FitsReader subclass makes use of an InputArchive to read first-class objects from additional FITS HDUs.

Definition at line 138 of file FitsReader.h.

138{ return false; }

The documentation for this class was generated from the following files: