ifw-fnd 2.0.1
 
Loading...
Searching...
No Matches
fits.hpp
Go to the documentation of this file.
1
7
8#pragma once
9
10#include <array>
11#include <iostream>
12#include <thread>
13
14#include <fmt/format.h>
15
16#include <boost/algorithm/string.hpp>
17#include <boost/assign.hpp>
18#include <boost/bimap.hpp>
19
20#include <fitsio.h>
21
24
25
26namespace ifw::fnd::fits {
27
29 // Based on: "BITPIX data type code values for FITS images":
30 // https://heasarc.gsfc.nasa.gov/fitsio/c/c_user/node20.html
31 enum class BitPix : int8_t {
33
34 INT8 = SBYTE_IMG,
35
36 UINT8 = BYTE_IMG, // 8-bit unsigned integers
37
38 INT16 = SHORT_IMG, // 16-bit signed integers
39
40 UINT16 = USHORT_IMG, // 16-bit unsigned integers, equivalent to
41 // BITPIX = 16, BSCALE = 1, BZERO = 32768
42
43 INT32 = LONG_IMG, // 32-bit signed integers
44
45 UINT32 = ULONG_IMG, // 32-bit unsigned integers, equivalent to
46 // BITPIX = 32, BSCALE = 1, BZERO = 2147483648
47
48 INT64 = ULONGLONG_IMG, // 64-bit unsigned integers, equivalent to
49 // BITPIX = 64, BSCALE = 1,
50 // BZERO = 9223372036854775808
51
52 UINT64 = LONGLONG_IMG, // 64-bit signed integers
53
54 FLOAT = FLOAT_IMG, // 32-bit single precision floating point
55
56 DOUBLE = DOUBLE_IMG // 64-bit double precision floating point
57 };
58
66 int fitsio_type = 0;
67 switch (data_type) {
69 fitsio_type = TSBYTE; // 8-bit signed byte
70 break;
72 fitsio_type = TBYTE; // 8-bit unsigned byte
73 break;
75 fitsio_type = TSHORT; // Signed short
76 break;
78 fitsio_type = TUSHORT; // Unsigned short
79 break;
81 fitsio_type = TINT; // Int
82 break;
84 fitsio_type = TUINT; // Unsigned int
85 break;
87 fitsio_type = TLONGLONG; // 64-bit long signed integer
88 break;
90 fitsio_type = TULONGLONG; // Unsigned long long
91 break;
93 fitsio_type = TFLOAT; // Single precision float
94 break;
96 fitsio_type = TDOUBLE; // Double precision float
97 break;
98 default:
99 throw std::runtime_error(fmt::format("{}: Unsupported data type for FITS: {}",
100 FNDLOC, static_cast<int>(data_type)));
101 }
102 return fitsio_type;
103 }
104
111 inline static BitPix IfwDataTypeToBitpix(ifw::fnd::datatype::DataType data_type) {
112 BitPix bitpix;
113 switch (data_type) {
114
116 bitpix = BitPix::INT8;
117 break;
118
120 bitpix = BitPix::UINT8;
121 break;
122
124 bitpix = BitPix::INT16;
125 break;
126
128 bitpix = BitPix::UINT16;
129 break;
130
132 bitpix = BitPix::INT32;
133 break;
134
136 bitpix = BitPix::UINT32;
137 break;
138
140 bitpix = BitPix::INT64;
141 break;
142
144 bitpix = BitPix::UINT64;
145 break;
146
148 bitpix = BitPix::FLOAT;
149 break;
150
152 bitpix = BitPix::DOUBLE;
153 break;
154
155 default:
156 throw std::runtime_error(fmt::format("{}: Unsupported data type for FITS BITPIX: {}",
157 FNDLOC, static_cast<int>(data_type)));
158 }
159 return bitpix;
160 }
161
168 inline static int BitpixToCfitsioDataType(BitPix bitpix) {
169 int cfitsio_datatype;
170
171 switch (bitpix) {
172
173 case BitPix::INT8:
174 cfitsio_datatype = TSBYTE;
175 break;
176
177 case BitPix::UINT8:
178 cfitsio_datatype = TBYTE;
179 break;
180
181 case BitPix::INT16:
182 cfitsio_datatype = TSHORT;
183 break;
184
185 case BitPix::UINT16:
186 cfitsio_datatype = TUSHORT;
187 break;
188
189 case BitPix::INT32:
190 cfitsio_datatype = TINT;
191 break;
192
193 case BitPix::UINT32:
194 cfitsio_datatype = TUINT;
195 break;
196
197 case BitPix::INT64:
198 cfitsio_datatype = TLONGLONG;
199 break;
200
201 case BitPix::UINT64:
202 cfitsio_datatype = TULONGLONG;
203 break;
204
205 case BitPix::FLOAT:
206 cfitsio_datatype = TFLOAT;
207 break;
208
209 case BitPix::DOUBLE:
210 cfitsio_datatype = TDOUBLE;
211 break;
212
213 default:
214 cfitsio_datatype = -1;
215 }
216 return cfitsio_datatype;
217 }
218
225 inline static int BitPixInBytes(BitPix bitpix) {
226
227 switch (bitpix) {
228
229 case BitPix::INT8:
230 return ifw::fnd::datatype::DU_SIZE_1;
231 break;
232
233 case BitPix::UINT8:
234 return ifw::fnd::datatype::DU_SIZE_1;
235 break;
236
237 case BitPix::INT16:
238 return ifw::fnd::datatype::DU_SIZE_2;
239 break;
240
241 case BitPix::UINT16:
242 return ifw::fnd::datatype::DU_SIZE_2;
243 break;
244
245 case BitPix::INT32:
246 return ifw::fnd::datatype::DU_SIZE_4;
247 break;
248
249 case BitPix::UINT32:
250 return ifw::fnd::datatype::DU_SIZE_4;
251 break;
252
253 case BitPix::INT64:
254 return ifw::fnd::datatype::DU_SIZE_8;
255 break;
256
257 case BitPix::UINT64:
258 return ifw::fnd::datatype::DU_SIZE_8;
259 break;
260
261 case BitPix::FLOAT:
262 return ifw::fnd::datatype::DU_SIZE_4;
263 break;
264
265 case BitPix::DOUBLE:
266 return ifw::fnd::datatype::DU_SIZE_8;
267 break;
268
269 default:
270 return -1;
271 }
272 }
273
275 inline static ifw::fnd::datatype::DataType BitpixToIfwDataType(BitPix bitpix) {
276 switch (bitpix) {
277 case BitPix::INT8:
279 break;
280 case BitPix::UINT8:
282 break;
283 case BitPix::INT16:
285 break;
286 case BitPix::UINT16:
288 break;
289 case BitPix::INT32:
291 break;
292 case BitPix::UINT32:
294 break;
295 case BitPix::INT64:
297 break;
298 case BitPix::UINT64:
300 break;
301 case BitPix::FLOAT:
303 break;
304 case BitPix::DOUBLE:
306 break;
307 default:
309 }
310 }
311
312}
#define FNDLOC
Macro generating a location identifier: "<iso-time>:<file>:<line>:<function>:<thread>".
Definition base.hpp:34
ifw-fnd logging abstraction.
DataType
Numerical representations of the standard types.
Definition dataType.hpp:54
@ CHAR
Definition dataType.hpp:57
@ UINT32
Definition dataType.hpp:63
@ UINT16
Definition dataType.hpp:61
@ INT64
Definition dataType.hpp:64
@ INT16
Definition dataType.hpp:60
@ INT32
Definition dataType.hpp:62
@ UINT64
Definition dataType.hpp:65
@ INVALID
Definition dataType.hpp:56
@ BYTE
Definition dataType.hpp:58
@ FLOAT
Definition dataType.hpp:66
@ DOUBLE
Definition dataType.hpp:67
This source file contains definitions of the types and constants to handle FITS.
Definition fits.hpp:26
BitPix
Defines enumerated for FITS BITPIX.
Definition fits.hpp:31
@ UNDEFINED
Definition fits.hpp:32
@ UINT32
Definition fits.hpp:45
@ UINT16
Definition fits.hpp:40
@ INT64
Definition fits.hpp:48
@ INT16
Definition fits.hpp:38
@ INT32
Definition fits.hpp:43
@ UINT64
Definition fits.hpp:52
@ FLOAT
Definition fits.hpp:54
@ UINT8
Definition fits.hpp:36
@ INT8
Definition fits.hpp:34
@ DOUBLE
Definition fits.hpp:56
int IfwDataTypeToCfitsioDataType(ifw::fnd::datatype::DataType data_type)
Definition fits.hpp:65