From d45e18b4970cd4fb87b14ee69f1d6b90935401c1 Mon Sep 17 00:00:00 2001 From: gaelforget Date: Mon, 4 Sep 2023 17:49:24 -0400 Subject: [PATCH 1/4] bump version + fix --- Project.toml | 2 +- src/Interpolation.jl | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index a77606f9..dde645bb 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MeshArrays" uuid = "cb8c808f-1acf-59a3-9d2b-6e38d009f683" authors = ["gaelforget "] -version = "0.3.0" +version = "0.3.1" [deps] CatViews = "81a5f4ea-a946-549a-aa7e-2a7f63a27d31" diff --git a/src/Interpolation.jl b/src/Interpolation.jl index 266e01cd..8bfaccc1 100644 --- a/src/Interpolation.jl +++ b/src/Interpolation.jl @@ -220,8 +220,6 @@ function interpolation_setup(;Γ=NamedTuple(), fil=joinpath(path,basename(url)) !isfile(fil) ? MeshArrays.download_file(url, fil) : nothing else - lon= - lat= (f,i,j,w)=InterpolationFactors(Γ,vec(lon),vec(lat)) fil=tempname()*"_interp_coeffs.jld2" MeshArrays.write_JLD2(fil; lon=lon, lat=lat, f=f, i=i, j=j, w=w) From 5a6fa20a550334362e3918647405d8139d6d9156 Mon Sep 17 00:00:00 2001 From: gaelforget Date: Mon, 4 Sep 2023 19:37:39 -0400 Subject: [PATCH 2/4] add heatmap_xy and Interpolate methods --- ext/MeshArraysMakieExt.jl | 33 ++++++++++++++++++++++++-------- src/Interpolation.jl | 40 +++++++++++++++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 12 deletions(-) diff --git a/ext/MeshArraysMakieExt.jl b/ext/MeshArraysMakieExt.jl index 6ff41350..ce20db19 100644 --- a/ext/MeshArraysMakieExt.jl +++ b/ext/MeshArraysMakieExt.jl @@ -103,20 +103,26 @@ function scatter!(ax,XC::MeshArray,YC::MeshArray; end """ - heatmap(MS::MeshArray;interpolation=nothing,globalmap=false,colorbar=true,title="",kwargs...) + heatmap(MS::MeshArray; interpolation=nothing,globalmap=false,x=nothing,y=nothing,colorbar=true,title="",kwargs...) + +Represent a `MeshArray` as a `heatmap`, or several, depending on keyword parameter choices. + +Additional keyword arguments will passed along to the `Makie.heatmap` call. ``` -heatmap(MS) -heatmap(MS,interpolation=λ) -heatmap(MS,interpolation=λ,title="ocean depth") +heatmap(MS) #will display tile by tile +heatmap(MS,interpolation=λ) #will interpolate on the fly +heatmap(MS,interpolation=λ,title="ocean depth") #same but w title +heatmap(MS,x=lon,y=lat) #only for simple domains; will show MS[1] ``` """ -function heatmap(MS::MeshArray;interpolation=nothing,globalmap=false,colorbar=true,title="",kwargs...) - +function heatmap(MS::MeshArray;interpolation=nothing,globalmap=false,x=nothing,y=nothing,colorbar=true,title="",kwargs...) if !isnothing(interpolation) heatmap_interpolation(MS,interpolation;colorbar=colorbar,title=title,kwargs...) elseif globalmap heatmap_globalmap(MS;colorbar=colorbar,title=title,kwargs...) + elseif !isnothing(x) + heatmap_xy(MS,x,y;colorbar=colorbar,title=title,kwargs...) else heatmap_tiled(MS;colorbar=colorbar,title=title,kwargs...) end @@ -138,6 +144,16 @@ function heatmap_globalmap(MS::MeshArray;title="",colorbar=true,kwargs...) fig end +heatmap_xy!(ax,MS::MeshArray,x::Array,y::Array;kwargs...) = heatmap!(ax,x,y,MS[1];kwargs...) + +function heatmap_xy(MS::MeshArray,x::Array,y::Array;title="",colorbar=true,kwargs...) + fig = Figure(resolution = (900,400), backgroundcolor = :grey95) + ax = Axis(fig[1,1],xlabel="longitude",ylabel="latitude",title=title) + hm1=heatmap_xy!(ax,MS,x,y;kwargs...) + colorbar ? Colorbar(fig[1,2], hm1, height = Relative(0.65)) : nothing + fig +end + function heatmap_interpolation!(ax,MS::MeshArray,λ::NamedTuple;kwargs...) DD=Interpolate(MS,λ.f,λ.i,λ.j,λ.w) DD=reshape(DD,size(λ.lon)) @@ -165,7 +181,7 @@ function heatmap_tiled(MS::MeshArray;title="", cr[1]==cr[2] ? cr=(cr[1]-eps(),cr[2]+eps()) : nothing for f in 1:nf - ax = Axis(fig[ii[f],jj[f]], title=title*" face $(f)") + nf > 1 ? ax = Axis(fig[ii[f],jj[f]], title=title*" face $(f)") : ax = Axis(fig[1,1], title=title) s=MS.fSize[f] x=collect(0.5:s[1]-0.5) @@ -175,7 +191,8 @@ function heatmap_tiled(MS::MeshArray;title="", hm1=heatmap!(ax,x,y,z;colorrange=cr,colormap=colormap,kwargs...) end - colorbar ? Colorbar(fig[1:3,3], limits=cr, colormap=colormap, height = Relative(0.65)) : nothing + nf > 1 ? jj=(1:nn,3) : jj=(1,2) + colorbar ? Colorbar(fig[jj...], limits=cr, colormap=colormap, height = Relative(0.65)) : nothing fig end diff --git a/src/Interpolation.jl b/src/Interpolation.jl index 8bfaccc1..ef6d0575 100644 --- a/src/Interpolation.jl +++ b/src/Interpolation.jl @@ -56,15 +56,17 @@ knn(xgrid::MeshArray,ygrid::MeshArray,lon::Number,lat::Number) = knn(xgrid::Mesh ``` using MeshArrays + +γ=GridSpec("LatLonCap",MeshArrays.GRID_LLC90) +Γ=GridLoad(γ; option="full") + lon=[i for i=-179.5:1.0:179.5, j=-89.5:1.0:89.5] lat=[j for i=-179.5:1.0:179.5, j=-89.5:1.0:89.5] - -Γ=GridLoad(GridSpec("LatLonCap",MeshArrays.GRID_LLC90); option="full") (f,i,j,w,j_f,j_x,j_y)=InterpolationFactors(Γ,vec(lon),vec(lat)) DD=Interpolate(Γ.Depth,f,i,j,w) -using Plots -contourf(vec(lon[:,1]),vec(lat[1,:]),DD,clims=(0.,6000.)) +using CairoMakie +heatmap(vec(lon[:,1]),vec(lat[1,:]),DD,colorrange=(0.,6000.)) ``` """ function Interpolate(z_in::MeshArray,f,i,j,w) @@ -79,6 +81,36 @@ function Interpolate(z_in::MeshArray,f,i,j,w) return z_out end +""" + Interpolate(z_in::MeshArray,f,i,j,w) + +``` +using MeshArrays + +γ=GridSpec("LatLonCap",MeshArrays.GRID_LLC90) +Γ=GridLoad(γ; option="full") + +lon=[i for i=-179.5:1.0:179.5, j=-89.5:1.0:89.5] +lat=[j for i=-179.5:1.0:179.5, j=-89.5:1.0:89.5] +(f,i,j,w,j_f,j_x,j_y)=InterpolationFactors(Γ,vec(lon),vec(lat)) +L=(lon=lon, lat=lat, f=f, i=i, j=j, w=w) + +using CairoMakie +heatmap(Interpolate(Γ.Depth,L)...,colorrange=(0.,6000.)) +``` + +or + +``` +heatmap(Γ.Depth,interpolation=L,colorrange=(0.,6000.)) +``` +""" +function Interpolate(z_in::MeshArray,λ::NamedTuple) + z=Interpolate(z_in,λ.f,λ.i,λ.j,λ.w) + z=reshape(z,size(λ.lon)) + return λ.lon[:,1],λ.lat[1,:],z +end + """ InterpolationFactors(Γ,lon::Array{T,1},lat::Array{T,1}) From 5e27c5a6223fbab0b6a3674dcf54ebd86d3508f4 Mon Sep 17 00:00:00 2001 From: gaelforget Date: Mon, 4 Sep 2023 20:33:44 -0400 Subject: [PATCH 3/4] extend heatmap_xy --- docs/src/start.md | 9 +++++++-- ext/MeshArraysMakieExt.jl | 5 +++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/src/start.md b/docs/src/start.md index 4d669a46..d3e62199 100644 --- a/docs/src/start.md +++ b/docs/src/start.md @@ -14,9 +14,14 @@ Pkg.test("MeshArrays") To create your first `MeshArray`, open the `Julia` REPL and type: -```@example +```@example 1 using MeshArrays -MeshArray(randn(20,10)) +C=MeshArray(randn(21,10)) +``` + +```@example 1 +using CairoMakie +heatmap(C,x=-10:10,y=1:10) ``` ## Grids diff --git a/ext/MeshArraysMakieExt.jl b/ext/MeshArraysMakieExt.jl index ce20db19..e964ac21 100644 --- a/ext/MeshArraysMakieExt.jl +++ b/ext/MeshArraysMakieExt.jl @@ -144,9 +144,10 @@ function heatmap_globalmap(MS::MeshArray;title="",colorbar=true,kwargs...) fig end -heatmap_xy!(ax,MS::MeshArray,x::Array,y::Array;kwargs...) = heatmap!(ax,x,y,MS[1];kwargs...) +heatmap_xy!(ax,MS::MeshArray,x::Union{UnitRange,Array},y::Union{UnitRange,Array};kwargs...) = heatmap!(ax,x,y,MS[1];kwargs...) +#heatmap_xy!(ax,MS::MeshArray,x::Union{UnitRange,Array},y::Union{UnitRange,Array};kwargs...) = surface!(ax,x,y,0*x;color=MS[1],shading=false, kwargs...) -function heatmap_xy(MS::MeshArray,x::Array,y::Array;title="",colorbar=true,kwargs...) +function heatmap_xy(MS::MeshArray,x::Union{UnitRange,Array},y::Union{UnitRange,Array};title="",colorbar=true,kwargs...) fig = Figure(resolution = (900,400), backgroundcolor = :grey95) ax = Axis(fig[1,1],xlabel="longitude",ylabel="latitude",title=title) hm1=heatmap_xy!(ax,MS,x,y;kwargs...) From 3f18260b3e3db44782392b2b329e3baa07ad0a88 Mon Sep 17 00:00:00 2001 From: gaelforget Date: Mon, 4 Sep 2023 20:35:54 -0400 Subject: [PATCH 4/4] improve docs --- docs/make.jl | 4 ++-- docs/src/API.md | 3 ++- docs/src/start.md | 21 +++++++++------------ 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index ff47e24a..d3f23b88 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -17,9 +17,9 @@ makedocs( pages = [ "Home" => "index.md", "Get Started" => "start.md", - "Video Examples" => "videos.md", - "Notebook Tutorials" => "tutorials.md", "Main Features" => "main.md", + "Notebook Tutorials" => "tutorials.md", + "Video Examples" => "videos.md", "API documentation" => "API.md", "Miscellaneous" => "detail.md", ] diff --git a/docs/src/API.md b/docs/src/API.md index 76f5afb7..c6593493 100644 --- a/docs/src/API.md +++ b/docs/src/API.md @@ -42,10 +42,11 @@ MeshArrays.write ## 3. Interpolation ```@docs -knn +interpolation_setup Interpolate InterpolationFactors StereographicProjection +knn ``` ## 4. Vector Fields diff --git a/docs/src/start.md b/docs/src/start.md index d3e62199..6256a668 100644 --- a/docs/src/start.md +++ b/docs/src/start.md @@ -1,17 +1,5 @@ # Get Started -## Install - -To install `MeshArrays.jl` and verify it works as expected, open the `Julia` REPL and type: - -``` -using Pkg -Pkg.add("MeshArrays") -Pkg.test("MeshArrays") -``` - -## Use - To create your first `MeshArray`, open the `Julia` REPL and type: ```@example 1 @@ -42,3 +30,12 @@ using MeshArrays,CairoMakie heatmap(Γ.YC,title="grid point latitudes") ``` +## Install + +To install `MeshArrays.jl` and verify it works as expected, open the `Julia` REPL and type: + +``` +using Pkg +Pkg.add("MeshArrays") +Pkg.test("MeshArrays") +```