-
Notifications
You must be signed in to change notification settings - Fork 0
/
LSDChannel.hpp
372 lines (333 loc) · 14.9 KB
/
LSDChannel.hpp
1
2
3
4
5
6
7
8
9
10
11
12
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// LSDChannel
// Land Surface Dynamics Channel
//
// An object within the University
// of Edinburgh Land Surface Dynamics group topographic toolbox
// for retaining information of channels
//
// This is a derivative class of LSDIndexChannel.
// LSDIndexChannel alone holds pointers to data in
// LSDFlowInfo and LSDRaster, whereas LSDChannel
// contains actual data about the channel such as
// elevation and drainage area.
//
// These two objects are seperated to save on memory overhead
// during runtime.
//
// Developed by:
// Simon M. Mudd
// Martin D. Hurst
// David T. Milodowski
// Stuart W.D. Grieve
// Declan A. Valters
// Fiona Clubb
//
// Copyright (C) 2013 Simon M. Mudd 2013
//
// Developer can be contacted by simon.m.mudd _at_ ed.ac.uk
//
// Simon Mudd
// University of Edinburgh
// School of GeoSciences
// Drummond Street
// Edinburgh, EH8 9XP
// Scotland
// United Kingdom
//
// This program is free software;
// you can redistribute it and/or modify it under the terms of the
// GNU General Public License as published by the Free Software Foundation;
// either version 2 of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY;
// without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// You should have received a copy of the
// GNU General Public License along with this program;
// if not, write to:
// Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor,
// Boston, MA 02110-1301
// USA
//
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
/** @file LSDChannel.hpp
@author Simon M. Mudd, University of Edinburgh
@author David Milodowski, University of Edinburgh
@author Martin D. Hurst, British Geological Survey
@author Stuart W. D. Grieve, University of Edinburgh
@author Fiona Clubb, University of Edinburgh
@version Version 0.0.1
@brief This object inherets from LSDIndexChannel and is used for chi analysis.
@date 30/08/2012
*/
//-----------------------------------------------------------------
//DOCUMENTATION URL: http://www.geos.ed.ac.uk/~s0675405/LSD_Docs/
//-----------------------------------------------------------------
#include <vector>
#include "TNT/tnt.h"
#include "LSDFlowInfo.hpp"
#include "LSDIndexChannel.hpp"
#include "LSDMostLikelyPartitionsFinder.hpp"
using namespace std;
using namespace TNT;
#ifndef LSDChannel_H
#define LSDChannel_H
///@brief This object inherets from LSDIndexChannel and is used for chi analysis.
class LSDChannel: public LSDIndexChannel
{
public:
/// @brief Defualt constructor. Just makes an empty channel
/// @author SMM
/// @date 24/09/14
LSDChannel() { cout << "I am an empty LSDChannel" << endl; }
/// @brief Creates an LSDChannel by copying from an IndexChannel.
///
/// @details The starting node is upstream and the ending node is downstream.
/// In this create function the junction indices are left blank (this can
/// describe a channel between two arbitraty points.
/// @param InChann LSDIndexChannel object.
/// @author SMM
/// @date 01/01/12
LSDChannel(LSDIndexChannel& InChann)
{ create_LSDC(InChann); }
/// @brief Creates an index channel with just the node index of the starting and ending nodes.
/// @details The starting node is upstream and the ending node is downstream.
/// In this create function the junction indices are left blank (this can
/// describe a channel between two arbitraty points.
/// @param StartNode Starting node.
/// @param EndNode Ending node.
/// @param FlowInfo LSDFlowInfo object.
/// @author SMM
/// @date 01/01/12
LSDChannel(int StartNode, int EndNode, LSDFlowInfo& FlowInfo)
{ create_LSDC(StartNode, EndNode, FlowInfo); }
/// @brief Creates an index channel with just the node index of the starting and ending nodes also includes junction information.
/// @details The starting node is upstream and the ending node is downstream.
/// In this create function the junction indices are left blank (this can
/// describe a channel between two arbitraty points.
/// @param StartJunction Starting junction.
/// @param StartNode Starting node.
/// @param EndJunction Ending junction.
/// @param EndNode Ending node.
/// @param FlowInfo LSDFlowInfo object.
/// @author SMM
/// @date 01/01/12
LSDChannel(int StartJunction, int StartNode,
int EndJunction, int EndNode, LSDFlowInfo& FlowInfo)
{ create_LSDC(StartJunction,StartNode,
EndJunction,EndNode, FlowInfo); }
/// @brief This calculates all the channel areas, elevations and chi parameters based on for a starting node index and ending node index.
/// @param StartNode Starting node.
/// @param EndNode Ending node.
/// @param downslope_chi Downslope Chi value.
/// @param m_over_n m over n ratio.
/// @param A_0 A_0 value.
/// @param FlowInfo LSDFlowInfo object.
/// @param Elevation_Raster Elevation LSDRaster object.
/// @author SMM
/// @date 01/01/12
LSDChannel(int StartNode, int EndNode, float downslope_chi,
float m_over_n, float A_0, LSDFlowInfo& FlowInfo,
LSDRaster& Elevation_Raster)
{ create_LSDC(StartNode, EndNode, downslope_chi,
m_over_n, A_0, FlowInfo, Elevation_Raster); }
/// @brief This calculates all the channel areas, elevations and chi parameters based on for a starting node index and ending node index.
/// @param StartNode Starting node.
/// @param EndNode Ending node.
/// @param downslope_chi Downslope Chi value.
/// @param m_over_n m over n ratio.
/// @param A_0 A_0 value.
/// @param FlowInfo LSDFlowInfo object.
/// @param Elevation_Raster Elevation LSDRaster object.
/// @param DA_raster Drainage area raster LSDRaster object
/// @author SMM
/// @date 01/01/12
LSDChannel(int StartNode, int EndNode, float downslope_chi,
float m_over_n, float A_0, LSDFlowInfo& FlowInfo,
LSDRaster& Elevation_Raster, LSDRaster& DA)
{ create_LSDC(StartNode, EndNode, downslope_chi,
m_over_n, A_0, FlowInfo, Elevation_Raster, DA); }
/// @brief This calculates all the channel areas, elevations and chi parameters based on for a given LSDChannelIndex.
/// @param downslope_chi Downslope Chi value.
/// @param m_over_n m over n ratio.
/// @param A_0 A_0 value.
/// @param InChann LSDIndexChannel object.
/// @param FlowInfo LSDFlowInfo object.
/// @param Elevation_Raster Elevation LSDRaster object.
/// @author SMM
/// @date 01/01/12
LSDChannel(float downslope_chi, float m_over_n, float A_0,
LSDIndexChannel& InChann, LSDFlowInfo& FlowInfo,
LSDRaster& Elevation_Raster)
{ create_LSDC(downslope_chi, m_over_n, A_0,
InChann, FlowInfo, Elevation_Raster); }
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//=-=-=-=-=-=-=INHERITED=-=-=-=-=-
// the following are incherited from LSDIndexChannel
// // get functions
// // these get data elements
// int get_StartJunction() const { return StartJunction; }
// int get_EndJunction() const { return EndJunction; }
// int get_StartNode() const { return StartNode; }
// int get_EndNode() const { return EndNode; }
//
// int get_NRows() const { return NRows; }
// int get_NCols() const { return NCols; }
// float get_XMinimum() const { return XMinimum; }
// float get_YMinimum() const { return YMinimum; }
// float get_DataResolution() const { return DataResolution; }
// int get_NoDataValue() const { return NoDataValue; }
//
// vector<int> get_RowSequence() const { return RowSequence; }
// vector<int> get_ColSequence() const { return ColSequence; }
// vector<int> get_NodeSequence() const { return NodeSequence; }
//
// int get_n_nodes_in_channel() const {return int(NodeSequence.size()); }
//
// int get_node_in_channel(int n_node);
// void get_node_row_col_in_channel(int n_node, int& node, int& row, int& col);
//
// // this prints the channel to an LSDIndexRaster in order to see where the channel is
// LSDIndexRaster print_index_channel_to_index_raster();
//=-=-=-=-=-=-=INHERITED=-=-=-=-=-
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// access the data
// these are primarily used for fitting of the profiles
/// @brief This function prints the channel to an LSDIndexRaster.
/// @return Index raster of channel nodes
/// @author FJC
/// @date 21/08/15
LSDIndexRaster print_channel_to_IndexRaster(LSDFlowInfo& FlowInfo);
/// @return Vector of chi values.
vector<float> get_Chi() { return Chi; }
/// @return Vector of elevation values.
vector<float> get_Elevation() { return Elevation; }
/// @brief This function uses a flow info object to calculate the chi values in the channel.
/// @param downslope_chi Downslope Chi value.
/// @param m_over_n m over n ratio.
/// @param A_0 A_0 value.
/// @param FlowInfo LSDFlowInfo object.
/// @author SMM
/// @date 01/01/12
void calculate_chi(float downslope_chi, float m_over_n, float A_0, LSDFlowInfo& FlowInfo );
/// @brief This function uses a flow info as well as a flow accumulation object
/// to calculate the chi values in the channel.
/// @param downslope_chi Downslope Chi value.
/// @param m_over_n m over n ratio.
/// @param A_0 A_0 value.
/// @param FlowAccum a raster of flow acucmulation. Usually this will be a drainage
/// area but in some cases it will be discharge so orographic effects can be
/// determined
/// @param FlowInfo LSDFlowInfo object.
/// @author SMM
/// @date 24/09/14
void calculate_chi(float downslope_chi, float m_over_n, float A_0,
LSDRaster& FlowAccum, LSDFlowInfo& FlowInfo );
#
/// @brief Get chi value at channel node.
/// @param ch_node Integer node index.
/// @return chi value at channel node.
/// @author SMM
/// @date 01/01/12
float retrieve_chi_at_channel_node(int ch_node) { return Chi[ch_node]; }
/// @brief Get node chi value, elevation and drainage area.
/// @param ch_node Integer node index.
/// @param elev Elevation data.
/// @param chi Chi Value
/// @param drainarea Drainage area.
/// @author SMM
/// @date 01/01/12
void retrieve_node_information(int ch_node, float& elev, float& chi, float& drainarea)
{ elev = Elevation[ch_node]; chi = Chi[ch_node]; drainarea = DrainageArea[ch_node]; }
/// @brief This function looks for the most likeley segments.
/// @param minimum_segment_length
/// @param sigma Sigma value.
/// @param target_nodes
/// @param b_vec Vector of b values.
/// @param m_vec Vector of m values.
/// @param r2_vec Vector of r-squared values.
/// @param DW_vec Vector of Durbin-Watson values.
/// @param thinned_chi
/// @param thinned_elev
/// @param fitted_elev
/// @param node_ref_thinned
/// @param these_segment_lengths
/// @param this_MLE
/// @param this_n_segments
/// @param n_data_nodes
/// @param this_AIC
/// @param this_AICc
/// @author SMM
/// @date 01/01/13
void find_most_likeley_segments(int minimum_segment_length, float sigma, int target_nodes,
vector<float>& b_vec, vector<float>& m_vec,
vector<float>& r2_vec,vector<float>& DW_vec,
vector<float>& thinned_chi, vector<float>& thinned_elev,
vector<float>& fitted_elev, vector<int>& node_ref_thinned,
vector<int>& these_segment_lengths,
float& this_MLE, int& this_n_segments, int& n_data_nodes,
float& this_AIC, float& this_AICc );
/// @brief This function looks for the best fit of a channel for a range of m_over_n values where the channel has segments.
/// @param n_movern
/// @param d_movern
/// @param start_movern
/// @param downslope_chi Downslope Chi value.
/// @param A_0 A_0 value.
/// @param FlowInfo LSDFlowInfo object.
/// @param minimum_segment_length
/// @param sigma Sigma value.
/// @param target_nodes
/// @author SMM
/// @date 01/01/13
void find_best_fit_m_over_n_with_segments(int n_movern, float d_movern,float start_movern,
float downslope_chi, float A_0, LSDFlowInfo& FlowInfo,
int minimum_segment_length, float sigma, float target_nodes );
/// @brief This function loops through m_over_n looking for best fit segments.
void find_best_fit_m_over_n_with_segments();
/// @brief This functions calculates channel heads based on chi segment fitting
/// @param min_seg_length_for_channel_heads
/// @param A_0
/// @param m_over_n
/// @param FlowInfo
/// @author FC
/// @date 25/09/13
int calculate_channel_heads(int min_seg_length_for_channel_heads, float A_0,
float m_over_n, LSDFlowInfo& FlowInfo);
/// @brief This function writes the channel to a csv file
/// @param filename the filename of the channel (whithout the .csv)
/// @author SMM
/// @date 24/09/14
void write_channel_to_csv(string path, string filename, LSDRaster& flow_dist);
protected:
// This is an inherited class so
// NOTE that there are DATA ELEMENTS INHERITED FROM LSDIndexChannel
/// @brief Elevation vector.
vector<float> Elevation;
/// @brief Chi vector.
vector<float> Chi;
/// @brief Drainage area vector.
vector<float> DrainageArea;
private:
void create_LSDC(LSDIndexChannel& IndexChannel);
void create_LSDC(int StartNode, int EndNode, LSDFlowInfo& FlowInfo);
void create_LSDC(int StartJunction, int StartNode,
int EndJunction, int EndNode, LSDFlowInfo& FlowInfo);
void create_LSDC(int SJN, int EJN, float downslope_chi,
float m_over_n, float A_0, LSDFlowInfo& FlowInfo,
LSDRaster& Elevation_Raster);
void create_LSDC(int SJN, int EJN, float downslope_chi,
float m_over_n, float A_0, LSDFlowInfo& FlowInfo,
LSDRaster& Elevation_Raster, LSDRaster& Drainage_Area_Raster);
void create_LSDC(float downslope_chi, float m_over_n, float A_0,
LSDIndexChannel& InChann, LSDFlowInfo& FlowInfo,
LSDRaster& Elevation_Raster);
};
#endif