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

Update cubeattribute to include an option to supply CubeAttributeInput directly #4244

Merged
merged 4 commits into from
Jan 8, 2021
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
10 changes: 10 additions & 0 deletions isis/src/base/apps/cubeatt/cubeatt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ namespace Isis {
p.EndProcess();
}

// Allows specification of both input and output attributes
void cubeatt(QString inputCubePath, CubeAttributeInput inAtt, QString outputCubePath, CubeAttributeOutput outputAttributes, bool propTables) {
Cube icube;
if (inAtt.bands().size() != 0) {
icube.setVirtualBands(inAtt.bands());
}
icube.open(inputCubePath);
cubeatt(&icube, outputCubePath, outputAttributes, propTables);
}

// Line processing routine
void cubeattProcess(Buffer &in, Buffer &out) {
// Loop and copy pixels in the line.
Expand Down
1 change: 1 addition & 0 deletions isis/src/base/apps/cubeatt/cubeatt.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Isis{
extern void cubeatt(Cube *icube, QString outputCubePath, CubeAttributeOutput outputAttributes, bool propTables=false);
extern void cubeatt(QString inputCubePath, CubeAttributeInput inputAttributes, QString outputCubePath, CubeAttributeOutput outputAttributes, bool propTables=false);
extern void cubeatt(Cube *icube, UserInterface &ui);
extern void cubeatt(UserInterface &ui);
}
Expand Down
8 changes: 6 additions & 2 deletions isis/src/base/objs/XmlToJson/XmlToJson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ namespace Isis {
// Translated json goal: a:[val1, val2]
// If the converted json has an array already, append, else make it an array
if (!output[element.tagName().toStdString()].is_array()) {
output[element.tagName().toStdString()] = {output[element.tagName().toStdString()]};
json repeatedArray;
repeatedArray.push_back(output[element.tagName().toStdString()]);
output[element.tagName().toStdString()] = repeatedArray;
}
output[element.tagName().toStdString()].push_back(converted[element.tagName().toStdString()]);
}
Expand All @@ -171,7 +173,9 @@ namespace Isis {
json temporaryJson;
convertXmlToJson(next, temporaryJson);
if (!output[element.tagName().toStdString()].is_array()) {
output[element.tagName().toStdString()] = {output[element.tagName().toStdString()]};
json repeatedArray;
repeatedArray.push_back(output[element.tagName().toStdString()]);
output[element.tagName().toStdString()] = repeatedArray;
}
output[element.tagName().toStdString()].push_back(temporaryJson);
}
Expand Down
68 changes: 67 additions & 1 deletion isis/tests/FunctionalTestsCubeatt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ TEST_F(SmallCube, FunctionalTestCubeattBitttypeAndRange) {
EXPECT_FLOAT_EQ(outputStats->Maximum(), 1.0);
}


TEST_F(SmallCube, FunctionalTestCubeattNoChange) {
QString cubePath = tempDir.path() + "/NoChangeCubeatt.cub";
QVector<QString> args = {"from=" + testCube->fileName(), "to=" + cubePath};
Expand Down Expand Up @@ -61,7 +62,6 @@ TEST_F(SmallCube, FunctionalTestCubeattNoChange) {
}



TEST_F(SmallCube, FunctionalTestCubeattVirtualBands) {
QString cubePath = tempDir.path() + "/VirtualBandsCubeatt.cub";
QVector<QString> args = {"from=" + testCube->fileName() + "+3,2,4,2,1,5,7,6,4", "to=" + cubePath};
Expand Down Expand Up @@ -98,3 +98,69 @@ TEST_F(SmallCube, FunctionalTestCubeattVirtualBands) {
}


// Test using an already open cube as input and ui
TEST_F(SmallCube, FunctionalTestCubeattInputCube) {
QString outputCubePath = tempDir.path() + "/bitTypeCubeatt.cub+8bit+0.0:1.0";
QVector<QString> args = {"from=" + testCube->fileName(), "to=" + outputCubePath};
UserInterface options(APP_XML, args);

cubeatt(testCube, options);
Cube outputCube(outputCubePath);

EXPECT_EQ(outputCube.pixelType(), PixelType::UnsignedByte);
// Setting the pixel range modifies the base/multiplier, so check those.
EXPECT_NE(outputCube.base(), 0);
EXPECT_NE(outputCube.multiplier(), 1);

// Test the DNs
Statistics *outputStats = outputCube.statistics();
EXPECT_FLOAT_EQ(outputStats->Minimum(), 0.0);
EXPECT_FLOAT_EQ(outputStats->Maximum(), 1.0);
}


// Test using an already open cube as input and specifying an output path and output attributes
TEST_F(SmallCube, FunctionalTestCubeattInputCubeOutputPath) {
QString outputCubePath = tempDir.path() + "/bitTypeCubeatt.cub";
CubeAttributeOutput attributeOutput("+8bit+0.0:1.0");

cubeatt(testCube, outputCubePath, attributeOutput);
Cube outputCube(outputCubePath);

// Setting the pixel range modifies the base/multiplier, so check those.
EXPECT_NE(outputCube.base(), 0);
EXPECT_NE(outputCube.multiplier(), 1);

// Test the DNs
Statistics *outputStats = outputCube.statistics();
EXPECT_FLOAT_EQ(outputStats->Minimum(), 0.0);
EXPECT_FLOAT_EQ(outputStats->Maximum(), 1.0);
}

// Test using the input/output paths and cube attribute input and output passed in directly
TEST_F(SmallCube, FunctionalTestCubeattInputAndOutputAttributes) {
QString inputCubePath = testCube->fileName();
CubeAttributeInput attributeInput("+3,2,4");
QString outputCubePath = tempDir.path() + "/bitTypeAndVirtualBandsCubeatt.cub";
CubeAttributeOutput attributeOutput("+200:300");

cubeatt(inputCubePath, attributeInput, outputCubePath, attributeOutput);

Cube outputCube(outputCubePath);

Statistics *outputStats = outputCube.statistics();
EXPECT_GE(outputStats->Minimum(), 200);
EXPECT_LE(outputStats->Maximum(), 300);
EXPECT_EQ(outputCube.bandCount(), 3);

Pvl *label = outputCube.label();
PvlGroup bandBin = label->findObject("IsisCube").findGroup("BandBin");
EXPECT_EQ(QString(bandBin["OriginalBand"][0]), "3");
EXPECT_EQ(QString(bandBin["OriginalBand"][1]), "2");
EXPECT_EQ(QString(bandBin["OriginalBand"][2]), "4");

// Test that DNs for each band have moved appropriately
EXPECT_DOUBLE_EQ(outputCube.statistics(1)->Average(), testCube->statistics(3)->Average());
EXPECT_DOUBLE_EQ(outputCube.statistics(2)->Average(), testCube->statistics(2)->Average());
EXPECT_DOUBLE_EQ(outputCube.statistics(3)->Average(), testCube->statistics(4)->Average());
}