-
Notifications
You must be signed in to change notification settings - Fork 3
Add Var.push_dim #354
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
base: main
Are you sure you want to change the base?
Add Var.push_dim #354
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #354 +/- ##
=======================================
Coverage 99.44% 99.44%
=======================================
Files 18 18
Lines 1965 1978 +13
=======================================
+ Hits 1954 1967 +13
Misses 11 11 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
b8809c7 to
3a8d485
Compare
| function push_dim(var::OutputVar, dim_name, dim_value, dim_attrib_pairs...;) | ||
| dims = deepcopy(var.dims) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work properly if dim_value is a Dates.DateTime. I am not too sure how crucial that functionality is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this because dims is a dict with values that are arrays of floats? Could you just make a new dict and the loop over the old one and add the keys/values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't plan on supporting this, it might be good to catch the case and give an informative error
| Base.permutedims(var::OutputVar, perm) | ||
| Var.push_dim | ||
| Var.reordered_as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am also not sure if this belongs in ClimaAnalysis extension in ClimaCalibrate or ClimaAnalysis.
| function push_dim(var::OutputVar, dim_name, dim_value, dim_attrib_pairs...;) | ||
| dims = deepcopy(var.dims) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this because dims is a dict with values that are arrays of floats? Could you just make a new dict and the loop over the old one and add the keys/values?
| If you want to change the order of the dimensions, then call `permutedims` after | ||
| this function. | ||
| """ | ||
| function push_dim(var::OutputVar, dim_name, dim_value, dim_attrib_pairs...;) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a huge fan of this function name, but I also can't think of a better name. Maybe something like
append_singleton_dim?
| function push_dim(var::OutputVar, dim_name, dim_value, dim_attrib_pairs...;) | ||
| dims = deepcopy(var.dims) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't plan on supporting this, it might be good to catch the case and give an informative error
nefrathenrici
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
| ## Add singleton dimension | ||
|
|
||
| This release introduces `push_dim` which allows the user to add a singleton | ||
| dimension to end of the dimensions of a `OutputVar`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| dimension to end of the dimensions of a `OutputVar`. | |
| dimension to the end of the dimensions of a `OutputVar`. |
| error( | ||
| "Dimension ($dim_name) cannot be added as it already corresponds to an existing dimension ($conventional_dim_names)", | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| error( | |
| "Dimension ($dim_name) cannot be added as it already corresponds to an existing dimension ($conventional_dim_names)", | |
| ) | |
| existing_dim = findfirst(d -> conventional_dim_name(d) == conventional_dim_name(dim_name), keys(dims)) | |
| error( | |
| "Dimension \"$dim_name\" cannot be added as it already corresponds to an existing dimension \"$existing_dim\" (both map to \"$(conventional_dim_name(dim_name))\")" | |
| ) |
Minor, but it would be good to print the conflicting dimension for the user.
| @test size(lat_var.data) == (2, 1) | ||
|
|
||
| # Error handling | ||
| @test_throws ErrorException ClimaAnalysis.push_dim(var, "lon", 42.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a test for adding a dimension with a different name but same conventional name? For example, adding a "longitude" dimension since the "lon" dimension exists already:
@test_throws ErrorException ClimaAnalysis.push_dim(var, "longitude", 42.0)
closes #353 - This PR adds
Var.push_dimwhich adds an extra dimension of length 1 to aOutputVar.