ARTS 2.5.11 (git: 725533f0)
energylevelmap.cc
Go to the documentation of this file.
1
9#include "energylevelmap.h"
10#include "special_interp.h"
11
12
14 if (not (value.nbooks() == levels.nelem() and
15 (vib_energy.nelem() == levels.nelem() or vib_energy.nelem() == 0))) {
16 return false; // Bad dimensions, vibrational energies and IDs and data of strange size
17 }
18
20 } else if (type == EnergyLevelMapType::Vector_t) {
21 if (value.npages() not_eq 1 or value.nrows() not_eq 1) {
22 return false; // Bad dimensions for vector type
23 }
24 } else if (type == EnergyLevelMapType::Numeric_t) {
25 if (value.npages() not_eq 1 or value.nrows() not_eq 1 or value.ncols() not_eq 1) {
26 return false; // Bad dimensions for numeric type
27 }
28 } else if (type == EnergyLevelMapType::None_t) {
29 if (value.npages() not_eq 0 or value.nrows() not_eq 0 or value.ncols() not_eq 0) {
30 return false; // Bad dimensions for none type
31 }
32 }
33
34 return std::all_of(vib_energy.begin(),
35 vib_energy.end(),
36 [](const auto& val) { return val >= 0; });
37}
38
39
41 const AbsorptionLines& band,
42 const Index& line_index) const
43{
45 "Must have Numeric_t, input type is bad");
46
47 Output2 x{/*.r_low=*/0, /*.r_upp=*/0};
48
49 bool found1=false;
50 bool found2=false;
51 for (size_t i=0; i<levels.size(); i++) {
52 const Quantum::Number::StateMatch lt(levels[i], band.lines[line_index].localquanta, band.quantumidentity);
53
54 if (lt == Quantum::Number::StateMatchType::Level and lt.low) {
55 found1 = true;
56 x.r_low = value(i, 0, 0, 0);
57 }
58
59 if (lt == Quantum::Number::StateMatchType::Level and lt.upp) {
60 found2 = true;
61 x.r_upp = value(i, 0, 0, 0);
62 }
63
64 if (found1 and found2)
65 break;
66 }
67
68 return x;
69}
70
72 const AbsorptionLines& band,
73 const Numeric T) const
74{
76 "Must have Numeric_t, input type is bad");
77
78 Output4 x{/*.E_low=*/0, /*.E_upp=*/0, /*.T_low=*/T, /*.T_upp=*/T};
79
80 bool found1=false;
81 bool found2=false;
82 for (Index i=0; i<levels.nelem(); i++) {
84
85 if (lt == Quantum::Number::StateMatchType::Level and lt.low) {
86 found1 = true;
87 x.T_low = value(i, 0, 0, 0);
88 x.E_low = vib_energy[i];
89 }
90
91 if (lt == Quantum::Number::StateMatchType::Level and lt.upp) {
92 found2 = true;
93 x.T_upp = value(i, 0, 0, 0);
94 x.E_upp = vib_energy[i];
95 }
96
97 if (found1 and found2) {
98 break;
99 }
100 }
101 return x;
102}
103
104EnergyLevelMap::EnergyLevelMap(Tensor4 data, ArrayOfQuantumIdentifier levels_, Vector energies) :
106 levels(std::move(levels_)),
107 vib_energy(std::move(energies)),
108 value(std::move(data))
109{
110 ThrowIfNotOK();
111}
112
113EnergyLevelMap::EnergyLevelMap(const Matrix& data, ArrayOfQuantumIdentifier levels_, Vector energies) :
115 levels(std::move(levels_)),
116 vib_energy(std::move(energies)),
117 value(data.nrows(), 1, 1, data.ncols())
118{
119 value(joker, 0, 0, joker) = data;
120 ThrowIfNotOK();
121}
122
123EnergyLevelMap::EnergyLevelMap(const Vector& data, ArrayOfQuantumIdentifier levels_, Vector energies) :
125 levels(std::move(levels_)),
126 vib_energy(std::move(energies)),
127 value(data.nelem(), 1, 1, 1)
128{
129 value(joker, 0, 0, 0) = data;
130 ThrowIfNotOK();
131}
132
133EnergyLevelMap EnergyLevelMap::InterpToGridPos(Index atmosphere_dim, const ArrayOfGridPos& p, const ArrayOfGridPos& lat, const ArrayOfGridPos& lon) const
134{
137 "Must have Tensor3_t, input type is bad");
138
140
141 Matrix itw_field;
142 interp_atmfield_gp2itw(itw_field, atmosphere_dim, p, lat, lon);
143
144 const Index nnlte = levels.nelem();
145 for (Index itnlte = 0; itnlte < nnlte; itnlte++)
146 interp_atmfield_by_itw(elm.value(itnlte, 0, 0, joker), atmosphere_dim,
147 value(itnlte, joker, joker, joker),
148 p, lat, lon, itw_field);
149 return elm;
150}
151
153{
156 return *this;
158 ,"Must have Vector_t, input type is bad");
159
160 ARTS_USER_ERROR_IF (ip >= value.ncols() or ip < 0,
161 "Bad dims for data:\n\tThe pressure dim of data contains: ",
162 value.ncols(), " values and you are requesting element index ", ip, "\n")
163
165 elm.value(joker, 0, 0, 0) = value(joker, 0, 0, ip);
166 return elm;
167}
168
169std::ostream& operator<<(std::ostream& os, const EnergyLevelMap& elm) {
170 return os << elm.type << '\n'
171 << elm.levels << '\n'
172 << elm.value << '\n'
173 << elm.vib_energy << '\n';
174}
175
176EnergyLevelMap EnergyLevelMap::operator()(Index ip, Index ilat, Index ilon) const
177{
179 return *this;
181 "Must have Tensor3_t, input type is bad");
182
183 auto elm = EnergyLevelMap(EnergyLevelMapType::Numeric_t, 1, 1, 1, *this);
184 elm.value(joker, 0, 0, 0) = value(joker, ip, ilat, ilon);
185 return elm;
186}
187
189 auto out = toEnergyLevelMapType(s);
192 "Only \"None\", \"Numeric\", \"Vector\", and \"Tensor3\" types accepted\n"
193 "You request to have an EnergyLevelMap of type: ",
194 s,
195 '\n')
196 return out;
197}
198
199std::ostream& operator<<(std::ostream& os, EnergyLevelMapType x) {return os << toString(x);}
Index nelem() const ARTS_NOEXCEPT
Definition array.h:75
#define ARTS_NOEXCEPT
Definition debug.h:83
#define ARTS_USER_ERROR_IF(condition,...)
Definition debug.h:137
EnergyLevelMapType toEnergyLevelMapTypeOrThrow(std::string_view s)
std::ostream & operator<<(std::ostream &os, const EnergyLevelMap &elm)
Class to map energy levels.
EnergyLevelMapType
constexpr EnergyLevelMapType toEnergyLevelMapType(std::string_view s) noexcept
constexpr std::string_view toString(EnergyLevelMapType x) noexcept
void interp_atmfield_gp2itw(Matrix &itw, const Index &atmosphere_dim, const ArrayOfGridPos &gp_p, const ArrayOfGridPos &gp_lat, const ArrayOfGridPos &gp_lon)
Converts atmospheric grid positions to weights for interpolation of an atmospheric field.
void interp_atmfield_by_itw(VectorView x, const Index &atmosphere_dim, ConstTensor3View x_field, const ArrayOfGridPos &gp_p, const ArrayOfGridPos &gp_lat, const ArrayOfGridPos &gp_lon, ConstMatrixView itw)
Interpolates an atmospheric field with pre-calculated weights by interp_atmfield_gp2itw.
Header file for special_interp.cc.
Array< SingleLine > lines
A list of individual lines.
QuantumIdentifier quantumidentity
Catalog ID.
bool OK() const ARTS_NOEXCEPT
EnergyLevelMap operator[](Index ip) const
Output2 get_ratio_params(const AbsorptionLines &band, const Index &line_index) const
Get the output required for Population::NLTE.
Output4 get_vibtemp_params(const AbsorptionLines &band, const Numeric T) const
Get the output required for Population::NLTE-VibrationalTemperatures.
EnergyLevelMap InterpToGridPos(Index atmosphere_dim, const ArrayOfGridPos &p, const ArrayOfGridPos &lat, const ArrayOfGridPos &lon) const
ArrayOfQuantumIdentifier levels
EnergyLevelMapType type
void ThrowIfNotOK() const ARTS_NOEXCEPT
EnergyLevelMap operator()(Index ip, Index ilat, Index ilon) const
StateMatchType operates so that a check less than a level should be 'better', bar None.