lsst.afw
20.0.0-9-g61a2a9a3d+63f5489896
|
Go to the documentation of this file.
25 namespace lsst {
namespace afw {
namespace image {
30 _fitsFile(new
fits::Fits(fileName,
"r",
fits::Fits::AUTO_CLOSE |
fits::Fits::AUTO_CHECK))
34 _hdu = _fitsFile->
getHdu();
40 _fitsFile(new
fits::Fits(manager,
"r",
fits::Fits::AUTO_CLOSE |
fits::Fits::AUTO_CHECK))
44 _hdu = _fitsFile->
getHdu();
57 _hdu = _fitsFile->
getHdu();
73 "FitsReader not initialized; desired HDU is probably missing."
81 checkFitsFile(_fitsFile);
88 if (origin ==
LOCAL) {
97 }
else if (origin ==
PARENT) {
106 checkFitsFile(_fitsFile);
107 if (_metadata ==
nullptr) {
111 auto computeShape = [
this](){
117 ndarray::Vector<ndarray::Size, 3> shape3 = _fitsFile->
getImageShape<3>();
118 if (shape3[0] != 1) {
121 str(boost::format(
"Error reading %s: HDU %d has 3rd dimension %d != 1") %
124 return shape3.last<2>();
128 str(boost::format(
"Error reading %s: HDU %d has %d dimensions") %
135 ndarray::Vector<ndarray::Size, 2> shape = computeShape();
146 template <
typename T>
149 static_assert(L::is_specialized,
"makeDTypeString requires a primitive numeric template parameter.");
170 template <
typename T>
173 checkFitsFile(_fitsFile);
176 if (subBBox.isEmpty()) {
178 }
else if (!fullBBox.contains(subBBox)) {
181 str(boost::format(
"Subimage box (%d,%d) %dx%d doesn't fit in image (%d,%d) %dx%d in HDU %d") %
182 subBBox.getMinX() % subBBox.getMinY() % subBBox.getWidth() % subBBox.getHeight() %
183 fullBBox.getMinX() % fullBBox.getMinY() % fullBBox.getWidth() % fullBBox.getHeight() % _hdu)
190 str(boost::format(
"Incompatible type for FITS image: on disk is %s (HDU %d), in-memory is %s. "
191 "Read with allowUnsafe=True to permit conversions that may overflow.") %
195 ndarray::Array<T, 2, 2>
result = ndarray::allocate(subBBox.getHeight(), subBBox.getWidth());
196 ndarray::Vector<int, 2> offset = ndarray::makeVector(subBBox.getMinY() - fullBBox.getMinY(),
197 subBBox.getMinX() - fullBBox.getMinX());
203 #define INSTANTIATE(T) \
204 template ndarray::Array<T, 2, 2> ImageBaseFitsReader::readArray( \
205 lsst::geom::Box2I const & bbox, \
206 ImageOrigin origin, \
ndarray::Array< T, 2, 2 > readArray(lsst::geom::Box2I const &bbox, ImageOrigin origin=PARENT, bool allowUnsafe=false)
Read the image's data array.
std::shared_ptr< daf::base::PropertyList > readMetadata(std::string const &fileName, int hdu=DEFAULT_HDU, bool strip=false)
Read FITS header.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
const int DEFAULT_HDU
Specify that the default HDU should be read.
std::string getFileName() const
Return the name of the file this reader targets.
An exception thrown when problems are found when reading or writing FITS files.
Extent2I const getDimensions() const noexcept
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
RAII scoped guard for moving the HDU in a Fits object.
lsst::geom::Point2I readXY0(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT)
Read the image origin from the on-disk image or a subimage thereof.
Point2I const getMin() const noexcept
Lifetime-management for memory that goes into FITS memory files.
ImageBaseFitsReader(std::string const &fileName, int hdu=fits::DEFAULT_HDU)
Construct a FITS reader object.
std::string readDType() const
Read a string describing the pixel type of the on-disk image.
#define LSST_FITS_EXCEPT(type, fitsObj,...)
A FITS-related replacement for LSST_EXCEPT that takes an additional Fits object and uses makeErrorMes...
std::unique_ptr< SchemaItem< U > > result
lsst::geom::Box2I readBBox(ImageOrigin origin=PARENT)
Read the bounding box of the on-disk image.
void setHdu(int hdu, bool relative=false)
Set the current HDU.
~ImageBaseFitsReader() noexcept
ndarray::Vector< ndarray::Size, N > getImageShape()
Return the shape of the current (image) HDU.
std::string getImageDType()
Return the numpy dtype equivalent of the image pixel type (e.g.
void readImage(ndarray::Array< T, N, N > const &array, ndarray::Vector< int, N > const &offset)
Read an array from a FITS image.
A base class for image defects.
int getHdu()
Return the current HDU (0-indexed; 0 is the Primary HDU).
std::string const wcsNameForXY0
#define LSST_EXCEPT(type,...)
std::shared_ptr< daf::base::PropertyList > readMetadata()
Read the image's FITS header.
Extent< int, 2 > Extent2I
lsst::geom::Point2I getImageXY0FromMetadata(daf::base::PropertySet &metadata, std::string const &wcsName, bool strip=false)
int getImageDim()
Return the number of dimensions in the current HDU.
An exception thrown when a FITS file has the wrong type.
bool checkCompressedImagePhu()
Go to the first image header in the FITS file.
bool checkImageType()
Return true if the current HDU is compatible with the given pixel type.