ARTS 2.5.0 (git: 9ee3ac6c)
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 "file.h"
27#include "geodetic.h"
28#include "matpackI.h"
29#include "mystring.h"
30#include "rte.h"
31#include "telsem.h"
32
34extern Numeric DEG2RAD;
35
36/* Workspace method: Doxygen documentation will be auto-generated */
38 const Numeric &lat,
39 const Numeric &lon,
40 const Numeric &theta,
41 const Vector &f,
42 const TelsemAtlas &atlas,
43 const Numeric &d_max,
44 const Verbosity &) {
45 chk_if_in_range("Latitude input to TELSEM2", lat, -90.0, 90.0);
46 chk_if_in_range("Longitude input to TELSEM2", lon, 0.0, 360.0);
47
48 Index cellnumber = atlas.calc_cellnum(lat, lon);
49 // Check if cell is in atlas.
50 if (!atlas.contains(cellnumber)) {
51 ARTS_USER_ERROR_IF (d_max <= 0.0,
52 "Given coordinates are not contained in "
53 " TELSEM atlas. To enable nearest neighbor"
54 "interpolation set *d_max* to a positive "
55 "value.");
56 cellnumber = atlas.calc_cellnum_nearest_neighbor(lat, lon);
57 Numeric lat_nn, lon_nn;
58 std::tie(lat_nn, lon_nn) = atlas.get_coordinates(cellnumber);
59 Numeric d = sphdist(lat, lon, lat_nn, lon_nn);
60 ARTS_USER_ERROR_IF (d > d_max,
61 "Distance of nearest neighbor exceeds provided limit (",
62 d, " > ", d_max, ").")
63 }
64
65 Index class1 = atlas.get_class1(cellnumber);
66 Index class2 = atlas.get_class2(cellnumber);
67 Vector emis_v = atlas.get_emis_v(cellnumber);
68 Vector emis_h = atlas.get_emis_h(cellnumber);
69
70 emis.resize(f.nelem(), 2);
71 for (Index i = 0; i < f.nelem(); ++i) {
72 std::tie(emis(i, 0), emis(i, 1)) =
73 atlas.emis_interp(theta, f[i] * 1e-9, class1, class2, emis_v, emis_h);
74 }
75}
76
77/* Workspace method: Doxygen documentation will be auto-generated */
79 const Index &atmosphere_dim,
80 const Vector &lat_grid,
81 const Vector &lat_true,
82 const Vector &lon_true,
83 const Vector &rtp_pos,
84 const TelsemAtlas &atlas,
85 const Verbosity &) {
86 // Checks
87 chk_latlon_true(atmosphere_dim, lat_grid, lat_true, lon_true);
88
89 Numeric lat, lon;
91 lat, lon, atmosphere_dim, lat_grid, lat_true, lon_true, rtp_pos);
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 surface_type = 1;
98 } else {
99 surface_type = 0;
100 }
101}
102
103/* Workspace method: Doxygen documentation will be auto-generated */
105 const Numeric &lat,
106 const Numeric &lon,
107 const TelsemAtlas &atlas,
108 const Verbosity &) {
109 chk_if_in_range("Latitude input to TELSEM2", lat, -90.0, 90.0);
110 chk_if_in_range("Longitude input to TELSEM2", lon, 0.0, 360.0);
111
112 Index cellnumber = atlas.calc_cellnum(lat, lon);
113 if (atlas.contains(cellnumber)) {
114 emis = atlas[cellnumber];
115 } else {
116 emis.resize(0);
117 }
118}
119
120/* Workspace method: Doxygen documentation will be auto-generated */
122 const String &directory,
123 const Index &month,
124 const String &filename_pattern,
125 const Verbosity &verbosity) {
127 const Index imonth = filename_pattern.find("@MM@");
128 if (imonth < 0) {
129 ostringstream os;
130 os << "Substring '@MM@' not found in filename_pattern for" << std::endl
131 << "month number replacement: " << filename_pattern;
132 }
133
134 std::ifstream is;
135
136 ostringstream month_ss;
137 if (month < 10) {
138 month_ss << 0;
139 }
140 month_ss << month;
141
142 String this_filename = filename_pattern;
143 this_filename.replace(imonth, 4, month_ss.str());
144 this_filename = directory + '/' + this_filename;
145
146 out2 << "Reading TELSEM atlas: " << this_filename << '\n';
147 open_input_file(is, this_filename);
148 atlas.read(is);
149 atlas.set_month(month);
150
151 String corr_filename = directory + '/' + "correlations";
152 out2 << "Reading correlations: " << corr_filename << '\n';
153 std::ifstream corr_is;
154 open_input_file(corr_is, corr_filename);
155 Tensor3 correlation(10, 7, 7);
156 String s;
157 for (Index i = 0; i < 10; i++) {
158 std::getline(corr_is, s);
159 for (Index j = 0; j < 7; j++) {
160 for (Index k = 0; k < 7; k++) {
161 corr_is >> correlation(i, j, k);
162 ARTS_USER_ERROR_IF (corr_is.fail(),
163 "Error reading correlation.");
164 }
165 std::getline(corr_is, s);
166 }
167 }
168 atlas.set_correl(correlation);
169}
170
171/* Workspace method: Doxygen documentation will be auto-generated */
173 const String &directory,
174 const String &filename_pattern,
175 const Verbosity &verbosity) {
177 const Index imonth = filename_pattern.find("@MM@");
178 if (imonth < 0) {
179 ostringstream os;
180 os << "Substring '@MM@' not found in filename_pattern for" << std::endl
181 << "month number replacement: " << filename_pattern;
182 }
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 >> 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}
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:107
Index nelem() const ARTS_NOEXCEPT
Returns the number of elements.
Definition: matpackI.cc:48
The Matrix class.
Definition: matpackI.h:1225
void resize(Index r, Index c)
Resize function.
Definition: matpackI.cc:1056
A telsem atlas.
Definition: telsem.h:59
void read(std::istream &is)
Definition: telsem.cc:46
Index calc_cellnum(Numeric lat, Numeric lon) const
Definition: telsem.cc:142
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:170
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:225
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:287
Vector get_emis_v(Index i) const
Definition: telsem.h:137
The Tensor3 class.
Definition: matpackIII.h:339
The Vector class.
Definition: matpackI.h:876
void resize(Index n)
Resize function.
Definition: matpackI.cc:408
#define ARTS_USER_ERROR_IF(condition,...)
Definition: debug.h:134
void open_input_file(ifstream &file, const String &name)
Open a file for reading.
Definition: file.cc:147
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:1335
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:37
Numeric EARTH_RADIUS
Numeric DEG2RAD
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:78
void telsem_atlasesReadAscii(ArrayOfTelsemAtlas &telsem_atlases, const String &directory, const String &filename_pattern, const Verbosity &verbosity)
WORKSPACE METHOD: telsem_atlasesReadAscii.
Definition: m_telsem.cc:172
void telsemAtlasLookup(Vector &emis, const Numeric &lat, const Numeric &lon, const TelsemAtlas &atlas, const Verbosity &)
WORKSPACE METHOD: telsemAtlasLookup.
Definition: m_telsem.cc:104
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:121
Implementation of Matrix, Vector, and such stuff.
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
#define CREATE_OUT2
Definition: messages.h:206
This file contains the definition of String, the ARTS string class.
#define d
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:2034
Declaration of functions in rte.cc.
This file contains the definition of the TELSEM atlas format.