Skip to content

Commit

Permalink
Implemented Spdlog #284
Browse files Browse the repository at this point in the history
  • Loading branch information
FloCiaglia committed Sep 17, 2019
1 parent 3747298 commit 25f2342
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 122 deletions.
14 changes: 7 additions & 7 deletions src/FlightLineData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int FlightLineData::setFlightLineData(std::string fileName){
pOpener.set_file_name(fileName.c_str());
pReader = pOpener.open();
if(pReader == NULL){
throw "Unable to Open File" + fileName;
spdlog::critical("Unable to Open File {}", fileName);
return 1;
}

Expand Down Expand Up @@ -356,18 +356,18 @@ int FlightLineData::calc_xyz_activation(std::vector<Peak*> *peaks){
(*it)->triggering_location * current_wave_gps_info.dx +
current_wave_gps_info.x_first;
if((*it)->x_activation < bb_x_min || (*it)->x_activation > bb_x_max+1){
std::cerr << "\nx activation: "<< (*it)->x_activation
<< " not in range: " << bb_x_min << " - " << bb_x_max <<
std::endl;
spdlog::error("\nx activation: {} not in range: {} - {}",
(*it)->x_activation, bb_x_min, bb_x_max);

}

(*it)->y_activation =
(*it)->triggering_location * current_wave_gps_info.dy +
current_wave_gps_info.y_first;
if((*it)->y_activation < bb_y_min || (*it)->y_activation > bb_y_max+1){
std::cerr << "\ny activation: "<< (*it)->y_activation
<< " not in range: " << bb_y_min << " - " << bb_y_max <<
std::endl;
spdlog::error("\ny activation: {} not in range: {} - {}",
(*it)->y_activation, bb_y_min, bb_y_max);

}

(*it)->z_activation =
Expand Down
52 changes: 16 additions & 36 deletions src/GaussianFitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,28 +440,22 @@ int GaussianFitter::find_peaks(std::vector<Peak*>* results,
}

// PRINT DATA AND MODEL FOR TESTING PURPOSES
#ifdef DEBUG
std::cout << "Gaussian sum based on guesses - before solve system:"
<< std::endl;
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);
}
std::cout << std::endl;
std::cout << std::endl;
#endif


fdf_params.trs = gsl_multifit_nlinear_trs_dogleg;
fdf_params.scale = gsl_multifit_nlinear_scale_more;
fdf_params.solver = gsl_multifit_nlinear_solver_svd;
fdf_params.fdtype = GSL_MULTIFIT_NLINEAR_CTRDIFF;

#ifdef DEBUG
std::cerr << "peakCount = " << peakCount << std::endl;
#endif
spdlog::error("peakCount = {}",peakCount);

if(!solve_system(x, &fdf, &fdf_params, max)){
incr_pass();
Expand Down Expand Up @@ -526,11 +520,9 @@ int GaussianFitter::find_peaks(std::vector<Peak*>* results,
peak->position_in_wave = i+1;
}

#ifdef FINAL_PEAK_TEST
std::cerr << "--------------------" << std::endl;
std::cerr << "results.size = " << results->size() << std::endl;
std::cerr << "is empty = " << results->empty() << std::endl;
#endif
spdlog::error("--------------------");
spdlog::error("results.size = {}", results->size());
spdlog::error("is empty = {}", results->empty());

if (!results->empty()) {
Peak* final_peak_ptr = results->back();
Expand All @@ -539,49 +531,39 @@ int GaussianFitter::find_peaks(std::vector<Peak*>* results,
}
i++;
}
#ifdef DEBUG
// PRINT DATA AND MODEL FOR TESTING PURPOSES
std::cout << "Gaussian sum in solve system and not failed:"
<< std::endl;
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);
}
std::cout << std::endl;
std::cout << std::endl;
#endif
}
else{
#ifdef DEBUG
// FOR TESTING PURPOSES
std::cout << "In solve system and failed:" <<std::endl;
std::cerr << "Amplitudes: " << std::endl;
spdlog::trace("In solve system and failed:");
spdlog::error("Amplitudes: ");

for(int i=0; i< (int)ampData.size(); i++){
std::cerr<< ampData[i] << " ";
spdlog::error("{}", ampData[i]);
}
std::cerr << std::endl ;
std::cerr << "Indices in time: " << std::endl;
spdlog::error("Indices in time: ");
for(int i=0; i< (int)idxData.size(); i++){
std::cerr<< idxData[i] << " ";
spdlog::error( "{}", idxData[i]);
}
std::cerr << std::endl ;
#endif

incr_fail();

#ifdef DEBUG
// PRINT DATA AND MODEL FOR TESTING PURPOSES
std::cout << "Gaussian sum in solve system failed:" <<std::endl;
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);
}
#endif
}

