30 #define __attribute__(x)
38 #include "boost/serialization/shared_ptr.hpp"
39 #include <boost/archive/binary_iarchive.hpp>
40 #include <boost/archive/binary_oarchive.hpp>
41 #include <boost/archive/text_iarchive.hpp>
42 #include <boost/archive/text_oarchive.hpp>
44 #include "lsst/daf/base.h"
45 #include "lsst/daf/persistence.h"
46 #include "lsst/log/Log.h"
54 LOG_LOGGER _log = LOG_GET(
"afw.MaskedImageFormatter");
57 using lsst::daf::base::Persistable;
58 using lsst::daf::persistence::BoostStorage;
59 using lsst::daf::persistence::FitsStorage;
60 using lsst::daf::persistence::FormatterStorage;
67 namespace formatters {
69 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
72 static std::string
name();
77 static std::string
name =
"MaskedImageU";
82 static std::string
name =
"MaskedImageI";
87 static std::string
name =
"MaskedImageF";
92 static std::string
name =
"MaskedImageD";
97 static std::string
name =
"MaskedImageL";
101 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
102 lsst::daf::persistence::FormatterRegistration
107 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
109 std::shared_ptr<lsst::pex::policy::Policy>)
110 : lsst::daf::persistence::Formatter(typeid(this)) {}
112 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
115 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
117 Persistable
const* persistable, std::shared_ptr<FormatterStorage> storage,
118 std::shared_ptr<lsst::daf::base::PropertySet> additionalData) {
119 LOGL_DEBUG(_log,
"MaskedImageFormatter write start");
123 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Persisting non-MaskedImage");
126 auto boost = std::dynamic_pointer_cast<BoostStorage>(storage);
128 LOGL_DEBUG(_log,
"MaskedImageFormatter write BoostStorage");
129 boost->getOArchive() & *ip;
130 LOGL_DEBUG(_log,
"MaskedImageFormatter write end");
133 auto fits = std::dynamic_pointer_cast<FitsStorage>(storage);
135 LOGL_DEBUG(_log,
"MaskedImageFormatter write FitsStorage");
138 if (additionalData) {
143 }
catch (std::exception
const& exc) {
144 LOGLS_WARN(_log,
"Unable to construct MaskedImage write options (" << exc.what() <<
145 "); writing with default options");
148 ip->
writeFits(fits->getPath(), imageOptions, maskOptions, varianceOptions);
149 LOGL_DEBUG(_log,
"MaskedImageFormatter write end");
152 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unrecognized FormatterStorage for MaskedImage");
155 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
157 std::shared_ptr<FormatterStorage> storage, std::shared_ptr<lsst::daf::base::PropertySet>) {
158 LOGL_DEBUG(_log,
"MaskedImageFormatter read start");
159 auto boost = std::dynamic_pointer_cast<BoostStorage>(storage);
162 LOGL_DEBUG(_log,
"MaskedImageFormatter read BoostStorage");
164 boost->getIArchive() & *ip;
165 LOGL_DEBUG(_log,
"MaskedImageFormatter read end");
168 auto fits = std::dynamic_pointer_cast<FitsStorage>(storage);
170 LOGL_DEBUG(_log,
"MaskedImageFormatter read FitsStorage");
172 LOGL_DEBUG(_log,
"MaskedImageFormatter read end");
175 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unrecognized FormatterStorage for MaskedImage");
178 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
180 Persistable*, std::shared_ptr<FormatterStorage>, std::shared_ptr<lsst::daf::base::PropertySet>) {
181 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unexpected call to update for MaskedImage");
184 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
185 template <
class Archive>
187 Archive& ar,
unsigned int const, Persistable* persistable) {
188 LOGL_DEBUG(_log,
"MaskedImageFormatter delegateSerialize start");
192 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Serializing non-MaskedImage");
194 ar & ip->_image & ip->_variance & ip->_mask;
195 LOGL_DEBUG(_log,
"MaskedImageFormatter delegateSerialize end");
198 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
199 std::shared_ptr<lsst::daf::persistence::Formatter>
201 std::shared_ptr<lsst::pex::policy::Policy> policy) {
202 return std::shared_ptr<lsst::daf::persistence::Formatter>(
207 #define INSTANTIATE(I, M, V) \
208 template class MaskedImageFormatter<I, M, V>; \
209 template void MaskedImageFormatter<I, M, V>::delegateSerialize<boost::archive::text_oarchive>( \
210 boost::archive::text_oarchive&, unsigned int const, Persistable*); \
211 template void MaskedImageFormatter<I, M, V>::delegateSerialize<boost::archive::text_iarchive>( \
212 boost::archive::text_iarchive&, unsigned int const, Persistable*); \
213 template void MaskedImageFormatter<I, M, V>::delegateSerialize<boost::archive::binary_oarchive>( \
214 boost::archive::binary_oarchive&, unsigned int const, Persistable*); \
215 template void MaskedImageFormatter<I, M, V>::delegateSerialize<boost::archive::binary_iarchive>( \
216 boost::archive::binary_iarchive&, unsigned int const, Persistable*);
Options for writing an image to FITS.
void writeFits(std::string const &fileName, std::shared_ptr< daf::base::PropertySet const > metadata=std::shared_ptr< daf::base::PropertySet const >(), std::shared_ptr< daf::base::PropertySet const > imageMetadata=std::shared_ptr< daf::base::PropertySet const >(), std::shared_ptr< daf::base::PropertySet const > maskMetadata=std::shared_ptr< daf::base::PropertySet const >(), std::shared_ptr< daf::base::PropertySet const > varianceMetadata=std::shared_ptr< daf::base::PropertySet const >()) const
Write a MaskedImage to a regular FITS file.
A class to manipulate images, masks, and variance as a single object.
table::Key< std::string > name
std::int32_t MaskPixel
default type for Masks and MaskedImage Masks
float VariancePixel
default type for MaskedImage variance images
#define INSTANTIATE(FROMSYS, TOSYS)