Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Populate the eORCA UUID cache without reading the grids #29

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/multio/action/encode/GribEncoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,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"));
Expand Down
27 changes: 22 additions & 5 deletions src/multio/action/encode/GridDownloader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "GribEncoder.h"

#include "atlas/grid/SpecRegistry.h"
#include "atlas/grid/Grid.h"
#include "atlas/grid/Iterator.h"
#include "atlas/library.h"
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -109,6 +114,23 @@ std::optional<GridCoordinates> 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");
Expand All @@ -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;
Expand All @@ -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();

Expand Down
2 changes: 2 additions & 0 deletions src/multio/action/encode/GridDownloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class GridDownloader : eckit::NonCopyable {
using GridCoordinateCache = std::unordered_map<DomainType, GridCoordinates>;
using GridUIDCache = std::unordered_map<DomainType, GridUIDType>;

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);
Expand Down
Loading