RTC Toolkit  2.0.0
fitsIoFunctions.hpp
Go to the documentation of this file.
1 
12 #ifndef RTCTK_COMPONENTFRAMEWORK_FITSIOFUNCTIONS_HPP
13 #define RTCTK_COMPONENTFRAMEWORK_FITSIOFUNCTIONS_HPP
14 
15 #include <boost/filesystem.hpp>
16 #include <cassert>
17 #include <fitsio.h>
18 #include <limits>
22 #include <string>
23 #include <type_traits>
24 #include <typeinfo>
25 #include <unistd.h>
26 
27 namespace {
28 
35 template <typename T>
36 void IdentifyCfitsioTypes(int& bitpix, int& datatype) {
37  if constexpr (std::is_integral_v<T>) {
38  if constexpr (std::is_same_v<T, bool>) {
39  bitpix = BYTE_IMG;
40  datatype = TBYTE;
41  } else if constexpr (sizeof(T) == 1) {
42  if constexpr (std::is_signed_v<T>) {
43  bitpix = SBYTE_IMG;
44  datatype = TSBYTE;
45  } else {
46  bitpix = BYTE_IMG;
47  datatype = TBYTE;
48  }
49  } else if constexpr (sizeof(T) == 2) {
50  if constexpr (std::is_signed_v<T>) {
51  bitpix = SHORT_IMG;
52  datatype = TSHORT;
53  } else {
54  bitpix = USHORT_IMG;
55  datatype = TUSHORT;
56  }
57  } else if constexpr (sizeof(T) == 4) {
58  if constexpr (std::is_signed_v<T>) {
59  bitpix = LONG_IMG;
60  if constexpr (sizeof(int) == 4) {
61  datatype = TINT;
62  } else if constexpr (sizeof(long) == 4) {
63  datatype = TLONG;
64  } else {
65  static_assert(sizeof(int) == 4 or sizeof(long) == 4,
66  "Require either int or long type to be 32 bits wide.");
67  }
68  } else {
69  bitpix = ULONG_IMG;
70  if constexpr (sizeof(unsigned int) == 4) {
71  datatype = TUINT;
72  } else if constexpr (sizeof(unsigned long) == 4) {
73  datatype = TULONG;
74  } else {
75  static_assert(
76  sizeof(unsigned int) == 4 or sizeof(unsigned long) == 4,
77  "Require either unsigned int or unsigned long type to be 32 bits wide.");
78  }
79  }
80  } else if constexpr (sizeof(T) == 8) {
81  if constexpr (std::is_signed_v<T>) {
82  bitpix = LONGLONG_IMG;
83  datatype = TLONGLONG;
84  } else {
85 #ifdef ULONGLONG_IMG
86  bitpix = ULONGLONG_IMG;
87  datatype = TULONGLONG;
88 #else
89  // If we are using an older Cfitsio library that does not have ULONGLONG_IMG defined
90  // then simply alias to using the signed version for the image code and data type.
91  bitpix = LONGLONG_IMG;
92  datatype = TLONGLONG;
93 #endif
94  }
95  } else {
96  static_assert(
97  sizeof(T) == 1 or sizeof(T) == 2 or sizeof(T) == 4 or sizeof(T) == 8,
98  "The integer type used as the template parameter must be one of 8, 16, 32, or 64"
99  " bits wide.");
100  }
101  }
102  if constexpr (std::is_floating_point_v<T>) {
103  if constexpr (sizeof(T) == 4) {
104  bitpix = FLOAT_IMG;
105  datatype = TFLOAT;
106  } else if constexpr (sizeof(T) == 8) {
107  bitpix = DOUBLE_IMG;
108  datatype = TDOUBLE;
109  } else {
110  static_assert(
111  sizeof(T) == 4 or sizeof(T) == 8,
112  "The floating-point type used as the template parameter must be float or double.");
113  }
114  } else {
115  static_assert(std::is_arithmetic_v<T>,
116  "The template parameter used must be an integer or floating-point type.");
117  }
118 }
119 
120 } // namespace
121 
122 namespace rtctk::componentFramework {
123 
129 std::string GetCfitsioErrorMsg(int status);
130 
137 std::string CfitsioImageTypeToString(int bitpix);
138 
145 std::string CfitsioDataTypeToString(int datatype);
146 
152 template <typename T, typename A>
153 void WriteMatrixToFits(const std::string& filename, const MatrixBuffer<T, A>& matrix) {
154  assert(int64_t(matrix.GetNrows()) <= int64_t(std::numeric_limits<long>::max()));
155  assert(int64_t(matrix.GetNcols()) <= int64_t(std::numeric_limits<long>::max()));
156 
157  // Workout the appropriate Cfitsio image type code and data type code to use, based on the type
158  // used with MatrixBuffer, i.e. the type of T.
159  int bitpix = 0;
160  int datatype = 0;
161  IdentifyCfitsioTypes<T>(bitpix, datatype);
162 
163  std::string tmpfilename = filename + ".new-" + std::to_string(getpid());
164 
165  // Create the new FITS file and open it for modifications.
166  fitsfile* fptr = nullptr;
167  int status = 0; // It is important to initialise this to zero before each Cfitsio API call.
168  if (fits_create_file(&fptr, tmpfilename.c_str(), &status) != 0) {
169  std::string msg =
170  "Failed to create FITS file '" + tmpfilename + "'. " + GetCfitsioErrorMsg(status);
171  CII_THROW(RtctkException, msg);
172  }
173 
174  try {
175  // Create the image header in the HDU.
176  long nrows = long(matrix.GetNrows());
177  long ncols = long(matrix.GetNcols());
178  long size[2] = {ncols, nrows};
179  status = 0;
180  if (fits_create_img(fptr, bitpix, 2, size, &status) != 0) {
181  std::string msg = "Failed to create the image type from FITS file '" + tmpfilename +
182  "'. " + GetCfitsioErrorMsg(status);
183  CII_THROW(RtctkException, msg);
184  }
185 
186  // Write the matrix data as pixels.
187  long fpixel[2] = {1, 1}; // Pixel start location. Cfitsio counts from 1, not 0.
188  long nelements = matrix.size();
189  // We are forced to use const_cast, since the fits_write_pix function does not accept
190  // const void*.
191  void* array = const_cast<void*>(reinterpret_cast<const void*>(matrix.data()));
192  status = 0;
193  if (fits_write_pix(fptr, datatype, fpixel, nelements, array, &status) != 0) {
194  std::string msg = "Failed to write the matrix to FITS file '" + tmpfilename + "'. " +
195  GetCfitsioErrorMsg(status);
196  CII_THROW(RtctkException, msg);
197  }
198  } catch (...) {
199  // Attempt to close the FITS file if an exception was thrown. But do not throw an additional
200  // exception if closing the file failed. Just log this error and rethrow the original
201  // exception.
202  status = 0;
203  if (fits_close_file(fptr, &status) != 0) {
204  LOG4CPLUS_ERROR(GetLogger(),
205  "Failed to close file '" + tmpfilename +
206  "' while handling an exception. " + GetCfitsioErrorMsg(status));
207  }
208  throw;
209  }
210 
211  status = 0;
212  if (fits_close_file(fptr, &status) != 0) {
213  std::string msg =
214  "Failed to close the FITS file '" + tmpfilename + "'. " + GetCfitsioErrorMsg(status);
215  CII_THROW(RtctkException, msg);
216  }
217 
218  // Rename the temporary file to its final value. Updating the file in this manner will make sure
219  // that different processes or threads will see changes to the file in an atomic manner. Either
220  // the old file will be visible, or the new file, but not a partially modified file.
221  try {
222  boost::filesystem::rename(tmpfilename, filename);
223  } catch (const std::exception& error) {
224  CII_THROW_WITH_NESTED(
226  error,
227  "Failed to rename FITS file '" + tmpfilename + "' to '" + filename + "'.")
228  }
229 }
230 
236 template <typename T, typename A>
237 void ReadMatrixFromFits(const std::string& filename, MatrixBuffer<T, A>& matrix) {
238  // Identify the Cfitsio data type code to be used and the expected Cfitsio image type code,
239  // based on the type used with MatrixBuffer, i.e. type of T.
240  int expected_bitpix = 0;
241  int datatype = 0;
242  IdentifyCfitsioTypes<T>(expected_bitpix, datatype);
243 
244  fitsfile* fptr = nullptr;
245  int status = 0; // It is important to initialise this to zero before every Cfitsio API call.
246  if (fits_open_image(&fptr, filename.c_str(), READONLY, &status) != 0) {
247  std::string msg =
248  "Failed to open FITS file '" + filename + "'. " + GetCfitsioErrorMsg(status);
249  CII_THROW(RtctkException, msg);
250  }
251 
252  try {
253  // Read and check that the pixel format used in the FITS file corresponds to the type used
254  // for the matrix object passed to this function.
255  int bitpix = -1;
256  status = 0;
257  if (fits_get_img_equivtype(fptr, &bitpix, &status) != 0) {
258  std::string msg = "Failed to read the image type from FITS file '" + filename + "'. " +
259  GetCfitsioErrorMsg(status);
260  CII_THROW(RtctkException, msg);
261  }
262  if (bitpix == LONGLONG_IMG) {
263  // NOTE: Correcting the bitpix for ULONGLONG_IMG. There is a bug in Cfitsio that returns
264  // LONGLONG_IMG instead of ULONGLONG_IMG.
265  char value[80]; // Use maximum possible FITS card size of 80 bytes.
266  status = 0;
267  int result = fits_read_keyword(fptr, "BZERO", value, nullptr, &status);
268  if (result != 0 and status != KEY_NO_EXIST) {
269  std::string msg = "Failed to read keyword BZERO from '" + filename + "'. " +
270  GetCfitsioErrorMsg(status);
271  CII_THROW(RtctkException, msg);
272  }
273  if (std::string(value) ==
274  std::to_string(std::numeric_limits<uint64_t>::max() / 2 + 1)) {
275 #ifdef ULONGLONG_IMG
276  bitpix = ULONGLONG_IMG;
277 #else
278  // If we are dealing with an older Cfitsio library that does not have ULONGLONG_IMG
279  // defined, then simply alias to using the signed version instead.
280  bitpix = LONGLONG_IMG;
281 #endif
282  }
283  }
284  if (bitpix != expected_bitpix) {
285  std::string msg = "The FITS file '" + filename + "' has the wrong image format of " +
286  CfitsioImageTypeToString(bitpix) +
287  ". Expected a FITS image of type " +
288  CfitsioImageTypeToString(expected_bitpix) + ".";
289  CII_THROW(RtctkException, msg);
290  }
291 
292  // Read and check that the number of image axes is 2.
293  int naxis = -1;
294  status = 0;
295  if (fits_get_img_dim(fptr, &naxis, &status) != 0) {
296  std::string msg = "Failed to read the number of image axes from FITS file '" +
297  filename + "'. " + GetCfitsioErrorMsg(status);
298  CII_THROW(RtctkException, msg);
299  }
300  if (naxis != 2) {
301  std::string msg = "The FITS file '" + filename +
302  "' has image dimensions that we cannot handle. Expect a 2D image "
303  "when loading as a matrix.";
304  CII_THROW(RtctkException, msg);
305  }
306 
307  long size[2] = {-1, -1};
308  status = 0;
309  if (fits_get_img_size(fptr, 2, size, &status) != 0) {
310  std::string msg = "Failed to read the image size from FITS file '" + filename + "'. " +
311  GetCfitsioErrorMsg(status);
312  CII_THROW(RtctkException, msg);
313  }
314 
315  using size_type = typename MatrixBuffer<T, A>::size_type;
316  auto nrows = size_type(size[1]);
317  auto ncols = size_type(size[0]);
318  long nelements = size[0] * size[1]; // Total number of pixels, i.e. rows * columns.
319 
320  long fpixel[2] = {1, 1}; // Pixel start location. Cfitsio counts from 1, not 0.
321  int anynull = 0; // Boolean flag indicating if there were any null/nil pixel values.
322  matrix.resize(nrows, ncols);
323  void* array = matrix.data();
324  status = 0;
325  int result =
326  fits_read_pix(fptr, datatype, fpixel, nelements, nullptr, array, &anynull, &status);
327  if (result != 0) {
328  std::string msg = "Failed to read the image from FITS file '" + filename + "'. " +
329  GetCfitsioErrorMsg(status);
330  CII_THROW(RtctkException, msg);
331  }
332  } catch (...) {
333  // Attempt to close the FITS file if an exception was thrown. But do not throw an additional
334  // exception if closing the file failed. Just log this error and rethrow the original
335  // exception.
336  status = 0;
337  if (fits_close_file(fptr, &status) != 0) {
338  LOG4CPLUS_ERROR(GetLogger(),
339  "Failed to close file '" + filename +
340  "' while handling an exception. " + GetCfitsioErrorMsg(status));
341  }
342  throw;
343  }
344 
345  status = 0;
346  if (fits_close_file(fptr, &status) != 0) {
347  std::string msg =
348  "Failed to close the FITS file '" + filename + "'. " + GetCfitsioErrorMsg(status);
349  CII_THROW(RtctkException, msg);
350  }
351 }
352 
358 template <typename T, typename A>
359 void WriteVectorToFits(const std::string& filename, const std::vector<T, A>& vector) {
360  assert(int64_t(vector.size()) <= int64_t(std::numeric_limits<long>::max()));
361 
362  // Workout the appropriate Cfitsio image type code and data type code to use, based on the type
363  // used with std::vector, i.e. the type of T.
364  int bitpix = 0;
365  int datatype = 0;
366  IdentifyCfitsioTypes<T>(bitpix, datatype);
367 
368  std::string tmpfilename = filename + ".new-" + std::to_string(getpid());
369 
370  // Create the new FITS file and open it for modifications.
371  fitsfile* fptr = nullptr;
372  int status = 0; // It is important to initialise this to zero before each Cfitsio API call.
373  if (fits_create_file(&fptr, tmpfilename.c_str(), &status) != 0) {
374  std::string msg =
375  "Failed to create FITS file '" + tmpfilename + "'. " + GetCfitsioErrorMsg(status);
376  CII_THROW(RtctkException, msg);
377  }
378 
379  try {
380  // Create the image header in the HDU.
381  long size = long(vector.size());
382  status = 0;
383  if (fits_create_img(fptr, bitpix, 1, &size, &status) != 0) {
384  std::string msg = "Failed to create the image type from FITS file '" + tmpfilename +
385  "'. " + GetCfitsioErrorMsg(status);
386  CII_THROW(RtctkException, msg);
387  }
388 
389  // Write the vector data as pixels.
390  long fpixel = 1; // Pixel start location. Cfitsio counts from 1, not 0.
391  long nelements = vector.size();
392  // We are forced to use const_cast, since the fits_write_pix function does not accept
393  // const void*.
394  void* array = const_cast<void*>(reinterpret_cast<const void*>(vector.data()));
395  status = 0;
396  if (fits_write_pix(fptr, datatype, &fpixel, nelements, array, &status) != 0) {
397  std::string msg = "Failed to write the vector to FITS file '" + tmpfilename + "'. " +
398  GetCfitsioErrorMsg(status);
399  CII_THROW(RtctkException, msg);
400  }
401  } catch (...) {
402  // Attempt to close the FITS file if an exception was thrown. But do not throw an additional
403  // exception if closing the file failed. Just log this error and rethrow the original
404  // exception.
405  status = 0;
406  if (fits_close_file(fptr, &status) != 0) {
407  LOG4CPLUS_ERROR(GetLogger(),
408  "Failed to close file '" + tmpfilename +
409  "' while handling an exception. " + GetCfitsioErrorMsg(status));
410  }
411  throw;
412  }
413 
414  status = 0;
415  if (fits_close_file(fptr, &status) != 0) {
416  std::string msg =
417  "Failed to close the FITS file '" + tmpfilename + "'. " + GetCfitsioErrorMsg(status);
418  CII_THROW(RtctkException, msg);
419  }
420 
421  // Rename the temporary file to its final value. Updating the file in this manner will make sure
422  // that different processes or threads will see changes to the file in an atomic manner. Either
423  // the old file will be visible, or the new file, but not a partially modified file.
424  try {
425  boost::filesystem::rename(tmpfilename, filename);
426  } catch (const std::exception& error) {
427  CII_THROW_WITH_NESTED(
429  error,
430  "Failed to rename FITS file '" + tmpfilename + "' to '" + filename + "'.")
431  }
432 }
433 
439 template <typename T, typename A>
440 void ReadVectorFromFits(const std::string& filename, std::vector<T, A>& vector) {
441  // Identify the Cfitsio data type code to be used and the expected Cfitsio image type code,
442  // based on the type used with std::vector, i.e. type of T.
443  int expected_bitpix = 0;
444  int datatype = 0;
445  IdentifyCfitsioTypes<T>(expected_bitpix, datatype);
446 
447  fitsfile* fptr = nullptr;
448  int status = 0; // It is important to initialise this to zero before every Cfitsio API call.
449  if (fits_open_image(&fptr, filename.c_str(), READONLY, &status) != 0) {
450  std::string msg =
451  "Failed to open FITS file '" + filename + "'. " + GetCfitsioErrorMsg(status);
452  CII_THROW(RtctkException, msg);
453  }
454 
455  try {
456  // Read and check that the pixel format used in the FITS file corresponds to the type used
457  // for the vector object passed to this function.
458  int bitpix = -1;
459  status = 0;
460  if (fits_get_img_equivtype(fptr, &bitpix, &status) != 0) {
461  std::string msg = "Failed to read the image type from FITS file '" + filename + "'. " +
462  GetCfitsioErrorMsg(status);
463  CII_THROW(RtctkException, msg);
464  }
465  if (bitpix == LONGLONG_IMG) {
466  // NOTE: Correcting the bitpix for ULONGLONG_IMG. There is a bug in Cfitsio that returns
467  // LONGLONG_IMG instead of ULONGLONG_IMG.
468  char value[80]; // Use maximum possible FITS card size of 80 bytes.
469  status = 0;
470  int result = fits_read_keyword(fptr, "BZERO", value, nullptr, &status);
471  if (result != 0 and status != KEY_NO_EXIST) {
472  std::string msg = "Failed to read keyword BZERO from '" + filename + "'. " +
473  GetCfitsioErrorMsg(status);
474  CII_THROW(RtctkException, msg);
475  }
476  if (std::string(value) ==
477  std::to_string(std::numeric_limits<uint64_t>::max() / 2 + 1)) {
478 #ifdef ULONGLONG_IMG
479  bitpix = ULONGLONG_IMG;
480 #else
481  // If we are dealing with an older Cfitsio library that does not have ULONGLONG_IMG
482  // defined, then simply alias to using the signed version instead.
483  bitpix = LONGLONG_IMG;
484 #endif
485  }
486  }
487  if (bitpix != expected_bitpix) {
488  std::string msg = "The FITS file '" + filename + "' has the wrong image format of " +
489  CfitsioImageTypeToString(bitpix) +
490  ". Expected a FITS image of type " +
491  CfitsioImageTypeToString(expected_bitpix) + ".";
492  CII_THROW(RtctkException, msg);
493  }
494 
495  // Read and check that the number of image axes is 2.
496  int naxis = -1;
497  status = 0;
498  if (fits_get_img_dim(fptr, &naxis, &status) != 0) {
499  std::string msg = "Failed to read the number of image axes from FITS file '" +
500  filename + "'. " + GetCfitsioErrorMsg(status);
501  CII_THROW(RtctkException, msg);
502  }
503  if (naxis != 1) {
504  std::string msg = "The FITS file '" + filename +
505  "' has image dimensions that we cannot handle. Expect a 1D image "
506  "when loading as a vector.";
507  CII_THROW(RtctkException, msg);
508  }
509 
510  long nelements = -1;
511  status = 0;
512  if (fits_get_img_size(fptr, 1, &nelements, &status) != 0) {
513  std::string msg = "Failed to read the 1D image size from FITS file '" + filename +
514  "'. " + GetCfitsioErrorMsg(status);
515  CII_THROW(RtctkException, msg);
516  }
517 
518  using size_type = typename std::vector<T, A>::size_type;
519  long fpixel = 1; // Pixel start location. Cfitsio counts from 1, not 0.
520  int anynull = 0; // Boolean flag indicating if there were any null/nil pixel values.
521  vector.resize(size_type(nelements));
522  void* array = vector.data();
523  status = 0;
524  int result =
525  fits_read_pix(fptr, datatype, &fpixel, nelements, nullptr, array, &anynull, &status);
526  if (result != 0) {
527  std::string msg = "Failed to read the image from FITS file '" + filename + "'. " +
528  GetCfitsioErrorMsg(status);
529  CII_THROW(RtctkException, msg);
530  }
531  } catch (...) {
532  // Attempt to close the FITS file if an exception was thrown. But do not throw an additional
533  // exception if closing the file failed. Just log this error and rethrow the original
534  // exception.
535  status = 0;
536  if (fits_close_file(fptr, &status) != 0) {
537  LOG4CPLUS_ERROR(GetLogger(),
538  "Failed to close file '" + filename +
539  "' while handling an exception. " + GetCfitsioErrorMsg(status));
540  }
541  throw;
542  }
543 
544  status = 0;
545  if (fits_close_file(fptr, &status) != 0) {
546  std::string msg =
547  "Failed to close the FITS file '" + filename + "'. " + GetCfitsioErrorMsg(status);
548  CII_THROW(RtctkException, msg);
549  }
550 }
551 
552 // The following are template specialisations for vectors and matrices of boolean values.
553 
557 template <typename A>
558 void WriteMatrixToFits(const std::string& filename, const MatrixBuffer<bool, A>& matrix) {
559  // Concert the boolean matrix to a matrix of 8 bit integers and write that to file instead.
560  MatrixBuffer<int8_t> int_matrix;
561  int_matrix.resize(matrix.GetNrows(), matrix.GetNcols());
562  for (MatrixBuffer<int8_t>::size_type n = 0; n < int_matrix.GetNrows(); ++n) {
563  for (MatrixBuffer<int8_t>::size_type m = 0; m < int_matrix.GetNcols(); ++m) {
564  int_matrix(n, m) = matrix(n, m) ? 1 : 0;
565  }
566  }
567  WriteMatrixToFits(filename, int_matrix);
568 }
569 
573 template <typename A>
574 void ReadMatrixFromFits(const std::string& filename, MatrixBuffer<bool, A>& matrix) {
575  // Load the matrix from file as 8 bit integers and convert it to a boolean matrix.
576  MatrixBuffer<int8_t> int_matrix;
577  ReadMatrixFromFits(filename, int_matrix);
578  matrix.resize(int_matrix.GetNrows(), int_matrix.GetNcols());
579  for (MatrixBuffer<int8_t>::size_type n = 0; n < int_matrix.GetNrows(); ++n) {
580  for (MatrixBuffer<int8_t>::size_type m = 0; m < int_matrix.GetNcols(); ++m) {
581  matrix(n, m) = int_matrix(n, m) == 1 ? true : false;
582  }
583  }
584 }
585 
589 template <typename A>
590 void WriteVectorToFits(const std::string& filename, const std::vector<bool, A>& vector) {
591  // Concert the boolean vector to a vector of 8 bit integers and write that to file instead.
592  std::vector<int8_t> int_vector;
593  int_vector.resize(vector.size());
594  for (std::vector<int8_t>::size_type n = 0; n < int_vector.size(); ++n) {
595  int_vector[n] = vector[n] ? 1 : 0;
596  }
597  WriteVectorToFits(filename, int_vector);
598 }
599 
603 template <typename A>
604 void ReadVectorFromFits(const std::string& filename, std::vector<bool, A>& vector) {
605  // Load the vector from file as 8 bit integers and convert it to a boolean vector.
606  std::vector<int8_t> int_vector;
607  ReadVectorFromFits(filename, int_vector);
608  vector.resize(int_vector.size());
609  for (std::vector<int8_t>::size_type n = 0; n < int_vector.size(); ++n) {
610  vector[n] = int_vector[n] == 1 ? true : false;
611  }
612 }
613 
625 const std::type_info& GetFitsImageType(const std::string& filename);
626 
637 std::size_t GetFitsImageSize(const std::string& filename);
638 
639 } // namespace rtctk::componentFramework
640 
641 #endif // RTCTK_COMPONENTFRAMEWORK_FITSIOFUNCTIONS_HPP
rtctk::componentFramework::CfitsioDataTypeToString
std::string CfitsioDataTypeToString(int datatype)
Returns a string representation of a Cfitsio data type code.
Definition: fitsIoFunctions.cpp:56
exceptions.hpp
Provides macros and utilities for exception handling.
rtctk::componentFramework::MatrixBuffer::GetNrows
size_type GetNrows() const
Definition: matrixBuffer.hpp:91
rtctk::componentFramework::ReadVectorFromFits
void ReadVectorFromFits(const std::string &filename, std::vector< T, A > &vector)
Reads a FITS file containing a 1D image into a std::vector object.
Definition: fitsIoFunctions.hpp:440
rtctk::componentFramework::MatrixBuffer::resize
constexpr void resize(size_type n, size_type m)
Definition: matrixBuffer.hpp:66
rtctk::componentFramework
Definition: commandReplier.cpp:20
rtctk::componentFramework::WriteVectorToFits
void WriteVectorToFits(const std::string &filename, const std::vector< T, A > &vector)
Writes std::vector data as a 1D image to a FITS file.
Definition: fitsIoFunctions.hpp:359
matrixBuffer.hpp
Declaration of the MatrixBuffer template class used in APIs.
rtctk::componentFramework::ReadMatrixFromFits
void ReadMatrixFromFits(const std::string &filename, MatrixBuffer< T, A > &matrix)
Reads a FITS file image into a MatrixBuffer object representing a matrix.
Definition: fitsIoFunctions.hpp:237
rtctk::componentFramework::WriteMatrixToFits
void WriteMatrixToFits(const std::string &filename, const MatrixBuffer< T, A > &matrix)
Writes MatrixBuffer data representing a matrix as an image to a FITS file.
Definition: fitsIoFunctions.hpp:153
rtctk::componentFramework::RtctkException
The RtctkException class is the base class for all Rtctk exceptions.
Definition: exceptions.hpp:207
rtctk::componentFramework::GetLogger
log4cplus::Logger & GetLogger(const std::string &name="")
Get handle to a specific logger (used with logging macros)
rtctk::componentFramework::GetFitsImageType
const std::type_info & GetFitsImageType(const std::string &filename)
Get the C++ type corresponding to a FITS image.
Definition: fitsIoFunctions.cpp:99
rtctk::componentFramework::GetFitsImageSize
std::size_t GetFitsImageSize(const std::string &filename)
Get the number of pixels in a FITS image.
Definition: fitsIoFunctions.cpp:246
logger.hpp
Logging Support Library based on log4cplus.
rtctk::componentFramework::CfitsioImageTypeToString
std::string CfitsioImageTypeToString(int bitpix)
Returns a string representation of a Cfitsio image type code.
Definition: fitsIoFunctions.cpp:27
rtctk::componentFramework::MatrixBuffer::GetNcols
size_type GetNcols() const
Definition: matrixBuffer.hpp:95
rtctk::componentFramework::MatrixBuffer
Definition: matrixBuffer.hpp:22
rtctkExampleDataTaskGenFitsData.filename
filename
Definition: rtctkExampleDataTaskGenFitsData.py:11
rtctk::componentFramework::GetCfitsioErrorMsg
std::string GetCfitsioErrorMsg(int status)
Helper function to convert a Cfitsio status code to a human readable message.
Definition: fitsIoFunctions.cpp:18