-
Notifications
You must be signed in to change notification settings - Fork 2
/
LSDCosmoData.cpp
5883 lines (4965 loc) · 216 KB
/
LSDCosmoData.cpp
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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// LSDCosmoData.cpp
// Land Surface Dynamics CosmoData
//
// An object within the University
// of Edinburgh Land Surface Dynamics group topographic toolbox
// for keeping track of cosmogenic data
//
// 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
//
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include <fstream>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <ctype.h>
#include <sstream>
#include <algorithm>
#include <vector>
#include "LSDStatsTools.hpp"
#include "LSDShapeTools.hpp"
#include "LSDCosmoData.hpp"
#include "LSDRaster.hpp"
#include "LSDFlowInfo.hpp"
#include "LSDJunctionNetwork.hpp"
#include "LSDBasin.hpp"
#include "LSDRasterInfo.hpp"
#include "TNT/tnt.h"
using namespace std;
using namespace TNT;
#ifndef LSDCosmoData_CPP
#define LSDCosmoData_CPP
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// The default create function. Doesn't do anything
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
void LSDCosmoData::create()
{
Muon_scaling = "Braucher";
}
void LSDCosmoData::create(string path_name, string param_name_prefix)
{
// Fix the path if it doesn't have a trailing slash
path_name = FixPath(path_name);
cout << "I am loading an LSDCosmoData object" << endl;
cout << "Your pathname is: " << path_name << endl;
cout << "You parameter name prefix is: " << param_name_prefix << endl;
// remove control characters from these strings
path_name.erase(remove_if(path_name.begin(), path_name.end(), ::iscntrl), path_name.end());
param_name_prefix.erase(remove_if(param_name_prefix.begin(), param_name_prefix.end(), ::iscntrl), param_name_prefix.end());
string combined_filename = path_name+param_name_prefix;
cout << "The combined filename is: " << combined_filename << endl;
// set the names of the data members
path = path_name;
param_name = param_name_prefix;
// set up extensions to the files
string crn_ext = "_CRNData.csv";
string files_ext = "_CRNRasters.csv";
string csv_ext = "csv";
string params_ext = ".CRNParam";
string outfile_ext = ".CRNParamReport";
string soil_ext = "_CRNSoilInfo.csv";
// get the filenames to open
string crn_fname = path_name+param_name_prefix+crn_ext;
string Rasters_fname = path_name+param_name_prefix+files_ext;
string parameters_fname = path_name+param_name_prefix+params_ext;
string soil_fname = path_name+param_name_prefix+soil_ext;
cout << "The files I am checking are: " << endl;
cout << crn_fname << endl;
cout << Rasters_fname << endl;
cout << parameters_fname << endl;
// check the parameter files
check_files(crn_fname,Rasters_fname,parameters_fname,soil_fname);
// Initiate default parameters
initiate_default_parameters();
// load the data.
cout << "Loading CRN data" << endl;
load_cosmogenic_data(crn_fname, csv_ext);
cout << "Number of samples: " << N_samples << endl;
// get the correct number of samples in the results vec
vector<double> for_calculator_empty(N_samples);
// set the map of scaling parameters with an empty map
map< string, map<int,double> > empty_map;
MapOfProdAndScaling = empty_map;
cout << "Loading file structures" << endl;
load_DEM_and_shielding_filenames_csv(Rasters_fname);
cout << "Loading parameters" << endl;
load_parameters(parameters_fname);
// check the input parameters
check_parameter_values();
// check the rasters
cout << "Hold on while I check the rasters. I don't want to eat dirty rasters!" << endl;
check_rasters();
cout << "The rasters seem okay. Mmmm, rasters." << endl;
// see if there is additional soil information
cout << "Checking soil information from the file:" << soil_fname << endl;
load_soil_info(soil_fname);
cout << "I'm all done loading the CRN data!" << endl;
cout << "=================================================" << endl << endl << endl;
// now print all the data into a report
string outfile_name = path_name+param_name_prefix+outfile_ext;
print_all_data_parameters_and_filestructures(outfile_name);
}
//==============================================================================
//==============================================================================
// This initiates default parameters in case they are not in the parameter file
//==============================================================================
void LSDCosmoData::initiate_default_parameters()
{
cout << "I am initiating default parameters, these will be overwittern by the paramfile...";
// flags for writing files
write_TopoShield_raster = true;
write_basin_index_raster = true;
// Set the parameters
// The default slope parameter for filling. Do not change.
min_slope = 0.0001;
//cout << "1" << endl;
// parameters for making stream networks and looking for channels
source_threshold = 12;
search_radius_nodes = 1;
threshold_stream_order = 1;
// the values of theta and phi step are based on testing by S. Grieve
// Note that Codilian recommends 5,5 but 10,15 leads to minimal errors
theta_step = 30;
phi_step = 30;
// some environment variables
prod_uncert_factor = 1; // this is a legacy parameter.
//cout << "Default theta and phi steps: " << theta_step << " " << phi_step << endl;
string test_scaling = "Braucher";
//cout << "Test scaling is: " << test_scaling << endl;
//cout << "default production_uncer_factor: " << prod_uncert_factor << endl;
Muon_scaling = test_scaling; // default muon scaling
//cout << "default muon scaling: " << Muon_scaling << endl;
// the atmospheric data is in the folder with the driver_functions
string path_to_atmospheric_data = "./";
//cout << "default path_to_atmospheric_data: " << path_to_atmospheric_data << endl;
// a boundary condition for the flow info object
vector<string> boundary_conditionst(4);
boundary_conditionst[0] = "n";
boundary_conditionst[1] = "n";
boundary_conditionst[2] = "n";
boundary_conditionst[3] = "n";
boundary_conditions = boundary_conditionst;
cout << "done." << endl;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// The create function that actually loads the file
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
void LSDCosmoData::load_cosmogenic_data(string filename, string filetype)
{
if(filetype != "csv" && filetype != "txt")
{
cout << "LSDCosmoData line 111 You have not selected a valid filetype!" << endl;
cout << "Options are csv and txt" << endl;
cout << "Defaulting to txt" << endl;
filetype = "txt";
}
// make sure the filename works
ifstream ifs(filename.c_str());
if( ifs.fail() )
{
cout << "\nFATAL ERROR: The file" << filename
<< "doesn't exist" << endl;
exit(EXIT_FAILURE);
}
// now populate the standardisation maps
standards_Be10["07KNSTD"] = 1.0;
standards_Be10["KNSTD"] = 0.9042;
standards_Be10["NIST_Certified"] = 1.0425;
standards_Be10["LLNL31000"] = 0.8761;
standards_Be10["LLNL10000"] = 0.9042;
standards_Be10["LLNL3000"] = 0.8644;
standards_Be10["LLNL1000"] = 0.9313;
standards_Be10["LLNL300"] = 0.8562;
standards_Be10["NIST_30000"] = 0.9313;
standards_Be10["NIST_30200"] = 0.9251;
standards_Be10["NIST_30300"] = 0.9221;
standards_Be10["NIST_30600"] = 0.9130;
standards_Be10["NIST_27900"] = 1.0;
standards_Be10["S555"] = 0.9124;
standards_Be10["S2007"] = 0.9124;
standards_Be10["BEST433"] = 0.9124;
standards_Be10["BEST433N"] = 1.0;
standards_Be10["S555N"] = 1.0;
standards_Be10["S2007N"] = 1.0;
standards_Al26["KNSTD"] = 1.0;
standards_Al26["ZAL94"] = 0.9134;
standards_Al26["SMAL11"] = 1.021;
standards_Al26["0"] = 1.0;
standards_Al26["ZAL94N"] = 1.0;
standards_Al26["ASTER"] = 1.021;
standards_Al26["Z92-0222"] = 1.0;
if(filetype == "csv")
{
load_csv_cosmo_data(filename);
}
else
{
load_txt_cosmo_data(filename);
}
// now loop through the data, getting the standardised concentrations
N_samples = int(sample_name.size());
// create the vec vec for holding sample results
vector<double> empty_vec;
vector< vector<double> > result_vecvec;
for(int i = 0; i<N_samples; i++)
{
// populate the results vector
result_vecvec.push_back(empty_vec);
// read the nuclide
if(nuclide[i] == "Be10")
{
// check to see if standard exists
if(standards_Be10.find(standardisation[i]) == standards_Be10.end())
{
cout << "Standardisation not found, assuming 07KNSTD" << endl;
standardisation[i] = "07KNSTD";
}
// adjust the 10Be concentration
Concentration.push_back(Concentration_unstandardised[i]*
standards_Be10[ standardisation[i] ]);
Concentration_uncertainty.push_back(Concentration_uncertainty_unstandardised[i]*
standards_Be10[ standardisation[i] ]);
}
else if (nuclide[i] == "Al26")
{
// check to see if standard exists
if(standards_Al26.find(standardisation[i]) == standards_Al26.end())
{
cout << "Standardisation not found, assuming KNSTD" << endl;
standardisation[i] = "KNSTD";
}
// adjust the 26Al concentration
Concentration.push_back(Concentration_unstandardised[i]*
standards_Al26[ standardisation[i] ]);
Concentration_uncertainty.push_back(Concentration_uncertainty_unstandardised[i]*
standards_Al26[ standardisation[i] ]);
}
else
{
cout << "You haven't selected a valid nuclide, choices are Be10 and Al26" << endl;
cout << "You chose: " << nuclide[i] << ", defaulting to Be10 and 07KNSTD" << endl;
nuclide[i] = "Be10";
Concentration.push_back(Concentration_unstandardised[i]);
Concentration_uncertainty.push_back(Concentration_uncertainty_unstandardised[i]);
}
}
erosion_rate_results = result_vecvec;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//
// This loads a csv file of cosmogenic data
// The first row is a header
// the following rows contain the data.
// The data columns are:
// column[0]: sample_name (NO SPACES OR COMMAS!!)
// column[1]: latitude (decimal degrees)
// column[2]: longitude (decimal degrees)
// column[3]: Nuclide (Be10 or Al26)
// column[4]: Nuclide concentration (atoms per gram)
// column[6]: Nuclide uncertainty (atoms per gram)
// column[7]: standardisation
//
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
void LSDCosmoData::load_csv_cosmo_data(string filename)
{
// make sure the filename works
ifstream ifs(filename.c_str());
if( ifs.fail() )
{
cout << "\nFATAL ERROR: Trying to load csv cosmo data file, but the file" << filename
<< "doesn't exist; LINE 245 LSDCosmoData" << endl;
exit(EXIT_FAILURE);
}
// initiate temporary vectors
vector<string> temp_sample_name;
vector<double> temp_latitude;
vector<double> temp_longitude;
vector<string> temp_nuclide;
vector<double> temp_Concentration_unstandardised;
vector<double> temp_Concentration_uncertainty_unstandardised;
vector<string> temp_standardisation;
// initiate the string to hold the file
string line_from_file;
vector<string> empty_string_vec;
vector<string> this_string_vec;
string temp_string;
// discard the first line
getline(ifs, line_from_file);
// now loop through the rest of the lines, getting the data.
while( getline(ifs, line_from_file))
{
// reset the string vec
this_string_vec = empty_string_vec;
// create a stringstream
stringstream ss(line_from_file);
while( ss.good() )
{
string substr;
getline( ss, substr, ',' );
// remove the spaces
substr.erase(remove_if(substr.begin(), substr.end(), ::isspace), substr.end());
// remove control characters
substr.erase(remove_if(substr.begin(), substr.end(), ::iscntrl), substr.end());
// add the string to the string vec
this_string_vec.push_back( substr );
}
//cout << "Yoyoma! size of the string vec: " << this_string_vec.size() << endl;
if ( int(this_string_vec.size()) < 7)
{
cout << "Hey there, I am trying to load your cosmo data but you seem not to have" << endl;
cout << "enough columns in your file. I am ignoring a line" << endl;
}
else
{
// now convert the data
//cout << "Getting sample name: " << this_string_vec[0] << endl;
// let the user know about offending underscores, and replace them
string s = this_string_vec[0];
string uscore = "_";
size_t found = s.find(uscore);
if (found!=std::string::npos)
{
cout << "I found an underscore in the sample name. Replacing with a dash." <<endl;
replace( s.begin(), s.end(), '_', '-');
cout << "New sample name is: " << s << endl;
}
temp_sample_name.push_back( s );
temp_latitude.push_back( atof( this_string_vec[1].c_str() ) );
temp_longitude.push_back( atof(this_string_vec[2].c_str() ) );
temp_nuclide.push_back( this_string_vec[3] );
temp_Concentration_unstandardised.push_back( atof(this_string_vec[4].c_str() ) );
temp_Concentration_uncertainty_unstandardised.push_back( atof(this_string_vec[5].c_str() ) );
temp_standardisation.push_back( this_string_vec[6] );
}
}
//for(int i = 0; i<temp_sample_name.size(); i++)
//{
// cout << endl << endl << "==============Sample "<< i << "=======" << endl;
// cout << temp_sample_name[i] << endl;
// cout << temp_latitude[i] << endl;
// cout << temp_longitude[i] << endl;
// cout << temp_nuclide[i] << endl;
// cout << temp_Concentration_unstandardised[i] << endl;
// cout << temp_Concentration_uncertainty_unstandardised[i] << endl;
// cout << temp_standardisation[i] << endl;
//}
// now update the data members
sample_name = temp_sample_name;
latitude = temp_latitude;
longitude = temp_longitude;
nuclide = temp_nuclide;
Concentration_unstandardised = temp_Concentration_unstandardised;
Concentration_uncertainty_unstandardised =
temp_Concentration_uncertainty_unstandardised;
standardisation = temp_standardisation;
//cout << "Done!" << endl;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// This loads information from a soil file
// The file contains several columns:
// sampleID,sample_top_depth,sample_bottom_depth,density
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
void LSDCosmoData::load_soil_info(string filename)
{
// initiate temporary vectors
vector<string> temp_sample_name;
vector<double> temp_top_depth;
vector<double> temp_sample_thickness;
vector<double> temp_density;
vector<int> temp_has_soil_data_index(N_samples,-1);
vector<int> valid_soil_samples;
vector<double> valid_top_eff_depth;
vector<double> valid_sample_eff_thickness;
double this_top_eff_depth;
double this_eff_thick;
// initiate the string to hold the file
string line_from_file;
vector<string> empty_string_vec;
vector<string> this_string_vec;
string temp_string;
// make sure the filename works
ifstream ifs(filename.c_str());
if( ifs.fail() )
{
cout << "\nThere isn't any soil information. If you think there should be, check your filename." << endl;
cout << "You looked for: " << filename << endl;
}
else
{
// discard the first line
getline(ifs, line_from_file);
// now loop through the rest of the lines, getting the data.
while( getline(ifs, line_from_file))
{
// reset the string vec
this_string_vec = empty_string_vec;
// create a stringstream
stringstream ss(line_from_file);
while( ss.good() )
{
string substr;
getline( ss, substr, ',' );
// remove the spaces
substr.erase(remove_if(substr.begin(), substr.end(), ::isspace), substr.end());
// remove control characters
substr.erase(remove_if(substr.begin(), substr.end(), ::iscntrl), substr.end());
// add the string to the string vec
this_string_vec.push_back( substr );
}
//cout << "Yoyoma! size of the string vec: " << this_string_vec.size() << endl;
if ( int(this_string_vec.size()) < 4)
{
cout << "Hey there, I am trying to load your soil data but you seem not to have" << endl;
cout << "enough columns in your file. I am ignoring a line" << endl;
}
else
{
// now convert the data
//cout << "Getting sample name: " << this_string_vec[0] << endl;
// let the user know about offending underscores, and replace them
string s = this_string_vec[0];
string uscore = "_";
size_t found = s.find(uscore);
if (found!=std::string::npos)
{
cout << "I found an underscore in the sample name. Replacing with a dash." <<endl;
replace( s.begin(), s.end(), '_', '-');
cout << "New sample name is: " << s << endl;
}
temp_sample_name.push_back( s );
temp_top_depth.push_back( atof( this_string_vec[1].c_str() ) );
temp_sample_thickness.push_back( atof(this_string_vec[2].c_str() ) );
temp_density.push_back( atof( this_string_vec[3].c_str() ) );
}
}
int n_soil_samples = int(temp_sample_name.size());
// now you need to check if the soil samples match up with and recorded samples
int soil_sample_counter = 0;
for (int i = 0; i< n_soil_samples; i++)
{
//cout << "I have a soil sample named " << temp_sample_name[i]
// << " and I'm trying to find it in the sample list" << endl;
for (int samp = 0; samp < N_samples; samp++)
{
if(sample_name[samp] == temp_sample_name[i])
{
cout << "You found a valid sample: " << sample_name[samp] << endl;
valid_soil_samples.push_back(samp);
// calculate the effective depths and thicknesses
// effective depths are in g/cm^2
// these assume that the density is in kg/m^3 and the
// thicknesses are in cm
this_top_eff_depth = temp_density[i]*temp_top_depth[i]*0.001;
valid_top_eff_depth.push_back( this_top_eff_depth );
this_eff_thick = temp_density[i]*temp_sample_thickness[i]*0.001;
valid_sample_eff_thickness.push_back(this_eff_thick);
cout << "This effective depth is: " << this_top_eff_depth << endl;
cout << "The eff thickness is: " << this_eff_thick << endl;
// have and index that points from the CRN sample to the vectors
// of soil data
temp_has_soil_data_index[samp] = soil_sample_counter;
soil_sample_counter++;
}
else
{
//cout << "No, this sample is called: " << sample_name[samp] << endl;
}
}
}
// now update the data members
soil_sample_index = valid_soil_samples;
soil_top_effective_depth = valid_top_eff_depth;
soil_effective_thickness = valid_sample_eff_thickness;
}
has_soil_data_index = temp_has_soil_data_index;
if (soil_sample_index.size() != 0)
{
cout << "The number of soil samples are: " << soil_sample_index.size() << " "
<< soil_top_effective_depth.size() << " " << soil_effective_thickness.size() << endl;
}
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// This function loads parameters
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
void LSDCosmoData::load_parameters(string filename)
{
ifstream infile;
infile.open(filename.c_str());
string parameter, value, lower;
if( infile.fail() )
{
cout << "Parameter file: " << filename << " does not exist." << endl;
cout << "Using default parameters." << endl;
}
// now ingest parameters
while (infile.good())
{
parse_line(infile, parameter, value);
lower = parameter;
if (parameter == "NULL")
continue;
for (unsigned int i=0; i<parameter.length(); ++i)
{
lower[i] = tolower(parameter[i]);
}
cout << "parameter is: " << lower << " and value is: " << value << endl;
// get rid of control characters
value = RemoveControlCharactersFromEndOfString(value);
// now set the parameters
if (lower == "min_slope")
{
min_slope = atof(value.c_str());
}
else if (lower == "source_threshold")
{
source_threshold = atoi(value.c_str());
}
else if (lower == "search_radius_nodes")
{
search_radius_nodes = atoi(value.c_str());
}
else if (lower == "threshold_stream_order")
{
threshold_stream_order = atoi(value.c_str());
}
else if (lower == "theta_step")
{
theta_step = atoi(value.c_str());
}
else if (lower == "phi_step")
{
phi_step = atoi(value.c_str());
}
else if (lower == "path_to_atmospheric_data")
{
path_to_atmospheric_data = value;
}
else if (lower == "muon_scaling")
{
if(value.find("braucher") == 0 || value.find("Braucher") == 0)
{
Muon_scaling = "Braucher";
cout << "You have selected Braucher scaling" << endl;
}
else if(value.find("granger") == 0 || value.find("Granger") == 0)
{
Muon_scaling = "Granger";
cout << "You have selected Granger scaling" << endl;
}
else if(value.find("Schaller") == 0 || value.find("schaller") == 0)
{
Muon_scaling = "Schaller";
cout << "You have selected Schaller scaling" << endl;
}
else if(value.find("newCRONUS") == 0 || value.find("newCRONUS") == 0)
{
Muon_scaling = "newCRONUS";
cout << "You have selected the new CRONUS scaling" << endl;
}
else
{
Muon_scaling = "Braucher";
cout << "You have not selected a valid scaling, defaulting to Braucher" << endl;
}
}
else if (lower == "write_toposhield_raster")
{
if(value.find("true") == 0 || value.find("True") == 0)
{
write_TopoShield_raster = true;
}
else if (value.find("false") == 0 || value.find("False") == 0)
{
write_TopoShield_raster = false;
}
else
{
write_TopoShield_raster = true;
cout << "You have not selected a valid toposhield write. Defaulting to true." << endl;
}
}
else if (lower == "write_basin_index_raster")
{
if(value.find("true") == 0 || value.find("True") == 0)
{
write_basin_index_raster = true;
}
else if (value.find("false") == 0 || value.find("False") == 0)
{
write_basin_index_raster = false;
}
else
{
write_basin_index_raster = true;
cout << "You have not selected a valid toposhield write. Defaulting to true." << endl;
}
}
else if (lower == "write_full_scaling_rasters")
{
if(value.find("true") == 0 || value.find("True") == 0)
{
write_full_scaling_rasters = true;
}
else if (value.find("false") == 0 || value.find("False") == 0)
{
write_full_scaling_rasters = false;
}
else
{
write_full_scaling_rasters = true;
cout << "You have not selected a valid toposhield write. Defaulting to true." << endl;
}
}
else
{
cout << "Line " << __LINE__ << ": No parameter '"
<< parameter << "' expected.\n\t> Check spelling." << endl;
}
}
infile.close();
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// This function loads the filenames
// for the DEMs or single value parameters.
// It reads the DEM, either the snow shield raster or a single value
// the self shield raster name or a single value, and the topo shield raster
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
void LSDCosmoData::load_DEM_and_shielding_filenames_csv(string filename)
{
//cout << "Getting filenames" << endl;
// this vecvec holds data for determining the dem, the snow shielding
// the self shielding and the topographic sheilding
vector< vector<string> > temp_DEM_names_vecvec;
// a string for null values
string null_str = "NULL";
// this vecvec holds information about snow, self and toposhielding.
vector< vector<double> > temp_snow_self_topo_shielding_params;
// a vector of strings for holding the DEM names.
// Elements without a DEM get a null value
vector<string> null_string_vec(4,null_str);
vector<string> this_snow_self_shield_names;
// a vector for holding parameter values.
vector<double> empty_snow_self(2,0);
vector<double> this_snow_self;
// make sure the filename works
ifstream ifs(filename.c_str());
if( ifs.fail() )
{
cout << "\nFATAL ERROR: Trying to load csv filenames file, but the file" << filename
<< "doesn't exist; LINE 348 LSDCosmoData" << endl;
exit(EXIT_FAILURE);
}
// initiate the string to hold the file
string line_from_file;
vector<string> empty_string_vec;
vector<string> this_string_vec;
string temp_string;
// now loop through the rest of the lines, getting the data.
while( getline(ifs, line_from_file))
{
// reset the string vec
this_string_vec = empty_string_vec;
// create a stringstream
stringstream ss(line_from_file);
while( ss.good() )
{
string substr;
getline( ss, substr, ',' );
// remove the spaces
substr.erase(remove_if(substr.begin(), substr.end(), ::isspace), substr.end());
// remove control characters
substr.erase(remove_if(substr.begin(), substr.end(), ::iscntrl), substr.end());
// add the string to the string vec
this_string_vec.push_back( substr );
}
// reset the vectors for this line
this_snow_self_shield_names = null_string_vec;
this_snow_self = empty_snow_self;
// now we need to see how many data elements we have
int n_strings_in_line = int(this_string_vec.size());
// the can hold 1, 2, 3 or 4 elements.
// If it holds 1, it only has the name of the DEM
// If it has 2, it has name of DEM and snow shielding
// If it has 3, it has name of DEM and self shielding
// If it has 4, the last element must be the name of the toposhield raster
// which has been precalculated
if(n_strings_in_line == 1)
{
this_snow_self_shield_names[0] = this_string_vec[0];
}
else if(n_strings_in_line == 2)
{
this_snow_self_shield_names[0] = this_string_vec[0];
// test if the second element is a number
string second = this_string_vec[1];
if(isdigit(second[0]))
{
this_snow_self[0] = atof(this_string_vec[1].c_str());
}
else
{
this_snow_self_shield_names[1] = this_string_vec[1];
}
}
else if(n_strings_in_line == 3)
{
this_snow_self_shield_names[0] = this_string_vec[0];
// test if the second element is a number
string second = this_string_vec[1];
if(isdigit(second[0]))
{
this_snow_self[0] = atof(this_string_vec[1].c_str());
}
else
{
this_snow_self_shield_names[1] = this_string_vec[1];
}
// test if the third element is a number
string third = this_string_vec[2];
if(isdigit(third[0]))
{
this_snow_self[1] = atof(this_string_vec[2].c_str());
}
else
{
this_snow_self_shield_names[2] = this_string_vec[2];
}
}
else if(n_strings_in_line == 4)
{
this_snow_self_shield_names[0] = this_string_vec[0];
// test if the second element is a number
string second = this_string_vec[1];
if(isdigit(second[0]))
{
this_snow_self[0] = atof(this_string_vec[1].c_str());
}
else
{
this_snow_self_shield_names[1] = this_string_vec[1];
}
// test if the third element is a number
string third = this_string_vec[2];
if(isdigit(third[0]))
{
this_snow_self[1] = atof(this_string_vec[2].c_str());
}
else
{
this_snow_self_shield_names[2] = this_string_vec[2];
}
this_snow_self_shield_names[3] = this_string_vec[3];
}
else
{
cout << "LSDCosmoData line 383, your cosmo data file names has the" << endl;
cout << "wrong number of elements on this line. " << endl;
cout << "I am only going to keep the DEM name" << endl;
this_snow_self_shield_names[0] = this_string_vec[0];
}
// push the parameters back into the vecvecs
temp_DEM_names_vecvec.push_back(this_snow_self_shield_names);
temp_snow_self_topo_shielding_params.push_back(this_snow_self);
}
// just check if there are no empty entries (thanks to hidden newline characters)
bool back_is_not_okay = 1;
//cout << "HEY FAT ALBERT" << endl;
while(back_is_not_okay)
{
int NDEMS = int(temp_DEM_names_vecvec.size());
string last_DEM_name = temp_DEM_names_vecvec[NDEMS-1][0];
cout << "Last_DEM_name:" << last_DEM_name << endl;
if(last_DEM_name == "")
{
cout << "Oh, BUGGER, who put a bunch of empty lines at the back of this file!" << endl;
cout << "Microsoft is probably to blame if you opened in excel." << endl;
cout << "I'm getting rid of this one." <<endl;
temp_DEM_names_vecvec.pop_back();
}
else
{
back_is_not_okay = 0;
}
}
DEM_names_vecvec = temp_DEM_names_vecvec;
snow_self_topo_shielding_params = temp_snow_self_topo_shielding_params;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//
// This loads a text file of cosmogenic data
// The first row is a header
// the following rows contain the data.
// The data columns are:
// column[0]: sample_name (NO SPACES OR COMMAS!!)
// column[1]: latitude (decimal degrees)
// column[2]: longitude (decimal degrees)
// column[3]: Nuclide (Be10 or Al26)
// column[4]: Nuclide concentration (atoms per gram)
// column[6]: Nuclide uncertainty (atoms per gram)
// column[7]: standardisation
//
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
void LSDCosmoData::load_txt_cosmo_data(string filename)
{
cout << "Opening text file: " << filename << endl;
// make sure the filename works
ifstream ifs(filename.c_str());
if( ifs.fail() )
{
cout << "\nFATAL ERROR: The file" << filename