Skip to content

Commit

Permalink
Merge pull request #174 from gaelforget/v0p3p20a
Browse files Browse the repository at this point in the history
V0p3p20a
  • Loading branch information
gaelforget authored Feb 12, 2025
2 parents 4017f88 + 1d932d1 commit 9c5752e
Show file tree
Hide file tree
Showing 7 changed files with 377 additions and 229 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 <gforget@mit.edu>"]
version = "0.3.19"
version = "0.3.20"

[deps]
CatViews = "81a5f4ea-a946-549a-aa7e-2a7f63a27d31"
Expand Down
82 changes: 57 additions & 25 deletions examples/Demos.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ Demonstrate basic functionalities (load grid, arithmetic, exchange, gradient,
etc.). Call sequence:
```
!isdir(MeshArrays.GRID_LLC90) ? error("missing files") : nothing
include("examples/Demos.jl")
(D,Dexch,Darr,DD)=demo1("LatLonCap",MeshArrays.GRID_LLC90);
```
"""
Expand Down Expand Up @@ -37,7 +36,7 @@ function demo1(gridChoice::String,GridParentDir="./")
DD=γ.read(Darr,D)
DD .== D

Γ=GridLoad(γ)
Γ=GridLoad,option="full")

(dFLDdx, dFLDdy)=gradient.YC,Γ)
(dFLDdxEx,dFLDdyEx)=exchange(dFLDdx,dFLDdy,4)
Expand Down Expand Up @@ -68,21 +67,19 @@ end
Demonstrate higher level functions using `smooth`. Call sequence:
```
(Rini,Rend,DXCsm,DYCsm)=demo2();
using Plots
include(joinpath(dirname(pathof(MeshArrays)),"../examples/Plots.jl"))
heatmap(Rend,title="smoothed noise",clims=(-0.5,0.5))
heatmap(Rini,title="raw noise",clims=(-0.5,0.5))
include("examples/Demos.jl")
(Rini,Rend,DXCsm,DYCsm)=demo2()
#gr(); contour(Rend,clims=(-0.5,0.5),levels=-0.5:0.1:0.5,fill=true)
using CairoMakie, MeshArrays
heatmap(Rend,title="smoothed noise",colorrange=(-0.5,0.5))
heatmap(Rini,title="raw noise",colorrange=(-0.5,0.5))
```
"""
function demo2()

#Pre-requisite: either load predefined grid using `demo1` or call `GridOfOnes`
isdir(MeshArrays.GRID_LLC90) ? Γ=GridLoad(ID:LLC90) : (γ,Γ)=Grids_simple.GridOfOnes("CubeSphere",6,100)
isdir(MeshArrays.GRID_LLC90) ? Γ=GridLoad(ID=:LLC90,option="full") : (γ,Γ)=Grids_simple.GridOfOnes("CubeSphere",6,100)

(Rini,Rend,DXCsm,DYCsm)=demo2(Γ)
end
Expand Down Expand Up @@ -125,19 +122,20 @@ end
Demonstrate ocean transport computations. Call sequence:
```
(UV,LC,Tr)=demo3();
using Plots; plot(Tr/1e6,title="meridional transport")
using Plots
include(joinpath(dirname(pathof(MeshArrays)),"../examples/Plots.jl"))
heatmap(1e-6*UV["U"],title="U comp. in Sv",clims=(-10,10))
heatmap(1e-6*UV["V"],title="V comp. in Sv",clims=(-10,10))
include("examples/Demos.jl")
de=demo3()
using CairoMakie, MeshArrays
lines!(Axis(Figure()[1,1],title="meridional transport"),de.lat,de.Tr/1e6)
fig1=current_figure()
fig2=heatmap(1e-6*de.TrspX,title="U comp. in Sv",colorrange=(-10,10))
fig3=heatmap(1e-6*de.TrspY,title="V comp. in Sv",colorrange=(-10,10))
```
"""
function demo3()

γ=GridSpec("LatLonCap",MeshArrays.GRID_LLC90)
Γ=GridLoad(γ)
γ=GridSpec(ID=:LLC90)
Γ=GridLoad,option=:full)

TrspX=γ.read.path*"TrspX.bin",MeshArray(γ,Float32))
TrspY=γ.read.path*"TrspY.bin",MeshArray(γ,Float32))
Expand All @@ -147,20 +145,54 @@ function demo3()

(UV, LC, Tr)=demo3(TrspX,TrspY,Γ)

(TrspX=TrspX,TrspY=TrspY,TauX=TauX,TauY=TauY,SSH=SSH,γ=γ,Γ=Γ,LC=LC,Tr=Tr,lat=-89.0:89.0,UV=UV)
end

function demo3(U::MeshArray,V::MeshArray::NamedTuple)

LC=LatitudeCircles(-89.0:89.0,Γ)

#UV=Dict("U"=>U,"V"=>V,"dimensions"=>["x","y","z","t"],"factors"=>["dxory","dz"])
UV=NamedTuple("U"=>U,"V"=>V,"dimensions"=>["x","y"])

UV=Dict("U"=>U,"V"=>V,"dimensions"=>["x","y"])
Tr=Array{Float64,1}(undef,length(LC));
for i=1:length(LC)
Tr[i]=ThroughFlow(UV,LC[i],Γ)
end

return UV, LC, Tr
end

"""
demo4()
Calculation of Ekman transport.
```
using MeshArrays, CairoMakie, DataDeps, JLD2
include("examples/Demos.jl")
de4=demo4()
lines!(Axis(Figure()[1,1]),de4.lat,de4.Tr); current_figure()
lines!(de4.lat,de4.TrPac,color=:red); limits!(-90,90,-20,20)
fig1=current_figure()
λ=interpolation_setup()
fig2=heatmap(de4.μ*de4.EkE,interpolation=λ,colorrange=(-1,1))
```
"""
function demo4()
de=demo3()
Γ=de.Γ
(EkX,EkY)=MeshArrays.EkmanTrsp(de.TauX,de.TauY,Γ)
(EkE,EkN)=UVtoUEVN(EkX,EkY,Γ)
μ=land_mask(Γ)

#global meridional transport
(_, LC, Tr)=demo3(EkX*Γ.DXG./1e6,EkY*Γ.DYG./1e6,Γ)
#regional meridional transport (Eastern Pacific example)
mask=demo.extended_basin(demo.ocean_basins(),:Pac)
mask[findall( (Γ.XC.>-110)*.XC.<180)+.XC.<-170) )].=0
(_, _, TrPac)=demo3(mask*EkX*Γ.DXG./1e6,mask*EkY*Γ.DYG./1e6,Γ)

(EkX=EkX, EkY=EkY, EkE=EkE, EkN=EkN, LC=LC, Tr=Tr, TrPac=TrPac, lat=-89.0:89.0, Γ=Γ, μ=μ)
end

##

Loading

0 comments on commit 9c5752e

Please sign in to comment.