Skip to content

Commit

Permalink
Add ifs-mapping action
Browse files Browse the repository at this point in the history
  • Loading branch information
geier1993 committed Jan 8, 2025
1 parent ad44f4a commit 5cb4ce9
Show file tree
Hide file tree
Showing 16 changed files with 246 additions and 50 deletions.
8 changes: 6 additions & 2 deletions src/ecom/common/om_multio_utils_v3_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,8 @@ SUBROUTINE MULTIO_WRITE_PARAMETRIZATION( MIO_HANDLE, MODEL_PARAMS )
LON_STRET_DEG = 180._JPRD_K/(2.0_JPRD_K*ASIN(1.0_JPRD_K))*REAL(YPI%RLOCEN,JPRD_K)

IF( YPI%NSTTYP .GE. 2 ) THEN
ERR = MIOMD%SET('gridType','stretched_rotated_sh')
PP_DEBUG_CRITICAL_COND_THROW( ERR.NE.MULTIO_SUCCESS, 1 )
ERR = MIOMD%SET('sphericalHarmonicsType','stretched_rotated_sh')
PP_DEBUG_CRITICAL_COND_THROW( ERR.NE.MULTIO_SUCCESS, 1 )
ERR = MIOMD%SET('latitudeOfStretchingPoleInDegrees', LAT_STRET_DEG )
Expand All @@ -458,15 +460,17 @@ SUBROUTINE MULTIO_WRITE_PARAMETRIZATION( MIO_HANDLE, MODEL_PARAMS )
ERR = MIOMD%SET('stretchingFactor',YPI%RSTRET)
PP_DEBUG_CRITICAL_COND_THROW( ERR.NE.MULTIO_SUCCESS, 1 )
ELSEIF( ABS(YPI%RSTRET-1.0_JPRD_K) .GE. 1.E-14_JPRD_K ) THEN
ERR = MIOMD%SET('gridType', 'stretched_sh' )
PP_DEBUG_CRITICAL_COND_THROW( ERR.NE.MULTIO_SUCCESS, 1 )
ERR = MIOMD%SET('sphericalHarmonicsType', 'stretched_sh' )
PP_DEBUG_CRITICAL_COND_THROW( ERR.NE.MULTIO_SUCCESS, 1 )
ERR = MIOMD%SET('stretchingFactor', YPI%RSTRET )
PP_DEBUG_CRITICAL_COND_THROW( ERR.NE.MULTIO_SUCCESS, 1 )
ELSE

ERR = MIOMD%SET('gridType','sh')
PP_DEBUG_CRITICAL_COND_THROW( ERR.NE.MULTIO_SUCCESS, 1 )
ERR = MIOMD%SET('sphericalHarmonicsType','sh')
PP_DEBUG_CRITICAL_COND_THROW( ERR.NE.MULTIO_SUCCESS, 1 )

ENDIF

