diff --git a/src/multio/action/encode/GribEncoder.cc b/src/multio/action/encode/GribEncoder.cc index 6300163d..2c01c76b 100644 --- a/src/multio/action/encode/GribEncoder.cc +++ b/src/multio/action/encode/GribEncoder.cc @@ -65,8 +65,8 @@ const std::map type_of_statistical_processing{ const std::map category_to_levtype{ {"ocean-grid-coordinate", "oceanSurface"}, {"ocean-2d", "oceanSurface"}, {"ocean-3d", "oceanModelLevel"}}; -const std::map type_of_generating_process{ - {"an", 0}, {"4v", 0}, {"fc", 2}, {"pf", 4}, {"tpa", 12}}; +const std::map type_of_generating_process{{"an", 0}, {"4v", 0}, {"fc", 2}, + {"cf", 4}, {"pf", 4}, {"tpa", 12}}; const std::unordered_set types_with_time_reference_offset{"fc", "fcmean", "cf", "pf", "4v"}; @@ -366,6 +366,9 @@ QueriedMarsKeys setMarsKeys(GribEncoder& g, const eckit::Configuration& md) { withFirstOf(valueSetter(g, "activity"), LookUpString(md, "activity")); withFirstOf(valueSetter(g, "experiment"), LookUpString(md, "experiment")); withFirstOf(valueSetter(g, "realization"), LookUpString(md, "realization")); + withFirstOf(valueSetter(g, "generation"), LookUpString(md, "generation")); + withFirstOf(valueSetter(g, "model"), LookUpString(md, "model")); + withFirstOf(valueSetter(g, "resolution"), LookUpString(md, "resolution")); } } } @@ -390,6 +393,14 @@ QueriedMarsKeys setMarsKeys(GribEncoder& g, const eckit::Configuration& md) { withFirstOf(valueSetter(g, "lengthOf4DvarWindow"), LookUpLong(md, "lengthOf4DvarWindow"), LookUpLong(md, "anlength")); + // Metadata for ensemble forecast + withFirstOf(valueSetter(g, "oceanAtmosphereCoupling"), LookUpLong(md, "oceanAtmosphereCoupling")); + withFirstOf(valueSetter(g, "legBaseDate"), LookUpLong(md, "legBaseDate")); + withFirstOf(valueSetter(g, "legBaseTime"), LookUpLong(md, "legBaseTime")); + withFirstOf(valueSetter(g, "legNumber"), LookUpLong(md, "legNumber")); + withFirstOf(valueSetter(g, "referenceDate"), LookUpLong(md, "referenceDate")); + withFirstOf(valueSetter(g, "climateDateFrom"), LookUpLong(md, "climateDateFrom")); + withFirstOf(valueSetter(g, "climateDateTo"), LookUpLong(md, "climateDateTo")); withFirstOf(valueSetter(g, "componentIndex"), LookUpLong(md, "componentIndex")); withFirstOf(valueSetter(g, "numberOfComponents"), LookUpLong(md, "numberOfComponents")); diff --git a/src/multio/action/encode/GridDownloader.cc b/src/multio/action/encode/GridDownloader.cc index cfed5dcd..b19f9f2d 100644 --- a/src/multio/action/encode/GridDownloader.cc +++ b/src/multio/action/encode/GridDownloader.cc @@ -14,6 +14,7 @@ #include "atlas/grid/Grid.h" #include "atlas/grid/Iterator.h" +#include "atlas/grid/SpecRegistry.h" #include "atlas/library.h" #include "atlas/parallel/mpi/mpi.h" @@ -79,6 +80,10 @@ AtlasInstance& AtlasInstance::instance() { GridDownloader::GridDownloader(const config::ComponentConfiguration& compConf) : encoder_(createEncoder(compConf)), templateMetadata_(), gridCoordinatesCache_(), gridUIDCache_() { + ScopedAtlasInstance scopedAtlasInstance; + + populateUIDCache(compConf); + if (encoder_ != nullptr) { initTemplateMetadata(); @@ -109,6 +114,23 @@ std::optional GridDownloader::getGridCoords(const GridDownloade return GridCoordinates{encodedLat, encodedLon}; } +void GridDownloader::populateUIDCache(const config::ComponentConfiguration& compConf) { + if (compConf.parsedConfig().has("unstructured-grid-type")) { + atlas::mpi::Scope mpi_scope("self"); + + const auto baseGridName = compConf.parsedConfig().getString("unstructured-grid-type"); + for (auto const& unstructuredGridSubtype : {"T", "U", "V", "W", "F"}) { + const auto completeGridName = baseGridName + "_" + unstructuredGridSubtype; + + const auto gridSpec = atlas::grid::SpecRegistry::get(completeGridName); + const auto gridUID = gridSpec.getString("uid"); + + gridUIDCache_.emplace(std::piecewise_construct, std::tuple(std::string(unstructuredGridSubtype) + " grid"), + std::tuple(gridUID)); + } + } +} + void GridDownloader::initTemplateMetadata() { templateMetadata_.set("step", 0); templateMetadata_.set("typeOfLevel", "oceanSurface"); @@ -133,8 +155,6 @@ multio::message::Metadata GridDownloader::createMetadataFromCoordsData(size_t gr } void GridDownloader::downloadOrcaGridCoordinates(const config::ComponentConfiguration& compConf) { - ScopedAtlasInstance scopedAtlasInstance; - const auto baseGridName = compConf.parsedConfig().getString("unstructured-grid-type"); for (auto const& unstructuredGridSubtype : {"T", "U", "V", "W", "F"}) { const auto completeGridName = baseGridName + "_" + unstructuredGridSubtype; @@ -147,9 +167,6 @@ void GridDownloader::downloadOrcaGridCoordinates(const config::ComponentConfigur const auto gridUID = grid.uid(); - gridUIDCache_.emplace(std::piecewise_construct, std::tuple(std::string(unstructuredGridSubtype) + " grid"), - std::tuple(gridUID)); - if (encoder_ != nullptr) { const auto gridSize = grid.size(); diff --git a/src/multio/action/encode/GridDownloader.h b/src/multio/action/encode/GridDownloader.h index b7c8f46b..89a5c56b 100644 --- a/src/multio/action/encode/GridDownloader.h +++ b/src/multio/action/encode/GridDownloader.h @@ -76,6 +76,8 @@ class GridDownloader : eckit::NonCopyable { using GridCoordinateCache = std::unordered_map; using GridUIDCache = std::unordered_map; + void populateUIDCache(const config::ComponentConfiguration& compConf); + void initTemplateMetadata(); multio::message::Metadata createMetadataFromCoordsData(size_t gridSize, const std::string& unstructuredGridSubtype, const std::string& gridUID, int paramId);