LSSTApplications  15.0+21,16.0+1,16.0+3,16.0+4,16.0+8,16.0-1-g2115a9e+2,16.0-1-g4515a79+6,16.0-1-g5c6f5ee+4,16.0-1-g7bb14cc,16.0-1-g80120d7+4,16.0-1-g98efed3+4,16.0-1-gb7f560d+1,16.0-14-gb4f0cd2fa,16.0-2-g1ad129e+1,16.0-2-g2ed7261+1,16.0-2-g311bfd2,16.0-2-g568a347+3,16.0-2-g852da13+6,16.0-2-gd4c87cb+3,16.0-3-g099ede0,16.0-3-g150e024+3,16.0-3-g1f513a6,16.0-3-g958ce35,16.0-4-g08dccf71+4,16.0-4-g128aaef,16.0-4-g84f75fb+5,16.0-4-gcfd1396+4,16.0-4-gde8cee2,16.0-4-gdfb0d14+1,16.0-5-g7bc0afb+3,16.0-5-g86fb31a+3,16.0-6-g2dd73041+4,16.0-7-g95fb7bf,16.0-7-gc37dbc2+4,w.2018.28
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
#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
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.
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:245
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:134
T dynamic_pointer_cast(T... args)
Abstract base class for all formatters.
Definition: Formatter.h:79
STL class.
T get(T... args)
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:47
#define __attribute__(x)
std::shared_ptr< geom::SkyWcs const > getWcs() const
Definition: Exposure.h:236
Class for boost::serialization storage.
Definition: BoostStorage.h:59
Base class for all persistable classes.
Definition: Persistable.h:73
void delegateSerialize(Archive &ar, unsigned int const version, lsst::daf::base::Persistable *persistable)
Template function that serializes a Persistable using boost::serialization.
Definition: FormatterImpl.h:58
void writeFits(std::string const &fileName) const
Write an Exposure to a regular multi-extension FITS file.
Definition: Exposure.cc:153
#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