Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6fe0fbe
kfolds runs, plus some comments
lazarusA Jul 7, 2025
204fcbe
see sites in each fold
lazarusA Jul 8, 2025
abf8aff
mkpath windows fix, but now it errors with model inconsistency
lazarusA Jul 8, 2025
e1acb3f
fixed legacy issues, paths, tbl parameters, info.jld2 error
lazarusA Jul 8, 2025
1e38bea
fix paths, and add missing import
lazarusA Jul 9, 2025
7df8e02
fixes support for lts 1.10
lazarusA Jul 10, 2025
4a6bd5b
explicitly set PRECOMPILE_TASKS, and don't include ForwardDiff and Si…
lazarusA Jul 10, 2025
50a2e79
setup slurm jobs
lazarusA Jul 10, 2025
ace9f52
more juice and don't save info.jld2 for every fold, TODO, needs a bet…
lazarusA Jul 10, 2025
4bba851
analysis
lazarusA Jul 18, 2025
29c88e7
Merge branch 'main' into la/consolidation
lazarusA Sep 24, 2025
48337c9
Merge branch 'main' into la/consolidation
lazarusA Sep 24, 2025
bac91a1
setup hybrid
lazarusA Sep 24, 2025
a20586e
rename file
lazarusA Sep 24, 2025
07a919f
new train file
lazarusA Sep 24, 2025
565dc08
todo
lazarusA Sep 24, 2025
58eb901
fold options
lazarusA Sep 25, 2025
b701b3f
get chunk size
lazarusA Sep 25, 2025
e65b046
prep tem information
dr-ko Oct 17, 2025
43e4603
Merge branch 'main' into la/consolidation
lazarusA Nov 5, 2025
b02555b
Merge branch 'la/consolidation' of https://github.com/EarthyScience/S…
dr-ko Nov 5, 2025
972dff3
revert settings
dr-ko Nov 5, 2025
74382c9
Merge pull request #33 from EarthyScience/mrg_la_consolidation
lazarusA Nov 5, 2025
f014c00
space spinup sequence
lazarusA Nov 5, 2025
b86edc9
import
lazarusA Nov 5, 2025
66eff84
GSITOOPFT
lazarusA Nov 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions examples/exp_fluxnet_hybrid/Project.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[deps]
CMAEvolutionStrategy = "8d3b24bd-414e-49e0-94fb-163cc3a3e411"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
GCMAES = "4aa9d100-eb0f-11e8-15f1-25748831eb3b"
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
MLUtils = "f1d291b0-491e-4a28-83b9-f70985020b54"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
Sindbad = "6686e6de-2010-4bf8-9178-b2bcc470766e"
SindbadData = "772b809f-5329-4bfd-a2e9-cc4714ce84b1"
SindbadML = "eb1d8004-2d42-4eef-b369-ed0645c101e8"
Expand All @@ -12,14 +14,26 @@ SindbadOptimization = "64fff8bd-0c13-402c-aa96-b97d0bc3655c"
SindbadSetup = "2b7f2987-8a1e-48b4-8a02-cc9e7c4eeb1c"
SindbadTEM = "f6108451-10cb-42fa-b0c1-67671cf08f15"
SindbadUtils = "a2ad09c8-73f9-4387-ada0-5c5a8c58f8ab"
SlurmClusterManager = "c82cd089-7bf7-41d7-976b-6b5d413cbe0a"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"

[sources]
Sindbad = {path = "../.."}
SindbadData = {path = "../../lib/SindbadData"}
SindbadML = {path = "../../lib/SindbadML"}
SindbadMetrics = {path = "../../lib/SindbadMetrics"}
SindbadOptimization = {path = "../../lib/SindbadOptimization"}
SindbadSetup = {path = "../../lib/SindbadSetup"}
SindbadTEM = {path = "../../lib/SindbadTEM"}
SindbadUtils = {path = "../../lib/SindbadUtils"}
[sources.Sindbad]
path = "../../"

[sources.SindbadData]
path = "../../lib/SindbadData"

[sources.SindbadML]
path = "../../lib/SindbadML"

