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

Feature/scaling action #38

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open

Conversation

stefaniereuter
Copy link
Contributor

Adding scaling action for Climate DT Phase 2 portfolio.

@codecov-commenter
Copy link

codecov-commenter commented Nov 19, 2024

Codecov Report

Attention: Patch coverage is 0% with 96 lines in your changes missing coverage. Please review.

Project coverage is 23.10%. Comparing base (099d8f8) to head (2427724).

Files with missing lines Patch % Lines
src/multio/action/scale/Scale.cc 0.00% 34 Missing ⚠️
src/multio/action/scale/Mapping.cc 0.00% 20 Missing ⚠️
src/multio/action/scale/Scaling.cc 0.00% 16 Missing ⚠️
src/multio/action/scale/Scaling.h 0.00% 15 Missing ⚠️
src/multio/action/scale/MetadataUtils.cc 0.00% 10 Missing ⚠️
src/multio/action/scale/Mapping.h 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop      #38      +/-   ##
===========================================
- Coverage    23.18%   23.10%   -0.08%     
===========================================
  Files          284      290       +6     
  Lines        30216    30312      +96     
  Branches      1104     1118      +14     
===========================================
  Hits          7005     7005              
- Misses       23211    23307      +96     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

src/multio/action/scale/Scale.cc Outdated Show resolved Hide resolved
src/multio/action/scale/Scale.cc Outdated Show resolved Hide resolved
}

std::string cparam{"xxx"};
if (auto param = msg.metadata().getOpt<std::string>(glossary().param); param) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need the ; param bit. If we use assignment in the if, the result is whether param has a valid value or not. But this practice is, anyway, questionable. But I'm personally fine with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This I got from Mirco as he was working on similar logic for his statistic class. I did some reading on this. It's true since I only use param and paramID within the if clause it should work but I think with cpp 17 the recommentation is to use as this?

src/multio/action/scale/Scale.cc Outdated Show resolved Hide resolved
std::set<std::string> paramsToScale_;

template <typename Precision>
message::Message ScaleMessage(message::Message&& msg) const;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just pass by lvalue reference and return void. I think it is simpler and safer in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry overlooked the first time I checked the comments. I agree can be reference. I'll try and test that

return;
}
// Apply the scaling factor using std::transform
std::transform(data, data + size, data,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, std::for_each is sufficient. It is simpler and thus preferable, I'd say.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I disagree in this case, I'm sorry. I think transform makes it clearer as to the context of the underlying action (which in fact is a transformation of data in place). I agree it could be done with for_each but I don't think it would be simpler. Nevertheless I'm also not very partial on this line of code. So if you really prefer for_each I can change the line to
std::for_each(data, data + size, [scaleFactor](Precision& value) { value = static_cast<Precision>(value * scaleFactor); });


ScaleScaling::ScaleScaling(const config::ComponentConfiguration& compConf) : hasScaling_(false), scaleFactor_{} {

const auto mappings = compConf.parsedConfig().has("mapping-definition")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be some duplication of logic here as well. Can we remove the one in Scale.cc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was weighing that option: I can either create individual plans for fields where scaling is needed or as I currently have add it to plans where only a subset of fields actually need scaling specified by case in the plan. BUT then I wanted to have a check to leave this action as early as possible. I can move the logic in a util function and call it, but this would still be in all three cases. Or I can remove the whole logic of checking as soon as possible. Or I can retrieve the param only in scale.cc and then pass it to the apply function (But this I didn't prefer since I wanted to have the Mapping and scaling as enclosed as possbile sind I pass the metadata anyway and hence have the information anyway)


void ScaleMapping::applyMapping(message::Metadata& md) const {
if (hasMapping_) {
std::string cparam{"xxx"};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments here about the logic and duplication (triplication). I'm a bit confused. I think we need this in two places but not in three?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see explanation above. Happy to change but would like to discuss what makes the most sense

src/multio/action/scale/Mapping.cc Outdated Show resolved Hide resolved
src/multio/action/scale/Mapping.cc Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants