Skip to content

Commit 6ce826a

Browse files
committed
DE-2319: Add GRIB reader as data source feature for NWP emulator
1 parent 0355966 commit 6ce826a

11 files changed

+935
-0
lines changed

.github/ci-config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ dependencies: |
33
ecmwf/eckit
44
ecmwf/fckit
55
ecmwf/atlas
6+
ecmwf/eccodes
67
dependency_cmake_options: |
78
ecmwf/atlas: "-DENABLE_FORTRAN=ON"
89
dependency_branch: develop

.github/ci-hpc-config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ build:
66
- ecmwf/eckit@develop
77
- ecmwf/fckit@develop
88
- ecmwf/atlas@develop
9+
- ecmwf/eccodes@develop
910
dependency_cmake_options:
1011
- ecmwf/atlas:-DENABLE_FORTRAN=ON
1112
parallel: 64

CMakeLists.txt

+10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
2020
### dependencies and options
2121
ecbuild_find_package( NAME eckit VERSION 1.18 REQUIRED )
2222
ecbuild_find_package( NAME atlas )
23+
ecbuild_find_package( NAME eccodes )
2324

2425
ecbuild_add_option( FEATURE BUILD_TOOLS
2526
DEFAULT ON
@@ -47,6 +48,15 @@ ecbuild_info("FCKIT_FOUND ${fckit_FOUND}")
4748
ecbuild_info("FCKIT_LIBRARIES ${FCKIT_LIBRARIES}")
4849
ecbuild_info("FCKIT_INCLUDE_DIRS ${FCKIT_INCLUDE_DIRS}")
4950

51+
############## PRECISION
52+
ecbuild_add_option( FEATURE NWP_EMULATOR_SINGLE_PRECISION
53+
DESCRIPTION "Single precision Atlas fields"
54+
DEFAULT OFF )
55+
56+
if( HAVE_NWP_EMULATOR_SINGLE_PRECISION )
57+
list(APPEND NWP_EMULATOR_DEFINITIONS WITH_NWP_EMULATOR_SINGLE_PRECISION )
58+
endif()
59+
5060
add_subdirectory( src )
5161
add_subdirectory( tests )
5262
add_subdirectory( examples )

src/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@
88
# does it submit to any jurisdiction.
99

1010
add_subdirectory(plume)
11+
12+
add_subdirectory(nwp_emulator)

src/nwp_emulator/CMakeLists.txt

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# (C) Copyright 2025- ECMWF.
2+
#
3+
# This software is licensed under the terms of the Apache Licence Version 2.0
4+
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
5+
#
6+
# In applying this licence, ECMWF does not waive the privileges and immunities
7+
# granted to it by virtue of its status as an intergovernmental organisation nor
8+
# does it submit to any jurisdiction.
9+
ecbuild_add_library(
10+
TARGET plume_nwp_emulator
11+
INSTALL_HEADERS LISTED
12+
HEADER_DESTINATION
13+
${INSTALL_INCLUDE_DIR}/nwp_emulator
14+
SOURCES
15+
data_reader.h
16+
grib_file_reader.h
17+
nwp_definitions.h
18+
nwp_data_provider.h
19+
nwp_data_provider.cc
20+
grib_file_reader.cc
21+
PUBLIC_INCLUDES
22+
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/src>
23+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>
24+
PRIVATE_INCLUDES
25+
"${MPI_INCLUDE_DIRS}"
26+
DEFINITIONS
27+
${NWP_EMULATOR_DEFINITIONS}
28+
PUBLIC_LIBS
29+
plume_plugin
30+
plume_plugin_manager
31+
eccodes
32+
eckit
33+
)

src/nwp_emulator/data_reader.h

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* (C) Copyright 2025- ECMWF.
3+
*
4+
* This software is licensed under the terms of the Apache Licence Version 2.0
5+
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6+
*
7+
* In applying this licence, ECMWF does not waive the privileges and immunities
8+
* granted to it by virtue of its status as an intergovernmental organisation nor
9+
* does it submit to any jurisdiction.
10+
*/
11+
#pragma once
12+
13+
#include <string>
14+
#include <vector>
15+
16+
#include "nwp_definitions.h"
17+
18+
namespace nwp_emulator {
19+
20+
/**
21+
* @class DataReader
22+
* @brief Base class for handling different types of data sources for the emulator.
23+
*/
24+
class DataReader {
25+
protected:
26+
std::string gridName_;
27+
std::vector<std::string> params_;
28+
29+
int stepCountLimit_; ///< Limitation on the number of steps the emulator can run
30+
int step_{0}; ///< Number of model steps
31+
int count_{0}; ///< Number of messages for the current step
32+
int index_{0}; ///< Index of the considered message at the current step
33+
34+
public:
35+
DataReader(int stepCountLimit) : stepCountLimit_(stepCountLimit) {}
36+
virtual ~DataReader() = default;
37+
38+
/**
39+
* @brief Provides the raw values for a single levelin the next message from the data source.
40+
*
41+
* Each of the inheriting readers will have a different way to generate raw model data for the provider,
42+
* which can use the parameters to map the raw values to a specific field, levtype and level.
43+
*
44+
* @param[out] shortName The name of the parameter represented by the raw values for the caller use.
45+
* @param[out] levtype The levtype of the parameter for the caller use.
46+
* @param[out] level The level of the levtype for the caller use.
47+
* @param[out] data The vector that contains the raw values for the field.
48+
*
49+
* @return true if the data generation is successful, false otherwise.
50+
*/
51+
virtual bool nextMessage(std::string& shortName, std::string& levtype, std::string& level,
52+
std::vector<FIELD_TYPE_REAL>& data) = 0;
53+
54+
/// Returns true when the reader has read model data for all the steps.
55+
virtual bool done() = 0;
56+
57+
/// Getters
58+
const std::string& getGridName() const { return gridName_; }
59+
int getStep() const { return step_; }
60+
const std::vector<std::string>& getParams() const { return params_; }
61+
};
62+
} // namespace nwp_emulator

0 commit comments

Comments
 (0)