[sources.SindbadMetrics]
path = "../../lib/SindbadMetrics"

[sources.SindbadSetup]
path = "../../lib/SindbadSetup"

[sources.SindbadTEM]
path = "../../lib/SindbadTEM"

[sources.SindbadUtils]
path = "../../lib/SindbadUtils"
3 changes: 2 additions & 1 deletion examples/exp_fluxnet_hybrid/analysis/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ ArchGDAL = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
DimensionalData = "0703355e-b756-11e9-17c0-8b28908087d0"
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
GeoMakie = "db073c08-6b98-4ee5-b6a4-5efafb3259c6"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
Expand All @@ -13,5 +12,7 @@ NetCDF = "30363a11-5582-574a-97bb-aa9a979735b9"
Proj = "c94c279d-25a6-4763-9509-64d165bea63e"
Rasters = "a3a2b9e3-a471-40c9-b274-f788e487c689"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
SwarmMakie = "0b1c068e-6a84-4e66-8136-5c95cafa83ed"
TypedTables = "9d95f2ec-7b3d-5a63-8d20-e2491e220bb9"
YAXArrays = "c21b50f5-aa40-41ea-b809-c0f5e47bfa5c"
Zarr = "0a941bbe-ad1d-11e8-39d9-ab76183a1d99"
143 changes: 98 additions & 45 deletions examples/exp_fluxnet_hybrid/analysis/fold_analysis.jl
Original file line number Diff line number Diff line change
@@ -1,32 +1,42 @@
ENV["JULIA_NUM_PRECOMPILE_TASKS"] = "1"
using CairoMakie
using SwarmMakie
using Flux
using Statistics
using TypedTables
using JLD2

path_ptmp = "/ptmp/lalonso/HybridOutput/"

path_ptmp = "/ptmp/lalonso/HybridOutputALL/"
exp_name = "HyALL_ALL"
_nfold = 5
nlayers = 3
n_neurons = 32
bs= 32
nepochs=500
experiment = "$(exp_name)_fold_$(_nfold)_nlayers_$(nlayers)_n_neurons_$(n_neurons)_batch_size_$(bs)/checkpoint"
# experiment = "$(exp_name)_kσ_1.0_fold_$(_nfold)_nlayers_$(nlayers)_n_neurons_$(n_neurons)_$(nepochs)epochs_batch_size_$(bs)/checkpoint"
checkpoint_path = joinpath(path_ptmp, experiment)
losses = JLD2.load(joinpath(checkpoint_path, "checkpoint_epoch_500.jld2"))
losses = JLD2.load(joinpath(checkpoint_path, "checkpoint_epoch_100.jld2"))
# "HyALL_ALL_kσ_1.0_fold_5_nlayers_3_n_neurons_32_500epochs_batch_size_32"
# "HyALL_ALL_kσ_1.0_fold_5_nlayers_3_n_neurons_32_batch_size_32_500epochs"

losses["loss_split_testing"]

# Load the training history
function load_losses(exp_name, _nfold, nlayers, n_neurons, bs, nepochs)
path_ptmp = "/ptmp/lalonso/HybridOutput/"
function load_losses(exp_name, _nfold, nlayers, n_neurons, bs, nepochs, load_nepochs)
path_ptmp = "/ptmp/lalonso/HybridOutputALL/"
if exp_name == "HyFixK_PFT"
bs = bs * 123
end
experiment = "$(exp_name)_fold_$(_nfold)_nlayers_$(nlayers)_n_neurons_$(n_neurons)_batch_size_$(bs)/checkpoint"
# experiment = "$(exp_name)_kσ_1.0_fold_$(_nfold)_nlayers_$(nlayers)_n_neurons_$(n_neurons)_$(nepochs)epochs_batch_size_$(bs)/checkpoint"
checkpoint_path = joinpath(path_ptmp, experiment)

μtrain = Float32[]
μval = Float32[]
μtest = Float32[]

