-
Notifications
You must be signed in to change notification settings - Fork 37
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 tests for unitful cellarea
#799
base: main
Are you sure you want to change the base?
Changes from 3 commits
a07be84
bcd7fb1
f5fce8b
3360f34
5a14cbe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,7 @@ | ||||||||||||||
using Rasters, DimensionalData, Rasters.Lookups, Proj | ||||||||||||||
using Test | ||||||||||||||
using DimensionalData: @dim, YDim | ||||||||||||||
import Unitful | ||||||||||||||
include(joinpath(dirname(pathof(Rasters)), "../test/test_utils.jl")) | ||||||||||||||
|
||||||||||||||
@testset "cellarea" begin | ||||||||||||||
|
@@ -70,4 +71,29 @@ include(joinpath(dirname(pathof(Rasters)), "../test/test_utils.jl")) | |||||||||||||
# test missing crs throws an error | ||||||||||||||
nocrsdimz = setcrs(dimz, nothing) | ||||||||||||||
@test_throws ArgumentError cellarea(nocrsdimz) | ||||||||||||||
|
||||||||||||||
@testset "Unitful cellarea" begin | ||||||||||||||
# Case 1: cellarea with unitful manifold | ||||||||||||||
# This is the simplest case | ||||||||||||||
unitful_manifold = Spherical(; radius = Spherical().radius * Unitful.u"m") | ||||||||||||||
unitful_cellarea = cellarea(unitful_manifold, dimz_3857) | ||||||||||||||
@test unitful_cellarea isa Raster{<:Unitful.Quantity} | ||||||||||||||
@test Unitful.ustrip.(parent(unitful_cellarea)) == cellarea(Spherical(; radius = unitful_manifold.radius |> Unitful.ustrip), dimz_3857) | ||||||||||||||
# Case 2: unitful dimensions | ||||||||||||||
ux_3857 = rebuild(x_3857; val = rebuild(val(x_3857); data = val(x_3857) .* Unitful.u"m", span = Regular(val(x_3857).span.step * Unitful.u"m"))) | ||||||||||||||
uy_3857 = rebuild(y_3857; val = rebuild(val(y_3857); data = val(y_3857) .* Unitful.u"m", span = Regular(val(y_3857).span.step * Unitful.u"m"))) | ||||||||||||||
unitful_dimz_3857 = (ux_3857, uy_3857) | ||||||||||||||
@test cellarea(Planar(), unitful_dimz_3857) isa Raster{<:Unitful.Quantity} | ||||||||||||||
@test Unitful.ustrip.(parent(cellarea(Planar(), unitful_dimz_3857))) == parent(cellarea(Planar(), dimz_3857)) | ||||||||||||||
# Unitful lookups shouldn't work without a unitful manifold | ||||||||||||||
@test_throws Unitful.DimensionError cellarea(unitful_dimz_3857) | ||||||||||||||
# The tests below fail because Unitful apparently can't convert to Float64... | ||||||||||||||
# (see https://github.com/PainterQubits/Unitful.jl/issues/742) | ||||||||||||||
# But we also have to re-convert back to the original unit type, which cellarea currently | ||||||||||||||
# doesn't do. | ||||||||||||||
|
||||||||||||||
Comment on lines
+90
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Unitful is like a free test suite for physical models, not converting is by design! If we are going to make units work here we need to do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense. Maybe we have a (This is getting to be a mouthful..) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah those names! But makes sense. Somehow we need some mapping from Proj units to Unitful. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does conversion from Proj to Unitful have to live in Rasters.jl? Shouldn't this be in a ProjUnitfulExt? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, we could introduce a nice interface to batch transform an array, but do it out of place in Proj.jl. Then the Unitful stuff could also live there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was initially going to put that here because this calls the C-API directly, but if it doesn't have to then there's no reason to stop this from calling Proj. |
||||||||||||||
# unitful_cellarea = cellarea(unitful_manifold, unitful_dimz_3857) | ||||||||||||||
# @test unitful_cellarea isa Raster{<:Unitful.Quantity} | ||||||||||||||
# @test Unitful.ustrip.(unitful_cellarea) == cellarea(unitful_manifold, dimz_3857) | ||||||||||||||
end | ||||||||||||||
end |
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 is also super complicated, should we have DD overloads to make constructing lookups with unitful easier?
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 think
set
will just work this out for us, no need torebuild
manually?