Skip to content

Commit

Permalink
Merge pull request #140 from gaelforget/v0p5p3b
Browse files Browse the repository at this point in the history
V0p5p3b
  • Loading branch information
gaelforget authored Nov 10, 2024
2 parents 430eb43 + fe12d8b commit 72bc66a
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 65 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "IndividualDisplacements"
uuid = "b92f0c32-5b7e-11e9-1d7b-238b2da8b0e6"
authors = ["gaelforget <[email protected]>"]
version = "0.5.2"
version = "0.5.3"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand Down
46 changes: 24 additions & 22 deletions examples/worldwide/global_ocean_circulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ using Pkg; Pkg.status()

# ╔═╡ 2acbfc79-3926-4c5a-9994-e3222c60c377
begin
import IndividualDisplacements, Climatology, MITgcm
using IndividualDisplacements
import Climatology, MITgcm
using Statistics, PlutoUI, CairoMakie

ECCOmodule = IndividualDisplacements.ECCO
CSV = IndividualDisplacements.CSV
DataFrames = IndividualDisplacements.DataFrames
Individuals = IndividualDisplacements.Individuals


output_path=joinpath(tempdir(),"global_ocean_tmp")
!isdir(output_path) ? mkdir(output_path) : nothing

Expand Down Expand Up @@ -59,9 +59,9 @@ begin

bind_j = (@bind j Select(1:6,default=3))
bind_k = (@bind ktxt Select(["0","1","10","30","40"],default="0"))
bind_ny = (@bind nytxt Select(["1/12","1","3","10"],default="10"))
bind_np = (@bind nptxt Select(["10","100","10000"],default="10000"))
bind_replay = (@bind do_replay CheckBox(default=true))
bind_ny = (@bind nytxt Select(["1/12","1","3","10"],default="1"))
bind_np = (@bind nptxt Select(["10","100","10000"],default="100"))
bind_replay = (@bind do_replay CheckBox(default=false))
bind_zoomin = (@bind zoom_in CheckBox(default=false))
bind_zrng = @bind zrng Select([0:11,11:21,21:27],default=0:11)

Expand All @@ -71,7 +71,6 @@ begin
file_base = basename(file_IC)[1:end-4]
backward_time ? file_base=file_base*"_◀◀" : file_base=file_base*"_▶▶"

# - k = $(bind_k) = flow field vertical level (set to 0 for 3D)
# - _optional :_ zrng = $(bind_zrng) = vertical coordindate range
# - _(only used if k==0; if otherwise then zrng effectively is k-0.5:k-0.5)_

