ARTS 2.5.10 (git: 2f1c442c)
m_telsem.cc
Go to the documentation of this file.
1/* Copyright (C) 2017
2 Oliver Lemke <olemke@core-dump.info>
3
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 2, or (at your option) any
7 later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 USA.
18*/
19
26#include "arts_conversions.h"
27#include "file.h"
28#include "geodetic.h"
29#include "matpackI.h"
30#include "mystring.h"
31#include "rte.h"
32#include "telsem.h"
33#include "check_input.h"
34
37
38/* Workspace method: Doxygen documentation will be auto-generated */
40 const Numeric &lat,
41 const Numeric &lon,
42 const Numeric &theta,
43 const Vector &f,
44 const TelsemAtlas &atlas,
45 const Numeric &d_max,
46 const Verbosity &) {
47 chk_if_in_range("Latitude input to TELSEM2", lat, -90.0, 90.0);
48 chk_if_in_range("Longitude input to TELSEM2", lon, 0.0, 360.0);
49
50 Index cellnumber = atlas.calc_cellnum(lat, lon);
51 // Check if cell is in atlas.
52 if (!atlas.contains(cellnumber)) {
53 ARTS_USER_ERROR_IF (d_max <= 0.0,
54 "Given coordinates are not contained in "
55 " TELSEM atlas. To enable nearest neighbor"
56 "interpolation set *d_max* to a positive "
57 "value.");
58 cellnumber = atlas.calc_cellnum_nearest_neighbor(lat, lon);
59 Numeric lat_nn, lon_nn;
60 std::tie(lat_nn, lon_nn) = atlas.get_coordinates(cellnumber);
61 Numeric d = sphdist(lat, lon, lat_nn, lon_nn);
62 ARTS_USER_ERROR_IF (d > d_max,
63 "Distance of nearest neighbor exceeds provided limit (",
64 d, " > ", d_max, ").")
65 }
66
67 Index class1 = atlas.get_class1(cellnumber);
68 Index class2 = atlas.get_class2(cellnumber);
69 Vector emis_v = atlas.get_emis_v(cellnumber);
70 Vector emis_h = atlas.get_emis_h(cellnumber);
71
72 emis.resize(f.nelem(), 2);
73 for (Index i = 0; i < f.nelem(); ++i) {
74 std::tie(emis(i, 0), emis(i, 1)) =
75 atlas.emis_interp(theta, f[i] * 1e-9, class1, class2, emis_v, emis_h);
76 }
77}
78
79/* Workspace method: Doxygen documentation will be auto-generated */
81 const Index &atmosphere_dim,
82 const Vector &lat_grid,
83 const Vector &lat_true,
84 const Vector &lon_true,
85 const Vector &rtp_pos,
86 const TelsemAtlas &atlas,
87 const Verbosity &) {
88 // Checks
89 chk_latlon_true(atmosphere_dim, lat_grid, lat_true, lon_true);
90
91 Numeric lat, lon;
93 lat, lon, atmosphere_dim, lat_grid, lat_true, lon_true, rtp_pos);
94 chk_if_in_range("Latitude input to TELSEM2", lat, -90.0, 90.0);
95 chk_if_in_range("Longitude input to TELSEM2", lon, 0.0, 360.0);
96
97 Index cellnumber = atlas.calc_cellnum(lat, lon);
98 if (atlas.contains(cellnumber)) {
99 surface_type = 1;
100 } else {
101 surface_type = 0;
102 }
103}
104
105/* Workspace method: Doxygen documentation will be auto-generated */
107 const Numeric &lat,
108 const Numeric &lon,
109 const TelsemAtlas &atlas,
110 const Verbosity &) {
111 chk_if_in_range("Latitude input to TELSEM2", lat, -90.0, 90.0);
112 chk_if_in_range("Longitude input to TELSEM2", lon, 0.0, 360.0);
113
114 Index cellnumber = atlas.calc_cellnum(lat, lon);
115 if (atlas.contains(cellnumber)) {
116 emis = atlas[cellnumber];
117 } else {
118 emis.resize(0);
119 }
120}
121
122/* Workspace method: Doxygen documentation will be auto-generated */
124 const String &directory,
125 const Index &month,
126 const String &filename_pattern,
127 const Verbosity &verbosity) {
129 const Index imonth = filename_pattern.find("@MM@");
131 "Substring '@MM@' not found in filename_pattern for\n",
132 "month number replacement: ",
133 filename_pattern)
134
135 std::ifstream is;
136
137 ostringstream month_ss;
138 if (month < 10) {
139 month_ss << 0;
140 }
141 month_ss << month;
142
143 String this_filename = filename_pattern;
144 this_filename.replace(imonth, 4, month_ss.str());
145 this_filename = directory + '/' + this_filename;
146
147 out2 << "Reading TELSEM atlas: " << this_filename << '\n';
148 open_input_file(is, this_filename);
149 atlas.read(is);
150 atlas.set_month(month);
151
152 String corr_filename = directory + '/' + "correlations";
153 out2 << "Reading correlations: " << corr_filename << '\n';
154 std::ifstream corr_is;
155 open_input_file(corr_is, corr_filename);
156 Tensor3 correlation(10, 7, 7);
157 String s;
158 for (Index i = 0; i < 10; i++) {
159 std::getline(corr_is, s);
160 for (Index j = 0; j < 7; j++) {
161 for (Index k = 0; k < 7; k++) {
162 corr_is >> double_imanip() >> correlation(i, j, k);
163 ARTS_USER_ERROR_IF (corr_is.fail(),
164 "Error reading correlation.");
165 }
166 std::getline(corr_is, s);
167 }
168 }
169 atlas.set_correl(correlation);
170}
171
172/* Workspace method: Doxygen documentation will be auto-generated */
174 const String &directory,
175 const String &filename_pattern,
176 const Verbosity &verbosity) {
178 const Index imonth = filename_pattern.find("@MM@");
180 "Substring '@MM@' not found in filename_pattern for\n",
181 "month number replacement: ",
182 filename_pattern)
183
184 telsem_atlases.resize(12);
185 for (Index i = 1; i <= 12; i++) {
186 std::ifstream is;
187 ostringstream month;
188 if (i < 10) month << 0;
189 month << i;
190 String this_filename = filename_pattern;
191 this_filename.replace(imonth, 4, month.str());
192 this_filename = directory + '/' + this_filename;
193
194 out2 << "Reading TELSEM atlas: " << this_filename << '\n';
195 open_input_file(is, this_filename);
196 telsem_atlases[i - 1].read(is);
197 telsem_atlases[i - 1].set_month(i);
198 }
199
200 std::ifstream is;
201 String corr_filename = directory + '/' + "correlations";
202 out2 << "Reading correlations: " << corr_filename << '\n';
203 open_input_file(is, corr_filename);
204 Tensor3 correlation(10, 7, 7);
205 String s;
206 for (Index i = 0; i < 10; i++) {
207 std::getline(is, s);
208 for (Index j = 0; j < 7; j++) {
209 for (Index k = 0; k < 7; k++) {
210 is >> double_imanip() >> correlation(i, j, k);
211 ARTS_USER_ERROR_IF (is.fail(), "Error reading correlation.");
212 }
213 std::getline(is, s);
214 }
215 }
216
217 for (Index i = 0; i < 12; i++) {
218 telsem_atlases[i].set_correl(correlation);
219 }
220}
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
Definition: check_input.cc:86
This can be used to make arrays out of anything.
Definition: array.h:48
Index nelem() const noexcept
Returns the number of elements.
Definition: matpackI.h:547
The Matrix class.
Definition: matpackI.h:1285
void resize(Index r, Index c)
Resize function.
Definition: matpackI.cc:1011
A telsem atlas.
Definition: telsem.h:59
void read(std::istream &is)
Definition: telsem.cc:48
Index calc_cellnum(Numeric lat, Numeric lon) const
Definition: telsem.cc:144
bool contains(Index cellnumber) const
Definition: telsem.h:85
Index get_class2(Index cellnumber) const
Definition: telsem.h:120
void set_month(Index m)
Definition: telsem.h:74
Index calc_cellnum_nearest_neighbor(Numeric lat, Numeric lon) const
Definition: telsem.cc:172
void set_correl(const Tensor3 &t)
Definition: telsem.h:78
Vector get_emis_h(Index cellnum) const
Definition: telsem.h:159
std::pair< Numeric, Numeric > get_coordinates(Index cellnum) const
Definition: telsem.cc:227
Index get_class1(Index cellnumber) const
Definition: telsem.h:102
std::pair< Numeric, Numeric > emis_interp(Numeric theta, Numeric freq, Index class1, Index class2, const ConstVectorView &ev, const ConstVectorView &eh) const
Definition: telsem.cc:289
Vector get_emis_v(Index i) const
Definition: telsem.h:137
The Tensor3 class.
Definition: matpackIII.h:352
The Vector class.
Definition: matpackI.h:910
void resize(Index n)
Resize function.
Definition: matpackI.cc:390
Input manipulator class for doubles to enable nan and inf parsing.
Definition: double_imanip.h:42
static const Index npos
Define npos:
Definition: mystring.h:209
#define ARTS_USER_ERROR_IF(condition,...)
Definition: debug.h:153
void open_input_file(ifstream &file, const std::string_view name)
Open a file for reading.
Definition: file.cc:128
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:1336
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:39
constexpr Numeric EARTH_RADIUS
Definition: m_telsem.cc:35
constexpr Numeric DEG2RAD
Definition: m_telsem.cc:36
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:80
void telsem_atlasesReadAscii(ArrayOfTelsemAtlas &telsem_atlases, const String &directory, const String &filename_pattern, const Verbosity &verbosity)
WORKSPACE METHOD: telsem_atlasesReadAscii.
Definition: m_telsem.cc:173
void telsemAtlasLookup(Vector &emis, const Numeric &lat, const Numeric &lon, const TelsemAtlas &atlas, const Verbosity &)
WORKSPACE METHOD: telsemAtlasLookup.
Definition: m_telsem.cc:106
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:123
Implementation of Matrix, Vector, and such stuff.
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
#define CREATE_OUT2
Definition: messages.h:205
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:1933
Declaration of functions in rte.cc.
This file contains the definition of the TELSEM atlas format.
#define d