for epoch in 1:nepochs
for epoch in 1:load_nepochs
losses = JLD2.load(joinpath(checkpoint_path, "checkpoint_epoch_$epoch.jld2"))
push!(μtrain, mean(losses["loss_training"]))
push!(μval, mean(losses["loss_validation"]))
Expand All @@ -36,6 +46,8 @@ function load_losses(exp_name, _nfold, nlayers, n_neurons, bs, nepochs)
return μtrain, μval, μtest
end

mkpath(joinpath(@__DIR__, "figs"))

function plot_training_history(μtrain, μval, μtest)
with_theme(theme_light()) do
fig = Figure(; size = (600, 400))
Expand All @@ -45,62 +57,72 @@ function plot_training_history(μtrain, μval, μtest)
lines!(ax, μtest, color = :olive, linewidth = 1.25, label = "test")
# ylims!(ax, 3, 4)
axislegend(ax, position = :rt)
save("history_losses_5.png", fig)
save(joinpath(@__DIR__, "figs/history_losses_5.png"), fig)
end
end

# ? load n-fold history
nepochs=500
_nfold = 5
nlayers= 2
nlayers= 3
n_neurons = 32
bs = 32
exp_name = "HyFixK_ALL"
# exp_name = "HyFixK_ALL"
exp_name = "HyALL_ALL"

μtrain, μval, μtest = load_losses(exp_name, _nfold, nlayers, n_neurons, bs, 500)
μtrain, μval, μtest = load_losses(exp_name, _nfold, nlayers, n_neurons, bs, 500, 210)
plot_training_history(μtrain, μval, μtest)


function plot_training_history_folds(exp_name, nlayers, n_neurons, bs, nepochs)
with_theme(theme_light()) do
fig = Figure(; size = (400, 900))
axs = [Axis(fig[row, 1]) for row in 1:5]
for (_nfold, ax) in enumerate(axs)
μtrain, μval, μtest = load_losses(exp_name, _nfold, nlayers, n_neurons, bs, nepochs)
function plot_training_history_folds(exp_name, nlayers, n_neurons, bs, nepochs; xpos = 185)
with_theme(theme_latexfonts()) do
fig = Figure(; size = (1200, 400), fontsize=24)
axs = [Axis(fig[row, col]; xgridstyle=:dash, ygridstyle=:dash, xlabel = "epoch", ylabel="loss")
for row in 1:2 for col in 1:3]
for (_nfold, ax) in enumerate(axs[1:5])
μtrain, μval, μtest = load_losses(exp_name, _nfold, nlayers, n_neurons, bs, 500, nepochs)

lines!(ax, μtrain, color = :dodgerblue, linewidth = 1.25, label = "training")
lines!(ax, μval, color = :orangered, linewidth = 1.25, label = "validation")
lines!(ax, μtest, color = :olive, linewidth = 1.25, label = "test")
ax.title = "fold $(_nfold)"
# ax.title = "fold $(_nfold)"
text!(ax, [xpos], [5.5], text="fold $(_nfold)", color = :grey25)
end
axislegend(axs[1], position = :rt, nbanks=3)
hidexdecorations!.(axs[1:4], ticks=false, grid=false)
Legend(fig[2, 3], axs[1], tellwidth=false, tellheight=false, halign=0,
framewidth=0.25, patchcolor = (:white, 0.25) )
# axislegend(axs[], position = :ct, nbanks=3, framewidth=0.25, patchcolor = (:white, 0.25))
hidexdecorations!.(axs[1:3], ticks=false, grid=false)
hidespines!(axs[end])
hidedecorations!(axs[end])
linkaxes!.(axs)
limits!.(axs, 0, nepochs, 2.7, 4.5)
limits!.(axs, 0, nepochs, 2.7, 6)
rowgap!(fig.layout, 0)
save("$(exp_name)_nlayers_$(nlayers)_n_neurons_$(n_neurons)_bs_$(bs)_history.png", fig)
hidespines!.(axs)
save("$(exp_name)_nlayers_$(nlayers)_n_neurons_$(n_neurons)_bs_$(bs)_history.pdf", fig)
end
end

