Skip to content

Commit 9d689f3

Browse files
authored
Update dependencies, move to Julia extensions (#104)
1 parent 3177919 commit 9d689f3

File tree

4 files changed

+106
-94
lines changed

4 files changed

+106
-94
lines changed

Project.toml

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
11
name = "ClimateBase"
22
uuid = "35604d93-0fb8-4872-9436-495b01d137e2"
33
authors = ["Datseris <[email protected]>", "Philippe Roy <[email protected]>"]
4-
version = "0.16.5"
4+
version = "0.17.0"
55

66
[deps]
77
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
88
DimensionalData = "0703355e-b756-11e9-17c0-8b28908087d0"
99
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
1010
NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
11-
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
1211
SignalDecomposition = "11a47235-7b84-4c7c-b885-fc3e2a9cf955"
1312
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1413
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1514
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
1615

16+
[weakdeps]
17+
GeoMakie = "db073c08-6b98-4ee5-b6a4-5efafb3259c6"
18+
19+
[extensions]
20+
ClimateBaseVisualizations = "GeoMakie"
21+
1722
[compat]
1823
DimensionalData = "0.20.1, 0.21, 0.22, 0.23, 0.24"
19-
Interpolations = "0.13.2, 0.14"
24+
GeoMakie = "0.6"
25+
Interpolations = "0.13.2, 0.14, 0.15"
2026
NCDatasets = "0.11, 0.12"
21-
Requires = "1"
22-
SignalDecomposition = "1"
27+
SignalDecomposition = "1.1"
2328
StaticArrays = "0.12, 1.0"
2429
StatsBase = "0.33, 0.34"
25-
julia = "1.5"
30+
julia = "1.9"
2631

2732
[extras]
2833
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

ext/ClimateBaseVisualizations.jl

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
module ClimateBaseVisualizations
2+
3+
using ClimateBase, GeoMakie
4+
5+
function ClimateBase.climplot(A, args...; scatter = spacestructure(A) == CoordinateSpace(),
6+
source = "+proj=longlat +datum=WGS84", dest = "+proj=eqearth",
7+
colorbar = true, name = string(DimensionalData.name(A)), coastkwargs = NamedTuple(), kwargs...)
8+
9+
# TODO: Perhaps setting custom colorrange leads to better plots?
10+
# vmin = haskey(kwargs, :vmin) ? kwargs[:vmin] : quantile(data, 0.025)
11+
# vmax = haskey(kwargs, :vmax) ? kwargs[:vmax] : quantile(data, 0.975)
12+
13+
fig = GeoMakie.Figure()
14+
ax = GeoMakie.GeoAxis(fig[1,1]; source, dest, title = GeoMakie.Observable(""))
15+
16+
coastplot = lines!(ax, GeoMakie.coastlines(); color = :black, overdraw = true, coastkwargs...)
17+
translate!(coastplot, 0, 0, 99) # ensure they are on top of other plotted elements
18+
19+
# TODO: @assert A has only space dimension
20+
21+
if scatter
22+
el = climscatter!(ax, A; kwargs...)
23+
else
24+
el = climsurface!(ax, A; kwargs...)
25+
end
26+
27+
if colorbar
28+
cb = GeoMakie.Colorbar(fig[1, 2], el; label = name)
29+
else
30+
cb = nothing
31+
end
32+
return fig, ax, el, cb
33+
end
34+
35+
##########################################################################################
36+
# # Scatter
37+
##########################################################################################
38+
# Notice that `A` is not declared as `ClimArray`, but assumed to be.
39+
# Duck-typing for Observables.
40+
function ClimateBase.climscatter!(ax, A; colormap = :dense, kwargs...)
41+
if hasdim(A, Coord)
42+
lonlat = dims(A, Coord).val
43+
elseif dims(A)[1] isa Lon
44+
londim = dims(A, Lon)
45+
latdim = dims(A, Lat)
46+
lonlat = [GeoMakie.Point2f0(l,lat) for lat in latdim for l in londim]
47+
else
48+
error("Unknown spatial dimensions for input.")
49+
end
50+
data = GeoMakie.lift(A -> vec(A.data), A)
51+
GeoMakie.scatter!(ax, lonlat; color = data, colormap, kwargs...)
52+
end
53+
54+
##########################################################################################
55+
# # Surface
56+
##########################################################################################
57+
# TODO: Change this to `contourf`
58+
59+
# Notice that `A` is not declared as `ClimArray`, but assumed to be.
60+
# Duck-typing for Observables.
61+
function ClimateBase.climsurface!(ax, A; colormap = :dense, kwargs...)
62+
# TODO: @assert A has only space
63+
if hasdim(A, Coord)
64+
# TODO: @pkeil this is for you
65+
error("Surface plots for `Coord` arrays are not supported yet!")
66+
end
67+
# TODO: This needs to depend on lon_0 or use the "meridian cut" function
68+
B = GeoMakie.lift(A -> longitude_circshift(A), A)
69+
lon = dims(B, Lon).val
70+
lat = dims(B, Lat).val
71+
data = GeoMakie.lift(B -> B.data, B)
72+
GeoMakie.surface!(ax, lon, lat, data; shading = false, colormap, kwargs...)
73+
end
74+
75+
76+
##########################################################################################
77+
# # Observables overloads
78+
##########################################################################################
79+
# These overloads allows me to write generic code that does not care if input
80+
# is observable or not. This leads to simple, clean, small, elegant code for
81+
# animating fields by simply replacing them with their observables.
82+
83+
GeoMakie.lift(f, x::ClimArray) = f(x)
84+
ClimateBase.DimensionalData.dims(o::GeoMakie.Observable, args...) = dims(o.val, args...)
85+
ClimateBase.DimensionalData.name(o::GeoMakie.Observable, args...) = name(o.val, args...)
86+
ClimateBase.spacestructure(A::GeoMakie.Observable) = spacestructure(A.val)
87+
88+
end

src/ClimateBase.jl

+1-7
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ include("tsa/continuation.jl")
2121
include("tsa/decomposition.jl")
2222

2323
include("exports.jl")
24-
25-
using Requires
26-
function __init__()
27-
@require GeoMakie="db073c08-6b98-4ee5-b6a4-5efafb3259c6" begin
28-
include("plotting/geomakie.jl")
29-
end
30-
end
24+
include("plotting/geomakie.jl")
3125

3226
end # module

src/plotting/geomakie.jl

+6-81
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export climscatter, climscatter!, climsurface!, climsurface, climplot
22

33
"""
44
climplot(A::ClimArray; kwargs...) → fig, ax, el, cb
5+
56
Main plotting function that dispatches to [`climscatter!`](@ref) if `A` has
67
an [`CoordinateSpace`](@ref) dimension, or to [`climsurface!`](@ref) for [`OrthogonalSpace`](@ref).
78
@@ -13,85 +14,9 @@ Plotting from ClimateBase.jl also works with `Observable`s that enclose a `ClimA
1314
You can update the values of the observable with another `ClimArray` with the same spatial
1415
dimension, and the plot will be updated. See documentation online for examples.
1516
"""
16-
function climplot(A, args...; scatter = spacestructure(A) == CoordinateSpace(),
17-
source = "+proj=longlat +datum=WGS84", dest = "+proj=eqearth",
18-
colorbar = true, name = string(DimensionalData.name(A)), kwargs...)
19-
20-
# TODO: Perhaps setting custom colorrange leads to better plots?
21-
# vmin = haskey(kwargs, :vmin) ? kwargs[:vmin] : quantile(data, 0.025)
22-
# vmax = haskey(kwargs, :vmax) ? kwargs[:vmax] : quantile(data, 0.975)
23-
24-
fig = GeoMakie.Figure()
25-
ax = GeoMakie.GeoAxis(fig[1,1]; source, dest, title = GeoMakie.Observable(""))
26-
27-
coastplot = lines!(ax, GeoMakie.coastlines(); color = :black, overdraw = true, coastkwargs...)
28-
translate!(coastplot, 0, 0, 99) # ensure they are on top of other plotted elements
29-
30-
# TODO: @assert A has only space dimension
31-
32-
if scatter
33-
el = climscatter!(ax, A; kwargs...)
34-
else
35-
el = climsurface!(ax, A; kwargs...)
36-
end
37-
38-
if colorbar
39-
cb = GeoMakie.Colorbar(fig[1, 2], el; label = name)
40-
else
41-
cb = nothing
42-
end
43-
return fig, ax, el, cb
44-
end
45-
46-
##########################################################################################
47-
# # Scatter
48-
##########################################################################################
49-
# Notice that `A` is not declared as `ClimArray`, but assumed to be.
50-
# Duck-typing for Observables.
51-
function climscatter!(ax, A; colormap = :dense, kwargs...)
52-
if hasdim(A, Coord)
53-
lonlat = dims(A, Coord).val
54-
elseif dims(A)[1] isa Lon
55-
londim = dims(A, Lon)
56-
latdim = dims(A, Lat)
57-
lonlat = [GeoMakie.Point2f0(l,lat) for lat in latdim for l in londim]
58-
else
59-
error("Unknown spatial dimensions for input.")
60-
end
61-
data = GeoMakie.lift(A -> vec(A.data), A)
62-
GeoMakie.scatter!(ax, lonlat; color = data, colormap, kwargs...)
63-
end
64-
65-
##########################################################################################
66-
# # Surface
67-
##########################################################################################
68-
# TODO: Change this to `contourf`
69-
70-
# Notice that `A` is not declared as `ClimArray`, but assumed to be.
71-
# Duck-typing for Observables.
72-
function climsurface!(ax, A; colormap = :dense, kwargs...)
73-
# TODO: @assert A has only space
74-
if hasdim(A, Coord)
75-
# TODO: @pkeil this is for you
76-
error("Surface plots for `Coord` arrays are not supported yet!")
77-
end
78-
# TODO: This needs to depend on lon_0 or use the "meridian cut" function
79-
B = GeoMakie.lift(A -> longitude_circshift(A), A)
80-
lon = dims(B, Lon).val
81-
lat = dims(B, Lat).val
82-
data = GeoMakie.lift(B -> B.data, B)
83-
GeoMakie.surface!(ax, lon, lat, data; shading = false, colormap, kwargs...)
84-
end
85-
86-
87-
##########################################################################################
88-
# # Observables overloads
89-
##########################################################################################
90-
# These overloads allows me to write generic code that does not care if input
91-
# is observable or not. This leads to simple, clean, small, elegant code for
92-
# animating fields by simply replacing them with their observables.
17+
function climplot end
9318

94-
GeoMakie.lift(f, x::ClimArray) = f(x)
95-
DimensionalData.dims(o::GeoMakie.Observable, args...) = dims(o.val, args...)
96-
DimensionalData.name(o::GeoMakie.Observable, args...) = name(o.val, args...)
97-
spacestructure(A::GeoMakie.Observable) = spacestructure(A.val)
19+
function climscatter end
20+
function climscatter! end
21+
function climsurface end
22+
function climsurface! end

0 commit comments

Comments
 (0)