ARTS 2.5.11 (git: 725533f0)
m_telsem.cc
Go to the documentation of this file.
1
7#include "arts_conversions.h"
8#include "file.h"
9#include "geodetic.h"
10#include "matpack_data.h"
11#include "mystring.h"
12#include "rte.h"
13#include "telsem.h"
14#include "check_input.h"
15
16inline constexpr Numeric EARTH_RADIUS=Constant::earth_radius;
17inline constexpr Numeric DEG2RAD=Conversion::deg2rad(1);
18
19/* Workspace method: Doxygen documentation will be auto-generated */
20void telsemStandalone(Matrix &emis,
21 const Numeric &lat,
22 const Numeric &lon,
23 const Numeric &theta,
24 const Vector &f,
25 const TelsemAtlas &atlas,
26 const Numeric &d_max,
27 const Verbosity &) {
28 chk_if_in_range("Latitude input to TELSEM2", lat, -90.0, 90.0);
29 chk_if_in_range("Longitude input to TELSEM2", lon, 0.0, 360.0);
30
31 Index cellnumber = atlas.calc_cellnum(lat, lon);
32 // Check if cell is in atlas.
33 if (!atlas.contains(cellnumber)) {
34 ARTS_USER_ERROR_IF (d_max <= 0.0,
35 "Given coordinates are not contained in "
36 " TELSEM atlas. To enable nearest neighbor"
37 "interpolation set *d_max* to a positive "
38 "value.");
39 cellnumber = atlas.calc_cellnum_nearest_neighbor(lat, lon);
40 Numeric lat_nn, lon_nn;
41 std::tie(lat_nn, lon_nn) = atlas.get_coordinates(cellnumber);
42 Numeric d = sphdist(lat, lon, lat_nn, lon_nn);
43 ARTS_USER_ERROR_IF (d > d_max,
44 "Distance of nearest neighbor exceeds provided limit (",
45 d, " > ", d_max, ").")
46 }
47
48 Index class1 = atlas.get_class1(cellnumber);
49 Index class2 = atlas.get_class2(cellnumber);
50 Vector emis_v = atlas.get_emis_v(cellnumber);
51 Vector emis_h = atlas.get_emis_h(cellnumber);
52
53 emis.resize(f.nelem(), 2);
54 for (Index i = 0; i < f.nelem(); ++i) {
55 std::tie(emis(i, 0), emis(i, 1)) =
56 atlas.emis_interp(theta, f[i] * 1e-9, class1, class2, emis_v, emis_h);
57 }
58}
59
60/* Workspace method: Doxygen documentation will be auto-generated */
61void telsemSurfaceTypeLandSea(Index &surface_type,
62 const Index &atmosphere_dim,
63 const Vector &lat_grid,
64 const Vector &lat_true,
65 const Vector &lon_true,
66 const Vector &rtp_pos,
67 const TelsemAtlas &atlas,
68 const Verbosity &) {
69 // Checks
70 chk_latlon_true(atmosphere_dim, lat_grid, lat_true, lon_true);
71
72 Numeric lat, lon;
74 lat, lon, atmosphere_dim, lat_grid, lat_true, lon_true, rtp_pos);
75 chk_if_in_range("Latitude input to TELSEM2", lat, -90.0, 90.0);
76 chk_if_in_range("Longitude input to TELSEM2", lon, 0.0, 360.0);
77
78 Index cellnumber = atlas.calc_cellnum(lat, lon);
79 if (atlas.contains(cellnumber)) {
80 surface_type = 1;
81 } else {
82 surface_type = 0;
83 }
84}
85
86/* Workspace method: Doxygen documentation will be auto-generated */
87void telsemAtlasLookup(Vector &emis,
88 const Numeric &lat,
89 const Numeric &lon,
90 const TelsemAtlas &atlas,
91 const Verbosity &) {
92 chk_if_in_range("Latitude input to TELSEM2", lat, -90.0, 90.0);
93 chk_if_in_range("Longitude input to TELSEM2", lon, 0.0, 360.0);
94
95 Index cellnumber = atlas.calc_cellnum(lat, lon);
96 if (atlas.contains(cellnumber)) {
97 emis = atlas[cellnumber];
98 } else {
99 emis.resize(0);
100 }
101}
102
103/* Workspace method: Doxygen documentation will be auto-generated */
105 const String &directory,
106 const Index &month,
107 const String &filename_pattern,
108 const Verbosity &verbosity) {
110 const Index imonth = filename_pattern.find("@MM@");
112 "Substring '@MM@' not found in filename_pattern for\n",
113 "month number replacement: ",
114 filename_pattern)
115
116 std::ifstream is;
117
118 ostringstream month_ss;
119 if (month < 10) {
120 month_ss << 0;
121 }
122 month_ss << month;
123
124 String this_filename = filename_pattern;
125 this_filename.replace(imonth, 4, month_ss.str());
126 this_filename = directory + '/' + this_filename;
127
128 out2 << "Reading TELSEM atlas: " << this_filename << '\n';
129 open_input_file(is, this_filename);
130 atlas.read(is);
131 atlas.set_month(month);
132
133 String corr_filename = directory + '/' + "correlations";
134 out2 << "Reading correlations: " << corr_filename << '\n';
135 std::ifstream corr_is;
136 open_input_file(corr_is, corr_filename);
137 Tensor3 correlation(10, 7, 7);
138 String s;
139 for (Index i = 0; i < 10; i++) {
140 std::getline(corr_is, s);
141 for (Index j = 0; j < 7; j++) {
142 for (Index k = 0; k < 7; k++) {
143 corr_is >> double_imanip() >> correlation(i, j, k);
144 ARTS_USER_ERROR_IF (corr_is.fail(),
145 "Error reading correlation.");
146 }
147 std::getline(corr_is, s);
148 }
149 }
150 atlas.set_correl(correlation);
151}
152
153/* Workspace method: Doxygen documentation will be auto-generated */
155 const String &directory,
156 const String &filename_pattern,
157 const Verbosity &verbosity) {
159 const Index imonth = filename_pattern.find("@MM@");
161 "Substring '@MM@' not found in filename_pattern for\n",
162 "month number replacement: ",
163 filename_pattern)
164
165 telsem_atlases.resize(12);
166 for (Index i = 1; i <= 12; i++) {
167 std::ifstream is;
168 ostringstream month;
169 if (i < 10) month << 0;
170 month << i;
171 String this_filename = filename_pattern;
172 this_filename.replace(imonth, 4, month.str());
173 this_filename = directory + '/' + this_filename;
174
175 out2 << "Reading TELSEM atlas: " << this_filename << '\n';
176 open_input_file(is, this_filename);
177 telsem_atlases[i - 1].read(is);
178 telsem_atlases[i - 1].set_month(i);
179 }
180
181 std::ifstream is;
182 String corr_filename = directory + '/' + "correlations";
183 out2 << "Reading correlations: " << corr_filename << '\n';
184 open_input_file(is, corr_filename);
185 Tensor3 correlation(10, 7, 7);
186 String s;
187 for (Index i = 0; i < 10; i++) {
188 std::getline(is, s);
189 for (Index j = 0; j < 7; j++) {
190 for (Index k = 0; k < 7; k++) {
191 is >> double_imanip() >> correlation(i, j, k);
192 ARTS_USER_ERROR_IF (is.fail(), "Error reading correlation.");
193 }
194 std::getline(is, s);
195 }
196 }
197
198 for (Index i = 0; i < 12; i++) {
199 telsem_atlases[i].set_correl(correlation);
200 }
201}
Common ARTS conversions.
void chk_latlon_true(const Index &atmosphere_dim, ConstVectorView lat_grid, ConstVectorView lat_true, ConstVectorView lon_true)
chk_latlon_true
void chk_if_in_range(const String &x_name, const Index &x, const Index &x_low, const Index &x_high)
chk_if_in_range
This can be used to make arrays out of anything.
Definition array.h:31
A telsem atlas.
Definition telsem.h:42
void read(std::istream &is)
Definition telsem.cc:29
Index calc_cellnum(Numeric lat, Numeric lon) const
Definition telsem.cc:125
bool contains(Index cellnumber) const
Definition telsem.h:68
Index get_class2(Index cellnumber) const
Definition telsem.h:103
void set_month(Index m)
Definition telsem.h:57
Index calc_cellnum_nearest_neighbor(Numeric lat, Numeric lon) const
Definition telsem.cc:153
void set_correl(const Tensor3 &t)
Definition telsem.h:61
Vector get_emis_h(Index cellnum) const
Definition telsem.h:142
std::pair< Numeric, Numeric > get_coordinates(Index cellnum) const
Definition telsem.cc:208
Index get_class1(Index cellnumber) const
Definition telsem.h:85
std::pair< Numeric, Numeric > emis_interp(Numeric theta, Numeric freq, Index class1, Index class2, const ConstVectorView &ev, const ConstVectorView &eh) const
Definition telsem.cc:270
Vector get_emis_v(Index i) const
Definition telsem.h:120
Input manipulator class for doubles to enable nan and inf parsing.
static const Index npos
Define npos:
Definition mystring.h:192
#define ARTS_USER_ERROR_IF(condition,...)
Definition debug.h:137
void open_input_file(ifstream &file, const std::string_view name)
Open a file for reading.
Definition file.cc:111
This file contains basic functions to handle ASCII files.
Numeric sphdist(const Numeric &lat1, const Numeric &lon1, const Numeric &lat2, const Numeric &lon2)
sphdist
Definition geodetic.cc:1318
void telsemStandalone(Matrix &emis, const Numeric &lat, const Numeric &lon, const Numeric &theta, const Vector &f, const TelsemAtlas &atlas, const Numeric &d_max, const Verbosity &)
WORKSPACE METHOD: telsemStandalone.
Definition m_telsem.cc:20
constexpr Numeric EARTH_RADIUS
Definition m_telsem.cc:16
constexpr Numeric DEG2RAD
Definition m_telsem.cc:17
void telsemSurfaceTypeLandSea(Index &surface_type, const Index &atmosphere_dim, const Vector &lat_grid, const Vector &lat_true, const Vector &lon_true, const Vector &rtp_pos, const TelsemAtlas &atlas, const Verbosity &)
WORKSPACE METHOD: telsemSurfaceTypeLandSea.
Definition m_telsem.cc:61
void telsem_atlasesReadAscii(ArrayOfTelsemAtlas &telsem_atlases, const String &directory, const String &filename_pattern, const Verbosity &verbosity)
WORKSPACE METHOD: telsem_atlasesReadAscii.
Definition m_telsem.cc:154
void telsemAtlasLookup(Vector &emis, const Numeric &lat, const Numeric &lon, const TelsemAtlas &atlas, const Verbosity &)
WORKSPACE METHOD: telsemAtlasLookup.
Definition m_telsem.cc:87
void telsem_atlasReadAscii(TelsemAtlas &atlas, const String &directory, const Index &month, const String &filename_pattern, const Verbosity &verbosity)
WORKSPACE METHOD: telsem_atlasReadAscii.
Definition m_telsem.cc:104
#define CREATE_OUT2
Definition messages.h:188
This file contains the definition of String, the ARTS string class.
constexpr Numeric earth_radius
Global constant, the radius of the Earth [m].
constexpr auto deg2rad(auto x) noexcept
Converts degrees to radians.
void pos2true_latlon(Numeric &lat, Numeric &lon, const Index &atmosphere_dim, const ConstVectorView &lat_grid, const ConstVectorView &lat_true, const ConstVectorView &lon_true, const ConstVectorView &pos)
Determines the true alt and lon for an "ARTS position".
Definition rte.cc:1914
Declaration of functions in rte.cc.
This file contains the definition of the TELSEM atlas format.
#define d