# ? load n-fold history
nepochs=500
_nfold = 5
nlayers= 2
n_neurons = 32
bs = 32
exp_name = "HyFixK_ALL" # HyFixK_PFT
plot_training_history_folds(exp_name, nlayers, n_neurons, bs, nepochs)
# nepochs=500
# _nfold = 5
# nlayers= 2
# n_neurons = 32
# bs = 32
# exp_name = "HyFixK_ALL" # HyFixK_PFT
# plot_training_history_folds(exp_name, nlayers, n_neurons, bs, nepochs)

exp_name = "HyFixK_PFT" #
plot_training_history_folds(exp_name, nlayers, n_neurons, bs, nepochs)
# exp_name = "HyFixK_PFT" #
# plot_training_history_folds(exp_name, nlayers, n_neurons, bs, nepochs)

exp_name = "HyALL_ALL"
nepochs = 150
plot_training_history_folds(exp_name, nlayers, n_neurons, bs, nepochs)
nepochs = 210
plot_training_history_folds(exp_name, 2, n_neurons, bs, nepochs; xpos = 170)
plot_training_history_folds(exp_name, 3, n_neurons, bs, 180; xpos = 170)

exp_name = "HyALL_PFT"
nepochs = 100
plot_training_history_folds(exp_name, 3, n_neurons, bs, nepochs)

# exp_name = "HyALL_PFT"
# nepochs = 100
# plot_training_history_folds(exp_name, 3, n_neurons, bs, nepochs)

# do per variable

Expand Down Expand Up @@ -147,8 +169,8 @@ split_tested = collect_folds()
function plot_box_split(split_m)
_constraints = ["gpp", "nee", "reco", "transpiration", "evapotranspiration", "agb", "ndvi"]
_colors = ["#4CAF50", "#1565C0", "#D32F2F", "#00ACC1", "#00897B", "#8D6E63", "#CDDC39"]
with_theme() do
fig = Figure(; size = (1200, 300))
with_theme(theme_latexfonts()) do
fig = Figure(; size = (1200, 300), fontsize=24)
axs = [Axis(fig[1, i]) for i in 1:7]
for (i, ax) in enumerate(axs)
tmp_vec = filter(!isnan, split_m[:,i])
Expand All @@ -165,7 +187,7 @@ function plot_box_split(split_m)
# hidexdecorations!.(axs, grid=false, label=false, ticklabels=false, ticks=true)
hidexdecorations!.(axs, grid=false, label=false, ticklabels=true)
hidespines!.(axs)
save("$(exp_name)_nlayers_$(nlayers)_n_neurons_$(n_neurons)_bs_$(bs)_box_test.png", fig)
save("$(exp_name)_nlayers_$(nlayers)_n_neurons_$(n_neurons)_bs_$(bs)_box_test.pdf", fig)
end
end

Expand All @@ -175,8 +197,8 @@ plot_box_split(split_tested)
function plot_violin_split(split_m)
_constraints = ["gpp", "nee", "reco", "transpiration", "evapotranspiration", "agb", "ndvi"]
_colors = ["#4CAF50", "#1565C0", "#D32F2F", "#00ACC1", "#00897B", "#8D6E63", "#CDDC39"]
with_theme() do
fig = Figure(; size = (1200, 300))
with_theme(theme_latexfonts()) do
fig = Figure(; size = (1200, 300), fontsize=24)
axs = [Axis(fig[1, i]) for i in 1:7]
for (i, ax) in enumerate(axs)
tmp_vec = filter(!isnan, split_m[:,i])
Expand All @@ -195,19 +217,50 @@ function plot_violin_split(split_m)
# hidexdecorations!.(axs, grid=false, label=false, ticklabels=false, ticks=true)
hidexdecorations!.(axs, grid=false, label=false, ticklabels=true)
hidespines!.(axs)
save("$(exp_name)_nlayers_$(nlayers)_n_neurons_$(n_neurons)_bs_$(bs)_violin_test.png", fig)
save("$(exp_name)_nlayers_$(nlayers)_n_neurons_$(n_neurons)_bs_$(bs)_violin_test.pdf", fig)
end
end

plot_violin_split(split_tested)

