GooseEYE 0.9.1
Loading...
Searching...
No Matches
Ensemble_heightheight.hpp
Go to the documentation of this file.
1
7#ifndef GOOSEEYE_ENSEMBLE_HEIGHTHEIGHT_HPP
8#define GOOSEEYE_ENSEMBLE_HEIGHTHEIGHT_HPP
9
10#include "GooseEYE.h"
11
12namespace GooseEYE {
13
14template <class T, class M>
15inline void Ensemble::heightheight(const T& f, const M& fmask)
16{
17 using mask_type = typename M::value_type;
18
19 static_assert(std::is_integral<mask_type>::value, "Integral mask required.");
20
21 GOOSEEYE_ASSERT(xt::has_shape(f, fmask.shape()), std::out_of_range);
22 GOOSEEYE_ASSERT(f.dimension() == m_shape_orig.size(), std::out_of_range);
23 GOOSEEYE_ASSERT(xt::all(xt::equal(fmask, 0) || xt::equal(fmask, 1)), std::out_of_range);
24 GOOSEEYE_ASSERT(m_stat == Type::heightheight || m_stat == Type::Unset, std::out_of_range);
25
26 // lock statistic
27 m_stat = Type::heightheight;
28
29 // not periodic (default): mask padded items
30 xt::pad_mode pad_mode = xt::pad_mode::constant;
31 int mask_value = 1;
32
33 // periodic: unmask padded items
34 if (m_periodic) {
35 pad_mode = xt::pad_mode::periodic;
36 mask_value = 0;
37 }
38
39 // apply padding
40 array_type::tensor<double, 3> F = xt::pad(xt::atleast_3d(f), m_pad, pad_mode);
42 xt::pad(xt::atleast_3d(fmask), m_pad, xt::pad_mode::constant, mask_value);
44 xt::pad(xt::atleast_3d(fmask), m_pad, xt::pad_mode::constant, mask_value);
45
46 // compute correlation
47 for (size_t h = m_pad[0][0]; h < F.shape(0) - m_pad[0][1]; ++h) {
48 for (size_t i = m_pad[1][0]; i < F.shape(1) - m_pad[1][1]; ++i) {
49 for (size_t j = m_pad[2][0]; j < F.shape(2) - m_pad[2][1]; ++j) {
50 // - skip masked
51 if (Fmask(h, i, j)) {
52 continue;
53 }
54 // - get comparison sub-matrix
55 auto Fi = xt::view(
56 F,
57 xt::range(h - m_pad[0][0], h + m_pad[0][1] + 1),
58 xt::range(i - m_pad[1][0], i + m_pad[1][1] + 1),
59 xt::range(j - m_pad[2][0], j + m_pad[2][1] + 1));
60 // - get inverse of comparison mask
61 auto Fmii = 1.0 - xt::view(
62 Fmaskd,
63 xt::range(h - m_pad[0][0], h + m_pad[0][1] + 1),
64 xt::range(i - m_pad[1][0], i + m_pad[1][1] + 1),
65 xt::range(j - m_pad[2][0], j + m_pad[2][1] + 1));
66 // - update sum of the m_first moment
67 m_first += xt::pow(Fi - F(h, i, j), 2.0) * Fmii;
68 // - update sum of the m_second moment
69 if (m_variance) {
70 m_second += xt::pow(Fi - F(h, i, j), 4.0) * Fmii;
71 }
72 // - normalisation
73 m_norm += Fmii;
74 }
75 }
76 }
77}
78
79template <class T>
80inline void Ensemble::heightheight(const T& f)
81{
82 array_type::array<int> mask = xt::zeros<int>(f.shape());
83 heightheight(f, mask);
84}
85
86} // namespace GooseEYE
87
88#endif
void heightheight(const T &f)
Add realization to height-height correlation.
#define GOOSEEYE_ASSERT(expr, assertion)
All assertions are implemented as:
Definition config.h:91
xt::xtensor< T, N > tensor
Fixed (static) rank array.
Definition config.h:155
Toolbox to compute statistics.
Definition config.h:128