PrintInfo.h
Go to the documentation of this file.
1/*!
2 * \file PrintInfo.h
3 * \brief Class to store and manage the PRINT information
4 * From the file.out file or FILE_OUT collection in MongoDB
5 *
6 * \author Junzhi Liu, LiangJun Zhu
7 * \version 1.2
8 * \date Aug., 2022
9 */
10#ifndef SEIMS_PRINTINFO_H
11#define SEIMS_PRINTINFO_H
12
13#include "basic.h"
14
15#include "seims.h"
16#include "ParamInfo.h"
17
18using namespace ccgl;
19
20/*!
21 * \enum AggregationType
22 * \ingroup module_setting
23 * \brief Aggregation type for OUTPUT
24 */
26 AT_Unknown = 0, ///< unknown
27 AT_Sum = 1, ///< sum
28 AT_Average = 2, ///< average
29 AT_Minimum = 3, ///< minimum
30 AT_Maximum = 4, ///< maximum
31 AT_SpecificCells = 5, ///< specific cells
32 AT_TimeSeries = 6 /// raster time series
33};
34
35/*!
36 * \ingroup module_setting
37 * \class PrintInfoItem
38 *
39 * \brief Class stores a single output item of an OuputID
40 *
41 */
43public:
44 //! Constructor
45 PrintInfoItem(int scenario_id = 0, int calibration_id = -1);
46
47 //! Destructor
49
50 //! Aggregated data, the second dimension contains: row, col, value
52 //! rows number, i.e., number of valid cells
54 //! For 1D raster/array data
55 FLTPT* m_1DData;
56 //! number of layers of raster data, greater or equal than 1
58 //! For 2D raster/array data
59 FLTPT** m_2DData;
60
61 //! For time series data of a single subbasin, DT_Single
62 map<time_t, FLTPT> TimeSeriesData;
63 //! For time series data of a single subbasin, DT_Raster1D or DT_Array1D
64 map<time_t, FLTPT*> TimeSeriesDataForSubbasin;
65 //! Count of #TimeSeriesDataForSubbasin
67 //! For time series data of DT_Raster1D(output some .tif files. Distinct from TimeSeriesDataForSubbasin,which output some .txt files)
68 map<time_t, float *> TimeSeriesDataForRaster;
69 //! Count of #TimeSeriesDataForRaster
71
72 //! Add 1D time series data result to #TimeSeriesDataForSubbasin
73 void add1DTimeSeriesResult(time_t, int n, const FLTPT* data);
74
75 //! Add 1D time series data result to #TimeSeriesDataForRaster
76 void add1DRasterTimeSeriesResult(time_t, int n, const float* data);
77
78 //! used only by PET_TS???
79 ///< The site id
80 int SiteID;
81 ///< The site index in output array1D variable
83
84 ///< The subbasin id
86 ///< The subbasin index
87 int SubbasinIndex;
88
89 ////! Start time string
90 //string StartTime;
91 //! Start time \a time_t
93
94 //! get start time \a time_t
95 time_t getStartTime() { return m_startTime; }
96
97 //! set start time \a time_t
98 void setStartTime(const time_t& st) { m_startTime = st; }
99
100 ////! End time string
101 //string EndTime;
102 //! End time \a time_t
103 time_t m_endTime;
104
105 //! Get end time \a time_t
106 time_t getEndTime() { return m_endTime; }
107
108 //! set end time \a time_t
109 void setEndTime(const time_t& st) { m_endTime = st; }
110
111 //! file suffix, e.g., txt, tif, asc, etc.
112 string Suffix;
113 //! output filename without suffix, core name without subbasin ID
114 string Corename;
115 //! output filename without suffix, and contain subbasin ID as prefix for MPI version
116 string Filename;
117 //! Aggregation type string
118 string AggType;
119
120 //! create "output" folder to store all results
121 void Flush(const string& projectPath, MongoGridFs* gfs, IntRaster* templateRaster, const string& header);
122
123 //! Determine if the given date is within the date range for this item
124 bool IsDateInRange(time_t dt);
125
126 //! Aggregate the 2D data from the given data parameter using the given method type.
127 //! However this **data restrict to 3 layers, i.e., Row, Col, Value
128 //! NO NEED TO USE?
129 void AggregateData(int numrows, FLTPT** data, AggregationType type, FLTPT NoDataValue);
130
131 //! Aggregate the 1D data from the given data parameter using the given method type
132 void AggregateData(time_t time, int numrows, FLTPT* data);
133
134 //! Aggregate the 2D raster data from the given data parameter using the given method type
135 void AggregateData2D(time_t time, int nRows, int nCols, FLTPT** data);
136
137 //! Set the Aggregation type
138 void setAggregationType(const AggregationType type) { m_AggregationType = type; }
139
140 //! Get the Aggregation type
141 AggregationType getAggregationType() { return m_AggregationType; };
142
143 //! convert the given string into a matching Aggregation type
144 static AggregationType MatchAggregationType(const string& type);
145
146private:
147 //! Scenario ID
148 int m_scenarioID;
149 //! Calibration ID
150 int m_calibrationID;
151 //! Counter of time series data, i.e., how many data has been aggregated.
152 int m_Counter;
153 //! Aggregation type of current print item
154 AggregationType m_AggregationType;
155};
156
157/*!
158 * \ingroup module_setting
159 * \class PrintInfo
160 * \brief Outputs of one variable, which may contain one or more `PrintInfoItem`
161 * \sa PrintInfoItem
162 */
164public:
165 //! Scenario ID
167 //! Calibration ID
169 //! Time interval of output
171 //! Unit of time interval, which can only be DAY, HR, SEC.
173 //! Module index of the OutputID
175 //! Unique Output ID, which should be one of "VAR_" defined in text.h and Output of any modules.
177 //! The calibration parameters corresponding to the output id, if stated.
179 //! For one OutputID, there may be several output items, e.g., different time period, different subbasin ID. etc.
180 vector<PrintInfoItem *> m_PrintItems;
181
182private:
183 //! Selected subbasin IDs for time series data, vector container
184 vector<int> m_subbasinSeleted;
185 //! Selected subbasin IDs for time series data, int array
186 int* m_subbasinSelectedArray;
187public:
188 //! Constructor, initialize an empty instance
189 PrintInfo(int scenario_id = 0, int calibration_id = -1);
190
191 //! Destructor
193
194 //! Get the number of output items
195 int ItemCount() const { return CVT_INT(m_PrintItems.size()); }
196
197 //! Get all the subbasin IDs (in float array) selected for this outputID
198 void getSubbasinSelected(int* count, int** subbasins);
199
200 //! Set the OutputID for this object
201 void setOutputID(string id) { m_OutputID = id; }
202
203 //! Get the OutputId for this object
204 string getOutputID() const { return m_OutputID; }
205
206 //! Get Header string (all field names) for current OutputID. TODO, how to make it more flexible? By LJ.
208
209 //! Set the interval
210 void setInterval(int interval) { m_Interval = interval; }
211
212 //! Get the interval
213 int getInterval() { return m_Interval; };
214
215 //! Set the interval units
216 void setIntervalUnits(string& units) { m_IntervalUnits = units; }
217
218 //! Get the interval units
219 string getIntervalUnits() const { return m_IntervalUnits; }
220
221 //! Add an output item with the given start time, end time and file name
222 void AddPrintItem(time_t start, time_t end, const string& file, const string& sufi);
223
224 //! Add an output item with the given aggregate type, start time, end time, file name and subbasin ID
225 void AddPrintItem(string& type, time_t start, time_t end, const string& file, const string& sufi,
226 int subbasinID = 0);
227
228 //! Add an output item with the given start time (string), end time (string) and file name, Overloaded method
229 void AddPrintItem(time_t start, time_t end, const string& file, string sitename, const string& sufi,
230 bool isSubbasin);
231
232 //! Get a reference to the output item located at the given index position
234};
235#endif /* SEIMS_PRINTINFO_H */
Class to store parameter item information.
@ AT_Unknown
unknown
Definition: PrintInfo.h:26
@ AT_Maximum
maximum
Definition: PrintInfo.h:30
@ AT_Minimum
minimum
Definition: PrintInfo.h:29
@ AT_SpecificCells
specific cells
Definition: PrintInfo.h:31
@ AT_Sum
sum
Definition: PrintInfo.h:27
@ AT_Average
average
Definition: PrintInfo.h:28
Basic definitions.
#define CVT_INT(param)
A reference to the postfix of executable file for RELWITHDEBINFO mode.
Definition: basic.h:325
Class to store and manage parameter information from the parameter database.
Definition: ParamInfo.h:37
void setIntervalUnits(string &units)
Set the interval units.
Definition: PrintInfo.h:216
FLTPT ** m_1DDataWithRowCol
Aggregated data, the second dimension contains: row, col, value.
Definition: PrintInfo.h:51
map< time_t, FLTPT > TimeSeriesData
For time series data of a single subbasin, DT_Single.
Definition: PrintInfo.h:62
void AddPrintItem(string &type, time_t start, time_t end, const string &file, const string &sufi, int subbasinID=0)
Add an output item with the given aggregate type, start time, end time, file name and subbasin ID.
void getSubbasinSelected(int *count, int **subbasins)
Get all the subbasin IDs (in float array) selected for this outputID.
void setStartTime(const time_t &st)
set start time time_t
Definition: PrintInfo.h:98
void AggregateData(time_t time, int numrows, FLTPT *data)
Aggregate the 1D data from the given data parameter using the given method type.
string Filename
output filename without suffix, and contain subbasin ID as prefix for MPI version
Definition: PrintInfo.h:116
int m_scenarioID
Scenario ID.
Definition: PrintInfo.h:166
string getOutputID() const
Get the OutputId for this object.
Definition: PrintInfo.h:204
void setInterval(int interval)
Set the interval.
Definition: PrintInfo.h:210
void AddPrintItem(time_t start, time_t end, const string &file, const string &sufi)
Add an output item with the given start time, end time and file name.
time_t getEndTime()
Get end time time_t.
Definition: PrintInfo.h:106
map< time_t, float * > TimeSeriesDataForRaster
For time series data of DT_Raster1D(output some .tif files. Distinct from TimeSeriesDataForSubbasin,...
Definition: PrintInfo.h:68
int SiteID
used only by PET_TS??? The site id
Definition: PrintInfo.h:80
void AggregateData(int numrows, FLTPT **data, AggregationType type, FLTPT NoDataValue)
Aggregate the 2D data from the given data parameter using the given method type.
void Flush(const string &projectPath, MongoGridFs *gfs, IntRaster *templateRaster, const string &header)
create "output" folder to store all results
int SiteIndex
The subbasin id.
Definition: PrintInfo.h:82
ParamInfo< FLTPT > * m_param
The calibration parameters corresponding to the output id, if stated.
Definition: PrintInfo.h:178
~PrintInfoItem()
Destructor.
map< time_t, FLTPT * > TimeSeriesDataForSubbasin
For time series data of a single subbasin, DT_Raster1D or DT_Array1D.
Definition: PrintInfo.h:64
void add1DTimeSeriesResult(time_t, int n, const FLTPT *data)
Add 1D time series data result to TimeSeriesDataForSubbasin.
~PrintInfo()
Destructor.
PrintInfoItem(int scenario_id=0, int calibration_id=-1)
Constructor.
string Corename
output filename without suffix, core name without subbasin ID
Definition: PrintInfo.h:114
vector< PrintInfoItem * > m_PrintItems
For one OutputID, there may be several output items, e.g., different time period, different subbasin ...
Definition: PrintInfo.h:180
int TimeSeriesDataForSubbasinCount
Count of TimeSeriesDataForSubbasin.
Definition: PrintInfo.h:66
FLTPT ** m_2DData
For 2D raster/array data.
Definition: PrintInfo.h:59
string getIntervalUnits() const
Get the interval units.
Definition: PrintInfo.h:219
void AddPrintItem(time_t start, time_t end, const string &file, string sitename, const string &sufi, bool isSubbasin)
Add an output item with the given start time (string), end time (string) and file name,...
void add1DRasterTimeSeriesResult(time_t, int n, const float *data)
Add 1D time series data result to TimeSeriesDataForRaster.
time_t m_startTime
Start time time_t.
Definition: PrintInfo.h:92
int m_calibrationID
Calibration ID.
Definition: PrintInfo.h:168
int m_Interval
Time interval of output.
Definition: PrintInfo.h:170
int m_nLayers
number of layers of raster data, greater or equal than 1
Definition: PrintInfo.h:57
string m_OutputID
Unique Output ID, which should be one of "VAR_" defined in text.h and Output of any modules.
Definition: PrintInfo.h:176
FLTPT * m_1DData
For 1D raster/array data.
Definition: PrintInfo.h:55
time_t getStartTime()
get start time time_t
Definition: PrintInfo.h:95
string Suffix
file suffix, e.g., txt, tif, asc, etc.
Definition: PrintInfo.h:112
void setOutputID(string id)
Set the OutputID for this object.
Definition: PrintInfo.h:201
bool IsDateInRange(time_t dt)
Determine if the given date is within the date range for this item.
AggregationType getAggregationType()
Get the Aggregation type.
Definition: PrintInfo.h:141
void AggregateData2D(time_t time, int nRows, int nCols, FLTPT **data)
Aggregate the 2D raster data from the given data parameter using the given method type.
int m_moduleIndex
Module index of the OutputID.
Definition: PrintInfo.h:174
int TimeSeriesDataForRasterCount
Count of TimeSeriesDataForRaster.
Definition: PrintInfo.h:70
void setEndTime(const time_t &st)
set end time time_t
Definition: PrintInfo.h:109
int getInterval()
Get the interval.
Definition: PrintInfo.h:213
string AggType
Aggregation type string.
Definition: PrintInfo.h:118
time_t m_endTime
End time time_t.
Definition: PrintInfo.h:103
int m_nRows
rows number, i.e., number of valid cells
Definition: PrintInfo.h:53
PrintInfo(int scenario_id=0, int calibration_id=-1)
Constructor, initialize an empty instance.
void setAggregationType(const AggregationType type)
Set the Aggregation type.
Definition: PrintInfo.h:138
string getOutputTimeSeriesHeader()
Get Header string (all field names) for current OutputID. TODO, how to make it more flexible?...
PrintInfoItem * getPrintInfoItem(int index)
Get a reference to the output item located at the given index position.
int ItemCount() const
Get the number of output items.
Definition: PrintInfo.h:195
string m_IntervalUnits
Unit of time interval, which can only be DAY, HR, SEC.
Definition: PrintInfo.h:172
static AggregationType MatchAggregationType(const string &type)
convert the given string into a matching Aggregation type
int SubbasinID
The subbasin index.
Definition: PrintInfo.h:85
Outputs of one variable, which may contain one or more PrintInfoItem
Definition: PrintInfo.h:163
Class stores a single output item of an OuputID.
Definition: PrintInfo.h:42
AggregationType
Aggregation type for OUTPUT.
Definition: PrintInfo.h:25
Common Cross-platform Geographic Library (CCGL)
The SEIMS related definitions and utilities header.
#define IntRaster
Integer-typed raster.
Definition: seims.h:126