Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-13110: export magic value to select default HDU #300

Merged
merged 1 commit into from
Jan 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions include/lsst/afw/fits.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "lsst/daf/base.h"
#include "ndarray.h"
#include "lsst/afw/fitsCompression.h"
#include "lsst/afw/fitsDefaults.h"

namespace lsst {
namespace afw {
Expand Down Expand Up @@ -300,7 +301,7 @@ class Fits {
* Set the current HDU.
*
* @param[in] hdu The HDU to move to (0-indexed; 0 is the Primary HDU).
* The special value of INT_MIN moves to the first extension
* The special value of DEFAULT_HDU moves to the first extension
* if the Primary HDU is empty (has NAXIS==0) and the
* the Primary HDU is the current one.
* @param[in] relative If true, move relative to the current HDU.
Expand Down Expand Up @@ -640,7 +641,7 @@ class Fits {
* @param strip if `true`, common FITS keys that usually have non-metadata intepretations
* (e.g. NAXIS, BITPIX) will be ignored.
*/
std::shared_ptr<daf::base::PropertyList> readMetadata(std::string const& fileName, int hdu = INT_MIN,
std::shared_ptr<daf::base::PropertyList> readMetadata(std::string const& fileName, int hdu = DEFAULT_HDU,
bool strip = false);
/** Read FITS header
*
Expand All @@ -652,7 +653,7 @@ std::shared_ptr<daf::base::PropertyList> readMetadata(std::string const& fileNam
* @param strip if `true`, common FITS keys that usually have non-metadata intepretations
* (e.g. NAXIS, BITPIX) will be ignored.
*/
std::shared_ptr<daf::base::PropertyList> readMetadata(fits::MemFileManager& manager, int hdu = INT_MIN,
std::shared_ptr<daf::base::PropertyList> readMetadata(fits::MemFileManager& manager, int hdu = DEFAULT_HDU,
bool strip = false);
/** Read FITS header
*
Expand Down
22 changes: 22 additions & 0 deletions include/lsst/afw/fitsDefaults.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// -*- lsst-c++ -*-
#ifndef LSST_AFW_fitsDefaults_h_INCLUDED
#define LSST_AFW_fitsDefaults_h_INCLUDED

#include <climits>

namespace lsst {
namespace afw {
namespace fits {

/**
* Specify that the default HDU should be read.
*
* This special HDU number indicates that the first extension
* should be used if the primary HDU is empty (i.e., has NAXIS=0)
* and the Primary HDU is the current.
*/
const int DEFAULT_HDU = INT_MIN;

}}} // namespace lsst::afw::fits

#endif
27 changes: 14 additions & 13 deletions include/lsst/afw/image/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "lsst/afw/image/ImageUtils.h"
#include "lsst/afw/image/Mask.h"
#include "lsst/afw/math/Function.h"
#include "lsst/afw/fitsDefaults.h"
#include "lsst/daf/base.h"
#include "lsst/daf/base/Citizen.h"
#include "lsst/pex/exceptions.h"
Expand Down Expand Up @@ -141,14 +142,14 @@ class Image : public ImageBase<PixelT> {
*
* @param[in] fileName File to read.
* @param[in] hdu HDU to read, 0-indexed (i.e. 0=Primary HDU). The special value
* of INT_MIN reads the Primary HDU unless it is empty, in which case it
* reads the first extension HDU.
* of afw::fits::DEFAULT_HDU reads the Primary HDU unless it is empty,
* in which case it reads the first extension HDU.
* @param[in,out] metadata Metadata read from the header (may be null).
* @param[in] bbox If non-empty, read only the pixels within the bounding box.
* @param[in] origin Coordinate system of the bounding box; if PARENT, the bounding box
* should take into account the xy0 saved with the image.
*/
explicit Image(std::string const& fileName, int hdu = INT_MIN,
explicit Image(std::string const& fileName, int hdu = fits::DEFAULT_HDU,
std::shared_ptr<lsst::daf::base::PropertySet> metadata =
std::shared_ptr<lsst::daf::base::PropertySet>(),
geom::Box2I const& bbox = geom::Box2I(), ImageOrigin origin = PARENT);
Expand All @@ -158,14 +159,14 @@ class Image : public ImageBase<PixelT> {
*
* @param[in] manager An object that manages the memory buffer to read.
* @param[in] hdu HDU to read, 0-indexed (i.e. 0=Primary HDU). The special value
* of INT_MIN reads the Primary HDU unless it is empty, in which case it
* reads the first extension HDU.
* of afw::fits::DEFAULT_HDU reads the Primary HDU unless it is empty,
* in which case it reads the first extension HDU.
* @param[in,out] metadata Metadata read from the header (may be null).
* @param[in] bbox If non-empty, read only the pixels within the bounding box.
* @param[in] origin Coordinate system of the bounding box; if PARENT, the bounding box
* should take into account the xy0 saved with the image.
*/
explicit Image(fits::MemFileManager& manager, int hdu = INT_MIN,
explicit Image(fits::MemFileManager& manager, int hdu = fits::DEFAULT_HDU,
std::shared_ptr<lsst::daf::base::PropertySet> metadata =
std::shared_ptr<lsst::daf::base::PropertySet>(),
geom::Box2I const& bbox = geom::Box2I(), ImageOrigin origin = PARENT);
Expand Down Expand Up @@ -294,10 +295,10 @@ class Image : public ImageBase<PixelT> {
*
* @param[in] filename Name of the file to read.
* @param[in] hdu Number of the "header-data unit" to read (where 0 is the Primary HDU).
* The default value of INT_MIN is interpreted as "the first HDU with
* NAXIS != 0".
* The default value of afw::fits::DEFAULT_HDU is interpreted as
* "the first HDU with NAXIS != 0".
*/
static Image readFits(std::string const& filename, int hdu = INT_MIN) {
static Image readFits(std::string const& filename, int hdu = fits::DEFAULT_HDU) {
return Image<PixelT>(filename, hdu);
}

Expand All @@ -306,10 +307,10 @@ class Image : public ImageBase<PixelT> {
*
* @param[in] manager Object that manages the memory to be read.
* @param[in] hdu Number of the "header-data unit" to read (where 0 is the Primary HDU).
* The default value of INT_MIN is interpreted as "the first HDU with
* NAXIS != 0".
* The default value of afw::fits::DEFAULT_HDU is interpreted as
* "the first HDU with NAXIS != 0".
*/
static Image readFits(fits::MemFileManager& manager, int hdu = INT_MIN) {
static Image readFits(fits::MemFileManager& manager, int hdu = fits::DEFAULT_HDU) {
return Image<PixelT>(manager, hdu);
}

Expand Down Expand Up @@ -430,7 +431,7 @@ class DecoratedImage : public lsst::daf::base::Persistable, public lsst::daf::ba
* @param bbox Only read these pixels
* @param origin Coordinate system of the bbox
*/
explicit DecoratedImage(std::string const& fileName, const int hdu = INT_MIN,
explicit DecoratedImage(std::string const& fileName, const int hdu = fits::DEFAULT_HDU,
geom::Box2I const& bbox = geom::Box2I(), ImageOrigin const origin = PARENT);

/**
Expand Down
23 changes: 13 additions & 10 deletions include/lsst/afw/image/Mask.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "lsst/afw/formatters/ImageFormatter.h"
#include "lsst/afw/image/ImageBase.h"
#include "lsst/afw/image/LsstImageTypes.h"
#include "lsst/afw/fitsDefaults.h"

namespace lsst {
namespace afw {
Expand Down Expand Up @@ -151,8 +152,8 @@ class Mask : public ImageBase<MaskPixelT> {
*
* @param[in] fileName File to read.
* @param[in] hdu HDU to read, 0-indexed (i.e. 0=Primary HDU). The special value
* of INT_MIN reads the Primary HDU unless it is empty, in which case it
* reads the first extension HDU.
* of afw::fits::DEFAULT_HDU reads the Primary HDU unless it is empty,
* in which case it reads the first extension HDU.
* @param[in,out] metadata Metadata read from the header (may be null).
* @param[in] bbox If non-empty, read only the pixels within the bounding box.
* @param[in] origin Coordinate system of the bounding box; if PARENT, the bounding box
Expand All @@ -164,7 +165,7 @@ class Mask : public ImageBase<MaskPixelT> {
* bitvalues will be left alone, but Mask's dictionary will be modified to match the
* on-disk version.
*/
explicit Mask(std::string const& fileName, int hdu = INT_MIN,
explicit Mask(std::string const& fileName, int hdu = fits::DEFAULT_HDU,
std::shared_ptr<lsst::daf::base::PropertySet> metadata =
std::shared_ptr<lsst::daf::base::PropertySet>(),
geom::Box2I const& bbox = geom::Box2I(), ImageOrigin origin = PARENT,
Expand All @@ -175,8 +176,8 @@ class Mask : public ImageBase<MaskPixelT> {
*
* @param[in] manager An object that manages the memory buffer to read.
* @param[in] hdu HDU to read, 0-indexed (i.e. 0=Primary HDU). The special value
* of INT_MIN reads the Primary HDU unless it is empty, in which case it
* reads the first extension HDU.
* of afw::fits::DEFAULT_HDU reads the Primary HDU unless it is empty,
* in which case it reads the first extension HDU.
* @param[in,out] metadata Metadata read from the header (may be null).
* @param[in] bbox If non-empty, read only the pixels within the bounding box.
* @param[in] origin Coordinate system of the bounding box; if PARENT, the bounding box
Expand All @@ -188,7 +189,7 @@ class Mask : public ImageBase<MaskPixelT> {
* bitvalues will be left alone, but Mask's dictionary will be modified to match the
* on-disk version.
*/
explicit Mask(fits::MemFileManager& manager, int hdu = INT_MIN,
explicit Mask(fits::MemFileManager& manager, int hdu = fits::DEFAULT_HDU,
std::shared_ptr<lsst::daf::base::PropertySet> metadata =
std::shared_ptr<lsst::daf::base::PropertySet>(),
geom::Box2I const& bbox = geom::Box2I(), ImageOrigin origin = PARENT,
Expand Down Expand Up @@ -397,9 +398,10 @@ class Mask : public ImageBase<MaskPixelT> {
*
* @param[in] filename Name of the file to read.
* @param[in] hdu Number of the "header-data unit" to read (where 0 is the Primary HDU).
* The default value of INT_MIN is interpreted as "the first HDU with NAXIS != 0".
* The default value of afw::fits::DEFAULT_HDU is interpreted as
* "the first HDU with NAXIS != 0".
*/
static Mask readFits(std::string const& filename, int hdu = INT_MIN) {
static Mask readFits(std::string const& filename, int hdu = fits::DEFAULT_HDU) {
return Mask<MaskPixelT>(filename, hdu);
}

Expand All @@ -408,9 +410,10 @@ class Mask : public ImageBase<MaskPixelT> {
*
* @param[in] manager Object that manages the memory to be read.
* @param[in] hdu Number of the "header-data unit" to read (where 0 is the Primary HDU).
* The default value of INT_MIN is interpreted as "the first HDU with NAXIS != 0".
* The default value of afw::fits::DEFAULT_HDU is interpreted as
* "the first HDU with NAXIS != 0".
*/
static Mask readFits(fits::MemFileManager& manager, int hdu = INT_MIN) {
static Mask readFits(fits::MemFileManager& manager, int hdu = fits::DEFAULT_HDU) {
return Mask<MaskPixelT>(manager, hdu);
}

Expand Down
7 changes: 4 additions & 3 deletions include/lsst/afw/image/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ namespace image {
* @deprecated Use lsst::afw::fits::readMetadata instead.
*
* @param[in] fileName File to read.
* @param[in] hdu HDU to read, 0-indexed. The special value of INT_MIN will read the
* first non-empty HDU.
* @param[in] hdu HDU to read, 0-indexed. The special value of afw::fits::DEFAULT_HDU
* will read the first non-empty HDU.
* @param[in] strip If true, ignore special header keys usually managed by cfitsio
* (e.g. NAXIS).
*/
inline std::shared_ptr<daf::base::PropertyList> readMetadata(std::string const& fileName, int hdu = INT_MIN,
inline std::shared_ptr<daf::base::PropertyList> readMetadata(std::string const& fileName,
int hdu = fits::DEFAULT_HDU,
bool strip = false) {
return afw::fits::readMetadata(fileName, hdu, strip);
}
Expand Down
11 changes: 7 additions & 4 deletions include/lsst/afw/table/Catalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "lsst/base.h"
#include "lsst/pex/exceptions.h"
#include "lsst/afw/fitsDefaults.h"
#include "lsst/afw/table/fwd.h"
#include "lsst/afw/table/io/FitsWriter.h"
#include "lsst/afw/table/io/FitsReader.h"
Expand Down Expand Up @@ -328,11 +329,12 @@ class CatalogT {
*
* @param[in] filename Name of the file to read.
* @param[in] hdu Number of the "header-data unit" to read (where 0 is the Primary HDU).
* The default value of INT_MIN is interpreted as "the first HDU with NAXIS != 0".
* The default value of afw::fits::DEFAULT_HDU is interpreted as
* "the first HDU with NAXIS != 0".
* @param[in] flags Table-subclass-dependent bitflags that control the details of how to read
* the catalog. See e.g. SourceFitsFlags.
*/
static CatalogT readFits(std::string const& filename, int hdu = INT_MIN, int flags = 0) {
static CatalogT readFits(std::string const& filename, int hdu = fits::DEFAULT_HDU, int flags = 0) {
return io::FitsReader::apply<CatalogT>(filename, hdu, flags);
}

Expand All @@ -341,11 +343,12 @@ class CatalogT {
*
* @param[in] manager Object that manages the memory to be read.
* @param[in] hdu Number of the "header-data unit" to read (where 0 is the Primary HDU).
* The default value of INT_MIN is interpreted as "the first HDU with NAXIS != 0".
* The default value of afw::fits::DEFAULT_HDU is interpreted as
* "the first HDU with NAXIS != 0".
* @param[in] flags Table-subclass-dependent bitflags that control the details of how to read
* the catalog. See e.g. SourceFitsFlags.
*/
static CatalogT readFits(fits::MemFileManager& manager, int hdu = INT_MIN, int flags = 0) {
static CatalogT readFits(fits::MemFileManager& manager, int hdu = fits::DEFAULT_HDU, int flags = 0) {
return io::FitsReader::apply<CatalogT>(manager, hdu, flags);
}

Expand Down
13 changes: 9 additions & 4 deletions include/lsst/afw/table/Exposure.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#define AFW_TABLE_Exposure_h_INCLUDED

#include "lsst/afw/geom/Box.h"
#include "lsst/afw/fitsDefaults.h"
#include "lsst/afw/table/BaseRecord.h"
#include "lsst/afw/table/BaseTable.h"
#include "lsst/afw/table/SortedCatalog.h"
Expand Down Expand Up @@ -326,11 +327,13 @@ class ExposureCatalogT : public SortedCatalogT<RecordT> {
*
* @param[in] filename Name of the file to read.
* @param[in] hdu Number of the "header-data unit" to read (where 0 is the Primary HDU).
* The default value of INT_MIN is interpreted as "the first HDU with NAXIS != 0".
* The default value of afw::fits::DEFAULT_HDU is interpreted as
* "the first HDU with NAXIS != 0".
* @param[in] flags Table-subclass-dependent bitflags that control the details of how to read
* the catalog. See e.g. SourceFitsFlags.
*/
static ExposureCatalogT readFits(std::string const& filename, int hdu = INT_MIN, int flags = 0) {
static ExposureCatalogT readFits(std::string const& filename, int hdu = fits::DEFAULT_HDU,
int flags = 0) {
return io::FitsReader::apply<ExposureCatalogT>(filename, hdu, flags);
}

Expand All @@ -339,11 +342,13 @@ class ExposureCatalogT : public SortedCatalogT<RecordT> {
*
* @param[in] manager Object that manages the memory to be read.
* @param[in] hdu Number of the "header-data unit" to read (where 0 is the Primary HDU).
* The default value of INT_MIN is interpreted as "the first HDU with NAXIS != 0".
* The default value of afw::fits::DEFAULT_HDU is interpreted as
* "the first HDU with NAXIS != 0".
* @param[in] flags Table-subclass-dependent bitflags that control the details of how to read
* the catalog. See e.g. SourceFitsFlags.
*/
static ExposureCatalogT readFits(fits::MemFileManager& manager, int hdu = INT_MIN, int flags = 0) {
static ExposureCatalogT readFits(fits::MemFileManager& manager, int hdu = fits::DEFAULT_HDU,
int flags = 0) {
return io::FitsReader::apply<ExposureCatalogT>(manager, hdu, flags);
}

Expand Down
7 changes: 4 additions & 3 deletions include/lsst/afw/table/Schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "ndarray.h"
#include "lsst/base.h"
#include "lsst/afw/fitsDefaults.h"
#include "lsst/afw/table/Key.h"
#include "lsst/afw/table/Field.h"
#include "lsst/afw/table/detail/SchemaImpl.h"
Expand Down Expand Up @@ -283,10 +284,10 @@ class Schema {
/** Construct from reading a FITS file.
*
* Reads from the nominated 'hdu' (0=PHU which cannot be a catalog,
* INT_MIN is a special value meaning read from the first HDU with NAXIS != 0).
* afw::fits::DEFAULT_HDU is a special value meaning read from the first HDU with NAXIS != 0).
*/
static Schema readFits(std::string const& filename, int hdu = INT_MIN);
static Schema readFits(fits::MemFileManager& manager, int hdu = INT_MIN);
static Schema readFits(std::string const& filename, int hdu = fits::DEFAULT_HDU);
static Schema readFits(fits::MemFileManager& manager, int hdu = fits::DEFAULT_HDU);
static Schema readFits(fits::Fits& fitsfile);

/** Construct from reading a FITS header
Expand Down