1 #include "purify/config.h"
8 void write_key(fitsfile *fptr,
const std::string &key,
const std::string &value,
9 const std::string &comment,
int *status) {
10 std::string entry = value;
11 if (fits_write_key(fptr, TSTRING,
const_cast<char *
>(key.c_str()),
12 reinterpret_cast<void *
>(
const_cast<char *
>(entry.c_str())),
13 const_cast<char *
>(comment.c_str()), status))
14 throw std::runtime_error(
"Problem writing key in fits file: " + key);
17 void write_key(fitsfile *fptr,
const std::string &key,
const char *value,
18 const std::string &comment,
int *status) {
19 write_key(fptr, key, std::string(value), comment, status);
22 void write_history(fitsfile *fptr,
const std::string &context,
const std::string &history,
24 const std::string entry = context +
": " + history;
25 if (fits_write_history(fptr,
const_cast<char *
>(entry.c_str()), status))
26 throw std::runtime_error(
"Problem writing comments in fits file");
31 const bool &overwrite) {
41 write3d(std::vector<Image<t_real>>(1, eigen_image), header, overwrite);
44 void write2d(
const Image<t_real> &eigen_image,
const std::string &fits_name,
45 const std::string &pix_units,
const bool &overwrite) {
60 write2d(eigen_image, header, overwrite);
64 const bool &overwrite) {
65 std::vector<long> naxes = {
static_cast<long>(eigen_images.at(0).rows()),
66 static_cast<long>(eigen_images.at(0).cols()),
67 static_cast<long>(eigen_images.size()), 1};
68 std::vector<long> fpixel = {1, 1, 1, 1};
70 Vector<t_real> image = Vector<t_real>::Zero(naxes.at(0) * naxes.at(1) * naxes.at(2));
71 for (
int i = 0; i < eigen_images.size(); i++)
72 image.segment(i * naxes.at(0) * naxes.at(1), naxes.at(0) * naxes.at(1)) =
73 Vector<t_real>::Map(eigen_images.at(i).data(), naxes.at(0) * naxes.at(1));
74 write3d<Vector<t_real>>(image, naxes.at(0), naxes.at(1), naxes.at(2), header, overwrite);
77 void write3d(
const std::vector<Image<t_real>> &eigen_images,
const std::string &fits_name,
78 const std::string &pix_units,
const bool &overwrite) {
91 write3d(eigen_images, header, overwrite);
95 std::vector<Image<t_complex>>
read3d(
const std::string &fits_name) {
96 std::vector<Image<t_complex>> eigen_images;
98 int rows, cols, channels, pols = 1;
99 read3d<Vector<double>>(fits_name, image, rows, cols, channels, pols);
100 for (
int i = 0; i < channels; i++) {
101 Vector<t_complex> eigen_image = Vector<t_complex>::Zero(rows * cols);
102 eigen_image.real() = image.segment(i * rows * cols, rows * cols);
103 eigen_images.push_back(Image<t_complex>::Map(eigen_image.data(), rows, cols));
109 Image<t_complex>
read2d(
const std::string &fits_name) {
116 const std::vector<Image<t_complex>> images =
read3d(fits_name);
void write2d(const Image< t_real > &eigen_image, const pfitsio::header_params &header, const bool &overwrite)
Write image to fits file.
void write_key(fitsfile *fptr, const std::string &key, const std::string &value, const std::string &comment, int *status)
write key to fits file header
Image< t_complex > read2d(const std::string &fits_name)
Read image from fits file.
void write3d(const std::vector< Image< t_real >> &eigen_images, const pfitsio::header_params &header, const bool &overwrite)
Write cube to fits file using header information.
std::vector< Image< t_complex > > read3d(const std::string &fits_name)
Read cube from fits file.
void write_history(fitsfile *fptr, const std::string &context, const std::string &history, int *status)
write history to fits file