Skip to content

Commit

Permalink
Merge pull request #115 from gaelforget/V0p3p1c
Browse files Browse the repository at this point in the history
V0p3p1c
  • Loading branch information
gaelforget authored Sep 5, 2023
2 parents 93629a0 + 3f18260 commit 00d9aa5
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MeshArrays"
uuid = "cb8c808f-1acf-59a3-9d2b-6e38d009f683"
authors = ["gaelforget <[email protected]>"]
version = "0.3.0"
version = "0.3.1"

[deps]
CatViews = "81a5f4ea-a946-549a-aa7e-2a7f63a27d31"
Expand Down
4 changes: 2 additions & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand Down
3 changes: 2 additions & 1 deletion docs/src/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ MeshArrays.write
## 3. Interpolation

```@docs
knn
interpolation_setup
Interpolate
InterpolationFactors
StereographicProjection
knn
```

## 4. Vector Fields
Expand Down
30 changes: 16 additions & 14 deletions docs/src/start.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
# 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
```@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
Expand All @@ -37,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")
```
34 changes: 26 additions & 8 deletions ext/MeshArraysMakieExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -138,6 +144,17 @@ function heatmap_globalmap(MS::MeshArray;title="",colorbar=true,kwargs...)
fig
end

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::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...)
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))
Expand Down Expand Up @@ -165,7 +182,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)
Expand All @@ -175,7 +192,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
Expand Down
42 changes: 36 additions & 6 deletions src/Interpolation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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})
Expand Down Expand Up @@ -220,8 +252,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)
Expand Down

0 comments on commit 00d9aa5

Please sign in to comment.