ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_ObsNudgingSeries.H
Go to the documentation of this file.
1 /**
2  * \file ERF_ObsNudgingSeries.H
3  */
4 #ifndef ERF_OBSNUDGINGSERIES_H_
5 #define ERF_OBSNUDGINGSERIES_H_
6 
7 #include <AMReX_REAL.H>
8 #include <AMReX_Vector.H>
9 
10 #include <array>
11 #include <istream>
12 #include <string>
13 
14 //
15 // The measurements of one observation-nudging station, as read from its file,
16 // and the profiles they give at a moment of the run.
17 //
18 // A station file is plain text. Everything from a '#' to the end of a line is
19 // a comment. The first line that is not blank names the columns, in any order:
20 //
21 // time z u v w theta su sv sw stheta
22 //
23 // time and z are required; the wind is given either as u v (east and north, or
24 // grid x and y, see wind_frame) or as speed direction (metres per second, and
25 // the meteorological direction the wind blows from, in degrees clockwise from
26 // north). w, theta and the standard deviations su sv sw stheta are optional,
27 // and a component with no column is not nudged at this station. Each row that
28 // follows is one height at one time. Rows are grouped by time in increasing
29 // order, and the heights within a time are in increasing order and the same at
30 // every time. An entry that is not a finite number ("nan"), or that equals the
31 // run's missing value, is missing: that component is not nudged at that height
32 // and time.
33 //
34 namespace obs_nudging {
35 
36 enum Comp : int { U = 0, V = 1, W = 2, Theta = 3, NComp = 4 };
37 
38 // The name of a component, for messages
39 const char* comp_name (int comp);
40 
41 // The measurements at one time. mean[c][h] and sigma[c][h] are component c at
42 // height h; a missing mean is NaN, and a missing sigma is 0.
44 {
45  double time = 0.0;
46  std::array<amrex::Vector<amrex::Real>, NComp> mean;
47  std::array<amrex::Vector<amrex::Real>, NComp> sigma;
48 };
49 
51 {
52  amrex::Vector<amrex::Real> heights; // strictly increasing
53  amrex::Vector<StationRecord> records; // strictly increasing in time
54  std::array<bool, NComp> has = {false, false, false, false};
55 };
56 
57 // Parse a station file from a stream. Returns false and sets error (naming the
58 // line) when the file is malformed. source is the name used in messages.
59 bool parse_station_series (std::istream& is, const std::string& source,
60  amrex::Real missing_value,
61  StationSeries& series, std::string& error);
62 
63 // The measured profile of one component at one moment: the heights at which
64 // it is available, with its mean and standard deviation there.
65 struct Profile
66 {
67  amrex::Vector<amrex::Real> z;
68  amrex::Vector<amrex::Real> mean;
69  amrex::Vector<amrex::Real> sigma;
70 
71  void clear () { z.clear(); mean.clear(); sigma.clear(); }
72 };
73 
74 //
75 // The profiles of every component at time t.
76 //
77 // A file with one time holds for the whole run. A file with several is
78 // interpolated linearly in time between the two records that bracket t, and a
79 // height is used only where both records have the component; before its first
80 // time and after its last the station is inactive and every profile is empty.
81 //
82 // The wind is then rotated from the frame of the file into the grid frame:
83 // (cos_alpha, sin_alpha) is the direction of the grid x axis measured
84 // counterclockwise from the file's x axis (true east for an earth-relative
85 // wind). Unless the rotation is the identity it needs u and v together, so a
86 // height at which either is missing is dropped from both, and the standard
87 // deviations are rotated as those of independent components.
88 //
89 // Returns true when the station is active at t.
90 //
91 bool profiles_at_time (const StationSeries& series, double t,
93  std::array<Profile, NComp>& profiles);
94 
95 } // namespace obs_nudging
96 
97 #endif
Real sin_alpha
Definition: ERF_Plotfile2DInterpolator.cpp:28
Real cos_alpha
Definition: ERF_Plotfile2DInterpolator.cpp:27
amrex::Real Real
Definition: ERF_ShocInterface.H:19
@ t
Definition: ERF_WSM6.H:272
Definition: ERF_ObsNudging.cpp:22
bool parse_station_series(std::istream &is, const std::string &source, Real missing_value, StationSeries &series, std::string &error)
Definition: ERF_ObsNudgingSeries.cpp:68
const char * comp_name(int comp)
Definition: ERF_ObsNudgingSeries.cpp:19
bool profiles_at_time(const StationSeries &series, double t, Real cos_alpha, Real sin_alpha, std::array< Profile, NComp > &profiles)
Definition: ERF_ObsNudgingSeries.cpp:299
Comp
Definition: ERF_ObsNudgingSeries.H:36
@ NComp
Definition: ERF_ObsNudgingSeries.H:36
@ U
Definition: ERF_ObsNudgingSeries.H:36
@ V
Definition: ERF_ObsNudgingSeries.H:36
@ W
Definition: ERF_ObsNudgingSeries.H:36
@ Theta
Definition: ERF_ObsNudgingSeries.H:36
Definition: ERF_ObsNudgingSeries.H:66
amrex::Vector< amrex::Real > sigma
Definition: ERF_ObsNudgingSeries.H:69
void clear()
Definition: ERF_ObsNudgingSeries.H:71
amrex::Vector< amrex::Real > mean
Definition: ERF_ObsNudgingSeries.H:68
amrex::Vector< amrex::Real > z
Definition: ERF_ObsNudgingSeries.H:67
Definition: ERF_ObsNudgingSeries.H:44
double time
Definition: ERF_ObsNudgingSeries.H:45
std::array< amrex::Vector< amrex::Real >, NComp > mean
Definition: ERF_ObsNudgingSeries.H:46
std::array< amrex::Vector< amrex::Real >, NComp > sigma
Definition: ERF_ObsNudgingSeries.H:47
Definition: ERF_ObsNudgingSeries.H:51
std::array< bool, NComp > has
Definition: ERF_ObsNudgingSeries.H:54
amrex::Vector< StationRecord > records
Definition: ERF_ObsNudgingSeries.H:53
amrex::Vector< amrex::Real > heights
Definition: ERF_ObsNudgingSeries.H:52