Commit b92ad29e authored by Norby, Tom's avatar Norby, Tom

statACompare util for validating calc against expected statA files.

parent d0a3ade0
Pipeline #112760 failed with stages
in 5 minutes and 28 seconds
......@@ -10,6 +10,7 @@
#include "haemmodel/concutil.hh"
using namespace radix;
int main(int argc, char **argv)
{
std::cout << "************************" << std::endl;
......@@ -64,7 +65,7 @@ int main(int argc, char **argv)
std::cerr << "ERROR: Could not open file: " << inputFile << std::endl;
return 1;
}
std::cout << "hi";
// normalize cdump
haem::cnormal(cdump, time, startSource);
......
......@@ -11,6 +11,7 @@
#include "haemmodel/concutil.hh"
using namespace radix;
int main(int argc, char **argv)
{
std::cout << "************************" << std::endl;
......
#include <map>
#include "haemmodel/concutil.hh"
using namespace radix;
using namespace std;
static time_t hourDiff(struct tm *laterTime, struct tm *earlierTime)
{
time_t later = mktime(laterTime);
......@@ -41,7 +45,7 @@ void haem::cnormal(HysplitCDump::SP cdump, float normalTime,
#endif // _WIN32
postEvent = float(hourDiff(&et, &st));
std::cout << "H+" << postEvent << std::endl;
cout << "H+" << postEvent << endl;
}
for (int pi = 0; pi < cdump->numPollutants(); ++pi)
......@@ -54,7 +58,7 @@ void haem::cnormal(HysplitCDump::SP cdump, float normalTime,
float conc;
short xi, yi;
cdump->point(ti, pi, li, nzi, xi, yi, conc);
conc *= std::pow(postEvent, 1.2f) / std::pow(normalTime, 1.2f);
conc *= pow(postEvent, 1.2f) / pow(normalTime, 1.2f);
cdump->setPoint(ti, pi, li, nzi, xi, yi, conc);
} // for each non zero point
} // for each altitude
......@@ -64,7 +68,7 @@ void haem::cnormal(HysplitCDump::SP cdump, float normalTime,
HysplitCDump::SP haem::speciesSelect(HysplitCDump::SP cdumpin, int species)
{
HysplitCDump::SP cdumpout = std::make_shared<HysplitCDump>();
HysplitCDump::SP cdumpout = make_shared<HysplitCDump>();
{
cdumpout->setId(cdumpin->id());
cdumpout->setNumLat(cdumpin->numLat());
......@@ -114,3 +118,56 @@ HysplitCDump::SP haem::speciesSelect(HysplitCDump::SP cdumpin, int species)
return cdumpout;
}
static map<string, double> statAParse(const string &statAFile,
vector<string> desiredKeys)
{
ifstream statAStream(statAFile);
map<string, double> statMap;
string statLine;
if (statAStream.is_open())
{
while (getline(statAStream, statLine))
{
for (size_t i = 0; i < desiredKeys.size(); i++)
{
if (statLine.find(desiredKeys[i]) != string::npos)
{
statMap[desiredKeys[i]] = atof(statLine.c_str());
break;
}
}
}
statAStream.close();
}
return statMap;
}
bool haem::statACompare(const string &calcFile, const string &expectFile,
const double relativeError)
{
map<string, double> calcMap, expectMap;
vector<string> desiredKeys = {
"Final rank (C,FB,FMS,KSP)", "Kolmogorov-Smirnov Parameter",
"Fig of merit in space (%)", "Fractional bias [2B/(C+M)]",
"Correlation coefficient"};
calcMap = statAParse(calcFile, desiredKeys);
expectMap = statAParse(expectFile, desiredKeys);
bool compare = true;
for (string key : desiredKeys)
{
cout << key << "\tCalc:" << calcMap[key] << "\tExpected:" << expectMap[key]
<< '\n';
double largerVal =
calcMap[key] > expectMap[key] ? calcMap[key] : expectMap[key];
double minAllowed = largerVal * (1 - relativeError);
if (calcMap[key] < minAllowed || expectMap[key] < minAllowed)
compare = false;
}
cout << "StatA " << (compare ? "PASSED " : "FAILED ")
<< "using a relative error of " << relativeError << "." << endl;
return compare;
}
......@@ -4,9 +4,10 @@
#include "radixcore/visibility.hh"
#include "radixio/hysplitcdump.hh"
using namespace radix;
namespace haem
{
using namespace radix;
enum StartSource
{
START_TIME,
......@@ -14,10 +15,14 @@ enum StartSource
};
RADIX_PUBLIC void cnormal(HysplitCDump::SP cdump, float normalTime,
StartSource startSource);
StartSource startSource = START_TIME);
RADIX_PUBLIC HysplitCDump::SP speciesSelect(HysplitCDump::SP cdumpin,
int species);
RADIX_PUBLIC bool statACompare(const std::string &calcFile,
const std::string &expectFile,
const double relativeError);
}; // namespace haem
#endif // HAEM_HAEMMODEL_CNORMAL_HH
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment