From 53ff0bf13c0d0d5c7e1211e2f347aaa47f0de6ba Mon Sep 17 00:00:00 2001 From: Austin Sanders Date: Thu, 4 Jun 2020 11:40:49 -0700 Subject: [PATCH 1/2] Added and tested functionality for 'N/A' stats calculation. --- isis/src/base/apps/stats/stats.cpp | 19 +++++++++++++++---- isis/tests/statsTests.cpp | 9 +++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/isis/src/base/apps/stats/stats.cpp b/isis/src/base/apps/stats/stats.cpp index 1760f0604a..177cc6bf00 100644 --- a/isis/src/base/apps/stats/stats.cpp +++ b/isis/src/base/apps/stats/stats.cpp @@ -21,17 +21,17 @@ namespace Isis { * the ISIS3 stats application. * * @param ui The User Interface to parse the parameters from - */ + */ void stats(UserInterface &ui) { Cube *inputCube = new Cube(); - + CubeAttributeInput inAtt(ui.GetAsString("FROM")); inputCube->setVirtualBands(inAtt.bands()); - + inputCube->open(ui.GetFileName("FROM")); stats(inputCube, ui); } - + /** * Compute the stats for an ISIS cube. This is the programmatic interface to * the ISIS3 stats application. @@ -133,6 +133,17 @@ namespace Isis { results += PvlKeyword("Minimum", toString(stats->Minimum())); results += PvlKeyword("Maximum", toString(stats->Maximum())); results += PvlKeyword("Sum", toString(stats->Sum())); + } else { + results += PvlKeyword("Average", "N/A"); + results += PvlKeyword("StandardDeviation", "N/A"); + results += PvlKeyword("Variance", "N/A"); + // These statistics only worked on a histogram + results += PvlKeyword("Median", "N/A"); + results += PvlKeyword("Mode", "N/A"); + results += PvlKeyword("Skew", "N/A"); + results += PvlKeyword("Minimum", "N/A"); + results += PvlKeyword("Maximum", "N/A"); + results += PvlKeyword("Sum", "N/A"); } results += PvlKeyword("TotalPixels", toString(stats->TotalPixels())); results += PvlKeyword("ValidPixels", toString(stats->ValidPixels())); diff --git a/isis/tests/statsTests.cpp b/isis/tests/statsTests.cpp index 09edc877c7..a5527064c2 100644 --- a/isis/tests/statsTests.cpp +++ b/isis/tests/statsTests.cpp @@ -134,6 +134,15 @@ TEST_F(stats_MockHist, TestStats) { EXPECT_EQ(1, (int) (band2Stats.findKeyword("LrsPixels"))); EXPECT_EQ(1, (int) (band2Stats.findKeyword("HisPixels"))); EXPECT_EQ(1, (int) (band2Stats.findKeyword("HrsPixels"))); + EXPECT_TRUE("N/A" == (band2Stats.findKeyword("Average"))); + EXPECT_TRUE("N/A" == (band2Stats.findKeyword("StandardDeviation"))); + EXPECT_TRUE("N/A" == (band2Stats.findKeyword("Variance"))); + EXPECT_TRUE("N/A" == (band2Stats.findKeyword("Median"))); + EXPECT_TRUE("N/A" == (band2Stats.findKeyword("Mode"))); + EXPECT_TRUE("N/A" == (band2Stats.findKeyword("Skew"))); + EXPECT_TRUE("N/A" == (band2Stats.findKeyword("Minimum"))); + EXPECT_TRUE("N/A" == (band2Stats.findKeyword("Maximum"))); + EXPECT_TRUE("N/A" == (band2Stats.findKeyword("Sum"))); } TEST(stats, ValidMinimum) { From 85a44e179e2f5a4d416ad40c1800165a0cec94f6 Mon Sep 17 00:00:00 2001 From: Austin Sanders Date: Thu, 4 Jun 2020 14:32:27 -0700 Subject: [PATCH 2/2] Added changelog and updated style to conform with isis standards. --- isis/src/base/apps/stats/stats.cpp | 4 +- isis/src/base/apps/stats/stats.xml | 83 ++++++++++++++++-------------- 2 files changed, 45 insertions(+), 42 deletions(-) diff --git a/isis/src/base/apps/stats/stats.cpp b/isis/src/base/apps/stats/stats.cpp index 177cc6bf00..d192551a25 100644 --- a/isis/src/base/apps/stats/stats.cpp +++ b/isis/src/base/apps/stats/stats.cpp @@ -133,11 +133,11 @@ namespace Isis { results += PvlKeyword("Minimum", toString(stats->Minimum())); results += PvlKeyword("Maximum", toString(stats->Maximum())); results += PvlKeyword("Sum", toString(stats->Sum())); - } else { + } + else { results += PvlKeyword("Average", "N/A"); results += PvlKeyword("StandardDeviation", "N/A"); results += PvlKeyword("Variance", "N/A"); - // These statistics only worked on a histogram results += PvlKeyword("Median", "N/A"); results += PvlKeyword("Mode", "N/A"); results += PvlKeyword("Skew", "N/A"); diff --git a/isis/src/base/apps/stats/stats.xml b/isis/src/base/apps/stats/stats.xml index 330529b6b8..de503ce764 100644 --- a/isis/src/base/apps/stats/stats.xml +++ b/isis/src/base/apps/stats/stats.xml @@ -7,12 +7,12 @@

This program computes a set of statistics for the pixels in each selected band - of an image cube, and outputs the results of each band. By default, all bands are - processed. The stats program generates statistics that will help you find new insights + of an image cube, and outputs the results of each band. By default, all bands are + processed. The stats program generates statistics that will help you find new insights in your data to make more accurate predictions and achieve better outcomes.

- +

Output:

@@ -20,9 +20,9 @@

The statistics are output to both the screen and the print.prt file in PVL format. Additionally, if the user specifies a file using the TO parameter, the statistics are written to that file in - PVL format (default) or as a comma delimited text file (FLAT file), as specified by the FORMAT parameter. - For multi-band images, each band has its own statistics information that will be appended to the - output file. The contents of the PVL file can be read using the getkey program. The + PVL format (default) or as a comma delimited text file (FLAT file), as specified by the FORMAT parameter. + For multi-band images, each band has its own statistics information that will be appended to the + output file. The contents of the PVL file can be read using the getkey program. The comma delimited text file can be imported into Excel or other applications. The statistics calculated and reported are as follows:

@@ -46,7 +46,7 @@ Maximum Low instrument saturation (LIS) pixels Sum High instrument saturation (HIS) pixels - +

If the output file exists and the APPEND parameter is set to "no," the contents will be overwritten. @@ -58,9 +58,9 @@ Sum High instrument saturation (HIS) pixels

You may process one or a few specific bands if you indicate the band(s) in which you desire - to gather statistics. A band may be specified by simply placing a - plus sign and the band number after the input filename (e.g., peaks.cub+3). For several - bands, commas and hyphens are used to communicate effectively with the program as in the + to gather statistics. A band may be specified by simply placing a + plus sign and the band number after the input filename (e.g., peaks.cub+3). For several + bands, commas and hyphens are used to communicate effectively with the program as in the following example: peaks.cub+2,4-6.

@@ -109,21 +109,21 @@ Sum High instrument saturation (HIS) pixels Fixed appTest to comply to changes in iString - + Added Above Range, Below Range reports - Removed references to CubeInfo + Removed references to CubeInfo - A bug where the VALIDMIN,VALIDMAX were ignored was fixed; + A bug where the VALIDMIN,VALIDMAX were ignored was fixed; these should always be used. Added the Format option for the output file. - Added Band Keyword - displays the first physical band used to get the + Added Band Keyword - displays the first physical band used to get the stats @@ -140,6 +140,9 @@ Sum High instrument saturation (HIS) pixels general edits for clarity. Also added undocumented output statistics to the list in the description. + + Updated to fill columns with N/A in cases where images contained only + special or invalid pixels. @@ -163,8 +166,8 @@ Sum High instrument saturation (HIS) pixels Input cube - This specifies the input cube. The default is - to calculate statistics for each band in the input cube, but this can be + This specifies the input cube. The default is + to calculate statistics for each band in the input cube, but this can be overridden using the band specifier (e.g., file.cub+3). @@ -182,8 +185,8 @@ Sum High instrument saturation (HIS) pixels No output file is created - This text file will contain the statistics for each individual band. - If it is written in PVL format (default), the values can be read using the + This text file will contain the statistics for each individual band. + If it is written in PVL format (default), the values can be read using the getkey program. This is useful for developing scripts. If it is written as a comma delimited text file (FLAT) the output can be easily imported into spreadsheet applications like Excel. @@ -199,9 +202,9 @@ Sum High instrument saturation (HIS) pixels Output file format (PVL or comma delimited text) - This is the format type for the output file. PVL format is the + This is the format type for the output file. PVL format is the default. The format is ignored unless the TO parameter is specified. - + PVL - + boolean @@ -233,15 +236,15 @@ Sum High instrument saturation (HIS) pixels

- If this option is not selected, the output from the stats + If this option is not selected, the output from the stats application is appended to the output file. If this option is - set to "NO" or "FALSE," any information in the TO file is + set to "NO" or "FALSE," any information in the TO file is overwritten.

- Note: This will append the formatted results to the end of the TO + Note: This will append the formatted results to the end of the TO file without regard to the formatting of the current contents. -

+

TRUE
@@ -258,7 +261,7 @@ Sum High instrument saturation (HIS) pixels No minimum DN value - The statistics will exclude any DN + The statistics will exclude any DN values below this value. @@ -272,7 +275,7 @@ Sum High instrument saturation (HIS) pixels No maximum DN value - The statistics will exclude any DN + The statistics will exclude any DN values above this value. @@ -283,17 +286,17 @@ Sum High instrument saturation (HIS) pixels Calculate statistics for all bands in a cube - This example shows the statistics computed for all bands in + This example shows the statistics computed for all bands in the input cube. When no band is specified by the user, stats - default behavior is to calculate statistics for all bands in a cube. + default behavior is to calculate statistics for all bands in a cube. from=peaks.cub to=peaks0_stats.log - Command to run stats in the command line mode using all bands in - peaks.cub and output the results to peaks0_stats.log. + Command to run stats in the command line mode using all bands in + peaks.cub and output the results to peaks0_stats.log. @@ -309,12 +312,12 @@ Sum High instrument saturation (HIS) pixels - + Calculate statistics for a single band from an input cube - This example shows the statistics computed from band 3 of the input - cube. A band may be specified by simply placing the plus sign and + This example shows the statistics computed from band 3 of the input + cube. A band may be specified by simply placing the plus sign and the band number after the input filename. @@ -322,7 +325,7 @@ Sum High instrument saturation (HIS) pixels from=peaks.cub+3 to=peaks1_stats.log - Command to run stats in the command line mode using the third band + Command to run stats in the command line mode using the third band of peaks.cub and output the results to peaks1_stats.log. @@ -342,9 +345,9 @@ Sum High instrument saturation (HIS) pixels Calculate statistics for multiple bands from an input cube - This example shows the statistics computed for selected bands of a cube. - In addition to the plus suffix, the comma and hyphen are used to specify - multiple bands from the input cube to process. + This example shows the statistics computed for selected bands of a cube. + In addition to the plus suffix, the comma and hyphen are used to specify + multiple bands from the input cube to process. @@ -352,7 +355,7 @@ Sum High instrument saturation (HIS) pixels Command to run stats in the command line mode using the second, fourth, - fifth, and sixth bands of peaks.cub and output the results to + fifth, and sixth bands of peaks.cub and output the results to peaks2_stats.log.