29 #include <boost/filesystem/path.hpp>
30 #include <boost/filesystem/operations.hpp>
31 #include <boost/regex.hpp>
32 #include <boost/algorithm/string/case_conv.hpp>
33 #include <boost/algorithm/string/trim.hpp>
42 namespace SourceXtractor {
47 : m_filename(filename), m_manager(manager), m_hdu_number(hdu_number) {
50 long naxes[2] = {1,1};
64 fits_get_img_param(fptr, 2, &bitpix, &naxis, naxes, &status);
65 if (status != 0 || naxis != 2) {
78 : m_filename(filename), m_manager(manager), m_hdu_number(1) {
85 fitsfile* fptr =
nullptr;
86 fits_create_file(&fptr, (
"!"+filename).c_str(), &status);
90 assert(fptr !=
nullptr);
92 long naxes[2] = {
width, height};
93 fits_create_img(fptr,
getImageType(), 2, naxes, &status);
96 auto headers = coord_system->getFitsHeaders();
97 for (
auto& h : headers) {
102 auto str = serializer.
str();
104 fits_update_card(fptr, padded_key.
str().c_str(), str.c_str(), &status);
107 fits_get_errstatus(status, err_txt);
108 throw Elements::Exception() <<
"Couldn't write the WCS headers (" << err_txt <<
"): " << str;
114 for (
int i = 0; i<
height; i++) {
115 long first_pixel[2] = {1, i+1};
116 fits_write_pix(fptr,
getDataType(), first_pixel, width, &buffer[0], &status);
118 fits_close_file(fptr, &status);
134 auto fptr = m_fits_file->getFitsFilePtr();
135 switchHdu(fptr, m_hdu_number);
137 auto tile = std::make_shared<ImageTile<T>>((
const_cast<FitsImageSource *
>(
this))->shared_from_this(),
x,
y,
width,
140 long first_pixel[2] = {x + 1, y + 1};
141 long last_pixel[2] = {x +
width, y + height};
142 long increment[2] = {1, 1};
145 auto image = tile->getImage();
146 fits_read_subset(fptr, getDataType(), first_pixel, last_pixel, increment,
147 nullptr, &image->getData()[0],
nullptr, &status);
158 auto fptr = m_fits_file->getFitsFilePtr();
159 switchHdu(fptr, m_hdu_number);
165 int width = image->getWidth();
166 int height = image->getHeight();
168 long first_pixel[2] = {x + 1, y + 1};
169 long last_pixel[2] = {x +
width, y + height};
172 fits_write_subset(fptr, getDataType(), first_pixel, last_pixel, &image->getData()[0], &status);
184 fits_movabs_hdu(fptr, hdu_number, &hdu_type, &status);
187 throw Elements::Exception() <<
"Could not switch to HDU # " << hdu_number <<
" in file " << m_filename;
189 if (hdu_type != IMAGE_HDU) {
198 number_of_records = 0;
201 auto& headers = getMetadata();
202 for (
auto record : headers) {
203 auto key = record.first;
206 if (record_string.
size() > 8) {
208 }
else if (record_string.
size() < 8) {
212 if (headers.at(key).m_value.type() ==
typeid(
std::string)) {
213 record_string +=
"= '" + VariantCast<std::string>(headers.at(key).m_value) +
"'";
216 record_string +=
"= " + VariantCast<std::string>(headers.at(key).m_value);
219 if (record_string.
size() > 80) {
224 if (record_string.
size() < 80) {
228 records += record_string;
234 records += record_string;
237 buffer->emplace_back(0);
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y