Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pmaciel committed Oct 30, 2024
1 parent 2d14328 commit 26230c6
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 23 deletions.
33 changes: 20 additions & 13 deletions src/mir/key/style/ECMWFStyle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,13 @@ void ECMWFStyle::sh2grid(action::ActionPlan& plan) const {
bool vod2uv = option(user, "vod2uv", false);
bool uv2uv = option(user, "uv2uv", false) || uv_input; // where "MIR knowledge of winds" is hardcoded

if (vod2uv && uv_input) {
throw exception::UserError("ECMWFStyle: option 'vod2uv' is incompatible with input U/V");
if (vod2uv) {
if (uv2uv) {
throw exception::UserError("ECMWFStyle: option 'vod2uv' is incompatible with 'uv2uv'");
}
if (uv_input) {
throw exception::UserError("ECMWFStyle: option 'vod2uv' is incompatible with input U/V");
}
}

if (resol.resultIsSpectral()) {
Expand All @@ -281,29 +286,31 @@ void ECMWFStyle::sh2grid(action::ActionPlan& plan) const {
auto target = target_gridded_from_parametrisation(parametrisation_, false);
if (!target.empty()) {
if (resol.resultIsSpectral()) {

plan.add("transform." + std::string(vod2uv ? "sh-vod-to-uv-" : "sh-scalar-to-") + target);

if (uv2uv) {
plan.add("filter.adjust-winds-scale-cos-latitude");
}

if ((vod2uv || uv2uv) && rotation) {
plan.add("filter.adjust-winds-directions");
}
}
else {

resol.prepare(plan);

if (uv2uv) {
plan.add("filter.adjust-winds-scale-cos-latitude");
}

// if the intermediate grid is the same as the target grid, the interpolation to the
// intermediate grid is not followed by an additional interpolation
std::string grid;
if (rotation || !user.get("grid", grid) || grid != resol.gridname()) {
plan.add("interpolate.grid2" + target);
}
}

if (vod2uv || uv2uv) {
ASSERT(vod2uv != uv2uv);

if (uv2uv) {
plan.add("filter.adjust-winds-scale-cos-latitude");
}

if (rotation) {
if ((vod2uv || uv2uv) && rotation) {
plan.add("filter.adjust-winds-directions");
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/mir/repres/regular/Lambert.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

#include "mir/repres/regular/Lambert.h"

#include <cmath>

#include "mir/param/MIRParametrisation.h"
#include "mir/util/Angles.h"
#include "mir/util/Exceptions.h"
Expand Down Expand Up @@ -88,8 +86,8 @@ void Lambert::fillGrib(grib_info& info) const {
info.grid.longitudeOfSouthernPoleInDegrees = longitudeOfSouthernPoleInDegrees_;
info.grid.uvRelativeToGrid = uvRelativeToGrid_ ? 1 : 0;

info.extra_set("DxInMetres", std::abs(x().step()));
info.extra_set("DyInMetres", std::abs(y().step()));
info.extra_set("DxInMetres", x().step());
info.extra_set("DyInMetres", y().step());
info.extra_set("Latin1InDegrees", reference[LLCOORDS::LAT]);
info.extra_set("Latin2InDegrees", reference[LLCOORDS::LAT]);
info.extra_set("LoVInDegrees", writeLonPositive_ ? util::normalise_longitude(reference[LLCOORDS::LON], 0)
Expand Down
3 changes: 1 addition & 2 deletions src/mir/repres/regular/RegularGrid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
#include "mir/repres/regular/RegularGrid.h"

#include <algorithm>
#include <cmath>
#include <memory>
#include <ostream>
#include <sstream>
#include <string>
#include <vector>

#include "eckit/config/Resource.h"
#include "eckit/utils/MD5.h"
Expand Down
15 changes: 12 additions & 3 deletions src/mir/util/Shape.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ namespace mir::util {


Shape::Shape(const param::MIRParametrisation& param) {
param.get("edition", edition = 0);

provided = param.get("shapeOfTheEarth", code = 6);

bool isOblate = false;
Expand All @@ -30,7 +28,7 @@ Shape::Shape(const param::MIRParametrisation& param) {
}


Shape::Shape(const Projection::Spec& spec) : edition(0) {
Shape::Shape(const Projection::Spec& spec) {
if (spec.has("radius")) {
code = 1L;
a = b = spec.getDouble("radius");
Expand Down Expand Up @@ -58,6 +56,17 @@ Shape& Shape::operator=(const Shape&) = default;

void Shape::fillGrib(grib_info& info, const Projection::Spec& spec) const {
// GRIB2 encoding of user-provided shape
long edition = info.packing.editionNumber;

const std::string EDITION("edition");
for (size_t j = 0; j < info.packing.extra_settings_count; ++j) {
auto& set = info.packing.extra_settings[j];
if (set.name == EDITION && set.type == CODES_TYPE_LONG) {
edition = set.long_value;
break;
}
}

if (edition != 2) {
return;
}
Expand Down
1 change: 0 additions & 1 deletion src/mir/util/Shape.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ struct Shape {
long code;
double a;
double b;
long edition;
bool provided;
};

Expand Down

0 comments on commit 26230c6

Please sign in to comment.