Expand All @@ -82,6 +81,7 @@ begin
- latitude box : $(bind_j)
- ny = $(bind_ny) = similated period (1/12 = 1 month)
- np = $(bind_np) = number of individuals (100 by default)
- k = $(bind_k) = flow field vertical level (set to 0 for 3D)
- replay = $(bind_replay) = load results from csv instead of recomputing
- zoom in = $(bind_zoomin) = zoom in rather than plotting whole Earth
"""
Expand Down Expand Up @@ -114,7 +114,7 @@ begin
#println("file_base = "*file_base)

k=parse(Int,ktxt) #vertical level or 0
k!==0 ? zs=[k-0.5:k-0.5] : zs=zrng
k!==0 ? zs=(k-0.5:k-0.5) : zs=zrng

Climatology.get_ecco_velocity_if_needed()

Expand Down Expand Up @@ -171,8 +171,8 @@ begin
I
end

# ╔═╡ 20ff7f0a-3b44-4580-8920-2ae6aa22c78f
I.D
# ╔═╡ f639ec15-a9a1-4dab-a37f-b2c96f6a80e1
#D.Γ.RC

# ╔═╡ 6158a5e4-89e0-4496-ab4a-044d1e3e8cc0
md""" ### 3.2 Monthly Step Function
Expand Down Expand Up @@ -214,6 +214,7 @@ if !do_replay
✔1
[step!(I) for y=1:ny, m=1:nm]
"lon" in names(I.🔴) ? nothing : add_lonlat!(I.🔴,D.XC,D.YC)
"d" in names(I.🔴) ? nothing : I.🔴.d.=-D.Γ.RC[k]
✔2="Done with Main Computation"
else
✔2="Skipping Main Computation (replay instead)"
Expand Down Expand Up @@ -367,6 +368,7 @@ PlutoUI = "7f904dfe-b85e-4ff6-b463-dae2292396a8"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
[compat]
CairoMakie = "~0.12.16"
Climatology = "~0.5.12"
MITgcm = "~0.5.0"
PlutoUI = "~0.7.60"
Expand All @@ -378,7 +380,7 @@ PLUTO_MANIFEST_TOML_CONTENTS = """
julia_version = "1.10.5"
manifest_format = "2.0"
project_hash = "e5a750eb23dc50dfae9c98cecb0cd5985fd84fd0"
project_hash = "bb5811c0e79a88f3ec92251cfbda3ab33172d8ba"
[[deps.ADTypes]]
git-tree-sha1 = "eea5d80188827b35333801ef97a40c2ed653b081"
Expand Down Expand Up @@ -1417,10 +1419,10 @@ uuid = "42e2da0e-8278-4e71-bc24-59509adca0fe"
version = "1.0.2"
[[deps.HDF5_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "LazyArtifacts", "LibCURL_jll", "Libdl", "MPICH_jll", "MPIPreferences", "MPItrampoline_jll", "MicrosoftMPI_jll", "OpenMPI_jll", "OpenSSL_jll", "TOML", "Zlib_jll", "libaec_jll"]
git-tree-sha1 = "82a471768b513dc39e471540fdadc84ff80ff997"
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "LLVMOpenMP_jll", "LazyArtifacts", "LibCURL_jll", "Libdl", "MPICH_jll", "MPIPreferences", "MPItrampoline_jll", "MicrosoftMPI_jll", "OpenMPI_jll", "OpenSSL_jll", "TOML", "Zlib_jll", "libaec_jll"]
git-tree-sha1 = "38c8874692d48d5440d5752d6c74b0c6b0b60739"
uuid = "0234f1f7-429e-5d53-9886-15a909be8d59"
version = "1.14.3+3"
version = "1.14.2+1"
[[deps.HTTP]]
deps = ["Base64", "CodecZlib", "ConcurrentUtilities", "Dates", "ExceptionUnwrapping", "Logging", "LoggingExtras", "MbedTLS", "NetworkOptions", "OpenSSL", "Random", "SimpleBufferStream", "Sockets", "URIs", "UUIDs"]
Expand Down Expand Up @@ -2148,10 +2150,10 @@ uuid = "30363a11-5582-574a-97bb-aa9a979735b9"
version = "0.12.0"
[[deps.NetCDF_jll]]
deps = ["Artifacts", "Blosc_jll", "Bzip2_jll", "HDF5_jll", "JLLWrappers", "LazyArtifacts", "LibCURL_jll", "Libdl", "MPICH_jll", "MPIPreferences", "MPItrampoline_jll", "MicrosoftMPI_jll", "OpenMPI_jll", "TOML", "XML2_jll", "Zlib_jll", "Zstd_jll", "libzip_jll"]
git-tree-sha1 = "4686378c4ae1d1948cfbe46c002a11a4265dcb07"
deps = ["Artifacts", "Blosc_jll", "Bzip2_jll", "HDF5_jll", "JLLWrappers", "LibCURL_jll", "Libdl", "OpenMPI_jll", "XML2_jll", "Zlib_jll", "Zstd_jll", "libzip_jll"]
git-tree-sha1 = "a8af1798e4eb9ff768ce7fdefc0e957097793f15"
uuid = "7243133f-43d8-5620-bbf4-c2c921802cf3"
version = "400.902.211+1"
version = "400.902.209+0"
[[deps.Netpbm]]
deps = ["FileIO", "ImageCore", "ImageMetadata"]
Expand Down Expand Up @@ -2240,10 +2242,10 @@ uuid = "05823500-19ac-5b8b-9628-191a04bc5112"
version = "0.8.1+2"
[[deps.OpenMPI_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "LazyArtifacts", "Libdl", "MPIPreferences", "TOML"]
git-tree-sha1 = "e25c1778a98e34219a00455d6e4384e017ea9762"
deps = ["Artifacts", "CompilerSupportLibraries_jll", "Hwloc_jll", "JLLWrappers", "LazyArtifacts", "Libdl", "MPIPreferences", "TOML", "Zlib_jll"]
git-tree-sha1 = "bfce6d523861a6c562721b262c0d1aaeead2647f"
uuid = "fe0851c0-eecd-5654-98d4-656369965a5c"
version = "4.1.6+0"
version = "5.0.5+0"
[[deps.OpenSSL]]
deps = ["BitFlags", "Dates", "MozillaCACerts_jll", "OpenSSL_jll", "Sockets"]
Expand Down Expand Up @@ -3525,12 +3527,12 @@ version = "3.6.0+0"
# ╟─2fb4d76d-56d5-4c3e-bc7c-ba0cac57e0e3
# ╟─f1215951-2eb2-490b-875a-91c1205b8f63
# ╠═f727992f-b72a-45bc-93f1-cc8daf89af0f
# ╠═20ff7f0a-3b44-4580-8920-2ae6aa22c78f
# ╠═f639ec15-a9a1-4dab-a37f-b2c96f6a80e1
# ╟─6158a5e4-89e0-4496-ab4a-044d1e3e8cc0
# ╟─a2375720-f599-43b9-a7fb-af17956309b6
# ╟─7efadea7-4542-40cf-893a-40a75e9c52be
# ╟─a3e45927-5d53-42be-b7b7-489d6e7a6fe5
# ╟─1044c5aa-1a56-45b6-a4c6-63d24eea878d
# ╠═1044c5aa-1a56-45b6-a4c6-63d24eea878d
# ╟─42959eb9-7c14-4892-bf41-a1a434b00e27
# ╟─fc16b761-8b1f-41de-b4fe-7fa9987d6167
# ╟─63b68e72-76c1-4104-bf76-dd9eefc4e225
Expand Down
25 changes: 13 additions & 12 deletions examples/worldwide/global_ocean_circulation_driver.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@

using Distributed, IndividualDisplacements
using Distributed, IndividualDisplacements, Climatology, MITgcm

if !isdefined(Main,:ECCO_FlowFields) && myid()==1
@everywhere include("ECCO_FlowFields.jl")
@everywhere using Main.ECCO_FlowFields, IndividualDisplacements, CSV
if !isdefined(Main,:CSV) && myid()==1
@everywhere using IndividualDisplacements, Climatology, MITgcm
@everywhere CSV=IndividualDisplacements.CSV
@everywhere ECCOmodule=IndividualDisplacements.ECCO

@everywhere path=IndividualDisplacements.datadeps.getdata("global_ocean_circulation_inputs")
@everywhere list=readdir(path)
Expand Down Expand Up @@ -65,21 +66,21 @@ backward_time = false
backward_time ? file_output=file_base*"_◀◀" : file_base=file_base*"_▶▶"

k=0
np=10000
ny=3 #number of years
np=1000 #number of particles
ny=1 #number of years
nm=12 #number of months

P,D=init_FlowFields(k=k,backward_time=backward_time)
P,D=ECCOmodule.init_FlowFields(k=k,backward_time=backward_time)

df = init_positions(np,filename=file_input)
df = IndividualDisplacements.init.init_positions(np,filename=file_input)
#"z" in names(df) ? nothing : df.z=10.0 .+ 0.0*df.x

S = init_storage(np,100,length(D.Γ.RC),50)
S = ECCOmodule.init_storage(np,100,length(D.Γ.RC),50)
I = Individuals(P,df.x,df.y,df.z,df.f,
(D=merge(D,S),∫=custom∫,🔧=custom🔧,🔴=deepcopy(custom🔴)))
(D=merge(D,S),∫=ECCOmodule.custom∫,🔧=ECCOmodule.custom🔧,🔴=deepcopy(ECCOmodule.custom🔴)))

T=(0.0,I.P.T[2])
custom∫!(I,T)
ECCOmodule.custom∫!(I,T)

[step!(I) for y=1:ny, m=1:nm]

Expand All @@ -92,5 +93,5 @@ end

function step!(I::Individuals)
I.D.🔄(I)
custom∫!(I)
ECCOmodule.custom∫!(I)
end
25 changes: 1 addition & 24 deletions examples/worldwide/three_dimensional_ocean.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,7 @@ end
md"""## Visualize Displacements"""

