Skip to content

Commit

Permalink
Per #1918, move normalize_data() from gen_ens_prod to normalize.h/.cc…
Browse files Browse the repository at this point in the history
… in the vx_util library so that that functionality is available to other MET tools. ci-run-unit
  • Loading branch information
JohnHalleyGotway committed Feb 20, 2022
1 parent e2facf7 commit 43048e3
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 142 deletions.
20 changes: 0 additions & 20 deletions met/src/basic/vx_config/config_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -471,20 +471,6 @@ enum MatchType {
MatchType_NoMerge // Match with no additional merging
};

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

//
// Enumeration for normalization options
//

enum NormalizeType {
NormalizeType_None, // No normalization
NormalizeType_ClimoAnom, // Subtract climo mean
NormalizeType_ClimoStdAnom, // Subtract climo mean and divide by standard deviation
NormalizeType_FcstAnom, // Subtract ensemble mean
NormalizeType_FcstStdAnom // Subtract ensemble mean and divide by standard deviation
};

////////////////////////////////////////////////////////////////////////
//
// Constants used in configuartion files
Expand Down Expand Up @@ -780,12 +766,6 @@ static const char conf_val_gamma[] = "GAMMA";
static const char conf_val_uniform[] = "UNIFORM";
static const char conf_val_beta[] = "BETA";

// Normalization options
static const char conf_val_climo_anom[] = "CLIMO_ANOM";
static const char conf_val_climo_std_anom[] = "CLIMO_STD_ANOM";
static const char conf_val_fcst_anom[] = "FCST_ANOM";
static const char conf_val_fcst_std_anom[] = "FCST_STD_ANOM";

//
// STAT-Analysis specific parameter key names
//
Expand Down
56 changes: 7 additions & 49 deletions met/src/basic/vx_config/config_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2835,47 +2835,6 @@ ConcatString matchtype_to_string(MatchType type) {

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

NormalizeType int_to_normalizetype(int v) {
NormalizeType t = NormalizeType_None;

// Convert integer to enumerated NormalizeType
if(v == conf_const.lookup_int(conf_val_none)) t = NormalizeType_None;
else if(v == conf_const.lookup_int(conf_val_climo_anom)) t = NormalizeType_ClimoAnom;
else if(v == conf_const.lookup_int(conf_val_climo_std_anom)) t = NormalizeType_ClimoStdAnom;
else if(v == conf_const.lookup_int(conf_val_fcst_anom)) t = NormalizeType_FcstAnom;
else if(v == conf_const.lookup_int(conf_val_fcst_std_anom)) t = NormalizeType_FcstStdAnom;
else {
mlog << Error << "\nint_to_normalizetype() -> "
<< "Unexpected value of " << v << ".\n\n";
exit(1);
}

return(t);
}

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

ConcatString normalizetype_to_string(NormalizeType type) {
ConcatString s;

// Convert enumerated NormalizeType to string
switch(type) {
case(NormalizeType_None): s = conf_val_none; break;
case(NormalizeType_ClimoAnom): s = conf_val_climo_anom; break;
case(NormalizeType_ClimoStdAnom): s = conf_val_climo_std_anom; break;
case(NormalizeType_FcstAnom): s = conf_val_fcst_anom; break;
case(NormalizeType_FcstStdAnom): s = conf_val_fcst_std_anom; break;
default:
mlog << Error << "\nnormalizetype_to_string() -> "
<< "Unexpected NormalizeType value of " << type << ".\n\n";
exit(1);
}

return(s);
}

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

DistType int_to_disttype(int v) {
DistType t = DistType_None;

Expand Down Expand Up @@ -3036,16 +2995,15 @@ NormalizeType parse_conf_normalize(Dictionary *dict) {
// Get the integer flag value for the current entry
v = dict->lookup_int(conf_key_normalize);

// Convert integer to enumerated WaveletType
if(v == conf_const.lookup_int(conf_val_none)) t = NormalizeType_None;
else if(v == conf_const.lookup_int(conf_val_climo_anom)) t = NormalizeType_ClimoAnom;
else if(v == conf_const.lookup_int(conf_val_climo_std_anom)) t = NormalizeType_ClimoStdAnom;
else if(v == conf_const.lookup_int(conf_val_fcst_anom)) t = NormalizeType_FcstAnom;
else if(v == conf_const.lookup_int(conf_val_fcst_std_anom)) t = NormalizeType_FcstStdAnom;
// Convert integer to enumerated NormalizeType
if(v == conf_const.lookup_int(normalizetype_none_str)) t = NormalizeType_None;
else if(v == conf_const.lookup_int(normalizetype_climo_anom_str)) t = NormalizeType_ClimoAnom;
else if(v == conf_const.lookup_int(normalizetype_climo_std_anom_str)) t = NormalizeType_ClimoStdAnom;
else if(v == conf_const.lookup_int(normalizetype_fcst_anom_str)) t = NormalizeType_FcstAnom;
else if(v == conf_const.lookup_int(normalizetype_fcst_std_anom_str)) t = NormalizeType_FcstStdAnom;
else {
mlog << Error << "\nparse_conf_normalize() -> "
<< "Unexpected config file value of " << v << " for \""
<< conf_key_normalize << "\".\n\n";
<< "Unexpected value of " << v << ".\n\n";
exit(1);
}

Expand Down
4 changes: 1 addition & 3 deletions met/src/basic/vx_config/config_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "config_file.h"
#include "data_file_type.h"
#include "config_gaussian.h"
#include "normalize.h"

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

Expand Down Expand Up @@ -120,9 +121,6 @@ extern ConcatString obssummary_to_string(ObsSummary, int);
extern MatchType int_to_matchtype(int);
extern ConcatString matchtype_to_string(MatchType);

extern NormalizeType int_to_normalizetype(int);
extern ConcatString normalizetype_to_string(NormalizeType);

extern DistType int_to_disttype(int);
extern DistType string_to_disttype(const char *);
extern ConcatString disttype_to_string(DistType);
Expand Down
1 change: 1 addition & 0 deletions met/src/basic/vx_util/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ libvx_util_a_SOURCES = ascii_table.cc ascii_table.h \
thresh_array.cc thresh_array.h \
make_path.cc make_path.h \
memory.cc memory.h \
normalize.cc normalize.h \
ordinal.cc ordinal.h \
roman_numeral.cc roman_numeral.h \
string_fxns.cc string_fxns.h \
Expand Down
125 changes: 125 additions & 0 deletions met/src/basic/vx_util/normalize.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
// ** 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 <cstdlib>
#include <iostream>
#include <math.h>
#include <string.h>
#include <unistd.h>

#include "normalize.h"

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

ConcatString normalizetype_to_string(const NormalizeType type) {
ConcatString s;

// Convert enumerated NormalizeType to string
switch(type) {

case NormalizeType_None:
s = normalizetype_none_str;
break;

case NormalizeType_ClimoAnom:
s = normalizetype_climo_anom_str;
break;

case NormalizeType_ClimoStdAnom:
s = normalizetype_climo_std_anom_str;
break;

case NormalizeType_FcstAnom:
s = normalizetype_fcst_anom_str;
break;

case NormalizeType_FcstStdAnom:
s = normalizetype_fcst_std_anom_str;
break;

default:
mlog << Error << "\nnormalizetype_to_string() -> "
<< "Unexpected NormalizeType value of " << type << ".\n\n";
exit(1);
}

return(s);
}

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

void normalize_data(DataPlane &dp, const NormalizeType type,
const DataPlane *cmn_ptr, const DataPlane *csd_ptr,
const DataPlane *fmn_ptr, const DataPlane *fsd_ptr) {

mlog << Debug(3) << "Normalizing input data using "
<< normalizetype_to_string(type) << ".\n";

// Supported types
switch(type) {

case NormalizeType_None:
break;

case NormalizeType_ClimoAnom:
if(!cmn_ptr || dp.nxy() != cmn_ptr->nxy()) {
mlog << Error << "\nnormalize_data() -> "
<< "the climatology mean is required for "
<< normalizetype_to_string(type) << ".\n\n";
exit(1);
}
dp.anomaly(*cmn_ptr);
break;

case NormalizeType_ClimoStdAnom:
if(!cmn_ptr || dp.nxy() != cmn_ptr->nxy() ||
!csd_ptr || dp.nxy() != csd_ptr->nxy()) {
mlog << Error << "\nnormalize_data() -> "
<< "the climatology mean and standard deviation are required for "
<< normalizetype_to_string(type) << ".\n\n";
exit(1);
}
dp.standard_anomaly(*cmn_ptr, *csd_ptr);
break;

case NormalizeType_FcstAnom:
if(!fmn_ptr || dp.nxy() != fmn_ptr->nxy()) {
mlog << Error << "\nnormalize_data() -> "
<< "the forecast mean is required for "
<< normalizetype_to_string(type) << ".\n\n";
exit(1);
}
dp.anomaly(*fmn_ptr);
break;

case NormalizeType_FcstStdAnom:
if(!fmn_ptr || dp.nxy() != fmn_ptr->nxy() ||
!fsd_ptr || dp.nxy() != fsd_ptr->nxy()) {
mlog << Error << "\nnormalize_data() -> "
<< "the forecast mean and standard deviation are required for "
<< normalizetype_to_string(type) << ".\n\n";
exit(1);
}
dp.standard_anomaly(*fmn_ptr, *fsd_ptr);
break;

default:
mlog << Error << "\nnormalize_data() -> "
<< "unexpected NormalizeType value ("
<< type << ")\n\n";
exit(1);
} // end switch

return;
}

///////////////////////////////////////////////////////////////////////////////
56 changes: 56 additions & 0 deletions met/src/basic/vx_util/normalize.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 __NORMALIZE_H__
#define __NORMALIZE_H__

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

#include "concat_string.h"
#include "data_plane.h"

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

//
// Enumeration for normalization types
//

enum NormalizeType {
NormalizeType_None, // No normalization
NormalizeType_ClimoAnom, // Subtract climo mean
NormalizeType_ClimoStdAnom, // Subtract climo mean and divide stdev
NormalizeType_FcstAnom, // Subtract fcst mean
NormalizeType_FcstStdAnom // Subtract fcst mean and divide stdev
};

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

//
// String corresponding to the enumerated values above
//
static const char normalizetype_none_str[] = "NONE";
static const char normalizetype_climo_anom_str[] = "CLIMO_ANOM";
static const char normalizetype_climo_std_anom_str[] = "CLIMO_STD_ANOM";
static const char normalizetype_fcst_anom_str[] = "FCST_ANOM";
static const char normalizetype_fcst_std_anom_str[] = "FCST_STD_ANOM";

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

extern ConcatString normalizetype_to_string(const NormalizeType);

extern void normalize_data(DataPlane &, const NormalizeType,
const DataPlane *, const DataPlane *,
const DataPlane *, const DataPlane *);

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

#endif // __NORMALIZE_H__

///////////////////////////////////////////////////////////////////////////////
1 change: 1 addition & 0 deletions met/src/basic/vx_util/vx_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "long_array.h"
#include "make_path.h"
#include "memory.h"
#include "normalize.h"
#include "num_array.h"
#include "ordinal.h"
#include "roman_numeral.h"
Expand Down
Loading

0 comments on commit 43048e3

Please sign in to comment.