From 7b9188ac9f40d8ccb2bf24f14cab2cd0a828f363 Mon Sep 17 00:00:00 2001 From: Aaron Orenstein Date: Wed, 2 Oct 2019 15:40:52 -0600 Subject: [PATCH 01/13] Noise level is now determined in Lidar Driver, not in guess_peaks (#332) --- src/GaussianFitter.cpp | 25 +------------------------ src/LidarDriver.cpp | 1 + 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/src/GaussianFitter.cpp b/src/GaussianFitter.cpp index 565b575..e657a8c 100644 --- a/src/GaussianFitter.cpp +++ b/src/GaussianFitter.cpp @@ -628,30 +628,7 @@ int GaussianFitter::guess_peaks(std::vector* results, //We need to start this function with a clear vector. //We can't call destructors because we don't know if the pointers //are pointing to space used in LidarVolume - results->clear(); - - //UPDATE: We are only using a noise level of 6 because we want all peaks - //with an amplitude >= 10 - //Level up to and including which peaks will be excluded - //For the unaltered wave, noise_level = 16 - //for the second derivative of the wave, noise_level = 3 - // this is creating guesses for a guassian fitter that does not do - // well if we have guesses that have an amplitude more than an order - // of magnitute apart. We are going to set the noise level to be the - // max value/ 10 - max*.05; - max = 0; - for(int i = 0; i<(int)ampData.size(); i++){ - if(ampData[i]>max){ - max = ampData[i]; - } - } - noise_level = ((float)max)*.09; - - spdlog::error("Max = {} Noise = {}", max, ((float)max)*.09); - - if (noise_level < 6){ - noise_level = 6; - } + results->clear(); //Sign of gradient: // = 1 for increasing diff --git a/src/LidarDriver.cpp b/src/LidarDriver.cpp index b01cea4..136a21c 100644 --- a/src/LidarDriver.cpp +++ b/src/LidarDriver.cpp @@ -82,6 +82,7 @@ void LidarDriver::fit_data(FlightLineData &raw_data, LidarVolume &fitted_data, PulseData pd; std::ostringstream stream; GaussianFitter fitter; + fitter.noise_level = 9; std::vector peaks; int peak_count = 0; From b2db8911f791f0a2eec115b0d1b1bcb7f1f8dc9f Mon Sep 17 00:00:00 2001 From: Aaron Orenstein Date: Wed, 2 Oct 2019 16:24:06 -0600 Subject: [PATCH 02/13] Set noise level in LidarDriver for the pls to csv program --- src/LidarDriver.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/LidarDriver.cpp b/src/LidarDriver.cpp index 136a21c..3f63666 100644 --- a/src/LidarDriver.cpp +++ b/src/LidarDriver.cpp @@ -198,6 +198,7 @@ void LidarDriver::fit_data_csv(FlightLineData &raw_data, PulseData pd; std::ostringstream stream; GaussianFitter fitter; + fitter.noise_level = 9; std::vector peaks; bool log_diagnostics = cmdLine.log_diagnostics; From 00216b47ba4f20c11524ba2a85143f1d21b55481 Mon Sep 17 00:00:00 2001 From: Jared White Date: Wed, 9 Oct 2019 08:50:02 -0600 Subject: [PATCH 03/13] Added noise_level as command argument (-n ) --- src/CmdLine.cpp | 7 ++++++- src/CmdLine.hpp | 3 +++ src/LidarDriver.cpp | 4 ++-- src/csv_CmdLine.cpp | 7 ++++++- src/csv_CmdLine.hpp | 3 +++ 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/CmdLine.cpp b/src/CmdLine.cpp index 1981aaf..45e94ee 100644 --- a/src/CmdLine.cpp +++ b/src/CmdLine.cpp @@ -57,6 +57,8 @@ void CmdLine::setUsageMessage() << " :Disables gaussian fitter, using first diff method instead" << std::endl; buffer << " -h" << " :Prints this help message" << std::endl; + buffer << " -n " + << " :Sets the noise level\n"; buffer << std::endl; buffer << "Product Type Options:" << std::endl; buffer << " -e " @@ -191,6 +193,7 @@ bool CmdLine::parse_args(int argc,char *argv[]){ { {"file", required_argument, NULL, 'f'}, {"help", no_argument, NULL, 'h'}, + {"noise_level", required_argument, NULL, 'n'}, {"firstdiff", no_argument, NULL, 'd'}, {"verbosity", required_argument, NULL, 'v'}, {"elevation", required_argument,NULL,'e'}, @@ -210,7 +213,7 @@ bool CmdLine::parse_args(int argc,char *argv[]){ * ":hf:s:" indicate that option 'h' is without arguments while * option 'f' and 's' require arguments */ - while((optionChar = getopt_long (argc, argv, "-:hdf:e:a:w:r:b:l:v:", + while((optionChar = getopt_long (argc, argv, "-:hdf:n:e:a:w:r:b:l:v:", long_options, &option_index))!= -1){ if (optionChar == 'f') { //Set the filename to parse fArg = optarg; @@ -219,6 +222,8 @@ bool CmdLine::parse_args(int argc,char *argv[]){ printUsageMessage = true; } else if (optionChar == 'd') { //Sets analysis method useGaussianFitting = false; + }else if (optionChar == 'n'){ + noise_level = std::stoi(optarg); } else if (optionChar == 'v') { set_verbosity(optarg); if (verb == (verbosity) NULL) { diff --git a/src/CmdLine.hpp b/src/CmdLine.hpp index e4e7023..79d7269 100644 --- a/src/CmdLine.hpp +++ b/src/CmdLine.hpp @@ -42,6 +42,9 @@ class CmdLine{ // use find_peaks parameter // True = gaussian fitting, False = first differencing bool useGaussianFitting; + + //TODO: What should be the default noise level? + int noise_level = 9; // Whether or not backscatter coefficient has been requested bool calcBackscatter; diff --git a/src/LidarDriver.cpp b/src/LidarDriver.cpp index 3f63666..5c56f76 100644 --- a/src/LidarDriver.cpp +++ b/src/LidarDriver.cpp @@ -82,7 +82,7 @@ void LidarDriver::fit_data(FlightLineData &raw_data, LidarVolume &fitted_data, PulseData pd; std::ostringstream stream; GaussianFitter fitter; - fitter.noise_level = 9; + fitter.noise_level = cmdLine.noise_level; std::vector peaks; int peak_count = 0; @@ -198,7 +198,7 @@ void LidarDriver::fit_data_csv(FlightLineData &raw_data, PulseData pd; std::ostringstream stream; GaussianFitter fitter; - fitter.noise_level = 9; + fitter.noise_level = cmdLine.noise_level; std::vector peaks; bool log_diagnostics = cmdLine.log_diagnostics; diff --git a/src/csv_CmdLine.cpp b/src/csv_CmdLine.cpp index 505cab0..6174295 100644 --- a/src/csv_CmdLine.cpp +++ b/src/csv_CmdLine.cpp @@ -88,6 +88,8 @@ void csv_CmdLine::setUsageMessage() << " :Disables gaussian fitter, using first diff method instead" << std::endl; buffer << " -h" << " :Prints this help message" << std::endl; + buffer << " -n " + << " :Sets the noise level\n"; buffer << " -p " << " :Writes peak data to CSV" << std::endl; buffer << " -l " @@ -179,6 +181,7 @@ bool csv_CmdLine::parse_args(int argc,char *argv[]){ { {"file", required_argument, NULL, 'f'}, {"help", no_argument, NULL, 'h'}, + {"noise_level", required_argument, NULL, 'n'}, {"firstdiff", no_argument, NULL, 'd'}, {"peaks", required_argument,NULL,'p'}, {"log-diag", no_argument, NULL, 'l'}, @@ -191,7 +194,7 @@ bool csv_CmdLine::parse_args(int argc,char *argv[]){ * ":hf:s:" indicate that option 'h' is without arguments while * option 'f' and 's' require arguments */ - while((optionChar = getopt_long (argc, argv, "-:hdf:p:l", + while((optionChar = getopt_long (argc, argv, "-:hdf:n:p:l", long_options, &option_index))!= -1){ if (optionChar == 'f') { //Set the filename to parse fArg = optarg; @@ -200,6 +203,8 @@ bool csv_CmdLine::parse_args(int argc,char *argv[]){ printUsageMessage = true; } else if (optionChar == 'd') { //Sets analysis method useGaussianFitting = false; + }else if (optionChar == 'n'){ + noise_level = std::stoi(optarg); } else if (optionChar == 'l') {//Sets log_diagnostics log_diagnostics = true; } else if (optionChar == 'p') { diff --git a/src/csv_CmdLine.hpp b/src/csv_CmdLine.hpp index 7a0d06e..c04baa8 100644 --- a/src/csv_CmdLine.hpp +++ b/src/csv_CmdLine.hpp @@ -40,6 +40,9 @@ class csv_CmdLine{ // True = gaussian fitting, False = first differencing bool useGaussianFitting; + //TODO What should be the default noise level? + int noise_level = 9; + // True stifles all output statements bool quiet; From 8b70242722ca5f80caad07392b83f8fc3487f619 Mon Sep 17 00:00:00 2001 From: Spencer Fleming Date: Wed, 9 Oct 2019 15:45:39 -0600 Subject: [PATCH 04/13] Actually changed max iter magic num to #define --- src/GaussianFitter_unittests.cpp | 34 +++++++++++++++++--------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/GaussianFitter_unittests.cpp b/src/GaussianFitter_unittests.cpp index 1962044..abc0c81 100644 --- a/src/GaussianFitter_unittests.cpp +++ b/src/GaussianFitter_unittests.cpp @@ -10,6 +10,8 @@ #include "Peak.hpp" #include +#define MAX_ITER 200 + class GaussianFitterTest: public testing::Test{ public: std::vector pulses; @@ -74,7 +76,7 @@ TEST_F(GaussianFitterTest, NayaniClipped1){ EXPECT_EQ(34 ,peaks.at(1)->amp); fitter.smoothing_expt(&Data); - int count = fitter.find_peaks(&peaks,ampData,idxData, 200); + int count = fitter.find_peaks(&peaks,ampData,idxData, MAX_ITER); EXPECT_EQ(2,count); } @@ -110,7 +112,7 @@ TEST_F(GaussianFitterTest, NayaniClipped2){ fitter.smoothing_expt(&Data); - int count = fitter.find_peaks(&peaks,ampData,idxData, 200); + int count = fitter.find_peaks(&peaks,ampData,idxData, MAX_ITER); EXPECT_EQ(1,peaks.size()); EXPECT_EQ(235,peaks.at(0)->amp); @@ -153,7 +155,7 @@ TEST_F(GaussianFitterTest, gaussianFitter){ EXPECT_EQ(240,peaks.at(0)->amp); fitter.smoothing_expt(&Data); - int count = fitter.find_peaks(&peaks,ampData,idxData, 200); + int count = fitter.find_peaks(&peaks,ampData,idxData, MAX_ITER); EXPECT_EQ(1,count); @@ -190,7 +192,7 @@ TEST_F(GaussianFitterTest, NayaniClipped3){ //the noise level for this waveform is 21.4 fitter.smoothing_expt(&Data); - int count = fitter.find_peaks(&peaks,ampData,idxData, 200); + int count = fitter.find_peaks(&peaks,ampData,idxData, MAX_ITER); EXPECT_EQ(1,count); //std::cerr << "--After guess_peaks and find_peaks--\n " << std::endl; @@ -230,7 +232,7 @@ TEST_F(GaussianFitterTest, NayaniClipped4){ EXPECT_EQ(240,peaks.at(0)->amp); fitter.smoothing_expt(&Data); - int count = fitter.find_peaks(&peaks,ampData,idxData, 200); + int count = fitter.find_peaks(&peaks,ampData,idxData, MAX_ITER); EXPECT_EQ(1,count); @@ -271,7 +273,7 @@ TEST_F(GaussianFitterTest, NayaniClipped5){ EXPECT_EQ(146,peaks.at(1)->amp); fitter.smoothing_expt(&Data); - int count = fitter.find_peaks(&peaks,ampData,idxData, 200); + int count = fitter.find_peaks(&peaks,ampData,idxData, MAX_ITER); EXPECT_EQ(2,count); @@ -314,7 +316,7 @@ TEST_F(GaussianFitterTest, NayaniClipped6){ fitter.smoothing_expt(&Data); - int count = fitter.find_peaks(&peaks,ampData,idxData, 200); + int count = fitter.find_peaks(&peaks,ampData,idxData, MAX_ITER); EXPECT_EQ(2,count); @@ -352,7 +354,7 @@ TEST_F(GaussianFitterTest, NayaniClipped7){ fitter.smoothing_expt(&Data); - int count = fitter.find_peaks(&peaks,ampData,idxData, 200); + int count = fitter.find_peaks(&peaks,ampData,idxData, MAX_ITER); EXPECT_EQ(2,count); @@ -392,7 +394,7 @@ TEST_F(GaussianFitterTest, NayaniClipped8){ EXPECT_EQ(21,peaks.at(2)->amp); fitter.smoothing_expt(&Data); - int count = fitter.find_peaks(&peaks,ampData,idxData, 200); + int count = fitter.find_peaks(&peaks,ampData,idxData, MAX_ITER); EXPECT_EQ(3,count); @@ -436,7 +438,7 @@ TEST_F(GaussianFitterTest, max_iter_1){ fitter.smoothing_expt(&Data); - int count = fitter.find_peaks(&peaks,ampData,idxData, 200); + int count = fitter.find_peaks(&peaks,ampData,idxData, MAX_ITER); EXPECT_EQ(2,count); @@ -474,7 +476,7 @@ TEST_F(GaussianFitterTest, max_iter_2){ fitter.smoothing_expt(&Data); - int count = fitter.find_peaks(&peaks,ampData,idxData, 200); + int count = fitter.find_peaks(&peaks,ampData,idxData, MAX_ITER); EXPECT_EQ(2, count); } @@ -510,7 +512,7 @@ TEST_F(GaussianFitterTest, max_iter_3){ EXPECT_EQ(33,peaks.at(1)->amp); fitter.smoothing_expt(&Data); - int count = fitter.find_peaks(&peaks,ampData,idxData, 200); + int count = fitter.find_peaks(&peaks,ampData,idxData, MAX_ITER); EXPECT_EQ(2,count); @@ -551,7 +553,7 @@ TEST_F(GaussianFitterTest, max_iter_4){ fitter.smoothing_expt(&Data); - int count = fitter.find_peaks(&peaks,ampData,idxData, 200); + int count = fitter.find_peaks(&peaks,ampData,idxData, MAX_ITER); EXPECT_EQ(3,count); } @@ -599,7 +601,7 @@ TEST_F(GaussianFitterTest, max_iter_5){ fitter.smoothing_expt(&Data); - int count = fitter.find_peaks(&peaks,ampData,idxData, 200); + int count = fitter.find_peaks(&peaks,ampData,idxData, MAX_ITER); EXPECT_EQ(7,count); @@ -637,7 +639,7 @@ TEST_F(GaussianFitterTest, trig_loc_1){ EXPECT_EQ(172,peaks.at(1)->amp); fitter.smoothing_expt(&Data); - int count = fitter.find_peaks(&peaks,ampData,idxData, 200); + int count = fitter.find_peaks(&peaks,ampData,idxData, MAX_ITER); EXPECT_EQ(2,count); @@ -676,7 +678,7 @@ TEST_F(GaussianFitterTest, trig_loc_2){ fitter.smoothing_expt(&Data); - int count = fitter.find_peaks(&peaks,ampData,idxData, 200); + int count = fitter.find_peaks(&peaks,ampData,idxData, MAX_ITER); EXPECT_EQ(2,count); From 167b7a9278cc82b55b12637e578c1a73ad442fcc Mon Sep 17 00:00:00 2001 From: Jared White Date: Wed, 9 Oct 2019 18:43:00 -0600 Subject: [PATCH 05/13] Added try/catch for stoi. Set default noise level to 6. Completes #332 --- src/CmdLine.cpp | 12 ++++++++++-- src/CmdLine.hpp | 8 ++++---- src/csv_CmdLine.cpp | 12 ++++++++++-- src/csv_CmdLine.hpp | 4 ++-- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/CmdLine.cpp b/src/CmdLine.cpp index 45e94ee..76d6f10 100644 --- a/src/CmdLine.cpp +++ b/src/CmdLine.cpp @@ -58,7 +58,7 @@ void CmdLine::setUsageMessage() buffer << " -h" << " :Prints this help message" << std::endl; buffer << " -n " - << " :Sets the noise level\n"; + << " :Sets the noise level. Defaults to 6.\n"; buffer << std::endl; buffer << "Product Type Options:" << std::endl; buffer << " -e " @@ -223,7 +223,15 @@ bool CmdLine::parse_args(int argc,char *argv[]){ } else if (optionChar == 'd') { //Sets analysis method useGaussianFitting = false; }else if (optionChar == 'n'){ - noise_level = std::stoi(optarg); + try{ + noise_level = std::stoi(optarg); + }catch(const std::invalid_argument& e){ + msgs.push_back("Cannot convert noise level to int. Error: " + std::string(e.what())); + printUsageMessage = true; + }catch(const std::out_of_range& e){ + msgs.push_back("Cannot fit noise level in type int. Error: " + std::string(e.what())); + printUsageMessage = true; + } } else if (optionChar == 'v') { set_verbosity(optarg); if (verb == (verbosity) NULL) { diff --git a/src/CmdLine.hpp b/src/CmdLine.hpp index 79d7269..178c3d0 100644 --- a/src/CmdLine.hpp +++ b/src/CmdLine.hpp @@ -42,12 +42,12 @@ class CmdLine{ // use find_peaks parameter // True = gaussian fitting, False = first differencing bool useGaussianFitting; - - //TODO: What should be the default noise level? - int noise_level = 9; + + //Default noise level + int noise_level = 6; // Whether or not backscatter coefficient has been requested - bool calcBackscatter; + bool calcBackscatter; //True stifles all output statements bool quiet; diff --git a/src/csv_CmdLine.cpp b/src/csv_CmdLine.cpp index 6174295..e27fd29 100644 --- a/src/csv_CmdLine.cpp +++ b/src/csv_CmdLine.cpp @@ -89,7 +89,7 @@ void csv_CmdLine::setUsageMessage() buffer << " -h" << " :Prints this help message" << std::endl; buffer << " -n " - << " :Sets the noise level\n"; + << " :Sets the noise level. defaults to 6.\n"; buffer << " -p " << " :Writes peak data to CSV" << std::endl; buffer << " -l " @@ -204,7 +204,15 @@ bool csv_CmdLine::parse_args(int argc,char *argv[]){ } else if (optionChar == 'd') { //Sets analysis method useGaussianFitting = false; }else if (optionChar == 'n'){ - noise_level = std::stoi(optarg); + try{ + noise_level = std::stoi(optarg); + }catch(const std::invalid_argument& e){ + msgs.push_back("Cannot convert noise level to int. Error: " + std::string(e.what())); + printUsageMessage = true; + }catch(const std::out_of_range& e){ + msgs.push_back("Cannot fit noise level in type int. Error: " + std::string(e.what())); + printUsageMessage = true; + } } else if (optionChar == 'l') {//Sets log_diagnostics log_diagnostics = true; } else if (optionChar == 'p') { diff --git a/src/csv_CmdLine.hpp b/src/csv_CmdLine.hpp index c04baa8..592cfb6 100644 --- a/src/csv_CmdLine.hpp +++ b/src/csv_CmdLine.hpp @@ -40,8 +40,8 @@ class csv_CmdLine{ // True = gaussian fitting, False = first differencing bool useGaussianFitting; - //TODO What should be the default noise level? - int noise_level = 9; + //Default noise level + int noise_level = 6; // True stifles all output statements bool quiet; From 09230282bfe8dbf769a1d280f35d636ee6d14bb7 Mon Sep 17 00:00:00 2001 From: Aaron Orenstein Date: Sun, 13 Oct 2019 13:54:13 -0600 Subject: [PATCH 06/13] Changed all print statements to output through spdlog at the trace level (#284) --- src/GaussianFitter.cpp | 78 +++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 42 deletions(-) diff --git a/src/GaussianFitter.cpp b/src/GaussianFitter.cpp index e657a8c..27801f9 100644 --- a/src/GaussianFitter.cpp +++ b/src/GaussianFitter.cpp @@ -375,6 +375,8 @@ int GaussianFitter::find_peaks(std::vector* results, std::vector ampData, std::vector idxData, const size_t max_iter) { + spdlog::trace("--NEW WAVEFORM--"); + incr_total(); //Error handling @@ -390,12 +392,15 @@ int GaussianFitter::find_peaks(std::vector* results, //get guessed peaks and figure out how many peaks there are size_t peakCount = guess_peaks(results, ampData, idxData); + spdlog::trace("Peak Count = {}", peakCount); + //No peaks found //Prvents the "Parameter 7 to routine source_gemv_r.h was incorrect" error if(peakCount == 0){ return 0; } + // FOR TESTING PURPOSES // fprintf(stderr, "Peak count is %d\n", peakCount); @@ -446,14 +451,14 @@ int GaussianFitter::find_peaks(std::vector* results, } // PRINT DATA AND MODEL FOR TESTING PURPOSES - spdlog::trace("Gaussian sum based on guesses - before solve system:"); - - for (int i = 0; i < n; ++i){ - double ti = fit_data.t[i]; - // double yi = fit_data.y[i]; - double fi = gaussianSum(x, ti); - printf("%f ", fi); - } + spdlog::trace("Gaussian sum based on guesses - before solve system:"); + std::ostringstream function; + for (int i = 0; i < n; ++i){ + double ti = fit_data.t[i]; + // double yi = fit_data.y[i]; + function << gaussianSum(x, ti) << " "; + } + spdlog::trace("Model Data: {}", function.str()); fdf_params.trs = gsl_multifit_nlinear_trs_dogleg; @@ -461,8 +466,6 @@ int GaussianFitter::find_peaks(std::vector* results, fdf_params.solver = gsl_multifit_nlinear_solver_svd; fdf_params.fdtype = GSL_MULTIFIT_NLINEAR_CTRDIFF; - spdlog::error("peakCount = {}",peakCount); - if(!solve_system(x, &fdf, &fdf_params, max, max_iter)){ incr_pass(); @@ -526,10 +529,6 @@ int GaussianFitter::find_peaks(std::vector* results, peak->position_in_wave = i+1; } - spdlog::error("--------------------"); - spdlog::error("results.size = {}", results->size()); - spdlog::error("is empty = {}", results->empty()); - if (!results->empty()) { Peak* final_peak_ptr = results->back(); final_peak_ptr->is_final_peak = true; //mark the last peak as @@ -537,39 +536,34 @@ int GaussianFitter::find_peaks(std::vector* results, } i++; } - // PRINT DATA AND MODEL FOR TESTING PURPOSES - spdlog::trace("Gaussian sum in solve system and not failed:"); - - for (int i = 0; i < n; ++i){ - double ti = fit_data.t[i]; - // double yi = fit_data.y[i]; - double fi = gaussianSum(x, ti); - printf("%f ", fi); - } + + spdlog::trace("Number of Peaks Found: {}", results->size()); + + // PRINT DATA AND MODEL FOR TESTING PURPOSES + spdlog::trace("Gaussian sum in solve system and not failed:"); + std::ostringstream model; + for (int i = 0; i < n; ++i){ + double ti = fit_data.t[i]; + model << gaussianSum(x, ti) << " "; + } + spdlog::trace("Model Data: {}", model.str()); } else{ - // FOR TESTING PURPOSES - spdlog::trace("In solve system and failed:"); - spdlog::error("Amplitudes: "); - - for(int i=0; i< (int)ampData.size(); i++){ - spdlog::error("{}", ampData[i]); - } - spdlog::error("Indices in time: "); - for(int i=0; i< (int)idxData.size(); i++){ - spdlog::error( "{}", idxData[i]); - } incr_fail(); - // PRINT DATA AND MODEL FOR TESTING PURPOSES - spdlog::trace("Gaussian sum in solve system failed:"); - for (int i = 0; i < n; ++i){ - double ti = fit_data.t[i]; - double yi = fit_data.y[i]; - double fi = gaussianSum(x, ti); - printf("%f %f %f\n", ti, yi, fi); - } + // PRINT DATA AND MODEL FOR TESTING PURPOSES + spdlog::trace("Gaussian sum in solve system failed:"); + std::ostringstream time, data, model; + for (int i = 0; i < n; ++i){ + double ti = fit_data.t[i]; + time << ti << " "; + data << fit_data.y[i] << " "; + model << gaussianSum(x, ti) << " "; + } + spdlog::trace("Time Data: {}",time.str()); + spdlog::trace("Amp Data: {}",data.str()); + spdlog::trace("Model Data: {}",model.str()); } free(fit_data.t); From ab34bc5aaef50ce1d7f9fe0f4cb04b12fe23c67c Mon Sep 17 00:00:00 2001 From: Spencer Fleming Date: Sun, 13 Oct 2019 14:31:11 -0600 Subject: [PATCH 07/13] Gaussian fitter instance var 'guess_lt0_default' to 'guess_lessthan_0_default' for clarity (#299) --- src/GaussianFitter.cpp | 4 ++-- src/GaussianFitter.hpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/GaussianFitter.cpp b/src/GaussianFitter.cpp index 27801f9..15e1949 100644 --- a/src/GaussianFitter.cpp +++ b/src/GaussianFitter.cpp @@ -20,7 +20,7 @@ GaussianFitter::GaussianFitter(){ g_tolerance = G_TOL; f_tolerance = F_TOL; - guess_lt0_default = GUESS_LT0_DEFAULT; + guess_lessthan_0_default = GUESS_LT0_DEFAULT; guess_upper_lim = GUESS_UPPER_LIM; guess_gt_upper_lim_default = GUESS_GT_UPPER_LIM_DEFAULT; @@ -700,7 +700,7 @@ int GaussianFitter::guess_peaks(std::vector* results, } if(guess< 0) { - guess = guess_lt0_default; + guess = guess_lessthan_0_default; } if (log_diagnostics) { diff --git a/src/GaussianFitter.hpp b/src/GaussianFitter.hpp index 960585d..41938c0 100644 --- a/src/GaussianFitter.hpp +++ b/src/GaussianFitter.hpp @@ -63,7 +63,7 @@ class GaussianFitter{ double g_tolerance; double f_tolerance; - int guess_lt0_default; + int guess_lessthan_0_default; int guess_upper_lim; int guess_gt_upper_lim_default; From cf8832ddb5db2a6aa0dd973f2f1ae5eba721a30f Mon Sep 17 00:00:00 2001 From: Spencer Fleming Date: Sun, 13 Oct 2019 14:51:51 -0600 Subject: [PATCH 08/13] Guess upper limit (20) and it's default (10) are now utilizing their respective instance variables correctly. (#299) --- src/GaussianFitter.cpp | 4 ++-- src/GaussianFitter.hpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/GaussianFitter.cpp b/src/GaussianFitter.cpp index 15e1949..1cf3756 100644 --- a/src/GaussianFitter.cpp +++ b/src/GaussianFitter.cpp @@ -22,7 +22,7 @@ GaussianFitter::GaussianFitter(){ guess_lessthan_0_default = GUESS_LT0_DEFAULT; guess_upper_lim = GUESS_UPPER_LIM; - guess_gt_upper_lim_default = GUESS_GT_UPPER_LIM_DEFAULT; + guess_upper_lim_default = GUESS_UPPER_LIM_DEFAULT; amp_upper_bound = AMP_UPPER_BOUND; amp_lower_bound = AMP_LOWER_BOUND; @@ -710,7 +710,7 @@ int GaussianFitter::guess_peaks(std::vector* results, guess); } - if(guess > 20) {guess = 10;} + if(guess > guess_upper_lim) {guess = guess_upper_lim_default;} peaks_found++; //Create a peak diff --git a/src/GaussianFitter.hpp b/src/GaussianFitter.hpp index 41938c0..cc23294 100644 --- a/src/GaussianFitter.hpp +++ b/src/GaussianFitter.hpp @@ -26,7 +26,7 @@ #define GUESS_LT0_DEFAULT 4 #define GUESS_UPPER_LIM 20 -#define GUESS_GT_UPPER_LIM_DEFAULT 10 +#define GUESS_UPPER_LIM_DEFAULT 10 #define AMP_UPPER_BOUND 2 #define AMP_LOWER_BOUND 10 @@ -63,9 +63,9 @@ class GaussianFitter{ double g_tolerance; double f_tolerance; - int guess_lessthan_0_default; - int guess_upper_lim; - int guess_gt_upper_lim_default; + int guess_lessthan_0_default; // If guess less than 0, it is set to this + int guess_upper_lim; // If guess greater than this value... + int guess_upper_lim_default; // It is set to this value int amp_upper_bound; // Val is multiplied by max data point in wave int amp_lower_bound; // Val is unmodified (no multiplication) From cdb352328f11d9833209f42a584157c1a36232e5 Mon Sep 17 00:00:00 2001 From: Aaron Orenstein Date: Wed, 16 Oct 2019 12:20:45 -0600 Subject: [PATCH 09/13] Trace logging level now works when inputting it into command line (#346) --- src/CmdLine.cpp | 16 +++++++++------- src/CmdLine.hpp | 6 +++--- src/pls_to_geotiff.cpp | 37 ++++++++++++++----------------------- 3 files changed, 26 insertions(+), 33 deletions(-) diff --git a/src/CmdLine.cpp b/src/CmdLine.cpp index 76d6f10..3ef98f9 100644 --- a/src/CmdLine.cpp +++ b/src/CmdLine.cpp @@ -135,7 +135,6 @@ CmdLine::CmdLine(){ printUsageMessage = false; useGaussianFitting = true; calcBackscatter = false; - verb = (verbosity) NULL; exeName = ""; setUsageMessage(); } @@ -153,14 +152,17 @@ std::string CmdLine::getInputFileName(bool pls){ /** * Tries to match option given with verbosity flag to a known value, * and if so, sets verbosity instance variable to match it. + * @param new_verb logger level inputted in the command line + * @return true if valid leve, else false */ -void CmdLine::set_verbosity (char* new_verb) { - int i; - for (i = 0; i < num_verbs; i++) { +bool CmdLine::set_verbosity (char* new_verb) { + for (int i = 0; i < num_verbs; i++) { if (!std::strncmp (new_verb, verbs[i].c_str(), 9)) { - verb = (verbosity) i; + verb = new_verb; + return true; } } + return false; } /** @@ -233,8 +235,8 @@ bool CmdLine::parse_args(int argc,char *argv[]){ printUsageMessage = true; } } else if (optionChar == 'v') { - set_verbosity(optarg); - if (verb == (verbosity) NULL) { + if (!set_verbosity(optarg)) { + msgs.push_back("Invalid logging level"); printUsageMessage = true; } } else if (optionChar == 'e' || optionChar == 'a' || optionChar == 'w' diff --git a/src/CmdLine.hpp b/src/CmdLine.hpp index 178c3d0..ca85502 100644 --- a/src/CmdLine.hpp +++ b/src/CmdLine.hpp @@ -15,6 +15,7 @@ #include #include #include +#include class CmdLine{ @@ -31,7 +32,7 @@ class CmdLine{ // else, use smooth second difference bool max_elev_flag; - void set_verbosity(char* new_verb); + bool set_verbosity(char* new_verb); public: //calibration constant (for backscatter option) @@ -53,8 +54,7 @@ class CmdLine{ bool quiet; // For conveying verbosity to main function in a readable way - enum verbosity { trace, debug, info, warn, error, critical }; - verbosity verb; + std::string verb = ""; CmdLine(); diff --git a/src/pls_to_geotiff.cpp b/src/pls_to_geotiff.cpp index 0187d88..d904928 100644 --- a/src/pls_to_geotiff.cpp +++ b/src/pls_to_geotiff.cpp @@ -6,7 +6,7 @@ #include // Activity level must be defined before spdlog is included. -#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE +#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_CRITICAL #include "spdlog/spdlog.h" #include "spdlog/async.h" @@ -31,28 +31,19 @@ int main (int argc, char *argv[]) { return 1; } - // Set verbosity if not null - if (cmdLineArgs.verb != (CmdLine::verbosity) NULL) { - switch (cmdLineArgs.verb) { - case CmdLine::verbosity::trace: - spdlog::set_level(spdlog::level::trace); - break; - case CmdLine::verbosity::debug: - spdlog::set_level(spdlog::level::debug); - break; - case CmdLine::verbosity::info: - spdlog::set_level(spdlog::level::info); - break; - case CmdLine::verbosity::warn: - spdlog::set_level(spdlog::level::warn); - break; - case CmdLine::verbosity::error: - spdlog::set_level(spdlog::level::err); - break; - case CmdLine::verbosity::critical: - spdlog::set_level(spdlog::level::critical); - break; - } + // Set verbosiy + if (cmdLineArgs.verb == "trace") { + spdlog::set_level(spdlog::level::trace); + } else if (cmdLineArgs.verb == "debug") { + spdlog::set_level(spdlog::level::debug); + } else if (cmdLineArgs.verb == "info") { + spdlog::set_level(spdlog::level::info); + } else if (cmdLineArgs.verb == "warn") { + spdlog::set_level(spdlog::level::warn); + } else if (cmdLineArgs.verb == "error") { + spdlog::set_level(spdlog::level::err); + } else if (cmdLineArgs.verb == "critical") { + spdlog::set_level(spdlog::level::critical); } //Collect start time From 0a35bca009f91be67cc583e1b70cb078b5b985b1 Mon Sep 17 00:00:00 2001 From: Jared White Date: Wed, 16 Oct 2019 20:45:15 -0600 Subject: [PATCH 10/13] Changed Integer defines in GaussianFitter.hpp into float defines (added decimal). Small case fix in usage message for csv_CmdLine.cpp --- src/GaussianFitter.hpp | 6 +++--- src/csv_CmdLine.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/GaussianFitter.hpp b/src/GaussianFitter.hpp index cc23294..e2d9c8d 100644 --- a/src/GaussianFitter.hpp +++ b/src/GaussianFitter.hpp @@ -20,9 +20,9 @@ #define MAX_ITER 200 #define TOL_SCALES true -#define X_TOL 100 -#define G_TOL 100 -#define F_TOL 100 +#define X_TOL 100. +#define G_TOL 100. +#define F_TOL 100. #define GUESS_LT0_DEFAULT 4 #define GUESS_UPPER_LIM 20 diff --git a/src/csv_CmdLine.cpp b/src/csv_CmdLine.cpp index e27fd29..dbfeded 100644 --- a/src/csv_CmdLine.cpp +++ b/src/csv_CmdLine.cpp @@ -89,7 +89,7 @@ void csv_CmdLine::setUsageMessage() buffer << " -h" << " :Prints this help message" << std::endl; buffer << " -n " - << " :Sets the noise level. defaults to 6.\n"; + << " :Sets the noise level. Defaults to 6.\n"; buffer << " -p " << " :Writes peak data to CSV" << std::endl; buffer << " -l " From 4cbe1f8b8a48b4693a1f10eccae29612c7b4ae51 Mon Sep 17 00:00:00 2001 From: Spencer Fleming Date: Thu, 17 Oct 2019 19:15:49 -0600 Subject: [PATCH 11/13] guess_upper_bound renamed to max_amp_multiplier(variable whos default is 2) (#297) --- src/GaussianFitter.cpp | 4 ++-- src/GaussianFitter.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/GaussianFitter.cpp b/src/GaussianFitter.cpp index 1cf3756..2394bc3 100644 --- a/src/GaussianFitter.cpp +++ b/src/GaussianFitter.cpp @@ -24,7 +24,7 @@ GaussianFitter::GaussianFitter(){ guess_upper_lim = GUESS_UPPER_LIM; guess_upper_lim_default = GUESS_UPPER_LIM_DEFAULT; - amp_upper_bound = AMP_UPPER_BOUND; + max_amp_multiplier = MAX_AMP_MULTIPLIER; amp_lower_bound = AMP_LOWER_BOUND; log_diagnostics = false; @@ -517,7 +517,7 @@ int GaussianFitter::find_peaks(std::vector* results, //calculate rise time peak->rise_time = peak->location - peak->triggering_location; - if(peak->amp >= amp_upper_bound*max || peak->amp < amp_lower_bound + if(peak->amp >= max_amp_multiplier*max || peak->amp < amp_lower_bound || peak->triggering_location > n || peak->triggering_location <0) { delete(peak); diff --git a/src/GaussianFitter.hpp b/src/GaussianFitter.hpp index e2d9c8d..4a87a50 100644 --- a/src/GaussianFitter.hpp +++ b/src/GaussianFitter.hpp @@ -28,7 +28,7 @@ #define GUESS_UPPER_LIM 20 #define GUESS_UPPER_LIM_DEFAULT 10 -#define AMP_UPPER_BOUND 2 +#define MAX_AMP_MULTIPLIER 2. #define AMP_LOWER_BOUND 10 class GaussianFitter{ @@ -67,7 +67,7 @@ class GaussianFitter{ int guess_upper_lim; // If guess greater than this value... int guess_upper_lim_default; // It is set to this value - int amp_upper_bound; // Val is multiplied by max data point in wave + int max_amp_multiplier; // Val is multiplied by max data point in wave int amp_lower_bound; // Val is unmodified (no multiplication) From 854891729a17b6c58f0200034aa1b333843bc8be Mon Sep 17 00:00:00 2001 From: Spencer Fleming Date: Thu, 17 Oct 2019 19:18:19 -0600 Subject: [PATCH 12/13] max_amp_multiplier is now a float. So is amp_lower_bound. (#297) --- src/GaussianFitter.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GaussianFitter.hpp b/src/GaussianFitter.hpp index 4a87a50..6212046 100644 --- a/src/GaussianFitter.hpp +++ b/src/GaussianFitter.hpp @@ -67,8 +67,8 @@ class GaussianFitter{ int guess_upper_lim; // If guess greater than this value... int guess_upper_lim_default; // It is set to this value - int max_amp_multiplier; // Val is multiplied by max data point in wave - int amp_lower_bound; // Val is unmodified (no multiplication) + float max_amp_multiplier; // Val is multiplied by max data point in wave + float amp_lower_bound; // Val is unmodified (no multiplication) private: From 43c61e4c02ef6685bf08fad02fd4cd87e8726a95 Mon Sep 17 00:00:00 2001 From: Spencer Fleming Date: Thu, 17 Oct 2019 19:36:41 -0600 Subject: [PATCH 13/13] Guess peaks peak width being less than zero now logs a warning before reverting to the default value (#337) --- src/GaussianFitter.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/GaussianFitter.cpp b/src/GaussianFitter.cpp index 2394bc3..9e752ab 100644 --- a/src/GaussianFitter.cpp +++ b/src/GaussianFitter.cpp @@ -700,6 +700,10 @@ int GaussianFitter::guess_peaks(std::vector* results, } if(guess< 0) { + spdlog::warn( + "Guess for peak width less than zero, reverting to default" + ); + guess = guess_lessthan_0_default; }