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> 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;
85 m_wcs = decltype(m_wcs)(wcs, [nwcs](
wcsprm* wcs) {
93 fits_close_file(fptr, &status);
97 if (wcsver[0] < 5 || (wcsver[0] == 5 && wcsver[1] < 18)) {
98 logger.info() <<
"wcslib " << wcsver[0] <<
"." << wcsver[1]
99 <<
" is not fully thread safe, using wrapped lincpy call!";
107 WorldCoordinate WCS::imageToWorld(ImageCoordinate image_coordinate)
const {
115 double pc_array[2] {image_coordinate.m_x + 1, image_coordinate.m_y + 1};
117 double ic_array[2] {0, 0};
118 double wc_array[2] {0, 0};
122 wcsp2s(&wcs_copy, 1, 1, pc_array, ic_array, &phi, &theta, wc_array, &status);
125 return WorldCoordinate(wc_array[0], wc_array[1]);
135 double pc_array[2] {0, 0};
136 double ic_array[2] {0, 0};
137 double wc_array[2] {world_coordinate.
m_alpha, world_coordinate.
m_delta};
141 wcss2p(&wcs_copy, 1, 1, wc_array, &phi, &theta, ic_array, pc_array, &status);
144 return ImageCoordinate(pc_array[0] - 1, pc_array[1] - 1);
156 for (
int i = 0; i < nkeyrec; ++i) {
157 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)
const char * wcslib_version(int vers[3])
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)