#include "EleFits/MefFile.h"
#include "EleFitsData/TestUtils.h"
#include "EleFitsUtils/ProgramOptions.h"
#include "ElementsKernel/ProgramHeaders.h"
using boost::program_options::value;
using namespace Euclid;
auto string_info = Fits::make_column_info<std::string>("STRING", "", 6);
auto string_data = Fits::Test::generate_random_vector<std::string>(rows);
auto string_col = make_column(string_info,
std::move(string_data));
auto scalar_info = Fits::make_column_info<std::complex<float>>("SCALAR");
auto scalar_data = Fits::Test::generate_random_vector<std::complex<float>>(rows);
auto scalar_col = make_column(scalar_info,
std::move(scalar_data));
auto vector_info = Fits::make_column_info<std::int16_t>("VECTOR", "", 3);
auto vector_data = Fits::Test::generate_random_vector<std::int16_t>(rows * vector_info.repeat_count());
auto vector_col = make_column(vector_info,
std::move(vector_data));
auto multidim_info = Fits::make_column_info<std::uint16_t>("MULTIDIM", "", 6, 4);
auto multidim_data = Fits::Test::generate_random_vector<std::uint16_t>(rows * multidim_info.repeat_count());
auto multidim_col = make_column(multidim_info,
std::move(multidim_data));
return f.
append_bintable(ext_name, {}, string_col, scalar_col, vector_col, multidim_col);
}
template <typename TInfo, typename T>
du.
write(make_column(info, rows, data));
}
const auto cols = du.
read_n(Fits::as<double>(
"VECTOR"), Fits::as<float>(
"MULTIDIM"));
double result = 0;
for (const auto& a : std::get<0>(cols)) {
result += a;
}
for (const auto& b : std::get<1>(cols)) {
result -= b;
}
return result;
}
for (long i = 0; i < col.row_count(); ++i) {
auto raster = col.field(i);
for (const auto& p : raster.domain()) {
if ((p[0] + p[1]) % 2 == 1) {
raster[p] = 0;
}
}
}
}
class EleFitsBintableExample : public Elements::Program {
public:
options.positional("output", value<std::string>()->default_value("/tmp/bintable.fits"), "Output file");
options.named("rows", value<long>()->default_value(42), "Number of rows");
return options.as_pair();
}
Logging logger = Logging::getLogger("EleFitsBintableExample");
const auto filename = args[
"output"].as<
std::string>();
const auto rows = args["rows"].as<long>();
logger.info("Opening or creating the file...");
logger.info("Creating a binary table HDU...");
const auto& bintable = write_bintable(f, ext_name, rows);
logger.info("Appending a column...");
const auto vec = Fits::Test::generate_random_vector<double>(rows, -1, 1);
append_column(bintable.columns(), info, vec.data());
logger.info("Reading columns...");
auto result = read_columns(bintable.columns());
logger.info() << " Result = " << result;
logger.info("Modifying a multidimensional column...");
view_as_raster(bintable.columns());
logger.info("Done.");
return ExitCode::OK;
}
};
MAIN_FOR(EleFitsBintableExample)
std::tuple< VecColumn< Ts, 1 >... > read_n(const TypedKey< Ts, TKey > &... keys) const
Read a tuple of columns with given names or indices.
void init(const TInfo &info, long index=-1) const
VecColumn< T, N > read(ColumnKey key) const
Read the column with given name or index.
Column-wise reader-writer for the binary table data unit.
Definition: BintableColumns.h:77
void write(const TColumn &column) const
Write a column.
long read_row_count() const
Get the current number of rows.
Binary table HDU reader-writer.
Definition: BintableHdu.h:21
Multi-Extension FITS file reader-writer.
Definition: MefFile.h:84
const BintableHdu & append_bintable(const std::string &name, const RecordSeq &records, const TColumns &... columns)
Append and write a new binary table extension.
Helper class to declare positional and named options, and help message.
Definition: ProgramOptions.h:32
Column informations, i.e. name, unit, field shape and value type.
Definition: ColumnInfo.h:133