28 #include <wcslib/wcs.h>
29 #include <wcslib/wcshdr.h>
30 #include <wcslib/wcsfix.h>
31 #include <wcslib/wcsprintf.h>
32 #include <wcslib/getwcstab.h>
39 #include <boost/algorithm/string/trim.hpp>
42 namespace SourceXtractor {
46 using namespace wcslib;
59 return lincpy(alloc, linsrc, lindst);
64 fitsfile *fptr = NULL;
66 fits_open_file(&fptr, fits_file_path.
c_str(), READONLY, &status);
69 fits_movabs_hdu(fptr, hdu_number, &hdu_type, &status);
71 if (status != 0 || hdu_type != IMAGE_HDU) {
72 throw Elements::Exception() <<
"Can't read WCS information from " << fits_file_path <<
" HDU " << hdu_number;
77 fits_hdr2str(fptr, 1, NULL, 0, &header, &nkeyrec, &status);
79 if (hdu_type == IMAGE_HDU) {
80 int nreject = 0, nwcs = 0;
93 fits_close_file(fptr, &status);
108 double pc_array[2] {image_coordinate.
m_x + 1, image_coordinate.
m_y + 1};
110 double ic_array[2] {0, 0};
111 double wc_array[2] {0, 0};
115 wcsp2s(&wcs_copy, 1, 1, pc_array, ic_array, &phi, &theta, wc_array, &status);
128 double pc_array[2] {0, 0};
129 double ic_array[2] {0, 0};
130 double wc_array[2] {world_coordinate.
m_alpha, world_coordinate.
m_delta};
134 wcss2p(&wcs_copy, 1, 1, wc_array, &phi, &theta, ic_array, pc_array, &status);
137 return ImageCoordinate(pc_array[0] - 1, pc_array[1] - 1);
145 throw Elements::Exception() <<
"Failed to get the FITS headers for the WCS coordinate system";
149 for (
int i = 0; i < nkeyrec; ++i) {
150 char *hptr = &raw_header[80 * i];
int wcspih(char *header, int nkeyrec, int relax, int ctrl, int *nreject, int *nwcs, struct wcsprm **wcs)
int wcsvfree(int *nwcs, struct wcsprm **wcs)
int wcsfree(struct wcsprm *wcs)
int wcshdo(int relax, struct wcsprm *wcs, int *nkeyrec, char **header)
int wcsp2s(struct wcsprm *wcs, int ncoord, int nelem, const double pixcrd[], double imgcrd[], double phi[], double theta[], double world[], int stat[])
int linset(struct linprm *lin)
int wcss2p(struct wcsprm *wcs, int ncoord, int nelem, const double world[], double phi[], double theta[], double imgcrd[], double pixcrd[], int stat[])
int wcsset(struct wcsprm *wcs)
int linfree(struct linprm *lin)
static Logging getLogger(const std::string &name="")
int lincpy(int alloc, const struct linprm *linsrc, struct linprm *lindst)