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) {
124 return shape3.last<2>();
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, \ Extent2I const getDimensions() const noexcept
int getImageDim()
Return the number of dimensions in the current HDU.
std::shared_ptr< daf::base::PropertyList > readMetadata()
Read the image's FITS header.
lsst::geom::Box2I readBBox(ImageOrigin origin=PARENT)
Read the bounding box of the on-disk image.
bool isEmpty() const noexcept
Return true if the box contains no points.
Reports attempts to exceed implementation-defined length limits for some classes. ...
std::string getFileName() const
Return the name of the file this reader targets.
bool checkImageType()
Return true if the current HDU is compatible with the given pixel type.
std::string readDType() const
Read a string describing the pixel type of the on-disk image.
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
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.
Point2I const getMin() const noexcept
An exception thrown when problems are found when reading or writing FITS files.
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.
ndarray::Vector< ndarray::Size, N > getImageShape()
Return the shape of the current (image) HDU.
ImageBaseFitsReader(std::string const &fileName, int hdu=fits::DEFAULT_HDU)
Construct a FITS reader object.
A base class for image defects.
Lifetime-management for memory that goes into FITS memory files.
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
~ImageBaseFitsReader() noexcept
void setHdu(int hdu, bool relative=false)
Set the current HDU.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Extent< int, 2 > Extent2I
lsst::geom::Point2I getImageXY0FromMetadata(daf::base::PropertySet &metadata, std::string const &wcsName, bool strip=false)
bool checkCompressedImagePhu()
Go to the first image header in the FITS file.
An exception thrown when a FITS file has the wrong type.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
int getHdu()
Return the current HDU (0-indexed; 0 is the Primary HDU).
#define LSST_FITS_EXCEPT(type, fitsObj,...)
A FITS-related replacement for LSST_EXCEPT that takes an additional Fits object and uses makeErrorMes...
An integer coordinate rectangle.
RAII scoped guard for moving the HDU in a Fits object.
std::string const wcsNameForXY0
ndarray::Array< T, 2, 2 > readArray(lsst::geom::Box2I const &bbox, ImageOrigin origin=PARENT, bool allowUnsafe=false)
Read the image's data array.
const int DEFAULT_HDU
Specify that the default HDU should be read.
std::shared_ptr< daf::base::PropertyList > readMetadata(std::string const &fileName, int hdu=DEFAULT_HDU, bool strip=false)
Read FITS header.