30 #define __attribute__(x) 36 #include "boost/serialization/shared_ptr.hpp" 37 #include "boost/serialization/binary_object.hpp" 38 #include <boost/archive/binary_oarchive.hpp> 39 #include <boost/archive/binary_iarchive.hpp> 43 #include "lsst/daf/base.h" 44 #include "lsst/daf/persistence.h" 45 #include "lsst/log/Log.h" 52 LOG_LOGGER _log = LOG_GET(
"afw.MaskFormatter");
55 using lsst::daf::base::Persistable;
56 using lsst::daf::persistence::BoostStorage;
57 using lsst::daf::persistence::FitsStorage;
58 using lsst::daf::persistence::FormatterStorage;
64 namespace formatters {
66 template <
typename imagePixelT>
69 static std::string
name();
74 static std::string
name =
"Mask";
78 template <
typename MaskPixelT>
82 template <
typename MaskPixelT>
84 : lsst::daf::persistence::Formatter(
typeid(
this)) {}
86 template <
typename MaskPixelT>
89 template <
typename MaskPixelT>
91 std::shared_ptr<lsst::daf::base::PropertySet> additionalData) {
92 LOGL_DEBUG(_log,
"MaskFormatter write start");
95 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Persisting non-Mask");
98 auto boost = std::dynamic_pointer_cast<BoostStorage>(storage);
100 LOGL_DEBUG(_log,
"MaskFormatter write BoostStorage");
101 boost->getOArchive() & *ip;
102 LOGL_DEBUG(_log,
"MaskFormatter write end");
105 auto fits = std::dynamic_pointer_cast<FitsStorage>(storage);
107 LOGL_DEBUG(_log,
"MaskFormatter write FitsStorage");
111 if (additionalData) {
114 }
catch (std::exception
const& exc) {
115 LOGLS_WARN(_log,
"Unable to construct mask write options (" << exc.what() <<
116 "); writing with default options");
121 vip->
writeFits(fits->getPath(), options);
122 LOGL_DEBUG(_log,
"MaskFormatter write end");
125 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unrecognized FormatterStorage for Mask");
128 template <
typename MaskPixelT>
130 std::shared_ptr<lsst::daf::base::PropertySet>) {
131 LOGL_DEBUG(_log,
"MaskFormatter read start");
133 auto boost = std::dynamic_pointer_cast<BoostStorage>(storage);
135 LOGL_DEBUG(_log,
"MaskFormatter read BoostStorage");
137 boost->getIArchive() & *ip;
138 LOGL_DEBUG(_log,
"MaskFormatter read end");
141 auto fits = std::dynamic_pointer_cast<FitsStorage>(storage);
143 LOGL_DEBUG(_log,
"MaskFormatter read FitsStorage");
145 LOGL_DEBUG(_log,
"MaskFormatter read end");
148 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unrecognized FormatterStorage for Mask");
151 template <
typename MaskPixelT>
153 std::shared_ptr<lsst::daf::base::PropertySet>) {
154 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unexpected call to update for Mask");
157 template <
typename MaskPixelT>
158 template <
class Archive>
160 LOGL_DEBUG(_log,
"MaskFormatter delegateSerialize start");
163 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Serializing non-Mask");
165 ar & ip->_offsetRows & ip->_offsetCols;
166 ar & ip->_maskPlaneDict;
170 if (Archive::is_saving::value) {
171 cols = ip->_vwImagePtr->cols();
172 rows = ip->_vwImagePtr->rows();
173 planes = ip->_vwImagePtr->planes();
175 ar& cols& rows& planes;
176 if (Archive::is_loading::value) {
177 ip->_vwImagePtr->set_size(cols, rows, planes);
179 unsigned int pixels = cols * rows * planes;
180 MaskPixelT* data = ip->_vwImagePtr->data();
181 ar& boost::serialization::make_array(data, pixels);
182 LOGL_DEBUG(_log,
"MaskFormatter delegateSerialize end");
185 template <
typename MaskPixelT>
187 std::shared_ptr<lsst::pex::policy::Policy> policy) {
Options for writing an image to FITS.
A base class for image defects.
Represent a 2-dimensional array of bitmask pixels.
std::int32_t MaskPixel
default type for Masks and MaskedImage Masks
void writeFits(std::string const &fileName, std::shared_ptr< lsst::daf::base::PropertySet const > metadata=std::shared_ptr< lsst::daf::base::PropertySet >(), std::string const &mode="w") const
Write a mask to a regular FITS file.