Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for desired precision in usgscsm_cam_test #394

Merged
merged 1 commit into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions bin/usgscsm_cam_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ struct Options {
std::string model; // the .json file in isd or model state format
std::string output_model_state; // the output model state in .json format
int sample_rate;
double subpixel_offset, height_above_datum;
Options(): sample_rate(0), subpixel_offset(0.0), height_above_datum(0.0) {}
double subpixel_offset, height_above_datum, desired_precision;
Options(): sample_rate(0), subpixel_offset(0.0), height_above_datum(0.0), desired_precision(0.0)
{}
};

void printUsage(std::string const& progName) {
Expand Down Expand Up @@ -85,11 +86,15 @@ bool parseOptions(int argc, char **argv, Options & opt) {
return false;
}

if (parsed_options["desired-precision"].empty())
parsed_options["desired-precision"] = "0.001"; // set default value

// Collect all other option values. If not set, the values will default to 0.
opt.output_model_state = parsed_options["output-model-state"];
opt.sample_rate = sample_rate_double;
opt.subpixel_offset = atof(parsed_options["subpixel-offset"].c_str());
opt.height_above_datum = atof(parsed_options["height-above-datum"].c_str());
opt.desired_precision = atof(parsed_options["desired-precision"].c_str());

return true;
}
Expand All @@ -116,7 +121,8 @@ bool readFileInString(std::string const& filename, std::string & str) {
}

// Sort the errors and print some stats
void printErrors(std::vector<double> & errors) {
void printErrors(std::vector<double> & errors, double desired_precision,
double max_achieved_precision) {
std::sort(errors.begin(), errors.end());

if (errors.empty()) {
Expand All @@ -129,6 +135,10 @@ void printErrors(std::vector<double> & errors) {
std::cout << "Median: " << errors[errors.size()/2] << "\n";
std::cout << "Max: " << errors.back() << "\n";
std::cout << "Count: " << errors.size() << "\n";

std::cout << std::endl;
std::cout << "Desired precision: " << desired_precision << std::endl;
std::cout << "Max achieved precision: " << max_achieved_precision << std::endl;
}

double pixDiffNorm(csm::ImageCoord const& a, csm::ImageCoord const& b) {
Expand Down Expand Up @@ -237,17 +247,25 @@ int main(int argc, char **argv) {
std::cout << "Row and column sample rate: " << opt.sample_rate << "\n";
std::cout << "Subpixel offset for each pixel: " << opt.subpixel_offset << "\n";
std::cout << "Ground height (relative to datum): " << opt.height_above_datum << "\n";
double max_achieved_precision = 0.0;
std::vector<double> errors;
for (int samp = 0; samp < image_size.samp; samp += opt.sample_rate) {
for (int line = 0; line < image_size.line; line += opt.sample_rate) {
csm::ImageCoord c(line + opt.subpixel_offset, samp + opt.subpixel_offset);
csm::EcefCoord ground = model->imageToGround(c, opt.height_above_datum);
csm::ImageCoord d = model->groundToImage(ground);

double achieved_precision = 0.0;
csm::EcefCoord ground = model->imageToGround(c, opt.height_above_datum,
opt.desired_precision, &achieved_precision);
max_achieved_precision = std::max(max_achieved_precision, achieved_precision);

csm::ImageCoord d = model->groundToImage(ground, opt.desired_precision,
&achieved_precision);
max_achieved_precision = std::max(max_achieved_precision, achieved_precision);
double error = pixDiffNorm(c, d);
errors.push_back(error);
}
}
printErrors(errors);
printErrors(errors, opt.desired_precision, max_achieved_precision);
}

return 0;
Expand Down
4 changes: 4 additions & 0 deletions docs/source/tools/usgscsm_cam_test.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,9 @@ Command line options
Let the ground be obtained from the datum for this camera by
adding to its radii this value (the units are meters).

--desired-precision <double (default: 0.001)>
Use this value for operations (ground-to-image and image-to-ground)
which need a precision value. Measured in pixels.

--help <no value>
Print the usage message.
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ endif()
# uses as input the output of the first test.
# 1. Save the model state for an ISD camera model.
add_test(NAME test_usgscsm_cam_test_save_state
COMMAND usgscsm_cam_test --model data/toughLroNacLineScan.json --sample-rate 100 --subpixel-offset 0.3 --height-above-datum 2307.5 --output-model-state model_state.json
COMMAND usgscsm_cam_test --model data/toughLroNacLineScan.json --sample-rate 100 --subpixel-offset 0.3 --height-above-datum 2307.5 --desired-precision 1e-8 --output-model-state model_state.json
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/tests)
# 2. Load back the state and save it again.
add_test(NAME test_usgscsm_cam_test_load_state
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class OrbitalLineScanSensorModel : public ::testing::Test {
isd.setFilename("data/orbitalLineScan.img");
UsgsAstroPlugin cameraPlugin;

model = std::shared_ptr<csm::Model>(cameraPlugin.constructModelFromISD(
model = std::shared_ptr<csm::Model>(cameraPlugin.constructModelFromISD(
isd, UsgsAstroLsSensorModel::_SENSOR_MODEL_NAME));
sensorModel = dynamic_cast<UsgsAstroLsSensorModel *>(model.get());

Expand Down
Loading