-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add support for unitful #70
Conversation
354fda3
to
e9f582e
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #70 +/- ##
==========================================
+ Coverage 96.31% 96.35% +0.03%
==========================================
Files 8 9 +1
Lines 516 548 +32
==========================================
+ Hits 497 528 +31
- Misses 19 20 +1 ☔ View full report in Codecov by Sentry. |
d69aed4
to
3a36abf
Compare
This commit adds support for physical units managed by Unitful.jl. Unitful is added as an extension. Currently, ClimaAnalysis.jl always includes this extension (and Unitful is a hard dependency of ClimaAnalysis), but this opens a pathway to making Unitful an optional dependency in the future if we decide to do so. (I am taking this idea from Unitful itself.) The technical choice on how to integrate Unitful is the following: In the constructor, ClimaAnalysis scans for the `units` keyword in the attributes. When found, we try to parse it with `Unitful.uparse`. If possible, we replace the value for `units` in `attributes` with the `Unitful` version. If it is not possible, we leave the string. When units are requested with `ClimaAnalysis.units`, we always return a string. The choice being made here is that we modify the input given (from `String` to `Unitful`), instead of creating a separate box where to put this information. The reason for this choice is that it removes the need to keep information synced and provide a single ground truth of what units are. We also decide to not attach units directly to `data` to avoid performance penalties with manipulating large arrays.
Extensions could have name collisions, adding ClimaAnalysis in front dramatically reduces the likelihood and follows conventions.
CliMA/ClimaAnalysis.jl#70 is _slightly_ breaking if units are accessed directly
CliMA/ClimaAnalysis.jl#70 is _slightly_ breaking if units are accessed directly
CliMA/ClimaAnalysis.jl#70 is _slightly_ breaking if units are accessed directly
CliMA/ClimaAnalysis.jl#70 is _slightly_ breaking if units are accessed directly
CliMA/ClimaAnalysis.jl#70 is _slightly_ breaking if units are accessed directly
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 a beautiful PR!
I have one question (curiosity) but no request
Why did you define convert_units docstring in Var.jl, and the actual function in ext/ClimaAnalysisUnitfulExt.jl?
Is it to keep ClimaAnalysisUnitfulExt focused on actual code, for better readability?
I had it there originally, but Documenter wouldn't find the docstring. |
CliMA/ClimaAnalysis.jl#70 is _slightly_ breaking if units are accessed directly
This commit adds support for physical units managed by Unitful.jl.
Unitful is added as an extension. Currently, ClimaAnalysis.jl always includes this extension (and Unitful is a hard dependency of
ClimaAnalysis), but this opens a pathway to making Unitful an optional dependency in the future if we decide to do so. (I am taking this idea from Unitful itself.)
The technical choice on how to integrate Unitful is the following:
In the constructor, ClimaAnalysis scans for the
units
keyword in the attributes. When found, we try to parse it withUnitful.uparse
. If possible, we replace the value forunits
inattributes
with theUnitful
version. If it is not possible, we leave the string.When units are requested with
ClimaAnalysis.units
, we always return a string.The choice being made here is that we modify the input given (from
String
toUnitful
), instead of creating a separate box where to put this information. The reason for this choice is that it removes the need to keep information synced and provide a single ground truth of what units are.We also decide to not attach units directly to
data
to avoid performance penalties with manipulating large arrays.This PR also cleans up a couple of things about extensions along the way.
Closes #53 (except for dimensions)