Skip to content

Commit

Permalink
Feature #2204 sum (#2205)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnHalleyGotway authored Jul 17, 2022
1 parent 312aa93 commit e8af847
Show file tree
Hide file tree
Showing 12 changed files with 223 additions and 13 deletions.
2 changes: 1 addition & 1 deletion data/config/Ascii2NcConfig_default
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ time_summary = {
width = 600;
grib_code = [ 11, 204, 211 ];
obs_var = [];
type = [ "min", "max", "range", "mean", "stdev", "median", "p80" ];
type = [ "min", "max", "range", "mean", "stdev", "median", "p80", "sum" ];
vld_freq = 0;
vld_thresh = 0.0;
}
Expand Down
2 changes: 1 addition & 1 deletion data/config/IODA2NCConfig_default
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ time_summary = {
width = 600;
grib_code = [];
obs_var = [ "TMP", "WDIR", "RH" ];
type = [ "min", "max", "range", "mean", "stdev", "median", "p80" ];
type = [ "min", "max", "range", "mean", "stdev", "median", "p80", "sum" ];
vld_freq = 0;
vld_thresh = 0.0;
}
Expand Down
2 changes: 1 addition & 1 deletion data/config/Madis2NcConfig_default
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ time_summary = {
width = 600;
grib_code = [ 11, 204, 211 ];
obs_var = [];
type = [ "min", "max", "range", "mean", "stdev", "median", "p80" ];
type = [ "min", "max", "range", "mean", "stdev", "median", "p80", "sum" ];
vld_freq = 0;
vld_thresh = 0.0;
}
Expand Down
2 changes: 1 addition & 1 deletion data/config/PB2NCConfig_default
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ time_summary = {
width = 600;
grib_code = [];
obs_var = [ "TMP", "WDIR", "RH" ];
type = [ "min", "max", "range", "mean", "stdev", "median", "p80" ];
type = [ "min", "max", "range", "mean", "stdev", "median", "p80", "sum" ];
vld_freq = 0;
vld_thresh = 0.0;
}
Expand Down
18 changes: 14 additions & 4 deletions docs/Users_Guide/config_options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2236,10 +2236,17 @@ one hour prior:
width = { beg = -3600; end = 0; }
The summaries will only be calculated for the specified GRIB codes.
The supported summaries are "min" (minimum), "max" (maximum), "range",
"mean", "stdev" (standard deviation), "median" and "p##" (percentile, with
the desired percentile value specified in place of ##).
The summaries will only be calculated for the specified GRIB codes
or observation variable ("obs_var") names.

When determining which observations fall within a time interval, data for the
beginning timestamp is included while data for the ending timestamp is excluded.
Users may need to adjust the "beg" and "end" settings in the "width" dictionary
to include the desired observations in each time interval.

The supported time summaries are "min" (minimum), "max" (maximum), "range",
"mean", "stdev" (standard deviation), "median", "sum", and "p##" (percentile,
with the desired percentile value specified in place of ##).

The "vld_freq" and "vld_thresh" options may be used to require that a certain
ratio of observations must be present and contain valid data within the time
Expand All @@ -2250,6 +2257,9 @@ setting "vld_thresh = 0.5" requires that at least 15 of the 30 expected
observations be present and valid for a summary value to be written. The
default "vld_thresh = 0.0" setting will skip over this logic.

When using the "sum" option, users should specify "vld_thresh = 1.0" to avoid
missing data values from affecting the resulting sum value.

The variable names are saved to NetCDF file if they are given instead of
grib_codes which are not available for non GRIB input. The "obs_var" option
was added and works like "grib_code" option (string value VS. int value).
Expand Down
52 changes: 52 additions & 0 deletions internal/test_unit/config/Ascii2NcConfig_rain_01H_sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
////////////////////////////////////////////////////////////////////////////////
//
// ASCII2NC configuration file.
//
// For additional information, please see the MET User's Guide.
//
////////////////////////////////////////////////////////////////////////////////

//
// The parameters listed below are used to summarize the ASCII data read in
//

//
// Time periods for the summarization
// obs_var (string array) is added and works like grib_code (int array)
// when the obs name is given instead of grib_code
//

time_summary = {
flag = TRUE;
raw_data = FALSE;
beg = "00";
end = "23";
step = 3600;
width = { beg = -3599; end = 1; }
grib_code = [ ];
obs_var = [ "rain" ];
type = [ "sum" ];
vld_freq = 15*60;
vld_thresh = 1.0;
}

//
// Mapping of input little_r report types to output message types
//
message_type_map = [
{ key = "FM-12 SYNOP"; val = "ADPSFC"; },
{ key = "FM-13 SHIP"; val = "SFCSHP"; },
{ key = "FM-15 METAR"; val = "ADPSFC"; },
{ key = "FM-18 BUOY"; val = "SFCSHP"; },
{ key = "FM-281 QSCAT"; val = "ASCATW"; },
{ key = "FM-32 PILOT"; val = "ADPUPA"; },
{ key = "FM-35 TEMP"; val = "ADPUPA"; },
{ key = "FM-88 SATOB"; val = "SATWND"; },
{ key = "FM-97 ACARS"; val = "AIRCFT"; }
];

//
// Indicate a version number for the contents of this configuration file.
// The value should generally not be modified.
//
version = "V11.0.0";
16 changes: 16 additions & 0 deletions internal/test_unit/xml/unit_ascii2nc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,20 @@
</output>
</test>

<test name="ascii2nc_rain_01H_sum">
<exec>&MET_BIN;/ascii2nc</exec>
<param> \
&DATA_DIR_OBS;/ascii/aws/aws_20220609_020000.txt \
&DATA_DIR_OBS;/ascii/aws/aws_20220609_021500.txt \
&DATA_DIR_OBS;/ascii/aws/aws_20220609_023000.txt \
&DATA_DIR_OBS;/ascii/aws/aws_20220609_024500.txt \
&DATA_DIR_OBS;/ascii/aws/aws_20220609_030000.txt \
&OUTPUT_DIR;/ascii2nc/aws_2022060903_rain_01H_sum.nc \
-config &CONFIG_DIR;/Ascii2NcConfig_rain_01H_sum
</param>
<output>
<point_nc>&OUTPUT_DIR;/ascii2nc/aws_2022060903_rain_01H_sum.nc</point_nc>
</output>
</test>

</met_test>
1 change: 1 addition & 0 deletions src/libcode/vx_summary/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ libvx_summary_a_SOURCES = \
summary_calc_mean.cc summary_calc_mean.h \
summary_calc_median.cc summary_calc_median.h \
summary_calc_min.cc summary_calc_min.h \
summary_calc_sum.cc summary_calc_sum.h \
summary_calc_percentile.cc summary_calc_percentile.h \
summary_calc_range.cc summary_calc_range.h \
summary_calc_stdev.cc summary_calc_stdev.h \
Expand Down
20 changes: 20 additions & 0 deletions src/libcode/vx_summary/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ am_libvx_summary_a_OBJECTS = libvx_summary_a-summary_calc.$(OBJEXT) \
libvx_summary_a-summary_calc_mean.$(OBJEXT) \
libvx_summary_a-summary_calc_median.$(OBJEXT) \
libvx_summary_a-summary_calc_min.$(OBJEXT) \
libvx_summary_a-summary_calc_sum.$(OBJEXT) \
libvx_summary_a-summary_calc_percentile.$(OBJEXT) \
libvx_summary_a-summary_calc_range.$(OBJEXT) \
libvx_summary_a-summary_calc_stdev.$(OBJEXT) \
Expand Down Expand Up @@ -142,6 +143,7 @@ am__depfiles_remade = ./$(DEPDIR)/libvx_summary_a-summary_calc.Po \
./$(DEPDIR)/libvx_summary_a-summary_calc_percentile.Po \
./$(DEPDIR)/libvx_summary_a-summary_calc_range.Po \
./$(DEPDIR)/libvx_summary_a-summary_calc_stdev.Po \
./$(DEPDIR)/libvx_summary_a-summary_calc_sum.Po \
./$(DEPDIR)/libvx_summary_a-summary_key.Po \
./$(DEPDIR)/libvx_summary_a-summary_obs.Po \
./$(DEPDIR)/libvx_summary_a-time_summary_interval.Po
Expand Down Expand Up @@ -357,6 +359,7 @@ libvx_summary_a_SOURCES = \
summary_calc_mean.cc summary_calc_mean.h \
summary_calc_median.cc summary_calc_median.h \
summary_calc_min.cc summary_calc_min.h \
summary_calc_sum.cc summary_calc_sum.h \
summary_calc_percentile.cc summary_calc_percentile.h \
summary_calc_range.cc summary_calc_range.h \
summary_calc_stdev.cc summary_calc_stdev.h \
Expand Down Expand Up @@ -422,6 +425,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvx_summary_a-summary_calc_percentile.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvx_summary_a-summary_calc_range.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvx_summary_a-summary_calc_stdev.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvx_summary_a-summary_calc_sum.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvx_summary_a-summary_key.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvx_summary_a-summary_obs.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvx_summary_a-time_summary_interval.Po@am__quote@ # am--include-marker
Expand Down Expand Up @@ -516,6 +520,20 @@ libvx_summary_a-summary_calc_min.obj: summary_calc_min.cc
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libvx_summary_a_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libvx_summary_a-summary_calc_min.obj `if test -f 'summary_calc_min.cc'; then $(CYGPATH_W) 'summary_calc_min.cc'; else $(CYGPATH_W) '$(srcdir)/summary_calc_min.cc'; fi`

libvx_summary_a-summary_calc_sum.o: summary_calc_sum.cc
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libvx_summary_a_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libvx_summary_a-summary_calc_sum.o -MD -MP -MF $(DEPDIR)/libvx_summary_a-summary_calc_sum.Tpo -c -o libvx_summary_a-summary_calc_sum.o `test -f 'summary_calc_sum.cc' || echo '$(srcdir)/'`summary_calc_sum.cc
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libvx_summary_a-summary_calc_sum.Tpo $(DEPDIR)/libvx_summary_a-summary_calc_sum.Po
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='summary_calc_sum.cc' object='libvx_summary_a-summary_calc_sum.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libvx_summary_a_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libvx_summary_a-summary_calc_sum.o `test -f 'summary_calc_sum.cc' || echo '$(srcdir)/'`summary_calc_sum.cc

libvx_summary_a-summary_calc_sum.obj: summary_calc_sum.cc
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libvx_summary_a_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libvx_summary_a-summary_calc_sum.obj -MD -MP -MF $(DEPDIR)/libvx_summary_a-summary_calc_sum.Tpo -c -o libvx_summary_a-summary_calc_sum.obj `if test -f 'summary_calc_sum.cc'; then $(CYGPATH_W) 'summary_calc_sum.cc'; else $(CYGPATH_W) '$(srcdir)/summary_calc_sum.cc'; fi`
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libvx_summary_a-summary_calc_sum.Tpo $(DEPDIR)/libvx_summary_a-summary_calc_sum.Po
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='summary_calc_sum.cc' object='libvx_summary_a-summary_calc_sum.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libvx_summary_a_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libvx_summary_a-summary_calc_sum.obj `if test -f 'summary_calc_sum.cc'; then $(CYGPATH_W) 'summary_calc_sum.cc'; else $(CYGPATH_W) '$(srcdir)/summary_calc_sum.cc'; fi`

libvx_summary_a-summary_calc_percentile.o: summary_calc_percentile.cc
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libvx_summary_a_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libvx_summary_a-summary_calc_percentile.o -MD -MP -MF $(DEPDIR)/libvx_summary_a-summary_calc_percentile.Tpo -c -o libvx_summary_a-summary_calc_percentile.o `test -f 'summary_calc_percentile.cc' || echo '$(srcdir)/'`summary_calc_percentile.cc
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libvx_summary_a-summary_calc_percentile.Tpo $(DEPDIR)/libvx_summary_a-summary_calc_percentile.Po
Expand Down Expand Up @@ -733,6 +751,7 @@ distclean: distclean-am
-rm -f ./$(DEPDIR)/libvx_summary_a-summary_calc_percentile.Po
-rm -f ./$(DEPDIR)/libvx_summary_a-summary_calc_range.Po
-rm -f ./$(DEPDIR)/libvx_summary_a-summary_calc_stdev.Po
-rm -f ./$(DEPDIR)/libvx_summary_a-summary_calc_sum.Po
-rm -f ./$(DEPDIR)/libvx_summary_a-summary_key.Po
-rm -f ./$(DEPDIR)/libvx_summary_a-summary_obs.Po
-rm -f ./$(DEPDIR)/libvx_summary_a-time_summary_interval.Po
Expand Down Expand Up @@ -789,6 +808,7 @@ maintainer-clean: maintainer-clean-am
-rm -f ./$(DEPDIR)/libvx_summary_a-summary_calc_percentile.Po
-rm -f ./$(DEPDIR)/libvx_summary_a-summary_calc_range.Po
-rm -f ./$(DEPDIR)/libvx_summary_a-summary_calc_stdev.Po
-rm -f ./$(DEPDIR)/libvx_summary_a-summary_calc_sum.Po
-rm -f ./$(DEPDIR)/libvx_summary_a-summary_key.Po
-rm -f ./$(DEPDIR)/libvx_summary_a-summary_obs.Po
-rm -f ./$(DEPDIR)/libvx_summary_a-time_summary_interval.Po
Expand Down
43 changes: 43 additions & 0 deletions src/libcode/vx_summary/summary_calc_sum.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
// ** Copyright UCAR (c) 1992 - 2022
// ** University Corporation for Atmospheric Research (UCAR)
// ** National Center for Atmospheric Research (NCAR)
// ** Research Applications Lab (RAL)
// ** P.O.Box 3000, Boulder, Colorado, 80307-3000, USA
// *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*


////////////////////////////////////////////////////////////////////////


using namespace std;

#include <iostream>

#include "summary_calc_sum.h"

////////////////////////////////////////////////////////////////////////


//
// Code for class SummaryCalcSum
//


////////////////////////////////////////////////////////////////////////


SummaryCalcSum::SummaryCalcSum() :
SummaryCalc()
{
}

////////////////////////////////////////////////////////////////////////

SummaryCalcSum::~SummaryCalcSum()
{
}

////////////////////////////////////////////////////////////////////////
// Protected/Private Methods
////////////////////////////////////////////////////////////////////////
56 changes: 56 additions & 0 deletions src/libcode/vx_summary/summary_calc_sum.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
// ** Copyright UCAR (c) 1992 - 2022
// ** University Corporation for Atmospheric Research (UCAR)
// ** National Center for Atmospheric Research (NCAR)
// ** Research Applications Lab (RAL)
// ** P.O.Box 3000, Boulder, Colorado, 80307-3000, USA
// *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*


////////////////////////////////////////////////////////////////////////


#ifndef __SUMMARYCALCSUM_H__
#define __SUMMARYCALCSUM_H__


////////////////////////////////////////////////////////////////////////


#include <iostream>

#include "summary_calc.h"

////////////////////////////////////////////////////////////////////////


class SummaryCalcSum : public SummaryCalc
{

public:

SummaryCalcSum();
virtual ~SummaryCalcSum();

virtual string getType() const
{
return "SUM";
}

virtual double calcSummary(const NumArray &num_array) const
{
return num_array.sum();
}

};


////////////////////////////////////////////////////////////////////////


#endif /* __SUMMARYCALCSUM_H__ */


////////////////////////////////////////////////////////////////////////


22 changes: 17 additions & 5 deletions src/libcode/vx_summary/summary_obs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ using namespace std;
#include "summary_calc_mean.h"
#include "summary_calc_median.h"
#include "summary_calc_min.h"
#include "summary_calc_sum.h"
#include "summary_calc_percentile.h"
#include "summary_calc_range.h"
#include "summary_calc_stdev.h"
Expand Down Expand Up @@ -176,11 +177,11 @@ bool SummaryObs::summarizeObs(const TimeSummaryInfo &summary_info)
{
mlog << Debug(3) << "Computing "
<< unix_to_yyyymmdd_hhmmss(time_interval->getBaseTime())
<< " time summary from "
<< " time summary ("
<< unix_to_yyyymmdd_hhmmss(time_interval->getStartTime())
<< " to "
<< " <= time < "
<< unix_to_yyyymmdd_hhmmss(time_interval->getEndTime())
<< ".\n";
<< ").\n";

// Initialize the map used to sort observations in this time period
// into their correct summary groups
Expand Down Expand Up @@ -365,6 +366,17 @@ vector< SummaryCalc* > SummaryObs::getSummaryCalculators(const TimeSummaryInfo &
else if (type == "median") {
calculators.push_back(new SummaryCalcMedian);
}
else if (type == "sum") {
calculators.push_back(new SummaryCalcSum);

// Check for vld_thresh = 1.0
if (!is_eq(info.vld_thresh, 1.0)) {
mlog << Warning << "\nIn the \"time_summary\" dictionary, "
<< "consider setting \"vld_thresh\" (" << info.vld_thresh
<< ") to 1.0 for the \"sum\" type to better handle "
<< "missing data.\n\n";
}
}
else if (type[0] == 'p') {
calculators.push_back(new SummaryCalcPercentile(type));
}
Expand Down Expand Up @@ -403,12 +415,12 @@ vector< TimeSummaryInterval > SummaryObs::getTimeIntervals(
vector< TimeSummaryInterval > time_intervals;
time_t interval_time = getIntervalTime(first_data_time, info.beg, info.end,
info.step, info.width_beg, info.width_end);
while (interval_time < last_data_time) {
while (interval_time <= last_data_time) {
// We need to process each day separately so that we can always start
// at the indicated start time on each day.
time_t day_end_time = getEndOfDay(interval_time);
while (interval_time < day_end_time &&
interval_time < last_data_time)
interval_time <= last_data_time)
{
// See if the current time is within the defined time intervals
if (isInTimeInterval(interval_time, info.beg, info.end)) {
Expand Down

0 comments on commit e8af847

Please sign in to comment.