casacore
Loading...
Searching...
No Matches
StokesIConversions.h
Go to the documentation of this file.
1#ifndef CASACORE_ALTERNATE_MANS_STOKES_I_CONVERSIONS_H_
2#define CASACORE_ALTERNATE_MANS_STOKES_I_CONVERSIONS_H_
3
4#include <stdexcept>
5
6namespace casacore {
7
13template <typename T>
14inline void ExpandFromStokesI(T *data, size_t n) {
15 for (size_t i = 0; i != n; ++i) {
16 const size_t index = n - i - 1;
17 const T value = data[index];
18 data[index * 4] = value;
19 data[index * 4 + 1] = T();
20 data[index * 4 + 2] = T();
21 data[index * 4 + 3] = value;
22 }
23}
24
25template <>
26inline void ExpandFromStokesI(bool *data, size_t n) {
27 for (size_t i = 0; i != n; ++i) {
28 const size_t index = n - i - 1;
29 const bool value = data[index];
30 data[index * 4] = value;
31 data[index * 4 + 1] = value;
32 data[index * 4 + 2] = value;
33 data[index * 4 + 3] = value;
34 }
35}
36
42template <typename T>
43inline void ExpandFromDiagonal(T *data, size_t n) {
44 for (size_t i = n*2; i > 0; i -= 2) {
45 const size_t index = i - 2;
46 data[index * 2 + 3] = data[index + 1];
47 data[index * 2 + 2] = T();
48 data[index * 2 + 1] = T();
49 data[index * 2] = data[index];
50 }
51}
52
64template <typename T>
65inline T *TransformToStokesI(const T *input, T *buffer, size_t n) {
66 for (size_t i = 0; i != n; ++i) {
67 buffer[i] = T((input[i * 4] + input[i * 4 + 3]) * T(0.5));
68 if (input[i * 4 + 1] != T(0) || input[i * 4 + 2] != T(0))
69 throw std::runtime_error(
70 "Stokes-I storage modes cannot store data for which the 2nd and 3rd "
71 "correlation are non-zero");
72 // While we could also check whether pp == qq, this is a bit more
73 // complicated because of rounding inaccuracies. The above check should
74 // catch the most crucial misuse of the stman, so a pp == qq check is not
75 // performed.
76 }
77 return buffer;
78}
79
80template <>
81inline bool *TransformToStokesI(const bool *input, bool *buffer, size_t n) {
82 for (size_t i = 0; i != n; ++i) {
83 const bool a = input[i * 4];
84 const bool b = input[i * 4 + 1];
85 const bool c = input[i * 4 + 2];
86 const bool d = input[i * 4 + 3];
87 if (a != b || a != c || a != d)
88 throw std::runtime_error(
89 "Stokes-I storage modes cannot store boolean data for which not all "
90 "correlations are equal");
91 buffer[i] = a;
92 }
93 return buffer;
94}
95
104template <typename T>
105inline void CheckIsDiagonal(const T *input, size_t n) {
106 for (size_t i = 0; i != n; ++i) {
107 const T b = input[i * 4 + 1];
108 const T c = input[i * 4 + 2];
109 if (b != T(0) || c != T(0))
110 throw std::runtime_error(
111 "Diagonal storage modes cannot store data for which the 2nd and 3rd "
112 "correlation are non-zero");
113 }
114}
115
116} // namespace casacore
117
118#endif
this file contains all the compiler specific defines
Definition mainpage.dox:28
void ExpandFromDiagonal(T *data, size_t n)
Performs in-place expansion of n pair of diagonal values such that each pair becomes 4 values with ze...
T * TransformToStokesI(const T *input, T *buffer, size_t n)
Calculates for every set of 4 input values the Stokes-I values by doing out = 0.5 * (in_pp + in_qq),...
void CheckIsDiagonal(const T *input, size_t n)
Check if every set of 4 input values contains only non-zeros on the diagonal (pp or qq).
NewDelAllocator< T > NewDelAllocator< T >::value
Definition Allocator.h:369
void ExpandFromStokesI(T *data, size_t n)
Expands n values from single Stokes I values to have 4 values, in place.