# ╔═╡ 8e371f54-d7f7-4f59-a2e1-9f673486f1fa
begin
"""
plot(I::Individuals)
Plot the initial and final positions as scatter plot in `lon,lat` or `x,y` plane.
"""
function myplot(I::Individuals)
🔴_by_t = IndividualDisplacements.DataFrames.groupby(I.🔴, :t)
set_theme!(theme_light())
fig=Figure(size = (900, 600))
try
a = Axis(fig[1, 1],xlabel="longitude",ylabel="latitude")
scatter!(a,🔴_by_t[1].lon,🔴_by_t[1].lat,color=:green2)
scatter!(a,🔴_by_t[end].lon,🔴_by_t[end].lat,color=:red)
catch
a = Axis(fig[1, 1],xlabel="longitude",ylabel="latitude")
scatter!(a,🔴_by_t[1].x,🔴_by_t[1].y,color=:green2)
scatter!(a,🔴_by_t[end].x,🔴_by_t[end].y,color=:red)
end
return fig
end

myplot(I)
end
plot( InDiPlot( data=(I=I,), options=(plot_type=:plot_start_end,) ) )

# ╔═╡ a6f4b5a0-7818-41a6-a4e5-30d80a727625

Expand Down
25 changes: 24 additions & 1 deletion ext/IndividualDisplacementsMakieExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ module IndividualDisplacementsMakieExt
simple_plot2(x.data[:I])
elseif string(o.plot_type)=="global_plot1"
global_plot1(x.data[:I],x.data[:df])
elseif string(o.plot_type)=="plot_start_end"
plot_start_end(x.data[:I])
else
println("unknown option (b)")
end
Expand Down Expand Up @@ -132,7 +134,7 @@ function global_plot1(I::Individuals,🔴::DataFrame;

np=Int(maximum(🔴.ID))
nt=length(unique(🔴.t))
ii=1:10000
ii=1:min(10000,np)

tmp1=🔴[np*0 .+ ii,:lon].!==🔴[np*(nt-1) .+ ii,:lon]
tmp2=🔴[np*0 .+ ii,:lat].!==🔴[np*(nt-1) .+ ii,:lat]
Expand Down Expand Up @@ -162,4 +164,25 @@ end

##

"""
plot_start_end(I::Individuals)
Plot the initial and final positions as scatter plot in `lon,lat` or `x,y` plane.
"""
function plot_start_end(I::Individuals)
🔴_by_t = IndividualDisplacements.DataFrames.groupby(I.🔴, :t)
set_theme!(theme_light())
fig=Figure(size = (900, 600))
try
a = Axis(fig[1, 1],xlabel="longitude",ylabel="latitude")
scatter!(a,🔴_by_t[1].lon,🔴_by_t[1].lat,color=:green2)
scatter!(a,🔴_by_t[end].lon,🔴_by_t[end].lat,color=:red)
catch
a = Axis(fig[1, 1],xlabel="longitude",ylabel="latitude")
scatter!(a,🔴_by_t[1].x,🔴_by_t[1].y,color=:green2)
scatter!(a,🔴_by_t[end].x,🔴_by_t[end].y,color=:red)
end
return fig
end

end
5 changes: 3 additions & 2 deletions src/example_ECCO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ module ECCO

import MeshArrays, DataDeps, CSV, JLD2

import IndividualDisplacements.OrdinaryDiffEq: solve, Tsit5, ODEProblem
import IndividualDisplacements: postprocess_MeshArray, add_lonlat!, OrdinaryDiffEq
import OrdinaryDiffEq: solve, Tsit5, ODEProblem
import IndividualDisplacements: update_location!, Individuals, uvMeshArrays, uvwMeshArrays
import IndividualDisplacements: FlowFields, data_path, read_data_ECCO, order
import IndividualDisplacements: FlowFields, ensemble_solver, data_path, read_data_ECCO, order
import IndividualDisplacements.DataFrames: DataFrame
import IndividualDisplacements.MeshArrays as MeshArrays
import IndividualDisplacements.MeshArrays: gcmgrid, MeshArray, exchange
Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
Climatology = "9e9a4d37-2d2e-41e3-8b85-f7978328d9c7"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
Expand Down
49 changes: 46 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Test, Documenter
using IndividualDisplacements, Climatology, MeshArrays, NetCDF, Suppressor
import MITgcm
using Test, Documenter, IndividualDisplacements, Suppressor
import Climatology, MeshArrays, NetCDF, MITgcm

Climatology.get_ecco_velocity_if_needed()
Climatology.get_occa_velocity_if_needed()
Expand All @@ -10,6 +9,50 @@ Climatology.get_ecco_variable_if_needed("SALT")
MeshArrays.GridLoad(MeshArrays.GridSpec("LatLonCap",MeshArrays.GRID_LLC90))
MeshArrays.GridLoad(MeshArrays.GridSpec("PeriodicChannel",MeshArrays.GRID_LL360))

@testset "ECCO" begin
import MITgcm, CairoMakie, Climatology, MITgcm

ECCOmodule = IndividualDisplacements.ECCO
CSV = IndividualDisplacements.CSV
DataFrames = IndividualDisplacements.DataFrames
Individuals = IndividualDisplacements.Individuals

k=0
P,D=ECCOmodule.init_FlowFields(k=k); np=100
df = IndividualDisplacements.init.init_gulf_stream(np , D)
S = ECCOmodule.init_storage(np,100,length(D.Γ.RC),50)
I = Individuals(P,df.x,df.y,df.z,df.fid,
(D=merge(D,S),∫=ECCOmodule.custom∫,🔧=ECCOmodule.custom🔧,🔴=deepcopy(ECCOmodule.custom🔴)))
my∫! = ∫!
T=(0.0,I.P.T[2])
my∫!(I,T)
@test isa(I,Individuals)

tmp_🔴=I.🔴
nt=length(unique(tmp_🔴.t))
xlims=(-85.0,5.0)
ylims=(20.0,67.0)

x=IndividualDisplacements.InDiPlot( data=(I=I,df=tmp_🔴,), options=(plot_type=:global_plot1,) )
fig,tt=CairoMakie.plot(x)
@test isa(fig,CairoMakie.Figure)
end

@testset "OCCA" begin
import CairoMakie, Climatology
OCCAmodule=IndividualDisplacements.OCCA
initial_positions=IndividualDisplacements.init.initial_positions
P,D=OCCAmodule.setup(nmax=5)
nf=100; lo=(-160.0,-150.0); la=(30.0,40.0); level=2.5;
df=initial_positions(D.Γ, nf, lo, la, level)
I=Individuals(P,df.x,df.y,df.z,df.fid,(🔴=OCCAmodule.custom🔴,🔧=OCCAmodule.custom🔧, D=D))
T=(0.0,10*86400.0)
∫!(I,T)

fig=CairoMakie.plot( InDiPlot( data=(I=I,), options=(plot_type=:plot_start_end,) ) )
@test isa(fig,CairoMakie.Figure)
end

@testset "downloads" begin
p0=IndividualDisplacements.datadeps.getdata("global_ocean_circulation_inputs")
IndividualDisplacements.datadeps.getdata("flt_example")
Expand Down

0 comments on commit 72bc66a

Please sign in to comment.