ERR = MIOMD%SET('pentagonalResolutionParameterJ',YPI%ISMAX)
Expand Down
52 changes: 26 additions & 26 deletions src/ecom/flavours/multio_no_enc_output_manager_v2_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -474,28 +474,28 @@ SUBROUTINE MULTIO_NO_ENC_WRITE_ATM_DP( THIS, YDMSG, VALUES_DP )
CERR = MIOMD%SET( "paramId", INT(YDMSG%PARAM_ID_, C_LONG) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

CERR = MIOMD%SET( "curr_step", INT(YDMSG%ISTEP_, C_LONG) )
CERR = MIOMD%SET( "currentStep", INT(YDMSG%ISTEP_, C_LONG) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

CERR = MIOMD%SET( "prev_pp", INT(YDMSG%IPREVPP_, C_LONG) )
CERR = MIOMD%SET( "previousProcessingPoint", INT(YDMSG%IPREVPP_, C_LONG) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

CERR = MIOMD%SET( "prefix", INT(YDMSG%IPREF_, C_LONG) )
CERR = MIOMD%SET( "ifsPrefix", INT(YDMSG%IPREF_, C_LONG) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

CERR = MIOMD%SET( "repres", INT(YDMSG%IREPRES_, C_LONG) )
CERR = MIOMD%SET( "ifsRepres", INT(YDMSG%IREPRES_, C_LONG) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

CERR = MIOMD%SET( "level", INT(YDMSG%ILEVG_, C_LONG) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

CERR = MIOMD%SET( "nvalues", INT(YDMSG%NVALUES_, C_LONG) )
CERR = MIOMD%SET( "numberOfValues", INT(YDMSG%NVALUES_, C_LONG) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

CERR = MIOMD%SET( "nmissing", INT(YDMSG%NUNDF_, C_LONG) )
CERR = MIOMD%SET( "numberOfMissingValues", INT(YDMSG%NUNDF_, C_LONG) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

CERR = MIOMD%SET( "missing_value", REAL(YDMSG%XUNDF_, C_DOUBLE) )
CERR = MIOMD%SET( "missingValue", REAL(YDMSG%XUNDF_, C_DOUBLE) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

! Write to multIO
Expand Down Expand Up @@ -659,28 +659,28 @@ SUBROUTINE MULTIO_NO_ENC_WRITE_ATM_SP( THIS, YDMSG, VALUES_SP )
CERR = MIOMD%SET( "paramId", INT(YDMSG%PARAM_ID_, C_LONG) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

CERR = MIOMD%SET( "curr_step", INT(YDMSG%ISTEP_, C_LONG) )
CERR = MIOMD%SET( "currentStep", INT(YDMSG%ISTEP_, C_LONG) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

CERR = MIOMD%SET( "prev_pp", INT(YDMSG%IPREVPP_, C_LONG) )
CERR = MIOMD%SET( "previousProcessingPoint", INT(YDMSG%IPREVPP_, C_LONG) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

CERR = MIOMD%SET( "prefix", INT(YDMSG%IPREF_, C_LONG) )
CERR = MIOMD%SET( "ifsPrefix", INT(YDMSG%IPREF_, C_LONG) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

CERR = MIOMD%SET( "level", INT(YDMSG%ILEVG_, C_LONG) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

CERR = MIOMD%SET( "repres", INT(YDMSG%IREPRES_, C_LONG) )
CERR = MIOMD%SET( "ifsRepres", INT(YDMSG%IREPRES_, C_LONG) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

CERR = MIOMD%SET( "nvalues", INT(YDMSG%NVALUES_, C_LONG) )
CERR = MIOMD%SET( "numberOfValues", INT(YDMSG%NVALUES_, C_LONG) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

CERR = MIOMD%SET( "nmissing",INT( YDMSG%NUNDF_, C_LONG) )
CERR = MIOMD%SET( "numberOfMissingValues",INT( YDMSG%NUNDF_, C_LONG) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

CERR = MIOMD%SET( "missing_value", REAL(YDMSG%XUNDF_, C_DOUBLE) )
CERR = MIOMD%SET( "missingValue", REAL(YDMSG%XUNDF_, C_DOUBLE) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

! Write to multIO
Expand Down Expand Up @@ -850,22 +850,22 @@ SUBROUTINE MULTIO_NO_ENC_WRITE_WAM_DP( THIS, YDMSG, VALUES_DP )
CERR = MIOMD%SET( "paramId", INT(YDMSG%PARAM_ID_, C_LONG) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

CERR = MIOMD%SET( "curr_step", INT(YDMSG%ISTEP_, C_LONG) )
CERR = MIOMD%SET( "currentStep", INT(YDMSG%ISTEP_, C_LONG) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

CERR = MIOMD%SET( "prefix", INT(YDMSG%IPREF_, C_LONG) )
CERR = MIOMD%SET( "ifsPrefix", INT(YDMSG%IPREF_, C_LONG) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

CERR = MIOMD%SET( "repres", INT(YDMSG%IREPRES_, C_LONG) )
CERR = MIOMD%SET( "ifsRepres", INT(YDMSG%IREPRES_, C_LONG) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

CERR = MIOMD%SET( "nvalues", INT(YDMSG%NVALUES_, C_LONG) )
CERR = MIOMD%SET( "numberOfValues", INT(YDMSG%NVALUES_, C_LONG) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

CERR = MIOMD%SET( "nmissing", INT(YDMSG%NUNDF_, C_LONG) )
CERR = MIOMD%SET( "numberOfMissingValues", INT(YDMSG%NUNDF_, C_LONG) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

CERR = MIOMD%SET( "missing_value", REAL(YDMSG%XUNDF_, C_DOUBLE) )
CERR = MIOMD%SET( "missingValue", REAL(YDMSG%XUNDF_, C_DOUBLE) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

CERR = MIOMD%SET( "angle", INT(YDMSG%IANGLE, C_LONG) )
Expand Down Expand Up @@ -1072,22 +1072,22 @@ SUBROUTINE MULTIO_NO_ENC_WRITE_WAM_SP( THIS, YDMSG, VALUES_SP )
CERR = MIOMD%SET( "paramId", INT(YDMSG%PARAM_ID_, C_LONG) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

CERR = MIOMD%SET( "curr_step", INT(YDMSG%ISTEP_, C_LONG) )
CERR = MIOMD%SET( "currentStep", INT(YDMSG%ISTEP_, C_LONG) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

CERR = MIOMD%SET( "prefix", INT(YDMSG%IPREF_, C_LONG) )
CERR = MIOMD%SET( "ifsPrefix", INT(YDMSG%IPREF_, C_LONG) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

CERR = MIOMD%SET( "repres", INT(YDMSG%IREPRES_, C_LONG) )
CERR = MIOMD%SET( "ifsRepres", INT(YDMSG%IREPRES_, C_LONG) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

CERR = MIOMD%SET( "nvalues", INT(YDMSG%NVALUES_, C_LONG) )
CERR = MIOMD%SET( "numberOfValues", INT(YDMSG%NVALUES_, C_LONG) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

CERR = MIOMD%SET( "nmissing", INT(YDMSG%NUNDF_, C_LONG) )
CERR = MIOMD%SET( "numberOfMissingValues", INT(YDMSG%NUNDF_, C_LONG) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

CERR = MIOMD%SET( "missing_value", REAL(YDMSG%XUNDF_, C_DOUBLE) )
CERR = MIOMD%SET( "missingValue", REAL(YDMSG%XUNDF_, C_DOUBLE) )
PP_DEBUG_DEVELOP_COND_THROW( CERR.NE.MULTIO_SUCCESS, 2 )

CERR = MIOMD%SET( "angle", INT(YDMSG%IANGLE, C_LONG) )
Expand Down
1 change: 1 addition & 0 deletions src/multio/action/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ add_subdirectory(interpolate)
add_subdirectory(interpolate-fesom)
add_subdirectory(select)
add_subdirectory(scale)
add_subdirectory(tag-filter)
23 changes: 13 additions & 10 deletions src/multio/action/ifs-mapping/IfsMapping.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,20 @@ ifs::UniqueFieldId IfsMapping::fieldIdFromMetadata(const message::Metadata& md)
using T = std::decay_t<decltype(val)>;
if constexpr (std::is_same_v<T, std::string>) {
m2gPrefixToLevType_.insert_or_assign(eckit::Value{glossary().ifsPrefix}, eckit::Value{val});
}
return;
}
if constexpr (std::is_same_v<T, std::int64_t>) {
m2gPrefixToLevType_.insert_or_assign(eckit::Value{glossary().ifsPrefix}, eckit::Value{val});
return;
}
NOTIMP;
});

m2gPrefixToLevType_.insert_or_assign(eckit::Value{glossary().paramId}, eckit::Value{res.paramId});
m2gPrefixToLevType_.insert_or_assign(eckit::Value{glossary().ifsPrefix}, eckit::Value{res.level});
m2gPrefixToLevType_.insert_or_assign(eckit::Value{glossary().level}, eckit::Value{res.level});


util::Mars2GribMetadataSetter keySetter{levTypeMd_};
util::Mars2GribMetadataSetter keySetter{levTypeMd_, true};
metkit::mars2grib::convertMars2Grib(m2gPrefixToLevType_, keySetter, metkit::mars2grib::ifsPrefixToLevTypeRuleList());
res.levtype = levTypeMd_.get<std::string>("levType");

Expand All @@ -216,21 +218,21 @@ const ifs::ParamIdInfo& IfsMapping::getParamIdInfo(std::int64_t pid) {
if (searchPid == paramIdInfo_.end()) {
m2gPid_.insert_or_assign("paramId", pid);
message::BaseMetadata md;
util::Mars2GribMetadataSetter keySetter{md};
util::Mars2GribMetadataSetter keySetter{md, true};
metkit::mars2grib::convertMars2Grib(m2gPid_, keySetter, metkit::mars2grib::statParamRuleList());

ifs::ParamIdInfo info;
if (auto search = md.find("typeOfStatisticalProcessing"); search != md.end()) {
info.typeOfStatisticalProcessing = search->second.get<std::int64_t>();
if (auto tosp = md.getOpt<std::int64_t>("typeOfStatisticalProcessing"); tosp) {
info.typeOfStatisticalProcessing = *tosp;
info.typeOfTimeRange = ifs::TypeOfTimeRange::FromLastPP;
info.emitStepZero = false;

if (auto searchLength = md.find("lengthOfTimeRange"); searchLength != md.end()) {
info.lengthOfTimeRange = searchLength->second.get<std::int64_t>();
if (auto len = md.getOpt<std::int64_t>("lengthOfTimeRange"); len) {
info.lengthOfTimeRange = *len;
info.typeOfTimeRange = ifs::TypeOfTimeRange::FixedSize;
}
if (auto searchIndicator = md.find("indicatorOfUnitForTimeRange"); searchIndicator != md.end()) {
info.indicatorOfUnitForTimeRange = searchIndicator->second.get<std::int64_t>();
if (auto ind = md.getOpt<std::int64_t>("indicatorOfUnitForTimeRange"); ind) {
info.indicatorOfUnitForTimeRange = ind;
}
} else {
info.typeOfTimeRange = ifs::TypeOfTimeRange::Instant;
Expand All @@ -257,4 +259,5 @@ void IfsMapping::print(std::ostream& os) const {


static ActionBuilder<IfsMapping> IfsMappingBuilder("ifs-mapping");

} // namespace multio::action
2 changes: 1 addition & 1 deletion src/multio/action/ifs-mapping/IfsMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
namespace multio::action::ifs {

/**
* Example messag metadata={"format":"raw","precision":"double","missing_value":1.79769e+308,"nmissing":0,"nvalues":654400,"level":1,"repres":1,"prefix":1,"prev_pp":-1,"curr_step":4,"paramID":133","model":"ifsosphere"}
* Example messag metadata={"format":"raw","precision":"double","missingValue":1.79769e+308,"numberOfMissingValues":0,"numberOfValues":654400,"level":1,"repres":1,"prefix":1,"previousProcessingPoint":-1,"currentStep":4,"paramId":133","model":"ifsosphere"}
*/

enum class Repres: std::int64_t {
Expand Down
17 changes: 17 additions & 0 deletions src/multio/action/tag-filter/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

ecbuild_add_library(

TARGET multio-action-tag-filter

SOURCES
TagFilter.cc
TagFilter.h

PRIVATE_INCLUDES
${ECKIT_INCLUDE_DIRS}

CONDITION

PUBLIC_LIBS
multio
)
74 changes: 74 additions & 0 deletions src/multio/action/tag-filter/TagFilter.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* (C) Copyright 1996- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
* In applying this licence, ECMWF does not waive the privileges and immunities
* granted to it by virtue of its status as an intergovernmental organisation nor
* does it submit to any jurisdiction.
*/

#include "TagFilter.h"

#include <algorithm>

#include "eckit/exception/Exceptions.h"

#include "multio/LibMultio.h"

using multio::message::Message;
using multio::message::match::MatchReduce;

namespace multio::action {

//--------------------------------------------------------------------------------------------------

TagFilter::TagFilter(const ComponentConfiguration& compConf) : ChainedAction{compConf}, tags_{} {
if (compConf.parsedConfig().has("tags")) {
if (compConf.parsedConfig().isString("tags")) {
tags_.emplace(message::Message::parseTag(compConf.parsedConfig().getString("tags")));
} else if (compConf.parsedConfig().isStringList("tags")) {
for(const auto& t: compConf.parsedConfig().getStringVector("tags")) {
tags_.emplace(message::Message::parseTag(t));
}
} else {
std::ostringstream oss;
oss << "TagFilter: Key \"tags\" must be a string or list of strings." << compConf.parsedConfig();
throw eckit::UserError(oss.str(), Here());
}
}
}

void TagFilter::executeImpl(Message msg) {
// Tag filter is important for parametrization -
// otherwise parametrization is made on a custom key "category"...
// which will be read for all followup metadata that has no explicit key "Tag"
if (!tags_.empty()) {
if (auto search = tags_.find(msg.tag()); search == tags_.end()) {
// Tag not found
return;
}
}

executeNext(std::move(msg));
}

void TagFilter::print(std::ostream& os) const {
os << "TagFilter(";
bool first = true;
for(auto t: tags_) {
if (!first) {
os << ", ";
first = false;
}
os << message::Message::tag2str(t);
}
}

//--------------------------------------------------------------------------------------------------

static ActionBuilder<TagFilter> TagFilterBuilder("tag-filter");

//--------------------------------------------------------------------------------------------------

} // namespace multio::action
47 changes: 47 additions & 0 deletions src/multio/action/tag-filter/TagFilter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* (C) Copyright 1996- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
* In applying this licence, ECMWF does not waive the privileges and immunities
* granted to it by virtue of its status as an intergovernmental organisation nor
* does it submit to any jurisdiction.
*/

/// @author Domokos Sarmany
/// @author Simon Smart
/// @author Tiago Quintino

/// @date Jan 2019

#pragma once

#include <iosfwd>
#include <iterator>
#include <set>
#include <vector>

#include "multio/action/ChainedAction.h"
#include "multio/message/MetadataMatcher.h"

namespace multio::action {

//----------------------------------------------------------------------------------------------------------------------

class TagFilter : public ChainedAction {
public:
explicit TagFilter(const ComponentConfiguration& compConf);

private: // methods
void print(std::ostream& os) const override;

bool matches(const message::Message& msg) const;

void executeImpl(message::Message msg) override;
private: // members
std::unordered_set<message::Message::Tag> tags_;
};

//----------------------------------------------------------------------------------------------------------------------

} // namespace multio::action
2 changes: 2 additions & 0 deletions src/multio/api/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ list( APPEND multio_action_plugins
multio-action-null
multio-action-print
multio-action-select
multio-action-tag-filter
multio-action-single-field-sink
multio-action-sink
multio-action-statistics
multio-action-transport
multio-action-renumber-healpix
multio-action-interpolate-fesom
multio-action-scale
multio-action-ifs-mapping
)

if( HAVE_MIR )
Expand Down
Loading

0 comments on commit 5cb4ce9

Please sign in to comment.