hysplitcdump.hh 7.2 KB
Newer Older
1
2
3
#ifndef RADIX_RADIXIO_HYSPLITCDUMP_HH_
#define RADIX_RADIXIO_HYSPLITCDUMP_HH_

4
#include <memory>
5
#include <sstream>
6
#include <string>
7
8
#include <vector>

9
#include "radixcore/visibility.hh"
10

11
12
namespace radix
{
LEFEBVREJP email's avatar
LEFEBVREJP email committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
 * @brief The HysplitLocation struct
 * Contains date (year, month, day)
 * and time (hour minutes) with
 * the location (lat, lon) and altitude (meters).
 */
struct RADIX_PUBLIC HysplitLocation
{
  int year, month, day, hour, minutes;
  float lat, lon, z;
};  // struct HysplitLocation

struct RADIX_PUBLIC HysplitTime
{
  int year, month, day, hour, minutes, forecast;
  std::string pretty() const
  {
    std::ostringstream ss;
    ss << month << "/" << day << "/" << year << " " << hour << " " << minutes;
    return ss.str();
  }
};  // struct Time

struct RADIX_PUBLIC HysplitPoint
{
  short xi;
  short yi;
  float concentration;
};  // struct HysplitPoint

43
44
class RADIX_PUBLIC HysplitCDump
{
45
46
 public:
  typedef std::shared_ptr<HysplitCDump> SP;
LEFEBVREJP email's avatar
LEFEBVREJP email committed
47

48
49
50
 private:
  // identification
  std::string mId;
LEFEBVREJP email's avatar
LEFEBVREJP email committed
51
52
  // initial time
  HysplitTime mTime;
53
54
55
  // number of starting locations
  int mNumLocations;
  // Array of particle starting locations
LEFEBVREJP email's avatar
LEFEBVREJP email committed
56
  std::vector<HysplitLocation> mStartLocations;
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
  // Grid number latitudes
  int mNumLat;
  // Grid number longitutde
  int mNumLon;
  // Size of latitude grid cell
  float mDeltaLat;
  // Size of longitude grid cell
  float mDeltaLon;
  // Lower left corner latitude
  float mCLat;
  // Lower left corner longitude
  float mCLon;
  // output levels in meters
  std::vector<int> mLevels;

  // Pollutant identifiers
  std::vector<std::string> mPollutants;

  // starting times
LEFEBVREJP email's avatar
LEFEBVREJP email committed
76
  std::vector<HysplitTime> mStartTimes;
77
  // ending times
LEFEBVREJP email's avatar
LEFEBVREJP email committed
78
  std::vector<HysplitTime> mEndTimes;
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

  // x grid points for concentrations
  // x(short) = [time][pollutant][level][#]
  std::vector<std::vector<std::vector<std::vector<short>>>> mXList;
  // y grid points for concentrations
  // y(short) = [time][pollutant][level][#]
  std::vector<std::vector<std::vector<std::vector<short>>>> mYList;
  // value for concentrations
  // concentration(float) = [time][pollutant][level][#]
  std::vector<std::vector<std::vector<std::vector<float>>>> mConcList;

 public:
  std::string id() const;
  void setId(const std::string &id);
  void dateTime(int &year, int &month, int &day, int &hour) const;
LEFEBVREJP email's avatar
LEFEBVREJP email committed
94
95
  // for python bindings
  const HysplitTime &dateTime() const;
96
97
98
99
100
101
  void setDateTime(int year, int month, int day, int hour);
  int forecastHour() const;
  void setForecastHour(int forecastHour);
  int numLocations() const;
  void location(int i, int &year, int &month, int &day, int &hour, float &lat,
                float &lon, float &z, int &minutes) const;
LEFEBVREJP email's avatar
LEFEBVREJP email committed
102
103
  // for python bindings
  const HysplitLocation &location(int i) const;
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132

  void addLocation(int year, int month, int day, int hour, float lat, float lon,
                   float z, int minutes);
  int numLat() const;
  void setNumLat(int numLat);
  int numLon() const;
  void setNumLon(int numLat);
  float deltaLat() const;
  void setDeltaLat(float deltaLat);
  float deltaLon() const;
  void setDeltaLon(float deltaLon);
  float cornerLat() const;
  void setCornerLat(float cLat);
  float cornerLon() const;
  void setCornerLon(float cLon);

  int numLevels() const;
  void addLevel(int altitude);
  int level(int index) const;

