Skip to content

Commit

Permalink
Add a streamplot example on geoaxis
Browse files Browse the repository at this point in the history
  • Loading branch information
asinghvi17 committed Jun 8, 2024
1 parent 26fa3fa commit f547b1f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ GeometryOps = "3251bfac-6a57-4b6d-aa61-ac1fef2975ab"
GraphMakie = "1ecd5474-83a3-4783-bb4f-06765db800d2"
ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19"
ImageTransformations = "02fcd773-0e25-5acc-982a-7f6622650795"
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
LibGEOS = "a90b1aa1-3769-5649-ba7e-abc5a9d163eb"
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
Expand Down
4 changes: 2 additions & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ examples = [
"orthographic.jl",
"geostationary_image.jl",
"multiple_crs.jl",
"rasters.jl",
"is_it_a_plane.jl",
joinpath("cartopy", "annotation.jl"),
joinpath("cartopy", "katrina.jl"),
joinpath("cartopy", "arrows.jl"),
joinpath("cartopy", "vesta.jl"),
joinpath("cartopy", "streamplot.jl"),
joinpath("gmt", "antioquia.jl"),
"german_lakes.jl",
"field_and_countries.jl",
"meshimage.jl",
"projections.jl",
"tissot.jl",
"rotating_earth.jl",
"rasters.jl",

]
example_dir = joinpath(dirname(@__DIR__), "examples")
for filename in examples
Expand Down
48 changes: 48 additions & 0 deletions examples/cartopy/streamplot.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# # Streamplot

# This example was translated from the [Cartopy streamplot example](https://scitools.org.uk/cartopy/docs/latest/gallery/vector_data/streamplot.html#sphx-glr-gallery-vector-data-streamplot-py).

using CairoMakie, GeoMakie
using Interpolations # for Streamplot on gridded data if necessary

f(x::Point2{T}) where T = Point2{T}(
10 * (2 * cos(2 * deg2rad(x[1]) + 3 * deg2rad(x[2] + 30)) ^ 2),
20 * cos(6 * deg2rad(x[1]))
)

pole_longitude=177.5
pole_latitude=37.5
fig, ax, plt = streamplot(
f, 311.9..391.1, -23.6..24.8;
arrow_size = 6,
source = "+proj=ob_tran +o_proj=latlon +o_lon_p=0 +o_lat_p=$(pole_latitude) +lon_0=$(180+pole_longitude) +to_meter=$(deg2rad(1) * 6378137.0)",
axis = (;
type = GeoAxis,
title = "Streamplot",
)
)
lp = lines!(ax, GeoMakie.coastlines(); linewidth = 0.5, color = :black, xautolimits = false, yautolimits = false)
translate!(lp, 0, 0, -1)
fig


# ## Gridded data
# You can also do a streamplot on gridded data via Interpolations.jl:
using Interpolations
xs = range(311.9, 391.1, 100)
ys = range(-23.6, 24.8, 100)
uvs = f.(Point2f.(xs, ys'))
#
uv_itp = LinearInterpolation((xs, ys), uvs)
#
streamplot(
x -> uv_itp(x...), 311.9..391.1, -23.6..24.8;
arrow_size = 6,
source = "+proj=ob_tran +o_proj=latlon +o_lon_p=0 +o_lat_p=$(pole_latitude) +lon_0=$(180+pole_longitude) +to_meter=$(deg2rad(1) * 6378137.0)",
axis = (;
type = GeoAxis,
title = "Streamplot on gridded data",
)
)
# and it looks pretty much the same!

0 comments on commit f547b1f

Please sign in to comment.