Skip to content
Open
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
6 changes: 4 additions & 2 deletions src/multio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ list( APPEND multio_datamod_srcs
datamod/core/Compare.h
datamod/core/Record.h
datamod/core/NestedRecord.h
datamod/types/Repres.cc
datamod/types/Repres.h
datamod/types/GridType.cc
datamod/types/GridType.h
datamod/types/TimeDuration.cc
datamod/types/TimeDuration.h
datamod/types/LevType.cc
Expand All @@ -167,6 +167,8 @@ list( APPEND multio_datamod_srcs
datamod/types/TypeOfLevel.h
datamod/types/TypeOfStatisticalProcessing.cc
datamod/types/TypeOfStatisticalProcessing.h
datamod/types/Grib2TimeDurationUnit.cc
datamod/types/Grib2TimeDurationUnit.h
datamod/ContainerInterop.h
datamod/Mapper.cc
datamod/Mapper.h
Expand Down
37 changes: 27 additions & 10 deletions src/multio/action/encode-mtg2/AtlasGeoSetter.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@

#include "multio/datamod/AtlasGeo.h"
#include "multio/datamod/ContainerInterop.h"
#include "multio/datamod/MarsMiscGeo.h"
#include "multio/datamod/core/Record.h"
#include "multio/datamod/types/Repres.h"
#include "multio/datamod/types/GridType.h"
#include "multio/message/Metadata.h"
#include "multio/message/Parametrization.h"

Expand All @@ -33,10 +34,23 @@ namespace dm = multio::datamod;
struct AtlasGeoSetter {
using GridTypeFunction = std::function<void(const std::string& scope, const std::string& gridName)>;

static void handleReducedGG(const std::string& scope, const std::string& gridName) {
message::Metadata md{{scope, true}};

auto geoGG = datamod::scopeRecord(dm::GeoReducedGGRecord{}, scope);

dm::setKeysFromAtlas(geoGG, gridName);

dm::dumpRecord(geoGG, md);

message::Parametrization::instance().update(md);
}

template <typename GGRec>
static void handleGG(const std::string& scope, const std::string& gridName) {
message::Metadata md{{scope, true}};

auto geoGG = datamod::scopeRecord(dm::GeoGGRecord{}, scope);
auto geoGG = datamod::scopeRecord(GGRec{}, scope);

dm::setKeysFromAtlas(geoGG, gridName);

Expand All @@ -48,7 +62,7 @@ struct AtlasGeoSetter {
static void handleLL(const std::string& scope, const std::string& gridName) {
message::Metadata md{{scope, true}};

auto geoLL = datamod::scopeRecord(dm::GeoLLRecord{}, scope);
auto geoLL = datamod::scopeRecord(dm::GeoRegularLLRecord{}, scope);

dm::setKeysFromAtlas(geoLL, gridName);

Expand All @@ -58,19 +72,22 @@ struct AtlasGeoSetter {
}

static void handleGrid(const std::string& scope, const std::string& gridName) {
// TODO(pgeier) Use gridType instead of repres in follow up PR
auto repres = dm::represFromGrid(gridName);
switch (repres) {
case dm::Repres::GG:
handleGG(scope, gridName);
auto gridType = dm::gridTypeFromGrid(gridName);
switch (gridType) {
case dm::GridType::ReducedGG:
handleGG<dm::GeoReducedGGRecord>(scope, gridName);
break;
case dm::GridType::RegularGG:
handleGG<dm::GeoRegularGGRecord>(scope, gridName);
break;
case dm::Repres::LL:
case dm::GridType::RegularLL:
handleLL(scope, gridName);
break;
default:
default: {
std::ostringstream oss;
oss << "GeoFromAtlas: No grid function specified for grid " << gridName << std::endl;
throw multio::message::MetadataException(oss.str(), Here());
}
}
}
};
Expand Down
3 changes: 2 additions & 1 deletion src/multio/action/encode-mtg2/EncodeMtg2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ using message::Peer;

mars2grib::RawOptions mapOpts(EncodeMtg2Options opts) {
mars2grib::RawOptions ret;
ret.cached = opts.cached.get();
ret.enableCache = opts.cached.get();
ret.enableReadbackTest = opts.readbackTest.get();
return ret;
};

Expand Down
4 changes: 3 additions & 1 deletion src/multio/action/encode-mtg2/EncodeMtg2.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ namespace dm = multio::datamod;
struct EncodeMtg2Options {
dm::Entry<bool, dm::mapper::BoolMapper> cached;
dm::Entry<bool, dm::mapper::BoolMapper> geoFromAtlas;
dm::Entry<bool, dm::mapper::BoolMapper> readbackTest;

static constexpr std::string_view record_name_ = "encode-mtg2";
static constexpr auto record_entries_
= std::make_tuple(dm::entryDef("cached", &EncodeMtg2Options::cached).withDefault(true),
dm::entryDef("geo-from-atlas", &EncodeMtg2Options::geoFromAtlas).withDefault(false));
dm::entryDef("geo-from-atlas", &EncodeMtg2Options::geoFromAtlas).withDefault(false),
dm::entryDef("readback-test", &EncodeMtg2Options::readbackTest).withDefault(false));
};


Expand Down
76 changes: 49 additions & 27 deletions src/multio/datamod/AtlasGeo.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,45 +54,67 @@ struct SetKeysFromAtlas<ScopedRecord<RecordType>> {
}
};

template <>
struct SetKeysFromAtlas<GeoGGRecord> {
void operator()(GeoGGRecord& geoGG, const std::string& gridName) const {
const auto gaussianGrid = createGrid<atlas::GaussianGrid>(gridName);
geoGG.numberOfParallelsBetweenAPoleAndTheEquator.set(gaussianGrid.N());

{
auto it = gaussianGrid.lonlat().begin();
template <typename GGRec,
std::enable_if_t<std::is_same_v<GGRec, GeoReducedGGRecord> || std::is_same_v<GGRec, GeoRegularGGRecord>, bool>
= true>
void setGGKeysFromAtlas(GGRec& geoGG, const std::string& gridName) {
const auto gaussianGrid = createGrid<atlas::GaussianGrid>(gridName);
geoGG.numberOfParallelsBetweenAPoleAndTheEquator.set(gaussianGrid.N());

geoGG.latitudeOfFirstGridPointInDegrees.set((*it)[1]);
geoGG.longitudeOfFirstGridPointInDegrees.set((*it)[0]);
geoGG.numberOfPointsAlongAMeridian.set(gaussianGrid.ny());

it += gaussianGrid.size() - 1;
geoGG.latitudeOfLastGridPointInDegrees.set((*it)[1]);
{
auto it = gaussianGrid.lonlat().begin();

const auto equator = gaussianGrid.N();
const auto maxLongitude = gaussianGrid.x(gaussianGrid.nx(equator) - 1, equator);
geoGG.longitudeOfLastGridPointInDegrees.set(maxLongitude);
}
geoGG.latitudeOfFirstGridPointInDegrees.set((*it)[1]);
geoGG.longitudeOfFirstGridPointInDegrees.set((*it)[0]);

{
auto tmp = gaussianGrid.nx();
std::vector<long> pl(tmp.size(), 0);
for (int i = 0; i < tmp.size(); ++i) {
pl[i] = long(tmp[i]);
}
geoGG.pl.set(std::move(pl));
it += gaussianGrid.size() - 1;
geoGG.latitudeOfLastGridPointInDegrees.set((*it)[1]);

const auto equator = gaussianGrid.N();
const auto maxLongitude = gaussianGrid.x(gaussianGrid.nx(equator) - 1, equator);
geoGG.longitudeOfLastGridPointInDegrees.set(maxLongitude);
}

if constexpr (std::is_same_v<GGRec, GeoRegularGGRecord>) {
geoGG.numberOfPointsAlongAParallel.set(gaussianGrid.nx(0));
geoGG.iDirectionIncrementInDegrees.set(360.0 / gaussianGrid.nx(0));
}

if constexpr (std::is_same_v<GGRec, GeoReducedGGRecord>) {
auto tmp = gaussianGrid.nx();
std::vector<long> pl(tmp.size(), 0);
for (int i = 0; i < tmp.size(); ++i) {
pl[i] = long(tmp[i]);
}
geoGG.pl.set(std::move(pl));
}

// Explicitly validate after manual setting
applyRecordDefaults(geoGG);
validateRecord(geoGG);
// Explicitly validate after manual setting
applyRecordDefaults(geoGG);
validateRecord(geoGG);
}

template <>
struct SetKeysFromAtlas<GeoReducedGGRecord> {
void operator()(GeoReducedGGRecord& geoGG, const std::string& gridName) const {
return setGGKeysFromAtlas(geoGG, gridName);
}
};

template <>
struct SetKeysFromAtlas<GeoRegularGGRecord> {
void operator()(GeoRegularGGRecord& geoGG, const std::string& gridName) const {
return setGGKeysFromAtlas(geoGG, gridName);
}
};


template <>
struct SetKeysFromAtlas<GeoLLRecord> {
void operator()(GeoLLRecord& geoLL, const std::string& gridName) const {
struct SetKeysFromAtlas<GeoRegularLLRecord> {
void operator()(GeoRegularLLRecord& geoLL, const std::string& gridName) const {
const auto regularLLGrid = createGrid<atlas::RegularLonLatGrid>(gridName);
geoLL.numberOfPointsAlongAParallel.set(regularLLGrid.nx());
geoLL.numberOfPointsAlongAMeridian.set(regularLLGrid.ny());
Expand Down
Loading
Loading