generated from NOAA-OWP/owp-open-source-project-template
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ForcingsEngineGriddedDataProvider): integrate tests; add gridded…
… domain; simplify test files
- Loading branch information
Showing
11 changed files
with
263 additions
and
50 deletions.
There are no files selected for viewing
Binary file not shown.
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,61 @@ | ||
time_step_seconds: 3600 | ||
initial_time: 0 | ||
NWM_VERSION: 4.0 | ||
NWM_CONFIG: "AORC" | ||
InputForcings: [12] | ||
InputForcingDirectories: [''] | ||
InputForcingTypes: ["NETCDF4"] | ||
InputMandatory: [1] | ||
OutputFrequency: 60 | ||
SubOutputHour: 0 | ||
SubOutFreq: 0 | ||
ScratchDir: "@FORCINGS_ENGINE_SCRATCH_DIR@" | ||
Output: 1 | ||
compressOutput: 0 | ||
floatOutput: 0 | ||
AnAFlag: 0 | ||
LookBack : -9999 | ||
RefcstBDateProc: "202301170000" | ||
RefcstEDateProc: "202301170100" | ||
ForecastFrequency: 60 | ||
ForecastShift: 0 | ||
ForecastInputHorizons: [14400] | ||
ForecastInputOffsets: [0] | ||
GeogridIn: "data/forcing/forcings-engine/Gauge_01073000_Grid.nc" | ||
SpatialMetaIn: "" | ||
GRID_TYPE: "gridded" | ||
LONVAR: 'Longitude' | ||
LATVAR: 'Latitude' | ||
HGTVAR: 'Elevation' | ||
SLOPE: 'Slope' | ||
SLOPE_AZIMUTH: 'Aspect' | ||
IgnoredBorderWidths: [0] | ||
RegridOpt: [1] | ||
ForcingTemporalInterpolation: [0] | ||
TemperatureBiasCorrection: [0] | ||
PressureBiasCorrection: [0] | ||
HumidityBiasCorrection: [0] | ||
WindBiasCorrection: [0] | ||
SwBiasCorrection: [0] | ||
LwBiasCorrection: [0] | ||
PrecipBiasCorrection: [0] | ||
TemperatureDownscaling: [0] | ||
ShortwaveDownscaling: [0] | ||
PressureDownscaling: [0] | ||
PrecipDownscaling: [0] | ||
HumidityDownscaling: [0] | ||
DownscalingParamDirs: ["@FORCINGS_ENGINE_SCRATCH_DIR@"] | ||
SuppPcp: [] | ||
SuppPcpForcingTypes: '' | ||
SuppPcpDirectories: '' | ||
SuppPcpParamDir: '' | ||
RegridOptSuppPcp: [] | ||
SuppPcpTemporalInterpolation: [] | ||
SuppPcpInputOffsets: [] | ||
SuppPcpMandatory: [] | ||
RqiMethod: 0 | ||
RqiThreshold: 0.9 | ||
cfsEnsNumber: '' | ||
custom_input_fcst_freq: [] | ||
includeLQFrac: 0 | ||
|
File renamed without changes.
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 |
---|---|---|
@@ -1,5 +1,13 @@ | ||
#include <forcing/ForcingsEngineDataProvider.hpp> | ||
|
||
#include "DataProviderSelectors.hpp" | ||
#include "GriddedDataSelector.hpp" | ||
|
||
#include "ForcingsEngineTestHelpers.hpp" | ||
|
||
template struct data_access::ForcingsEngineDataProvider<double, CatchmentAggrDataSelector>; | ||
template struct data_access::ForcingsEngineDataProvider<double, GriddedDataSelector>; | ||
|
||
std::shared_ptr<utils::ngenPy::InterpreterUtil> ForcingsEngineDataProviderTest::gil_ = nullptr; | ||
std::time_t ForcingsEngineDataProviderTest::time_start = 0; | ||
std::time_t ForcingsEngineDataProviderTest::time_end = 0; |
109 changes: 109 additions & 0 deletions
109
test/forcing/ForcingsEngineGriddedDataProvider_Test.cpp
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,109 @@ | ||
#include <gtest/gtest.h> | ||
|
||
#ifndef NGEN_FORCINGS_GRIDDED_CONFIG_PATH | ||
#error "Gridded config file path not defined! Set `-DNGEN_FORCINGS_GRIDDED_CONFIG_PATH`. " \ | ||
"Note: you should not be seeing this compile error. Please contact an ngen developer." | ||
#endif | ||
|
||
#include "ForcingsEngineTestHelpers.hpp" | ||
|
||
#include <forcing/ForcingsEngineGriddedDataProvider.hpp> | ||
|
||
struct ForcingsEngineGriddedDataProviderTest | ||
: public ForcingsEngineDataProviderTest | ||
{ | ||
using provider_type = data_access::ForcingsEngineGriddedDataProvider; | ||
|
||
ForcingsEngineGriddedDataProviderTest() | ||
: ForcingsEngineDataProviderTest() | ||
{} | ||
|
||
static std::unique_ptr<provider_type> provider_; | ||
|
||
static void SetUpTestSuite(); | ||
}; | ||
|
||
using TestFixture = ForcingsEngineGriddedDataProviderTest; | ||
|
||
std::unique_ptr<TestFixture::provider_type> TestFixture::provider_ = nullptr; | ||
|
||
constexpr const char* config_file = NGEN_FORCINGS_GRIDDED_CONFIG_PATH; | ||
|
||
constexpr auto cat_11223_mask = geojson::box_t{ | ||
/*min_corner=*/{ -71.0554067, 43.1423006 }, | ||
/*max_corner=*/{ -70.9668753, 43.185111 } | ||
}; | ||
|
||
constexpr auto cat_11410_mask = geojson::box_t{ | ||
/*min_corner=*/{ -71.0577593, 43.1375584 }, | ||
/*max_corner=*/{ -71.0210404, 43.1761626 } | ||
}; | ||
|
||
void TestFixture::SetUpTestSuite() | ||
{ | ||
ForcingsEngineDataProviderTest::SetUpTestSuite(); | ||
|
||
TestFixture::time_start = data_access::detail::parse_time("2023-01-17 01:00:00"); | ||
TestFixture::time_end = TestFixture::time_start + 3600 + 3600; | ||
|
||
TestFixture::provider_ = std::make_unique<data_access::ForcingsEngineGriddedDataProvider>( | ||
/*init=*/config_file, | ||
/*time_begin_seconds=*/TestFixture::time_start, | ||
/*time_end_seconds=*/TestFixture::time_end, | ||
/*mask=*/cat_11223_mask | ||
); | ||
} | ||
|
||
/** | ||
* Tests for the flyweight-like design of provider storage by getting | ||
* a new instance of the forcings engine and verifying that it points | ||
* to the same address as the static initialized `provider_` member, | ||
* based on matching `init`, and shared over distinct `divide_id`. | ||
*/ | ||
TEST_F(ForcingsEngineGriddedDataProviderTest, Storage) | ||
{ | ||
auto new_inst = std::make_unique<data_access::ForcingsEngineGriddedDataProvider>( | ||
/*init=*/config_file, | ||
/*time_begin_seconds=*/TestFixture::time_start, | ||
/*time_end_seconds=*/TestFixture::time_end, | ||
/*mask=*/cat_11410_mask | ||
); | ||
|
||
ASSERT_EQ(new_inst->model(), provider_->model()); | ||
} | ||
|
||
TEST_F(ForcingsEngineGriddedDataProviderTest, VariableAccess) | ||
{ | ||
ASSERT_TRUE(boost::geometry::equals(provider_->mask().extent, cat_11223_mask)); | ||
|
||
constexpr std::array<const char*, 8> expected_variables = { | ||
"U2D_ELEMENT", | ||
"V2D_ELEMENT", | ||
"LWDOWN_ELEMENT", | ||
"SWDOWN_ELEMENT", | ||
"T2D_ELEMENT", | ||
"Q2D_ELEMENT", | ||
"PSFC_ELEMENT", | ||
"RAINRATE_ELEMENT" | ||
}; | ||
|
||
const auto outputs = provider_->get_available_variable_names(); | ||
|
||
// Check that each expected variable is in the list of available outputs. | ||
for (const auto& expected : expected_variables) { | ||
EXPECT_NE( | ||
std::find(outputs.begin(), outputs.end(), expected), | ||
outputs.end() | ||
); | ||
} | ||
|
||
auto selector = GriddedDataSelector{"PSFC", time_start, 3600, "seconds"}; | ||
auto result = provider_->get_values(selector, data_access::ReSampleMethod::SUM); | ||
EXPECT_EQ(result.size(), 48980); | ||
// EXPECT_NEAR(result, 99580.52, 1e-2); | ||
|
||
// selector = CatchmentAggrDataSelector{"cat-11223", "LWDOWN", time_start + 3600, 3600, "seconds"}; | ||
// auto result2 = provider_->get_values(selector, data_access::ReSampleMethod::SUM); | ||
// ASSERT_GT(result2.size(), 0); | ||
// EXPECT_NEAR(result2[0], 0, 1e-6); | ||
} |
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.