-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Per #1918, move normalize_data() from gen_ens_prod to normalize.h/.cc…
… in the vx_util library so that that functionality is available to other MET tools. ci-run-unit
- Loading branch information
1 parent
e2facf7
commit 43048e3
Showing
10 changed files
with
197 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////////////// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__ | ||
|
||
/////////////////////////////////////////////////////////////////////////////// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.