function plot_beeswarm_split(split_m)
_constraints = ["gpp", "nee", "reco", "transpiration", "evapotranspiration", "agb", "ndvi"]
_colors = ["#4CAF50", "#1565C0", "#D32F2F", "#00ACC1", "#00897B", "#8D6E63", "#CDDC39"]
with_theme(theme_latexfonts()) do
fig = Figure(; size = (1200, 300), fontsize=24)
axs = [Axis(fig[1, i]) for i in 1:7]
for (i, ax) in enumerate(axs)
tmp_vec = filter(!isnan, split_m[:,i])

beeswarm!(ax, fill(1, length(tmp_vec)), tmp_vec; color = (_colors[i], 0.65), markersize = 6)
# boxplot!(ax, fill(1, length(tmp_vec)), tmp_vec; width=0.35, strokecolor = :white,
# strokewidth=1.5, whiskercolor=:white, mediancolor=:white,
# color = :transparent)
ax.title= rich("$(_constraints[i])", color=:grey15, font=:bold)
ax.yticks=[0, 0.25, 0.5, 0.75, 1.0]
end
axs[1].ylabel = "Loss"
ylims!.(axs, 0, 1)
xlims!.(axs, 0.5, 1.5)
hideydecorations!.(axs[2:end], ticks=true, grid=false)
# hidexdecorations!.(axs, grid=false, label=false, ticklabels=false, ticks=true)
hidexdecorations!.(axs, grid=false, label=false, ticklabels=true)
hidespines!.(axs)
save("$(exp_name)_nlayers_$(nlayers)_n_neurons_$(n_neurons)_bs_$(bs)_beeswarm_test.pdf", fig)
end
end

# ! Collect all experiments
# "HyFixK_ALL", "HyFixK_PFT", "HyALL_ALL", "HyALL_PFT"
split_tested_HyALL_ALL = collect_folds("HyALL_ALL", 400, 32, 2, 32)
split_tested_HyALL_PFT = collect_folds("HyALL_PFT", 300, 32, 2, 32)
split_tested_HyFixK_ALL = collect_folds("HyFixK_ALL", 500, 32, 2, 32)
split_tested_HyFixK_PFT = collect_folds("HyFixK_PFT", 500, 32, 2, 32)
split_tested_HyALL_ALL = collect_folds("HyALL_ALL", 200, 32, 2, 32)
# split_tested_HyALL_PFT = collect_folds("HyALL_PFT", 300, 32, 2, 32)
# split_tested_HyFixK_ALL = collect_folds("HyFixK_ALL", 500, 32, 2, 32)
# split_tested_HyFixK_PFT = collect_folds("HyFixK_PFT", 500, 32, 2, 32)
plot_box_split(split_tested_HyALL_ALL)
plot_violin_split(split_tested_HyALL_ALL)
plot_beeswarm_split(split_tested_HyALL_ALL)



function plot_box_split_all(split_m1, split_m2, split_m3, split_m4)
_constraints = ["gpp", "nee", "reco", "transpiration", "evapotranspiration", "agb", "ndvi"]
Expand Down
13 changes: 12 additions & 1 deletion examples/exp_fluxnet_hybrid/exp_fluxnet_hybrid.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# activate project's environment and develop the package
using Pkg
Pkg.activate("examples/exp_fluxnet_hybrid")
Pkg.develop(path=pwd())
Pkg.instantiate()

# get data
# $examples/data> scp -r lalonso@ruthenia:/Net/Groups/BGI/work_5/scratch/lalonso/CovariatesFLUXNET_3.zarr .
# @examples/data> scp -r lalonso@ruthenia:/Net/Groups/BGI/work_4/scratch/lalonso/FLUXNET_v2023_12_1D.zarr .

# start using the package
using SindbadData
using SindbadData.DimensionalData
using SindbadData.AxisKeys
Expand All @@ -7,7 +18,7 @@ using SindbadML
using SindbadML.JLD2
using ProgressMeter
using SindbadOptimization
include("load_covariates.jl")
# include("load_covariates.jl")

# load folds # $nfold $nlayer $neuron $batchsize
_nfold = 5 #Base.parse(Int, ARGS[1])
Expand Down
Loading
Loading