29 #include <CCfits/CCfits>
30 #include <boost/filesystem.hpp>
31 #include <type_traits>
35 namespace GridContainer {
44 static constexpr
int BPIX = BYTE_IMG;
49 static constexpr
int BPIX = SHORT_IMG;
54 static constexpr
int BPIX = LONG_IMG;
59 static constexpr
int BPIX = LONGLONG_IMG;
64 static constexpr
int BPIX = FLOAT_IMG;
69 static constexpr
int BPIX = DOUBLE_IMG;
94 template <
typename... AxesTypes>
102 auto& axis = std::get<I - 1>(axes_tuple);
111 for (
size_t i = 0; i < axis.size(); ++i) {
113 row_list.push_back(
Table::Row{{(int)i, fits_value}, column_info});
119 .
setHduName(axis.name() +
"_" + array_hdu_name)
127 template <
typename GridCellManager,
typename... AxesTypes>
135 CCfits::FITS fits(filename.string(), CCfits::Write);
143 fits.addImage(hdu_name, bpix, ext_ax);
146 for (
auto value : grid) {
150 fits.currentExtension().write(1, grid.size(), data);
156 template <
typename Gr
idType>
162 template <
int I,
typename =
void>
181 auto axis_name = hdu.name().substr(0, hdu.name().size() - grid_name.
size() - 1);
184 auto& column = hdu.column(
"Value");
185 column.read(data, 1, column.rows());
186 }
catch (CCfits::FitsException
e) {
199 auto axis = readAxis<I>(grid_name, fits.extension(hdu_index));
210 auto name = fits.extension(hdu_index).name();
211 return readAxesTuple(fits, name, hdu_index + GridType::axisNumber(),
TemplateLoopCounter<GridType::axisNumber() - 1>{});
215 template <
typename Gr
idType>
216 GridType
gridFitsImport(
const boost::filesystem::path& filename,
int hdu_index) {
217 CCfits::FITS fits(filename.string(), CCfits::Read);
224 fits.extension(hdu_index).read(data);
227 for (
auto iter = grid.begin(); iter != grid.end(); ++iter, ++i) {
FitsWriter & setFormat(Format format)
Set the FITS table format.
size_t size() const
Returns the total number of cells of the grid.
const std::string & qualifiedName() const
Returns the qualified name as a string.
FITS binary table HDU format.
const std::tuple< GridAxis< AxesTypes >...> & getAxesTuple() const
Returns a tuple containing the information of all the grid axes.
static void addGridAxesToFitsFile(const boost::filesystem::path &, const std::string &, const std::tuple< GridAxis< AxesTypes >...> &, const TemplateLoopCounter< 0 > &)
static FitsType axisToFits(const T &value)
static void addGridAxesToFitsFile(const boost::filesystem::path &filename, const std::string &array_hdu_name, const std::tuple< GridAxis< AxesTypes >...> &axes_tuple, const TemplateLoopCounter< I > &)
static AxesTupleType< GridType::axisNumber()-1 >::type readAllAxes(CCfits::FITS &fits, int hdu_index)
static XYDataset::QualifiedName FitsToAxis(const FitsType &value)
TableWriter implementation for writing tables in FITS format.
typename std::remove_reference< decltype(std::declval< GridType >().template getAxis< I >())>::type AxisType
decltype(std::tuple_cat(std::declval< previous >(), std::declval< std::tuple< AxisType< I >>>())) type
typename std::remove_reference< decltype(std::declval< GridType >().template getAxis< I >())>::type GridAxisType
typename AxesTupleType< I-1 >::type previous
FitsWriter & setHduName(const std::string &name)
Set the HDU name where the table is written.
Provides information related with an axis of a GridContainer.
void gridFitsExport(const boost::filesystem::path &filename, const std::string &hdu_name, const GridContainer< GridCellManager, AxesTypes...> &grid)
Exports a Grid as a FITS file.
static std::vector< size_t > createAxesSizesVector(const std::tuple< GridAxis< Axes >...> &axes, const TemplateLoopCounter< I > &)
Creates a vector which contains the sizes of the given axes.
Represents one row of a Table.
static GridAxisType< I > readAxis(const std::string &grid_name, CCfits::ExtHDU &hdu)
Provides information about the columns of a Table.
static std::tuple readAxesTuple(CCfits::FITS &, const std::string &, int, const TemplateLoopCounter<-1 > &)
GridCellManager::data_type data_type
The type of the data kept by the GridCellManager.
Represents a name qualified with a set of groups.
GridType gridFitsImport(const boost::filesystem::path &filename, int hdu_index)
Imports a Grid from a FITS file.
Contains the description of a specific column of a Table.
static FitsType axisToFits(const XYDataset::QualifiedName &value)
static T FitsToAxis(const FitsType &value)
static AxesTupleType< I >::type readAxesTuple(CCfits::FITS &fits, const std::string &grid_name, int hdu_index, const TemplateLoopCounter< I > &)