42 class PeakFitsWriter :
public afw::table::io::FitsWriter {
44 explicit PeakFitsWriter(Fits* fits,
int flags) : afw::table::io::FitsWriter(fits, flags) {}
47 virtual void _writeTable(std::shared_ptr<afw::table::BaseTable const>
const& table, std::size_t nRows);
50 void PeakFitsWriter::_writeTable(std::shared_ptr<afw::table::BaseTable const>
const& t, std::size_t nRows) {
51 std::shared_ptr<PeakTable const> table = std::dynamic_pointer_cast<PeakTable
const>(t);
53 throw LSST_EXCEPT(lsst::pex::exceptions::LogicError,
54 "Cannot use a PeakFitsWriter on a non-Peak table.");
57 _fits->writeKey(
"AFW_TYPE",
"PEAK",
"Tells lsst::afw to load this as a Peak table.");
71 class PeakFitsReader :
public afw::table::io::FitsReader {
73 PeakFitsReader() : afw::table::io::FitsReader(
"PEAK") {}
75 virtual std::shared_ptr<afw::table::BaseTable> makeTable(
76 afw::table::io::FitsSchemaInputMapper& mapper, std::shared_ptr<daf::base::PropertyList> metadata,
77 int ioFlags,
bool stripMetadata)
const {
79 table->setMetadata(metadata);
85 static PeakFitsReader
const peakFitsReader;
96 return os << (boost::format(
"%d: (%d,%d) (%.3f,%.3f)") % record.
getId() % record.
getIx() %
101 typedef std::list<std::weak_ptr<PeakTable> > CachedTableList;
102 static CachedTableList cache;
104 throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError,
105 "Schema for Peak must contain at least the keys defined by makeMinimalSchema().");
110 CachedTableList::iterator iter = cache.begin();
111 while (iter != cache.end()) {
112 std::shared_ptr<PeakTable> p = iter->lock();
114 iter = cache.erase(iter);
120 if (iter != cache.begin()) {
121 cache.splice(cache.begin(), cache, iter);
130 cache.push_front(newTable);
135 std::shared_ptr<afw::table::IdFactory>
const& idFactory)
136 : afw::table::BaseTable(schema), _idFactory(idFactory) {}
139 : afw::table::BaseTable(other),
140 _idFactory(other._idFactory ? other._idFactory->
clone() : other._idFactory) {}
142 PeakTable::MinimalSchema::MinimalSchema() {
144 fx =
schema.addField<
float>(
"f_x",
"subpixel column position",
"pixel");
145 fy =
schema.addField<
float>(
"f_y",
"subpixel row position",
"pixel");
146 ix =
schema.addField<
int>(
"i_x",
"column position of highest pixel",
"pixel");
147 iy =
schema.addField<
int>(
"i_y",
"row position of highest pixel",
"pixel");
148 peakValue =
schema.addField<
float>(
"peakValue",
"value of [smoothed] image at peak position",
"count");
149 schema.getCitizen().markPersistent();
152 PeakTable::MinimalSchema& PeakTable::getMinimalSchema() {
153 static MinimalSchema it;
157 std::shared_ptr<afw::table::io::FitsWriter> PeakTable::makeFitsWriter(fits::Fits* fitsfile,
int flags)
const {
158 return std::make_shared<PeakFitsWriter>(fitsfile, flags);
162 return std::shared_ptr<PeakTable>(
new PeakTable(*
this));
166 std::shared_ptr<PeakRecord> record(
new PeakRecord(getSelf<PeakTable>()));
175 template class CatalogT<afw::detection::PeakRecord>;
176 template class CatalogT<afw::detection::PeakRecord const>;
std::int64_t RecordId
Type used for unique IDs for records.
Defines the fields and offsets for a table.
std::ostream & operator<<(std::ostream &os, PeakRecord const &record)
std::shared_ptr< afw::table::IdFactory > getIdFactory()
Return the object that generates IDs for the table (may be null).
Table class for Peaks in Footprints.
static std::shared_ptr< PeakTable > make(afw::table::Schema const &schema, bool forceNew=false)
Obtain a table that can be used to create records with given schema.
std::shared_ptr< afw::table::BaseRecord > _makeRecord() override
Default-construct an associated record (protected implementation).
int getIy() const
Convenience accessors for the keys in the minimal schema.
PeakTable(afw::table::Schema const &schema, std::shared_ptr< afw::table::IdFactory > const &idFactory)
static std::shared_ptr< IdFactory > makeSimple()
Return a simple IdFactory that simply counts from 1.
int getIx() const
Convenience accessors for the keys in the minimal schema.
static bool checkSchema(afw::table::Schema const &other)
Return true if the given schema is a valid PeakTable schema.
float getFy() const
Convenience accessors for the keys in the minimal schema.
float getFx() const
Convenience accessors for the keys in the minimal schema.
PeakRecord(std::shared_ptr< PeakTable > const &table)
std::shared_ptr< afw::table::BaseTable > _clone() const override
Clone implementation with noncovariant return types.
Record class that represents a peak in a Footprint.
afw::table::Schema schema
afw::table::RecordId getId() const
Convenience accessors for the keys in the minimal schema.
virtual void _writeTable(std::shared_ptr< BaseTable const > const &table, std::size_t nRows)
Write a table and its schema.