Skip to content

Commit

Permalink
Merge branch 'DOI-USGS:dev' into bugfix/jigsawAdjustedPtCorrections
Browse files Browse the repository at this point in the history
  • Loading branch information
kledmundson authored Jan 17, 2025
2 parents 6deadc3 + 992df27 commit fa94d2f
Show file tree
Hide file tree
Showing 41 changed files with 2,935 additions and 2,644 deletions.
16 changes: 14 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ release.

## [Unreleased]

### Added
- Added serial number translation for ideal camera [#5662](https://github.com/DOI-USGS/ISIS3/issues/5662)

### Changed

### Fixed
- Fixed kaguyatc2isis invalid BandBin values [#5629](https://github.com/DOI-USGS/ISIS3/issues/5629)
- Fixed SpiceClient to handle redirect requests.
- Fixed jigsaw to default OUTADJUSTMENTH5 option to false and allow this feature to run on read-only images [#5700](https://github.com/DOI-USGS/ISIS3/issues/5700)
- Fixed Cube::fromIsd to add "LineScanTimes" table from HRSC isds [#5668](https://github.com/DOI-USGS/ISIS3/issues/5668)

## [9.0.0] - 09-25-2024

### Added
Expand All @@ -44,8 +55,10 @@ release.
- Added Chandrayaan2 template for isisimport
- Added majority replacement for reduce app [#5101](https://github.com/DOI-USGS/ISIS3/issues/5101).
- Added HRSC support in socetlinescankeywords [#5465](https://github.com/DOI-USGS/ISIS3/issues/5465)
- Added option to save and apply bundle adjustment values in `jigsaw` [#4474](https://github.com/DOI-USGS/ISIS3/issues/4474)
- Added the ability to pass column types in csv2table to set the column types in the resulting ISIS table [#5631](https://github.com/DOI-USGS/ISIS3/pull/5631)

### Changed
### Changed
- Refactored the pixel2map app
- Updated pixel2map documentation
- Changed PVL parsing to no longer allow valueless keywords [#5573](https://github.com/DOI-USGS/ISIS3/pull/5573)
Expand Down Expand Up @@ -99,7 +112,6 @@ file. Slightly modified the FunctionalTestJigsawBundleXYZ ctest accordingly. Iss
- Fixed gllssi2isis to support V1.1 data [#5396](https://github.com/DOI-USGS/ISIS3/issues/5396)

### Added
- Added option to save and apply bundle adjustment values in `jigsaw` [#4474](https://github.com/DOI-USGS/ISIS3/issues/4474)
- 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.2.0] - 2024-04-18
Expand Down
575 changes: 68 additions & 507 deletions README.md

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
channels:
- conda-forge
- defaults


dependencies:
- ale =0.10.0,<1
- aom
Expand Down
30 changes: 30 additions & 0 deletions isis/appdata/serialnumbers/IdealIdealSerialNumber.trn
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Group = Keyword1
Auto = 1
InputKey = SpacecraftName
InputGroup = "IsisCube,Instrument"
InputPosition = (IsisCube, Instrument)
OutputName = Keyword1
OutputPosition = (Group, SerialNumberKeywords)
Translation = (*, *)
End_Group

Group = Keyword2
Auto = 1
InputKey = InstrumentId
InputGroup = "IsisCube,Instrument"
InputPosition = (IsisCube, Instrument)
OutputName = Keyword2
OutputPosition = (Group, SerialNumberKeywords)
Translation = (*, *)
End_Group

Group = Keyword3
Auto = 1
InputKey = EphemerisTime
InputGroup = "IsisCube,Instrument"
InputPosition = (IsisCube, Instrument)
OutputName = Keyword3
OutputPosition = (Group, SerialNumberKeywords)
Translation = (*, *)
End_Group
End
218 changes: 218 additions & 0 deletions isis/src/base/apps/csv2table/csv2table.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
/** 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 "csv2table.h"

#include <vector>

#include <QRegularExpression>
#include <QString>

#include "Cube.h"
#include "CSVReader.h"
#include "IException.h"
#include "IString.h"
#include "Pvl.h"
#include "PvlObject.h"
#include "Table.h"
#include "TableField.h"
#include "TableRecord.h"

using namespace std;

namespace Isis {
/**
* csminit a cube in an Application
*
* @param ui The Application UI
* @param(out) log The Pvl that attempted models will be logged to
*/
void csv2table(UserInterface &ui, Pvl *log) {
// Read the CSV file and get the header
QString csvFileName = ui.GetFileName("csv");
CSVReader reader;
try {
reader = CSVReader(csvFileName, true);
}
catch(IException &e) {
QString msg = "Failed to read CSV file [" + csvFileName + "].";
throw IException(e, IException::Io, msg, _FILEINFO_);
}
int numColumns = reader.columns();
int numRows = reader.rows();
if (numColumns < 1 || numRows < 1) {
QString msg = "CSV file does not have data.\nFile has [" + toString(numRows) +
"] rows and [" + toString(numColumns) +"] columns.";
throw IException(IException::User, msg, _FILEINFO_);
}

std::vector<QString> fieldTypes;
ui.GetAsString("coltypes", fieldTypes);

std::vector<TableField::Type> tableTypes;
if (fieldTypes.size() == 1 && fieldTypes[0] == "") {
for (int i = 0; i < numColumns; i++) {
tableTypes.push_back(TableField::Double);
}
}
else {
if (fieldTypes.size() == numColumns) {
for (QString type: fieldTypes) {
QString upper_type = type.toUpper();
if (upper_type == "INTEGER") {
tableTypes.push_back(TableField::Type::Integer);
}
else if (upper_type == "DOUBLE") {
tableTypes.push_back(TableField::Type::Double);
}
else if (upper_type == "TEXT") {
tableTypes.push_back(TableField::Type::Text);
}
else if (upper_type == "REAL") {
tableTypes.push_back(TableField::Type::Real);
}
else {
QString msg = "Field [" + type + "] cannot be translated. Accepted types are "
"Integer, Double, Text, and Real";
throw IException(IException::User, msg, _FILEINFO_);
}
}
}
else {
int numFields = fieldTypes.size();
QString msg = "Number of fields provided does not equal the number of columns in the CSV. "
"Number of fields [" + toString(numFields) +
"] vs Number of Columns [" + toString(numColumns) + "]";
throw IException(IException::User, msg, _FILEINFO_);
}
}


CSVReader::CSVAxis header = reader.getHeader();

// Construct an empty table with the CSV header as field names
// Collect identical field names together, including those with (###) at the end, so a single
// table field with multiple values can be created.
TableRecord tableRow;
QRegularExpression rex(R"((?<name>\w+)(\((?<index>[0-9]*)\)|))");
for (int columnIndex = 0; columnIndex < numColumns; columnIndex++) {
QRegularExpressionMatch match = rex.match(header[columnIndex]);
if (match.hasMatch()) {
QString name = match.captured("name");
QString index = match.captured("index");

// If the next column header is different, create a field for this one
QRegularExpressionMatch nextMatch = (columnIndex<numColumns-1)?rex.match(header[columnIndex+1]):QRegularExpressionMatch();
if ((columnIndex == numColumns-1) || (nextMatch.hasMatch() && (name != nextMatch.captured("name")))) {
TableField columnField(name, tableTypes[columnIndex], (index.length()>0)?(index.toInt()+1):1);
tableRow += columnField;
}
}
}

QString tableName = ui.GetString("tablename");
Table table(tableName, tableRow);

// Fill the table from the csv
for (int rowIndex = 0; rowIndex < numRows; rowIndex++) {
CSVReader::CSVAxis csvRow = reader.getRow(rowIndex);
for (int columnIndex = 0, fieldIndex = 0; columnIndex < numColumns; ) {
if (tableRow[fieldIndex].size() == 1 ||
tableRow[fieldIndex].isText()) {
switch(tableTypes[columnIndex]) {
case TableField::Type::Integer:
tableRow[fieldIndex] = toInt(csvRow[columnIndex++]);
break;
case TableField::Type::Double:
tableRow[fieldIndex] = toDouble(csvRow[columnIndex++]);
break;
case TableField::Type::Text:
tableRow[fieldIndex] = QString(csvRow[columnIndex++]);
break;
case TableField::Type::Real:
tableRow[fieldIndex] = (float)toDouble(csvRow[columnIndex++]);
break;
}
}
else {
std::vector<int> intVector;
std::vector<double> dblVector;
std::vector<float> realVector;
QString strMsg = "TableRecord can't handle list of Strings";
switch(tableTypes[columnIndex]) {
case TableField::Type::Integer:
for (int arrayLen = 0; arrayLen < tableRow[fieldIndex].size(); arrayLen++) {
intVector.push_back(toInt(csvRow[columnIndex++]));
}
tableRow[fieldIndex] = intVector;
break;
case TableField::Type::Double:
for (int arrayLen = 0; arrayLen < tableRow[fieldIndex].size(); arrayLen++) {
dblVector.push_back(toDouble(csvRow[columnIndex++]));
}
tableRow[fieldIndex] = dblVector;
break;
case TableField::Type::Text:
throw IException(IException::User, strMsg, _FILEINFO_);
break;
case TableField::Type::Real:
for (int arrayLen = 0; arrayLen < tableRow[fieldIndex].size(); arrayLen++) {
realVector.push_back((float)toDouble(csvRow[columnIndex++]));
}
tableRow[fieldIndex] = realVector;
break;
}
intVector.clear();
dblVector.clear();
realVector.clear();
}
fieldIndex++;
}
table += tableRow;
}

// If a set of additional label keywords was given then add them to the table's pvl description
if (ui.WasEntered("label")) {
QString labelPvlFilename = ui.GetFileName("label");
Pvl labelPvl;
try {
labelPvl.read(labelPvlFilename);
}
catch(IException &e) {
QString msg = "Failed to read PVL label file [" + labelPvlFilename + "].";
throw IException(e, IException::Io, msg, _FILEINFO_);
}

PvlObject &tableLabel = table.Label();
for (int keyIndex = 0; keyIndex < labelPvl.keywords(); keyIndex++) {
tableLabel.addKeyword(labelPvl[keyIndex]);
}
}

// Write the table to the cube
QString outCubeFileName(ui.GetCubeName("to"));
Cube outCube;
try {
outCube.open(outCubeFileName, "rw");
}
catch(IException &e) {
QString msg = "Could not open output cube [" + outCubeFileName + "].";
throw IException(e, IException::Io, msg, _FILEINFO_);
}

try {
outCube.write(table);
}
catch(IException &e) {
QString msg = "Could not write output table [" + tableName +
"] to output cube [" + outCubeFileName + "].";
throw IException(e, IException::Io, msg, _FILEINFO_);
}

outCube.close();
}
}
18 changes: 18 additions & 0 deletions isis/src/base/apps/csv2table/csv2table.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef csv2table_h
#define csv2table_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. **/

/* SPDX-License-Identifier: CC0-1.0 */

#include "Pvl.h"
#include "UserInterface.h"

namespace Isis {
extern void csv2table(UserInterface &ui, Pvl *log=nullptr);
}

#endif
15 changes: 15 additions & 0 deletions isis/src/base/apps/csv2table/csv2table.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
Added ability to convert CSV files with indicies into table field arrays
instead of individual table fields.
</change>
<change name="Adam Paquette" date="2024-10-08">
Added the ability to pass types for each column in the CSV
</change>
</history>

<groups>
Expand Down Expand Up @@ -94,6 +97,18 @@
the cube it will be overwritten.
</description>
</parameter>

<parameter name = "coltypes">
<type>string</type>
<brief>Column types of the table</brief>
<description>
ISIS command line list of Tablefield types. Specified as such, '(type1, type2)'
where the allowed types are "Double", "Integer", "Float", "Text".
</description>
<default>
<item></item>
</default>
</parameter>
</group>

</groups>
Expand Down
Loading

0 comments on commit fa94d2f

Please sign in to comment.