  int numPollutants() const;
  void addPollutant(const std::string &pol);
  std::string pollutant(int index) const;

  int numStartTimes() const;
  void addStartTime(int year, int month, int day, int hour, int minute,
                    int forecast);
  void startTime(int i, int &year, int &month, int &day, int &hour, int &minute,
                 int &forecast) const;
LEFEBVREJP email's avatar
LEFEBVREJP email committed
133
134
  // for python bindings
  const HysplitTime &startTime(int i) const;
135
136
137
138
139
  int numEndTimes() const;
  void addEndTime(int year, int month, int day, int hour, int minute,
                  int forecast);
  void endTime(int i, int &year, int &month, int &day, int &hour, int &minute,
               int &forecast) const;
LEFEBVREJP email's avatar
LEFEBVREJP email committed
140
141
  // for python bindings
  const HysplitTime &endTime(int i) const;
142
143
144
145
146
147
148

  int numNonZeroPoints(int timeIndex, int pollutantIndex, int levelIndex) const;
  void setNumNonZeroPoints(int timeIndex, int pollutantIndex, int levelIndex,
                           int nxyp);
  void setPoint(int timeIndex, int pollutantIndex, int levelIndex,
                int nonZeroIndex, short xi, short yi, float concentration);
  void point(int timeIndex, int pollutantIndex, int levelIndex,
LEFEBVREJP email's avatar
LEFEBVREJP email committed
149
150
151
152
             int nonZeroIndex, short &xi, short &yi,
             float &concentration) const;
  // for python bindings
  HysplitPoint point(int ti, int pi, int li, int nzi) const;
153
};  // class HysplitCDump
154
155
156
157
/**
 * @class HysplitCDump
 * @brief HYSPLIT Concentration file interface
 */
158
template <typename data_type>
159
160
class RADIX_PUBLIC HysplitCDumpStream
{
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
 private:
  data_type mData;

 public:
  HysplitCDumpStream(data_type container);
  /**
   * @brief read_from a hysplit concentration file
   * @param file Path to hysplit concentration file
   *
   * Requires data_type to have the following methods:
   * setId(const std::string&)
   * setDateTime(int year, int month, int day, int hour)
   * setForcastHour(int)
   * addLocation(int year, int month, int day, int hour, float lat, float lon,
   * float z, int minutes) setNumLat(int) setNumLon(int) setDeltaLat(float)
   * setDeltaLon(float)
   * setCornerLat(float)
   * setCornerLon(float)
   * addLevel(int)
   * addPollutant(const std::string&)
   * addStartTime(int year, int month, int day, int hour, int minute, int
   * forecast) addEndTime(int year, int month, int day, int hour, int minute,
   * int forecast) setNumNonZeroPoints(int timeIndex, int pollutantIndex, int
   * levelIndex, int numPoints) setPoint(int timeIndex, int pollutantIndex, int
   * levelIndex, int nonZeroIndex, short xIndex, short yIndex, float
   * concentration)
   * @return true on success, false otherwise
   */
  bool read_from(const std::string &file);
  /**
   * @brief write_to create a hysplit concentration file
   * @param file Path to the file
   *
   * Requires data_type to have the following methods:
   * id() const
   * int dateTime(int& year, int& month, int& day, int& hour) const
   * int forecastHour() const
   * int numLocations() const
   * void location(int i, int& year, int& month, int& day, int& hour, float&
   * lat, float& lon, float& z, int& minutes) const int numLat() const int
   * numLon() const float deltaLat() const float deltaLon() const float
   * cornerLat() const float cornerLon() const int numLevels() const int
   * level(int) const int numPollutants() const std::string pollutant(int i)
   * const int numStartTimes() const void startTime(int i, int& year, int&
   * month, int& day, int& hour, int& minute, int& forecast) const int
   * numEndTimes() const void endTime(int i, int& year, int& month, int& day,
   * int& hour, int& minute, int& forecast) const int numNonZeroPoints(int
   * timeIndex,int pollutantIndex, int levelIndex) const void point(int
   * timeIndex,int pollutantIndex, int levelIndex, int nonZeroIndex, short&
   * xIndex, short& yIndex, float& concentration) const
   * @return true on success, false otherwise
   */
  bool write_to(const std::string &file) const;
};  // class
}  // namespace radix
216
217
218
219

#include "radixio/hysplitcdump.i.hh"

#endif /** RADIX_RADIXIO_HYSPLITCDUMP_HH_ */