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 lrowacphomap with versioned defaults for PHOALGO and PHOPARCUBE parameters #5452

Merged
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ release.
- Added new option in `ctxcal` to use monthly computed flatfield files for "Frown" removal in CTX images. [#5338](https://github.com/DOI-USGS/ISIS3/pull/5338)
- CSMCamera can now read and use the body rotation from ALE produced ISDs [#5072](https://github.com/DOI-USGS/ISIS3/pull/5072)
- CSMSkyMap added to CSMCamera for use with local rover projections in ISIS [#5072](https://github.com/DOI-USGS/ISIS3/pull/5072)

- Added versioned default values to lrowacphomap's PHOALGO and PHOPARCUBE parameters and updated lrowacphomap to handle them properly. [#5452](https://github.com/DOI-USGS/ISIS3/pull/5452)

## [8.1.0] - 2024-01-08

Expand Down
129 changes: 92 additions & 37 deletions isis/src/lro/apps/lrowacphomap/lrowacphomap.cpp
Original file line number Diff line number Diff line change
@@ -1,42 +1,76 @@
#include <string>
#include "lrowacphomap.h"

#include <memory>
#include <vector>

#include <QList>
#include <QString>

#include "Buffer.h"
#include "Cube.h"
#include "CubeAttribute.h"
#include "FileName.h"
#include "HapkeLRO.h"
#include "HapkeLROC.h"
#include "IException.h"
#include "PhotometricFunction.h"
#include "ProcessByBrick.h"
#include "Pvl.h"
#include "PvlGroup.h"
#include "SpecialPixel.h"

#include "lrowacphomap.h"

using namespace std;
using namespace Isis;

#include "UserInterface.h"

namespace Isis {
/**
* @brief Apply Hapke photometric correction to a WAC cube.
*
* This is the programmatic interface to the lrowacphomap application.
*
* @author 2021-08-02 Cordell Michaud
*
* @internal
* @history 2021-08-02 Cordell Michaud - Code adapted from lrowacphomap by Kris Becker
* @history 2024-04-02 Cordell Michaud - Changed icube to be a regular Cube object rather than
* a pointer
*
* @param ui the user interface to parse parameters from
*/
Pvl lrowacphomap(UserInterface &ui) {
// Set up the input cube
Cube *icube = new Cube();
Cube icube;
CubeAttributeInput inAtt = ui.GetInputAttribute("FROM");
if (inAtt.bands().size() != 0) {
icube->setVirtualBands(inAtt.bands());
icube.setVirtualBands(inAtt.bands());
}
icube->open(ui.GetCubeName("FROM"));
icube.open(ui.GetCubeName("FROM"));

Pvl log = lrowacphomap(icube, ui);
Pvl log = lrowacphomap(&icube, ui);

delete icube;
icube = NULL;
icube.close();

return log;
}

/**
* @brief Apply Hapke photometric correction to a WAC cube.
*
* This is the programmatic interface to the lrowacphomap application.
*
* @author 2021-08-02 Cordell Michaud
*
* @internal
* @history 2021-08-02 Cordell Michaud - Code adapted from lrowacphomap by Kris Becker
* @history 2024-04-02 Cordell Michaud - Converted phoLro and phoLroc to smart pointers and
* added handling for new PHOALGO and PHOPARCUBE defaults
*
* @param icube the input cube to apply Hapke photometric correction to
* @param ui the user interface to parse parameters from
*/
Pvl lrowacphomap(Cube *icube, UserInterface &ui) {
Pvl log;

HapkeLRO *phoLro = NULL;
HapkeLROC *phoLroc = NULL;
std::shared_ptr<HapkeLRO> phoLro;
std::shared_ptr<HapkeLROC> phoLroc;
QString algoName;

bool normalized;
Expand All @@ -54,13 +88,14 @@ namespace Isis {

if (ui.WasEntered("BACKPLANE")) {
if (icube->bandCount() != 1) {
string msg = "Invalid Image: The backplane option can only be used with a single image band at a time.";
QString msg = "Invalid Image: The backplane option can only be used with a single image "
"band at a time.";
throw IException(IException::User, msg, _FILEINFO_);
}

CubeAttributeInput backplaneCai = ui.GetInputAttribute("BACKPLANE");

vector<QString> bands = backplaneCai.bands();
std::vector<QString> bands = backplaneCai.bands();

if (bands.size() == 0) {
bands.clear();
Expand All @@ -71,7 +106,7 @@ namespace Isis {
bands.push_back("5");
}
else if (bands.size() != 5) {
string msg = "Invalid Backplane: The backplane must be exactly 5 bands";
QString msg = "Invalid Backplane: The backplane must be exactly 5 bands";
throw IException(IException::User, msg, _FILEINFO_);
}

Expand All @@ -91,13 +126,32 @@ namespace Isis {
}

// Get the name of the parameter files
Pvl par(ui.GetFileName("PHOALGO"));
Cube *parCube = new Cube();
CubeAttributeInput parCubeAtt = ui.GetInputAttribute("PHOPARCUBE");
if (parCubeAtt.bands().size() != 0) {
parCube->setVirtualBands(parCubeAtt.bands());
QString algoFile = ui.GetAsString("PHOALGO");
FileName algoFileName(algoFile);
if (algoFileName.isVersioned()) {
algoFileName = algoFileName.highestVersion();
}
if (!algoFileName.fileExists()) {
QString msg = algoFileName.expanded() + " does not exist.";
throw IException(IException::User, msg, _FILEINFO_);
}
Pvl par(algoFileName.expanded());

QString parCubeFile = ui.GetCubeName("PHOPARCUBE");
FileName parCubeFileName(parCubeFile);
if (parCubeFileName.isVersioned()) {
parCubeFileName = parCubeFileName.highestVersion();
}
if (!parCubeFileName.fileExists()) {
QString msg = parCubeFileName.expanded() + " does not exist.";
throw IException(IException::User, msg, _FILEINFO_);
}
CubeAttributeInput parCubeAtt(parCubeFileName);
Cube parCube(parCubeFileName);
std::vector<QString> parCubeBands = parCubeAtt.bands();
if (parCubeBands.size() != 0) {
parCube.setVirtualBands(QList<QString>(parCubeBands.begin(), parCubeBands.end()));
}
parCube->open(ui.GetCubeName("PHOPARCUBE"));

p.SetBrickSize(128, 128, icube->bandCount());

Expand All @@ -107,7 +161,7 @@ namespace Isis {
normalized = ui.GetBoolean("NORMALIZED");

if (algoName == "HAPKELRO") {
phoLro = new HapkeLRO(par, *icube, !useBackplane, parCube);
phoLro = std::make_shared<HapkeLRO>(par, *icube, !useBackplane, &parCube);
phoLro->setMinimumPhaseAngle(ui.GetDouble("MINPHASE"));
phoLro->setMaximumPhaseAngle(ui.GetDouble("MAXPHASE"));
phoLro->setMinimumEmissionAngle(ui.GetDouble("MINEMISSION"));
Expand All @@ -118,7 +172,7 @@ namespace Isis {
phoLro->setNormalized(normalized);
}
else if (algoName == "HAPKELROC") {
phoLroc = new HapkeLROC(par, *icube, !useBackplane, parCube);
phoLroc = std::make_shared<HapkeLROC>(par, *icube, !useBackplane, &parCube);
phoLroc->setMinimumPhaseAngle(ui.GetDouble("MINPHASE"));
phoLroc->setMaximumPhaseAngle(ui.GetDouble("MAXPHASE"));
phoLroc->setMinimumEmissionAngle(ui.GetDouble("MINEMISSION"));
Expand Down Expand Up @@ -147,11 +201,13 @@ namespace Isis {
*
* @internal
* @history 2021-07-19 Cordell Michaud - Code adapted from lrowacphomap by Kris Becker
* @history 2024-04-02 Cordell Michaud - Changed to capture phoLro and phoLroc by value
*
* @param in Buffer containing input data
* @param out Buffer of photometrically corrected data
*/
auto phoCal = [&phoLro, &phoLroc, algoName, useDem, photometryOnly](Buffer &in, Buffer &out) -> void {
auto phoCal = [phoLro, phoLroc, algoName, useDem, photometryOnly](
Buffer &in, Buffer &out) -> void {
for (int i = 0; i < in.size(); i++) {
// Don't correct special pixels
if (IsSpecial(in[i])) {
Expand Down Expand Up @@ -189,12 +245,13 @@ namespace Isis {
*
* @internal
* @history 2021-07-19 Cordell Michaud - Code adapted from lrowacphomap by Kris Becker
* @history 2024-04-02 Cordell Michaud - Changed to capture phoLro and phoLroc by value
*
* @param in Buffer containing input data
* @param out Buffer of photometrically corrected data
*/
auto phoCalWithBackplane = [&phoLro, &phoLroc, algoName, photometryOnly](std::vector<Isis::Buffer *> &in, std::vector<Isis::Buffer *> &out) -> void {

auto phoCalWithBackplane = [phoLro, phoLroc, algoName, photometryOnly](
std::vector<Buffer *> &in, std::vector<Buffer *> &out) -> void {
Buffer &image = *in[0];
Buffer &phase = *in[1];
Buffer &emission = *in[2];
Expand All @@ -208,17 +265,20 @@ namespace Isis {
if (IsSpecial(image[i])) {
calibrated[i] = image[i];
}
else if (IsSpecial(phase[i]) || IsSpecial(emission[i]) || IsSpecial(incidence[i]) || IsSpecial(lat[i]) || IsSpecial(lon[i])) {
else if (IsSpecial(phase[i]) || IsSpecial(emission[i]) || IsSpecial(incidence[i])
|| IsSpecial(lat[i]) || IsSpecial(lon[i])) {
calibrated[i] = Isis::Null;
}
else {
// Get correction and test for validity
double ph = Null;
if (algoName == "HAPKELRO") {
ph = phoLro->photometry(incidence[i], emission[i], phase[i], lat[i], lon[i], image.Band(i));
ph = phoLro->photometry(incidence[i], emission[i], phase[i], lat[i], lon[i],
image.Band(i));
}
else if (algoName == "HAPKELROC") {
ph = phoLroc->photometry(incidence[i], emission[i], phase[i], lat[i], lon[i], image.Band(i));
ph = phoLroc->photometry(incidence[i], emission[i], phase[i], lat[i], lon[i],
image.Band(i));
}

if (!photometryOnly) {
Expand Down Expand Up @@ -253,11 +313,6 @@ namespace Isis {
ocube->putGroup(photo);
log.addGroup(photo);

delete phoLro;
phoLro = NULL;
delete phoLroc;
phoLroc = NULL;

return log;
}
}
7 changes: 7 additions & 0 deletions isis/src/lro/apps/lrowacphomap/lrowacphomap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@
<change name="Cordell Michaud" date="2022-05-10">
Refactored lrowacphomap for testability and added functional tests.
</change>
<change name="Cordell Michaud" date="2024-04-02">
Added new default for PHOALGO.
Added new default for PHOPARCUBE.
</change>
</history>

<category>
Expand Down Expand Up @@ -326,6 +330,8 @@
<parameter name="PHOALGO">
<type>filename</type>
<fileMode>input</fileMode>
<defaultPath>$lro/calibration</defaultPath>
<default><item>$lro/calibration/WAC_hapke_full.????.pvl</item></default>
<brief>
Pvl file
</brief>
Expand Down Expand Up @@ -353,6 +359,7 @@
<parameter name="PHOPARCUBE">
<type>cube</type>
<fileMode>input</fileMode>
<default><item>$lro/calibration/WAC_global_7bands_1x1_wbhs70NS_const_each_pole.????.cub</item></default>
<brief>
Parameter cube
</brief>
Expand Down
Loading