free(fit_data.t);
Expand Down Expand Up @@ -660,10 +642,8 @@ int GaussianFitter::guess_peaks(std::vector<Peak*>* results,
}
noise_level = ((float)max)*.09;

#ifdef DEBUG
std::cerr << "Max = " << max << " Noise = " << ((float)max)*.09
<< std::endl;
#endif
spdlog::error("Max = {} Noise = {}", max, ((float)max)*.09);


if (noise_level < 6){
noise_level = 6;
Expand Down
57 changes: 34 additions & 23 deletions src/GetPLSDetails.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,34 @@
#include "pulsewriter.hpp"
#include "PulseData.hpp"

// Activity level must be defined before spdlog is included.
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE

#include "spdlog/spdlog.h"
#include "spdlog/async.h"
#include "spdlog/sinks/stdout_color_sinks.h"
int main (int argc, char *argv[]) {

// Setting up logger
spdlog::set_pattern("[%^%=8l%$] %v");
// Sets new pattern for timestamp

auto logger = spdlog::create_async<spdlog::sinks::stdout_color_sink_mt>(
"logger");

PULSEreadOpener pOpener;
PULSEreader *pReader;

if(argc < 2){
std::cerr << "Usage: " << argv[0] << " <path to .pls file>" <<std::endl;
spdlog::error("Usage: {} <path to .pls file>", argv[0]);
return 1;
}

std::string fileName = argv[1];
pOpener.set_file_name(fileName.c_str());
pReader = pOpener.open();
if(pReader == NULL){
throw "Unable to Open File" + fileName;
spdlog::critical("Unable to Open File {}", fileName);
return 1;
}

Expand Down Expand Up @@ -66,34 +79,32 @@ int main (int argc, char *argv[]) {
std::string utm_str = tokens[0];
std::string geog_cs = tokens[1];

std::cout << "\nReading information from the header of: " << argv[1]
<< std::endl;
std::cout << "----------------------------------------";
spdlog::trace("\nReading information from the header of: {}", argv[1]);

spdlog::trace("----------------------------------------")
for(std::size_t i = 0; i < strlen(argv[1]); i++){
std::cout << "-";
spdlog::trace("-");
}
std::cout << std::endl;
std::cout << "No of pulses: " << number_of_pulses << std::endl;
spdlog::trace("No of pulses: {}", number_of_pulses);

std::cout << "\nUTM: " << utm_str << std::endl;
std::cout << "Geog_cs: "<< geog_cs << std::endl;
spdlog::trace("\nUTM: {}", utm_str);
spdlog::trace("Geog_cs: {}", geog_cs);

std::cout << "\nMin x: "<< bb_x_min << std::endl;
std::cout << "Max x: "<< bb_x_max << std::endl;
std::cout << "Min y: "<< bb_y_min << std::endl;
std::cout << "Max y: "<< bb_y_max << std::endl;
spdlog::trace("\nMin x: {}", bb_x_min);
spdlog::trace("Max x: {}", bb_x_max);
spdlog::trace("Min y: {}", bb_y_min);
spdlog::trace("Max y: {}", bb_y_max);

fprintf(stdout,"\nMin x: %Lf\nMax y: %Lf\n",bb_x_min,bb_y_max);

std::cout << "\nCalculating i, j max, mins and extents:"<< std::endl;
std::cout << "---------------------------------------"<< std::endl;
std::cout << "\nBounding box 'x_idx' min: "<< bb_x_idx_min << std::endl;
std::cout << "Bounding box 'x_idx' max: "<< bb_x_idx_max << std::endl;
std::cout << "Bounding box 'y_idx' min: "<< bb_y_idx_min << std::endl;
std::cout << "Bounding box 'y_idx' max: "<< bb_y_idx_max << std::endl;
spdlog::trace("\nCalculating i, j max, mins and extents:");
spdlog::trace("---------------------------------------");
spdlog::trace("\nBounding box 'x_idx' min: {}", bb_x_idx_min);
spdlog::trace("Bounding box 'x_idx' max: {}", bb_x_idx_max);
spdlog::trace("Bounding box 'y_idx' min: {}", bb_y_idx_min);
spdlog::trace("Bounding box 'y_idx' max: {}", bb_y_idx_max);

std::cout << "\nBounding box 'x_idx' extent: "<< x_idx_extent << std::endl;
std::cout << "Bounding box 'y_idx' extent: "<< y_idx_extent << std::endl;
std::cout << std::endl;
spdlog::trace("\nBounding box 'x_idx' extent: {}", x_idx_extent);
spdlog::trace("Bounding box 'y_idx' extent: {}", y_idx_extent);

}
34 changes: 16 additions & 18 deletions src/LidarDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,11 @@ void LidarDriver::calc_product_size(FlightLineData &data, int num_products){
//Use dimensional analysis to cancel out all units except for bytes
bytes = bytes_per_val * vals_per_product * num_products / prefix_conversion;

#ifdef DEBUG
std::cerr << "Values per product: " << vals_per_product << std::endl;
std::cerr << "Bytes per value (float): " << bytes_per_val << std::endl;
std::cerr << "Conversion to " << units.at(i) << ". Divide by " <<
prefix_conversion << std::endl;
std::cerr << "Total bytes needed: " << bytes << std::endl;
#endif
spdlog::error("Values per product: {}", vals_per_product);
spdlog::trace("Bytes per value (float): {}", bytes_per_val);
spdlog::trace("Conversion to {}. Divide by {}", units.at(i), prefix_conversion);
spdlog::trace("Total bytes needed: {}", bytes);

}

//Find the best unit
Expand All @@ -68,8 +66,8 @@ void LidarDriver::calc_product_size(FlightLineData &data, int num_products){
//Round to two decimals
bytes = floorf(bytes * 100) / 100;

std::cout << num_products << " Tif files will require approximately " <<
bytes << units.at(i) << std::endl;
spdlog::trace("{} Tif files will require approximately {} {}", num_products,
bytes, units.at(i));
}

/**
Expand Down Expand Up @@ -363,10 +361,10 @@ void LidarDriver::produce_product(LidarVolume &fitted_data,
sizeof(float));
float avg = 0 ;
float dev = 0;
#ifdef DEBUG
std::cerr << "Entering write image loop. In "<< __FILE__ << ":" << __LINE__
<< std::endl;
#endif

spdlog::error("Entering write image loop. In {} : {}", __FILE__, __LINE__);



//loop through every pixel position
for (y = fitted_data.y_idx_extent - 1; y >= 0; y--) {
Expand Down Expand Up @@ -410,18 +408,18 @@ void LidarDriver::produce_product(LidarVolume &fitted_data,
break;
}
}
#ifdef DEBUG
std::cerr << "In writeImage loop. Writing band: "<< x << "," << y
<< ". In " << __FILE__ << ":" << __LINE__ << std::endl;
#endif

spdlog::error("In writeImage loop. Writing band: {}, {}. In {} : {}", x, y,
__FILE__, __LINE__);

//add the pixel values to the raster, one column at a time
// Refer to http://www.gdal.org/classGDALRasterBand.html
retval = gdal_ds->GetRasterBand(1)->RasterIO(GF_Write, 0,
fitted_data.y_idx_extent - y - 1, fitted_data.x_idx_extent, 1,
pixel_values, fitted_data.x_idx_extent, 1, GDT_Float32, 0, 0,
NULL);
if (retval != CE_None) {
std::cerr << "Error during writing band: 1 " << std::endl;
spdlog::error("Error during writing band: 1 ");
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/LidarVolume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Author: ravi

#include "LidarVolume.hpp"

#include "spdlog/spdlog.h"

//Default constructor
LidarVolume::LidarVolume(){
Expand Down Expand Up @@ -114,7 +114,7 @@ void LidarVolume::insert_peak(Peak* peak){

// make sure we are in our bounding box
if((long int)x_idx > x_idx_extent || (long int)y_idx > y_idx_extent){
std::cerr << "ERROR: Invalid peak ignored" << std::endl;
spdlog::error("ERROR: Invalid peak ignored");
return;
}
unsigned long int p = position(y_idx,x_idx);
Expand Down
16 changes: 7 additions & 9 deletions src/Peak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "math.h"
#include "Peak.hpp"
#include <iostream>
#include "spdlog/spdlog.h"

//Default constructor
Peak::Peak(){
Expand Down Expand Up @@ -75,15 +76,12 @@ void Peak::calcBackscatter(double emitted_amp, double emitted_fwhm,
backscatter_coefficient = calibration_constant *
(pow(range, 2)*amp*standard_dev) / (emitted_amp*n_atm);

#ifdef debug
std::cout << "Outgoing Amplitude = " << emitted_amp
<< std::endl;
std::cout << "Returning Amplitude = " << amp << std::endl;
std::cout << "Range = " << range << std::endl;
std::cout << "Standard Deviation = " << standard_dev << std::endl;
std::cout << "Atmoshperic Transmission Factor = " << n_atm << std::endl;
std::cout << "Backscatter Coefficient = " << backscatter_coefficient << std::endl;
#endif
spdlog::trace("Outgoing Amplitude = {}", emitted_amp);
spdlog::trace("Returning Amplitude = {}", amp);
spdlog::trace("Range = {}", range);
spdlog::trace("Standard Deviation = {}", standard_dev);
spdlog::trace("Atmoshperic Transmission Factor = {}", n_atm);
spdlog::trace("Backscatter Coefficient = {}", backscatter_coefficient);
}

/**
Expand Down
Loading

0 comments on commit 25f2342

Please sign in to comment.