LSSTApplications  16.0+42,16.0-1-gce273f5+8,16.0-10-g230e10e+1,16.0-11-g9fe0e56+17,16.0-11-gce733cf+17,16.0-12-g5ad1ebf+9,16.0-12-gc85596e+2,16.0-13-gde155d7+2,16.0-14-g9428de4d,16.0-14-gc1cf4a94+2,16.0-15-g8e16a51+14,16.0-2-g0febb12+7,16.0-2-g839ba83+32,16.0-2-g9d5294e+22,16.0-2-gab3db49+7,16.0-2-gf41ba6b+6,16.0-2-gf4e7cdd+5,16.0-3-g6923fb6+15,16.0-3-g8e51203+2,16.0-3-g9645794+6,16.0-3-gcfd6c53+20,16.0-35-g34c7dfe62+1,16.0-4-g03cf288+11,16.0-4-g32d12de,16.0-4-g5f3a788+7,16.0-4-g7690030+30,16.0-4-g8a0f11a+16,16.0-4-ga5d8928+16,16.0-5-g0da18be+7,16.0-5-g4940a70,16.0-5-g563880a+2,16.0-5-g7742071+2,16.0-5-gb3f8a4b+26,16.0-6-g3610b4f+5,16.0-6-gf0acd13+14,16.0-8-g4dec96c+7,16.0-8-gc315727+16,16.0-9-g1de645c+7,16.0-9-gcc4efb7+6,w.2018.36
LSSTDataManagementBasePackage
ExposureFormatter.cc
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
25 /*
26  * Implementation of ExposureFormatter class
27  */
28 
29 #ifndef __GNUC__
30 #define __attribute__(x) /*NOTHING*/
31 #endif
32 static char const* SVNid __attribute__((unused)) = "$Id$";
33 
34 #include <cstdint>
35 #include <iostream>
36 #include <string>
37 
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>
43 
44 #include "lsst/daf/base.h"
45 #include "lsst/pex/exceptions.h"
46 #include "lsst/daf/persistence.h"
47 #include "lsst/log/Log.h"
52 
53 // #include "lsst/afw/image/LSSTFitsResource.h"
54 
55 namespace {
56 LOG_LOGGER _log = LOG_GET("afw.ExposureFormatter");
57 }
58 
59 namespace lsst {
60 namespace afw {
61 namespace formatters {
62 
63 namespace dafBase = lsst::daf::base;
65 
66 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
68 public:
69  static std::string name();
70 };
71 
72 template <>
74  static std::string name = "ExposureU";
75  return name;
76 }
77 template <>
79  static std::string name = "ExposureI";
80  return name;
81 }
82 template <>
84  static std::string name = "ExposureF";
85  return name;
86 }
87 template <>
89  static std::string name = "ExposureD";
90  return name;
91 }
92 template <>
94  static std::string name = "ExposureL";
95  return name;
96 }
97 
98 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
103 
104 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
107  : daf::persistence::Formatter(typeid(this)), _policy(policy) {}
108 
109 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
111 
112 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
116  LOGL_DEBUG(_log, "ExposureFormatter write start");
118  dynamic_cast<image::Exposure<ImagePixelT, MaskPixelT, VariancePixelT> const*>(persistable);
119  if (ip == 0) {
120  throw LSST_EXCEPT(pex::exceptions::RuntimeError, "Persisting non-Exposure");
121  }
122  // TODO: Replace this with something better in DM-10776
124  if (boost) {
125  LOGL_DEBUG(_log, "ExposureFormatter write BoostStorage");
126  boost->getOArchive() & *ip;
127  LOGL_DEBUG(_log, "ExposureFormatter write end");
128  return;
129  }
131  if (fits) {
132  LOGL_DEBUG(_log, "ExposureFormatter write FitsStorage");
133 
134  fits::ImageWriteOptions imageOptions, maskOptions, varianceOptions;
135  if (additionalData) {
136  try {
137  imageOptions = fits::ImageWriteOptions(*additionalData->getAsPropertySetPtr("image"));
138  maskOptions = fits::ImageWriteOptions(*additionalData->getAsPropertySetPtr("mask"));
139  varianceOptions = fits::ImageWriteOptions(*additionalData->getAsPropertySetPtr("variance"));
140  } catch (std::exception const& exc) {
141  LOGLS_WARN(_log, "Unable to construct Exposure write options ("
142  << exc.what() << "); writing with default options");
143  }
144  }
145 
146  ip->writeFits(fits->getPath(), imageOptions, maskOptions, varianceOptions);
147  LOGL_DEBUG(_log, "ExposureFormatter write end");
148  return;
149  }
150  throw LSST_EXCEPT(pex::exceptions::RuntimeError, "Unrecognized FormatterStorage for Exposure");
151 }
152 
153 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
157  LOGL_DEBUG(_log, "ExposureFormatter read start");
158  // TODO: Replace this with something better in DM-10776
160  if (boost) {
161  LOGL_DEBUG(_log, "ExposureFormatter read BoostStorage");
164  boost->getIArchive() & *ip;
165  LOGL_DEBUG(_log, "ExposureFormatter read end");
166  return ip;
167  }
169  if (fits) {
170  LOGL_DEBUG(_log, "ExposureFormatter read FitsStorage");
172  if (additionalData->exists("llcX")) {
173  int llcX = additionalData->get<int>("llcX");
174  int llcY = additionalData->get<int>("llcY");
175  int width = additionalData->get<int>("width");
176  int height = additionalData->get<int>("height");
177  box = lsst::geom::Box2I(lsst::geom::Point2I(llcX, llcY), lsst::geom::Extent2I(width, height));
178  }
180  if (additionalData->exists("imageOrigin")) {
181  std::string originStr = additionalData->get<std::string>("imageOrigin");
182  if (originStr == "LOCAL") {
183  origin = image::LOCAL;
184  } else if (originStr == "PARENT") {
185  origin = image::PARENT;
186  } else {
188  (boost::format("Unknown ImageOrigin type %s specified in additional"
189  "data for retrieving Exposure from fits") %
190  originStr
191 
192  )
193  .str());
194  }
195  }
198  LOGL_DEBUG(_log, "ExposureFormatter read end");
199  return ip;
200  }
201  throw LSST_EXCEPT(pex::exceptions::RuntimeError, "Unrecognized FormatterStorage for Exposure");
202 }
203 
204 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
209  // - KTL - 2007-11-29
210  throw LSST_EXCEPT(pex::exceptions::RuntimeError, "Unexpected call to update for Exposure");
211 }
212 
213 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
214 template <class Archive>
216  Archive& ar, unsigned int const, dafBase::Persistable* persistable) {
217  LOGL_DEBUG(_log, "ExposureFormatter delegateSerialize start");
220  if (ip == 0) {
221  throw LSST_EXCEPT(pex::exceptions::RuntimeError, "Serializing non-Exposure");
222  }
224  ar& * ip->getMetadata() & ip->_maskedImage; // & wcs; // TODO: replace this with what?
225  LOGL_DEBUG(_log, "ExposureFormatter delegateSerialize end");
226 }
227 
228 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
234 }
235 
237 #define INSTANTIATE(I, M, V) \
238  template class ExposureFormatter<I, M, V>; \
239  template void ExposureFormatter<I, M, V>::delegateSerialize<boost::archive::text_oarchive>( \
240  boost::archive::text_oarchive&, unsigned int const, dafBase::Persistable*); \
241  template void ExposureFormatter<I, M, V>::delegateSerialize<boost::archive::text_iarchive>( \
242  boost::archive::text_iarchive&, unsigned int const, dafBase::Persistable*); \
243  template void ExposureFormatter<I, M, V>::delegateSerialize<boost::archive::binary_oarchive>( \
244  boost::archive::binary_oarchive&, unsigned int const, dafBase::Persistable*); \
245  template void ExposureFormatter<I, M, V>::delegateSerialize<boost::archive::binary_iarchive>( \
246  boost::archive::binary_iarchive&, unsigned int const, dafBase::Persistable*);
247 
254 } // namespace formatters
255 } // namespace afw
256 } // namespace lsst
#define LOGLS_WARN(logger, message)
Log a warn-level message using an iostream-based interface.
Definition: Log.h:657
lsst::daf::base::Persistable * read(std::shared_ptr< lsst::daf::persistence::FormatterStorage > storage, std::shared_ptr< lsst::daf::base::PropertySet > additionalData) override
#define LOG_LOGGER
Definition: Log.h:712
Definition: Span.h:36
A class to contain the data, WCS, and other information needed to describe an image of the sky...
Definition: Exposure.h:78
Options for writing an image to FITS.
Definition: fits.h:218
void write(lsst::daf::base::Persistable const *persistable, std::shared_ptr< lsst::daf::persistence::FormatterStorage > storage, std::shared_ptr< lsst::daf::base::PropertySet > additionalData) override
Construct a static instance of this helper class to register a Formatter subclass in the FormatterReg...
Definition: Formatter.h:138
Class for FITS file storage.
Definition: FitsStorage.h:52
daf_persistence package header file
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition: Log.h:513
table::Key< table::Array< std::uint8_t > > wcs
Definition: SkyWcs.cc:66
Fits * fits
Definition: FitsWriter.cc:90
STL class.
LSST DM logging module built on log4cxx.
void update(lsst::daf::base::Persistable *persistable, std::shared_ptr< lsst::daf::persistence::FormatterStorage > storage, std::shared_ptr< lsst::daf::base::PropertySet > additionalData) override
#define __attribute__(x)
Class implementing persistence and retrieval for Exposures.
A base class for image defects.
Definition: cameraGeom.dox:3
T what(T... args)
Interface for PropertySetFormatter class.
std::shared_ptr< lsst::daf::base::PropertySet > getMetadata() const
Return flexible metadata.
Definition: Exposure.h:243
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:129
T dynamic_pointer_cast(T... args)
Abstract base class for all formatters.
Definition: Formatter.h:79
STL class.
T get(T... args)
static void delegateSerialize(Archive &ar, unsigned int const version, lsst::daf::base::Persistable *persistable)
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:47
std::shared_ptr< geom::SkyWcs const > getWcs() const
Definition: Exposure.h:234
Class for boost::serialization storage.
Definition: BoostStorage.h:59
static std::shared_ptr< lsst::daf::persistence::Formatter > createInstance(std::shared_ptr< lsst::pex::policy::Policy > policy)
Base class for all persistable classes.
Definition: Persistable.h:73
void writeFits(std::string const &fileName) const
Write an Exposure to a regular multi-extension FITS file.
Definition: Exposure.cc:154
ExposureFormatter(ExposureFormatter const &)=default
#define LOG_GET(logger)
Returns a Log object associated with logger.
Definition: Log.h:83
float VariancePixel
default type for MaskedImage variance images
An integer coordinate rectangle.
Definition: Box.h:54
#define INSTANTIATE(FROMSYS, TOSYS)
Definition: Detector.cc:156
Reports errors that are due to events beyond the control of the program.
Definition: Runtime.h:104