ARTS 2.5.11 (git: 6827797f)
radiation_field.cc
Go to the documentation of this file.
1
9#include "radiation_field.h"
10#include "arts_conversions.h"
11#include "sorting.h"
12
13void error_in_integrate(const String& error_msg,
14 const Numeric& value_that_should_be_unity) {
15 ARTS_USER_ERROR_IF (std::abs(value_that_should_be_unity - 1.0) > 1e-4,
16 "Failure in normalization:\n", error_msg, "\n")
17}
18
19Numeric test_integrate_convolved(const Eigen::Ref<Eigen::VectorXcd> &F,
20 const Vector& f) {
21 Numeric val = 0.0;
22
23 const Index n = f.nelem();
24 for (Index i = 0; i < n - 1; i++)
25 val += 0.5 * (f[i + 1] - f[i]) * (F[i].real() + F[i + 1].real());
26
27 return val; // Should return 1.0 for normalized F
28}
29
30Numeric test_integrate_zenith(const Vector& cosza,
31 const Array<Index>& sorted_index) {
32 Numeric val = 0.0;
33
34 const Index n = cosza.nelem();
35 for (Index i = 0; i < n - 1; i++)
36 val += 0.5 * (cosza[sorted_index[i]] - cosza[sorted_index[i + 1]]);
37
38 return val; // Should return 1.0 for normalized cosza
39}
40
42 const Eigen::VectorXcd& F,
43 const Vector& f) {
44 Numeric val = 0.0;
45
46 const Index n = f.nelem();
47 for (Index i = 0; i < n - 1; i++)
48 val += 0.5 * (f[i + 1] - f[i]) *
49 (I(i, 0) * F[i].real() + I(i + 1, 0) * F[i + 1].real());
50
51 return val;
52}
53
55 const Eigen::VectorXcd& F,
56 const Vector& f) {
57 Numeric val = 0.0;
58
59 const Index n = f.nelem();
60 for (Index i = 0; i < n - 1; i++)
61 val += 0.5 * (f[i + 1] - f[i]) *
62 (T(i, 0, 0) * F[i].real() + T(i + 1, 0, 0) * F[i + 1].real());
63
64 return 1.0 - val;
65}
66
67Numeric integrate_zenith(const ConstVectorView& j,
68 const Vector& cosza,
69 const Array<Index>& sorted_index) {
70 Numeric val = 0.0;
71
72 const Index n = cosza.nelem();
73 for (Index i = 0; i < n - 1; i++)
74 val += 0.25 * (cosza[sorted_index[i]] - cosza[sorted_index[i + 1]]) *
75 (j[sorted_index[i]] + j[sorted_index[i + 1]]);
76
77 return val;
78}
79
80Index grid_index_from_gp(const GridPos& gp) {
81 if (gp.fd[1] == 1.0)
82 return gp.idx;
83 return gp.idx + 1;
84}
85
87 ArrayOfVector& cosza,
88 const ArrayOfPpath& ppath_field) {
89 Index nalt = 0;
90 for (auto& path : ppath_field)
91 for (auto& gp : path.gp_p) nalt = std::max(nalt, grid_index_from_gp(gp));
92 nalt += 1;
93
94 // Get the data, which is of unknown length
95 Array<ArrayOfNumeric> zeniths_array(nalt, ArrayOfNumeric(0));
96 for (auto& path : ppath_field) {
97 for (Index ip = 0; ip < path.np; ip++) {
98 const Index ind = grid_index_from_gp(path.gp_p[ip]);
99 zeniths_array[ind].push_back(path.los(ip, 0));
100 }
101 }
102
103 // Finalize sorting
104 sorted_index.resize(nalt);
105 cosza.resize(nalt);
106 for (Index i = 0; i < nalt; i++) {
107 Vector& data = cosza[i];
108 data.resize(zeniths_array[i].nelem());
109
110 for (Index j = 0; j < data.nelem(); j++) data[j] = zeniths_array[i][j];
111 get_sorted_indexes(sorted_index[i], data);
112
113 for (Index j = 0; j < data.nelem(); j++)
114 data[j] = Conversion::cosd(data[j]);
115 }
116}
Array< Numeric > ArrayOfNumeric
An array of Numeric.
Definition: array.h:124
Common ARTS conversions.
This can be used to make arrays out of anything.
Definition: array.h:31
#define ARTS_USER_ERROR_IF(condition,...)
Definition: debug.h:135
auto cosd(auto x) noexcept
Returns the cosine of the deg2rad of the input.
void sorted_index_of_ppath_field(ArrayOfArrayOfIndex &sorted_index, ArrayOfVector &cosza, const ArrayOfPpath &ppath_field)
Get sorting of zenith angles in field of ppath.
Numeric test_integrate_convolved(const Eigen::Ref< Eigen::VectorXcd > &F, const Vector &f)
Integrate the line shape.
void error_in_integrate(const String &error_msg, const Numeric &value_that_should_be_unity)
Throws an error if integration values are bad.
Numeric integrate_zenith(const ConstVectorView &j, const Vector &cosza, const Array< Index > &sorted_index)
Convolve source function with 1D sphere and integrate.
Index grid_index_from_gp(const GridPos &gp)
Get a discrete position from grid pos.
Numeric test_integrate_zenith(const Vector &cosza, const Array< Index > &sorted_index)
Integrate cos(za) over the angles.
Numeric integrate_convolved(const RadiationVector &I, const Eigen::VectorXcd &F, const Vector &f)
Convolve intensity and line shape and integrate.
Radiation field calculations.
Contains sorting routines.
void get_sorted_indexes(ArrayOfIndex &sorted, const T &data)
get_sorted_indexes
Definition: sorting.h:39
Structure to store a grid position.
Definition: interpolation.h:56
std::array< Numeric, 2 > fd
Definition: interpolation.h:58
Index idx
Definition: interpolation.h:57
Radiation Vector for Stokes dimension 1-4.
Class to keep track of Transmission Matrices for Stokes Dim 1-4.