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

[WIP] Initiate GoeMakie branch #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ ClimateTools = "4f4ee721-4970-5af2-8560-6c1d960e3231"
Conda = "8f4d0f93-b110-5947-807f-2305c1781a2d"
CondaBinDeps = "a9693cdc-2bc8-5703-a9cd-1da358117377"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
GeoMakie = "db073c08-6b98-4ee5-b6a4-5efafb3259c6"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"

Choose a reason for hiding this comment

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

You may want to change these to CairoMakie and AbstractPlotting, which don't bring in the GLMakie dependency.

Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we only depend on AbstractPlotting and GeoMakie, without enforcing a backend? That's what I do in InteractiveChaos for example (no GeoMakie there)

Choose a reason for hiding this comment

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

Yep, that's also doable, there aren't any explicit ties to CairoMakie.

MakieLayout = "5a521ce4-ebb9-4793-b5b7-b334dfe8393c"
NetCDF = "30363a11-5582-574a-97bb-aa9a979735b9"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
Expand Down
3 changes: 3 additions & 0 deletions src/ClimatePlots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ using Reexport
@reexport using ClimateBase
using PyCall
using PyPlot
using GeoMakie
using Proj4
using Statistics
import Base.show

Expand All @@ -32,5 +34,6 @@ export plot, mapclimgrid, hist
export contourf, contour, pcolormesh
export BBox
export PlotInfo
export surface

end # module
60 changes: 60 additions & 0 deletions src/maps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,63 @@ function pcolormesh(C::ClimGrid; region::String="auto", states::Bool=true, leve

return true, ax, projection, cbar
end


"""
surface(C::ClimGrid)

Surface plot of ClimGrid C.
"""
function surface(C::ClimGrid; projection="moll", cmap=:deep)

C2 = periodmean(C)

Cmean = C2.data.data

longrid, latgrid = ClimateTools.getgrids(C)


# texttime(i) = string(C.model, " - ", year(timevec[i]), " - ", month(timevec[i]), " - ", day(timevec[i]))
titletext = C.model#"$(attrib["long_name"]), units=[$units], average of 19 years"

projection = projection
cmap = :deep

source = Projection("+proj=lonlat +lon_0=0")
dest = Projection("+proj=$projection +lon_0=0")

# source = LonLat()
# dest = WinkelTripel()

# xs, ys = xygrid(lons, lats)
Proj4.transform!(source, dest, vec(longrid), vec(latgrid))

# get aspect ratio
xmin, xmax = extrema(longrid)
ymin, ymax = extrema(latgrid)
aspect_ratio = (ymax - ymin) / (xmax - xmin)

total_crange = (minimum(Cmean), maximum(Cmean))
# total_crange = (0, 400)

# function plotfield(Amean, crange = (minimum(Amean), maximum(Amean));
# cmap = :viridis, titletext)
scene, layout = layoutscene(40; resolution = (900, 475));
# cmap = to_colormap(:viridis, 100)
earthscene = layout[1, 1] = LScene(scene);

sf = surface!(earthscene, longrid, latgrid, zeros(size(longrid)); color = Cmean,
shading = false, show_axis = false, colorrange = crange, colormap = cmap);

geoaxis!(earthscene, -180, 180, -90, 90; crs = (src = source, dest = dest,));

Choose a reason for hiding this comment

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

It might be better to use the bounding boxes of the original latgrid and longrid here. Also, if ClimateTools.getgrids returns the original grids, beware that this will mutate them, so you should probably ensure they're copied.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks!

coastlines!(earthscene; crs = (src = source, dest = dest,));

colorbar = layout[1, 2] = LColorbar(scene, sf, width = 20);
colsize!(layout, 1, Relative(1))
rowsize!(layout, 1, Aspect(1, aspect_ratio))
tt = layout[0, :] = LText(scene, titletext, textsize = 22);

return scene, sf, tt
# end

end