ifw-fnd 1.0.0
Loading...
Searching...
No Matches
fits.hpp
Go to the documentation of this file.
1
14#ifndef IFW_FND_DEFS_FITS_HPP_H_
15#define IFW_FND_DEFS_FITS_HPP_H_
16
17#include <array>
18#include <iostream>
19#include <thread>
20
21#include <fmt/format.h>
22
23#include <boost/algorithm/string.hpp>
24#include <boost/assign.hpp>
25#include <boost/bimap.hpp>
26
27#include <fitsio.h>
28
31
32
33namespace ifw::fnd::fits {
34
36 // Based on: "BITPIX data type code values for FITS images":
37 // https://heasarc.gsfc.nasa.gov/fitsio/c/c_user/node20.html
38 enum class BitPix : int8_t {
39 UNDEFINED = -1,
40
41 INT8 = SBYTE_IMG,
42
43 UINT8 = BYTE_IMG, // 8-bit unsigned integers
44
45 INT16 = SHORT_IMG, // 16-bit signed integers
46
47 UINT16 = USHORT_IMG, // 16-bit unsigned integers, equivalent to
48 // BITPIX = 16, BSCALE = 1, BZERO = 32768
49
50 INT32 = LONG_IMG, // 32-bit signed integers
51
52 UINT32 = ULONG_IMG, // 32-bit unsigned integers, equivalent to
53 // BITPIX = 32, BSCALE = 1, BZERO = 2147483648
54
55 INT64 = ULONGLONG_IMG, // 64-bit unsigned integers, equivalent to
56 // BITPIX = 64, BSCALE = 1,
57 // BZERO = 9223372036854775808
58
59 UINT64 = LONGLONG_IMG, // 64-bit signed integers
60
61 FLOAT = FLOAT_IMG, // 32-bit single precision floating point
62
63 DOUBLE = DOUBLE_IMG // 64-bit double precision floating point
64 };
65
73 int fitsio_type = 0;
74 switch (data_type) {
76 fitsio_type = TSBYTE; // 8-bit signed byte
77 break;
79 fitsio_type = TBYTE; // 8-bit unsigned byte
80 break;
82 fitsio_type = TSHORT; // Signed short
83 break;
85 fitsio_type = TUSHORT; // Unsigned short
86 break;
88 fitsio_type = TINT; // Int
89 break;
91 fitsio_type = TUINT; // Unsigned int
92 break;
94 fitsio_type = TLONGLONG; // 64-bit long signed integer
95 break;
97 fitsio_type = TULONGLONG; // Unsigned long long
98 break;
100 fitsio_type = TFLOAT; // Single precision float
101 break;
103 fitsio_type = TDOUBLE; // Double precision float
104 break;
105 default:
106 throw std::runtime_error(fmt::format("{}: Unsupported data type for FITS: {}",
107 IFWLOC, static_cast<int>(data_type)));
108 }
109 return fitsio_type;
110 }
111
118 inline static BitPix IfwDataTypeToBitpix(ifw::fnd::datatype::DataType data_type) {
119 BitPix bitpix;
120 switch (data_type) {
121
123 bitpix = BitPix::INT8;
124 break;
125
127 bitpix = BitPix::UINT8;
128 break;
129
131 bitpix = BitPix::INT16;
132 break;
133
135 bitpix = BitPix::UINT16;
136 break;
137
139 bitpix = BitPix::INT32;
140 break;
141
143 bitpix = BitPix::UINT32;
144 break;
145
147 bitpix = BitPix::INT64;
148 break;
149
151 bitpix = BitPix::UINT64;
152 break;
153
155 bitpix = BitPix::FLOAT;
156 break;
157
159 bitpix = BitPix::DOUBLE;
160 break;
161
162 default:
163 throw std::runtime_error(fmt::format("{}: Unsupported data type for FITS BITPIX: {}",
164 IFWLOC, static_cast<int>(data_type)));
165 }
166 return bitpix;
167 }
168
175 inline static int BitpixToCfitsioDataType(BitPix bitpix) {
176 int cfitsio_datatype;
177
178 switch (bitpix) {
179
180 case BitPix::INT8:
181 cfitsio_datatype = TSBYTE;
182 break;
183
184 case BitPix::UINT8:
185 cfitsio_datatype = TBYTE;
186 break;
187
188 case BitPix::INT16:
189 cfitsio_datatype = TSHORT;
190 break;
191
192 case BitPix::UINT16:
193 cfitsio_datatype = TUSHORT;
194 break;
195
196 case BitPix::INT32:
197 cfitsio_datatype = TINT;
198 break;
199
200 case BitPix::UINT32:
201 cfitsio_datatype = TUINT;
202 break;
203
204 case BitPix::INT64:
205 cfitsio_datatype = TLONGLONG;
206 break;
207
208 case BitPix::UINT64:
209 cfitsio_datatype = TULONGLONG;
210 break;
211
212 case BitPix::FLOAT:
213 cfitsio_datatype = TFLOAT;
214 break;
215
216 case BitPix::DOUBLE:
217 cfitsio_datatype = TDOUBLE;
218 break;
219
220 default:
221 cfitsio_datatype = -1;
222 }
223 return cfitsio_datatype;
224 }
225
232 inline static int BitPixInBytes(BitPix bitpix) {
233
234 switch (bitpix) {
235
236 case BitPix::INT8:
237 return ifw::fnd::datatype::DU_SIZE_1;
238 break;
239
240 case BitPix::UINT8:
241 return ifw::fnd::datatype::DU_SIZE_1;
242 break;
243
244 case BitPix::INT16:
245 return ifw::fnd::datatype::DU_SIZE_2;
246 break;
247
248 case BitPix::UINT16:
249 return ifw::fnd::datatype::DU_SIZE_2;
250 break;
251
252 case BitPix::INT32:
253 return ifw::fnd::datatype::DU_SIZE_4;
254 break;
255
256 case BitPix::UINT32:
257 return ifw::fnd::datatype::DU_SIZE_4;
258 break;
259
260 case BitPix::INT64:
261 return ifw::fnd::datatype::DU_SIZE_8;
262 break;
263
264 case BitPix::UINT64:
265 return ifw::fnd::datatype::DU_SIZE_8;
266 break;
267
268 case BitPix::FLOAT:
269 return ifw::fnd::datatype::DU_SIZE_4;
270 break;
271
272 case BitPix::DOUBLE:
273 return ifw::fnd::datatype::DU_SIZE_8;
274 break;
275
276 default:
277 return -1;
278 }
279 }
280
282 inline static ifw::fnd::datatype::DataType BitpixToIfwDataType(BitPix bitpix) {
283 switch (bitpix) {
284 case BitPix::INT8:
286 break;
287 case BitPix::UINT8:
289 break;
290 case BitPix::INT16:
292 break;
293 case BitPix::UINT16:
295 break;
296 case BitPix::INT32:
298 break;
299 case BitPix::UINT32:
301 break;
302 case BitPix::INT64:
304 break;
305 case BitPix::UINT64:
307 break;
308 case BitPix::FLOAT:
310 break;
311 case BitPix::DOUBLE:
313 break;
314 default:
316 }
317 }
318
319}
320
321#endif
#define IFWLOC
Macro generating a location identifier: "<file>:<line>:<function>:<thread>".
Definition base.hpp:120
DataType
Numerical representations of the standard types.
Definition dataType.hpp:61
This source file contains definitions of the types and constants to handle FITS.
Definition fits.hpp:33
BitPix
Defines enumerated for FITS BITPIX.
Definition fits.hpp:38
int IfwDataTypeToCfitsioDataType(ifw::fnd::datatype::DataType data_type)
Definition fits.hpp:72