Skip to content
Snippets Groups Projects
Unverified Commit a2cccf1e authored by Amy Stamile's avatar Amy Stamile Committed by GitHub
Browse files

Convert dstripe to gtests (#5665)

* Convert dstripe to gtests

* add changelog

* Fixed build error
parent 1764f59c
No related branches found
No related tags found
No related merge requests found
...@@ -55,6 +55,7 @@ file. Slightly modified the FunctionalTestJigsawBundleXYZ ctest accordingly. Iss ...@@ -55,6 +55,7 @@ file. Slightly modified the FunctionalTestJigsawBundleXYZ ctest accordingly. Iss
- Fixed FunctionalTestCamstatsDefaultParameters test by increasing the runtime speed [#5459](https://github.com/DOI-USGS/ISIS3/issues/5459) - Fixed FunctionalTestCamstatsDefaultParameters test by increasing the runtime speed [#5459](https://github.com/DOI-USGS/ISIS3/issues/5459)
- Fixed XmlToJson namespaced key conversion [#5652](https://github.com/DOI-USGS/ISIS3/pull/5652) - Fixed XmlToJson namespaced key conversion [#5652](https://github.com/DOI-USGS/ISIS3/pull/5652)
- Fixed PHOTOMET not accepting backplanes [#5281](https://github.com/DOI-USGS/ISIS3/issues/5281) - Fixed PHOTOMET not accepting backplanes [#5281](https://github.com/DOI-USGS/ISIS3/issues/5281)
- Fixed dstripe parallel test failing by converting tests to gtests [#5613](https://github.com/DOI-USGS/ISIS3/issues/5613)
## [8.3.0] - 2024-09-30 ## [8.3.0] - 2024-09-30
......
/** This is free and unencumbered software released into the public domain.
The authors of ISIS do not claim copyright on the contents of this file.
For more details about the LICENSE terms and the AUTHORS, you will
find files of those names at the top level of this repository. **/
/* SPDX-License-Identifier: CC0-1.0 */
#include "dstripe.h"
#include <QFile>
#include "Application.h"
#include "ProcessByLine.h"
#include "ProgramLauncher.h"
#include "SpecialPixel.h"
using namespace std;
namespace Isis {
void difference(vector<Buffer *> &input, vector<Buffer *> &output);
void dstripe(UserInterface &ui) {
Cube icube;
CubeAttributeInput inAtt = ui.GetInputAttribute("FROM");
if (inAtt.bands().size() != 0) {
icube.setVirtualBands(inAtt.bands());
}
icube.open(ui.GetCubeName("FROM"));
dstripe(&icube, ui);
}
void dstripe(Cube *icube, UserInterface &ui) {
ProcessByLine p;
int highLines, highSamples, lowLines, lowSamples;
p.SetInputCube(icube);
// Get the boxcar sizes to be used by the low and highpass filters
// All numbers have to be odd. If nothing is entered into the UI,
// NS and/or NL are used.
if (ui.GetString("MODE") == "VERTICAL") {
if (ui.WasEntered("VHNS")) {
highSamples = ui.GetInteger("VHNS");
} else {
highSamples = icube->sampleCount();
if (highSamples % 2 == 0) highSamples -= 1;
}
if (ui.WasEntered("VLNL")) {
lowLines = ui.GetInteger("VLNL");
} else {
lowLines = icube->lineCount();
if (lowLines % 2 == 0) lowLines -= 1;
}
lowSamples = ui.GetInteger("VLNS");
highLines = ui.GetInteger("VHNL");
} else {
if (ui.WasEntered("HHNL")) {
highLines = ui.GetInteger("HHNL");
} else {
highLines = icube->lineCount();
if (highLines % 2 == 0) highLines -= 1;
}
if (ui.WasEntered("HLNS")) {
lowSamples = ui.GetInteger("HLNS");
} else {
lowSamples = icube->sampleCount();
if (lowSamples % 2 == 0) lowSamples -= 1;
}
highSamples = ui.GetInteger("HHNS");
lowLines = ui.GetInteger("HLNL");
}
// Algorithm: lowpass(from, temp) -> hipass(temp, noise) -> to = from-noise
// Run lowpass filter on input
QString tempFileName =
FileName::createTempFile("$TEMPORARY/dstripe.temporary.cub").expanded();
QString lowParams = "";
lowParams += "from= " + ui.GetCubeName("FROM");
lowParams += " to= " + tempFileName + " ";
lowParams += " samples= " + toString(lowSamples);
lowParams += " lines= " + toString(lowLines);
ProgramLauncher::RunIsisProgram("lowpass", lowParams);
// Make a copy of the lowpass filter results if the user wants it
if (!ui.GetBoolean("DELETENOISE")) {
QString lowParams = "";
lowParams += "from= " + ui.GetCubeName("FROM");
lowParams += " to= " + ui.GetCubeName("LPFNOISE");
lowParams += " samples= " + toString(lowSamples);
lowParams += " lines= " + toString(lowLines);
ProgramLauncher::RunIsisProgram("lowpass", lowParams);
}
// Run highpass filter after lowpass is done, i.e. highpass(lowpass(input))
QString tempNoiseFileName =
FileName::createTempFile("$TEMPORARY/dstripe.noise.temporary.cub")
.expanded();
QString highParams = "";
highParams += " from= " + tempFileName + " ";
highParams += " to= " + tempNoiseFileName + " ";
highParams += " samples= " + toString(highSamples);
highParams += " lines= " + toString(highLines);
ProgramLauncher::RunIsisProgram("highpass", highParams);
QFile::remove(tempFileName);
// Take the difference (FROM-NOISE) and write it to output
CubeAttributeInput inatt;
p.SetInputCube(tempNoiseFileName, inatt);
CubeAttributeOutput &outatt = ui.GetOutputAttribute("TO");
p.SetOutputCube(ui.GetCubeName("TO"), outatt);
p.StartProcess(difference);
p.EndProcess();
if (ui.GetBoolean("DELETENOISE")) {
QFile::remove(tempNoiseFileName);
}
}
// Subtracts noise from the input buffer, resulting in a cleaner output image
void difference(vector<Buffer *> &input, vector<Buffer *> &output) {
Buffer &from = *input[0];
Buffer &noise = *input[1];
Buffer &to = *output[0];
for(int i = 0; i < from.size(); i++) {
if(IsSpecial(from[i]) || IsSpecial(noise[i])) {
to[i] = from[i];
}
else {
to[i] = from[i] - noise[i];
}
}
}
} // namespace Isis
\ No newline at end of file
/** This is free and unencumbered software released into the public domain.
The authors of ISIS do not claim copyright on the contents of this file.
For more details about the LICENSE terms and the AUTHORS, you will
find files of those names at the top level of this repository. **/
/* SPDX-License-Identifier: CC0-1.0 */
#ifndef dstripe_h
#define dstripe_h
#include "Cube.h"
#include "UserInterface.h"
namespace Isis {
extern void dstripe(Cube *icube, UserInterface &ui);
extern void dstripe(UserInterface &ui);
}
#endif
\ No newline at end of file
#include "Isis.h" /** This is free and unencumbered software released into the public domain.
The authors of ISIS do not claim copyright on the contents of this file.
For more details about the LICENSE terms and the AUTHORS, you will
find files of those names at the top level of this repository. **/
#include <QFile> /* SPDX-License-Identifier: CC0-1.0 */
#include "Isis.h"
#include "dstripe.h"
#include "Application.h" #include "Application.h"
#include "ProcessByLine.h"
#include "ProgramLauncher.h"
#include "SpecialPixel.h"
using namespace std;
using namespace Isis; using namespace Isis;
void difference(vector<Buffer *> &input, vector<Buffer *> &output);
void IsisMain() { void IsisMain() {
ProcessByLine p;
Cube *icube = p.SetInputCube("FROM");
UserInterface &ui = Application::GetUserInterface(); UserInterface &ui = Application::GetUserInterface();
int highLines, highSamples, lowLines, lowSamples; dstripe(ui);
// Get the boxcar sizes to be used by the low and highpass filters
// All numbers have to be odd. If nothing is entered into the UI,
// NS and/or NL are used.
if(ui.GetString("MODE") == "VERTICAL") {
if(ui.WasEntered("VHNS")) {
highSamples = ui.GetInteger("VHNS");
}
else {
highSamples = icube->sampleCount();
if(highSamples % 2 == 0) highSamples -= 1;
}
if(ui.WasEntered("VLNL")) {
lowLines = ui.GetInteger("VLNL");
}
else {
lowLines = icube->lineCount();
if(lowLines % 2 == 0) lowLines -= 1;
} }
lowSamples = ui.GetInteger("VLNS");
highLines = ui.GetInteger("VHNL");
}
else {
if(ui.WasEntered("HHNL")) {
highLines = ui.GetInteger("HHNL");
}
else {
highLines = icube->lineCount();
if(highLines % 2 == 0) highLines -= 1;
}
if(ui.WasEntered("HLNS")) {
lowSamples = ui.GetInteger("HLNS");
}
else {
lowSamples = icube->sampleCount();
if(lowSamples % 2 == 0) lowSamples -= 1;
}
highSamples = ui.GetInteger("HHNS");
lowLines = ui.GetInteger("HLNL");
}
// Algorithm: lowpass(from, temp) -> hipass(temp, noise) -> to = from-noise
// Run lowpass filter on input
QString tempFileName = FileName::createTempFile("$TEMPORARY/dstripe.temporary.cub").expanded();
QString lowParams = "";
lowParams += "from= " + ui.GetCubeName("FROM");
lowParams += " to= " + tempFileName + " ";
lowParams += " samples= " + toString(lowSamples);
lowParams += " lines= " + toString(lowLines);
ProgramLauncher::RunIsisProgram("lowpass", lowParams);
// Make a copy of the lowpass filter results if the user wants it
if(!ui.GetBoolean("DELETENOISE")) {
QString lowParams = "";
lowParams += "from= " + ui.GetCubeName("FROM");
lowParams += " to= " + ui.GetCubeName("LPFNOISE");
lowParams += " samples= " + toString(lowSamples);
lowParams += " lines= " + toString(lowLines);
ProgramLauncher::RunIsisProgram("lowpass", lowParams);
}
// Run highpass filter after lowpass is done, i.e. highpass(lowpass(input))
QString tempNoiseFileName = FileName::createTempFile("$TEMPORARY/dstripe.noise.temporary.cub").expanded();
QString highParams = "";
highParams += " from= "+tempFileName + " ";
highParams += " to= " + tempNoiseFileName + " ";
highParams += " samples= " + toString(highSamples);
highParams += " lines= " + toString(highLines);
ProgramLauncher::RunIsisProgram("highpass", highParams);
QFile::remove(tempFileName);
// Take the difference (FROM-NOISE) and write it to output
CubeAttributeInput att;
p.SetInputCube(tempNoiseFileName, att);
p.SetOutputCube("TO");
p.StartProcess(difference);
p.EndProcess();
if(ui.GetBoolean("DELETENOISE")) {
QFile::remove(tempNoiseFileName);
}
}
// Subtracts noise from the input buffer, resulting in a cleaner output image
void difference(vector<Buffer *> &input, vector<Buffer *> &output) {
Buffer &from = *input[0];
Buffer &noise = *input[1];
Buffer &to = *output[0];
for(int i = 0; i < from.size(); i++) {
if(IsSpecial(from[i]) || IsSpecial(noise[i])) {
to[i] = from[i];
}
else {
to[i] = from[i] - noise[i];
}
}
}
BLANKS = "%-6s"
LENGTH = "%-40s"
include $(ISISROOT)/make/isismake.tststree
APPNAME = dstripe
include $(ISISROOT)/make/isismake.tsts
commands:
$(APPNAME) from=$(INPUT)/isisTruth.cub \
to=$(OUTPUT)/dstrTruth1.cub > /dev/null;
APPNAME = dstripe
include $(ISISROOT)/make/isismake.tsts
commands:
cat $(INPUT)/root.lis | xargs -n1 -P 2 -IX $(APPNAME) from=$(INPUT)/X.cub to=$(OUTPUT)/X.dstr.cub mode=vert vlnl=51 vhns=51 > /dev/null;
#include <QTemporaryDir>
#include "Fixtures.h"
#include "Pvl.h"
#include "PvlGroup.h"
#include "TestUtilities.h"
#include "Histogram.h"
#include "dstripe.h"
#include "gtest/gtest.h"
using namespace Isis;
static QString APP_XML = FileName("$ISISROOT/bin/xml/dstripe.xml").expanded();
TEST(Dstripe, FunctionalTestDstripeName) {
QTemporaryDir prefix;
QString outCubeFileName = prefix.path() + "/outTemp.cub";
QVector<QString> args = {"from=data/dstripe/dstripe-default.cub",
"to=" + outCubeFileName};
UserInterface options(APP_XML, args);
try {
dstripe(options);
} catch (IException &e) {
FAIL() << "Unable to open image: " << e.what() << std::endl;
}
Cube cube(outCubeFileName);
std::unique_ptr<Histogram> hist (cube.histogram(0));
EXPECT_NEAR(hist->Average(), 99.405224835973755, .000001);
EXPECT_NEAR(hist->Sum(), 19877864, .000001);
EXPECT_EQ(hist->ValidPixels(), 199968);
EXPECT_NEAR(hist->StandardDeviation(), 18.246570191788862, .000001);
}
TEST(Dstripe, FunctionalTestDstripeParallel) {
QTemporaryDir prefix;
QString outCubeFileName = prefix.path() + "/outTemp.cub";
QVector<QString> args = {"from=data/dstripe/dstripe-parallel.cub",
"mode=vert", "vlnl=51", "vhns=51",
"to=" + outCubeFileName};
UserInterface options(APP_XML, args);
try {
dstripe(options);
} catch (IException &e) {
FAIL() << "Unable to open image: " << e.what() << std::endl;
}
Cube cube(outCubeFileName);
std::unique_ptr<Histogram> hist (cube.histogram(0));
EXPECT_NEAR(hist->Average(), 2.2391462548711162e-05, .000001);
EXPECT_NEAR(hist->Sum(), 0.71652680155875714, .000001);
EXPECT_EQ(hist->ValidPixels(), 32000);
EXPECT_NEAR(hist->StandardDeviation(), 3.2450333566072249e-06, .000001);
}
\ No newline at end of file
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment