Skip to content

Commit

Permalink
Merge branch 'hotfix/2.1.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
dsarmany committed Jul 18, 2024
2 parents 202f9da + 51816f2 commit a7db422
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
15 changes: 13 additions & 2 deletions src/multio/action/encode/GribEncoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ const std::map<const std::string, const long> type_of_statistical_processing{
const std::map<const std::string, const std::string> category_to_levtype{
{"ocean-grid-coordinate", "oceanSurface"}, {"ocean-2d", "oceanSurface"}, {"ocean-3d", "oceanModelLevel"}};

const std::map<const std::string, const long> type_of_generating_process{
{"an", 0}, {"4v", 0}, {"fc", 2}, {"pf", 4}, {"tpa", 12}};
const std::map<const std::string, const long> type_of_generating_process{{"an", 0}, {"4v", 0}, {"fc", 2},
{"cf", 4}, {"pf", 4}, {"tpa", 12}};


const std::unordered_set<std::string> types_with_time_reference_offset{"fc", "fcmean", "cf", "pf", "4v"};
Expand Down Expand Up @@ -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"));
}
}
}
Expand All @@ -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"));
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 @@ -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"

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

0 comments on commit a7db422

Please sign in to comment.