Skip to content

Commit 6f8c3b7

Browse files
committed
Fix local tests
1 parent 1b780e7 commit 6f8c3b7

File tree

9 files changed

+53
-41
lines changed

9 files changed

+53
-41
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
.vscode/
44

5-
test/plots/
5+
test/plots/
6+
plots/

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "OceanTransportMatrixBuilder"
22
uuid = "c2b4a04e-6049-4fc4-aa6a-5508a29a1e1c"
33
authors = ["Benoit Pasquier <[email protected]> and contributors"]
4-
version = "0.6.0"
4+
version = "0.6.1"
55

66
[deps]
77
Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ using NetCDF
3030
using YAXArrays
3131
using OceanTransportMatrixBuilder
3232

33-
inputdir = "/Users/benoitpasquier/Data/TMIP/data/ACCESS-ESM1-5/historical/r1i1p1f1/Jan1990-Dec1999"
33+
inputdir = "$(ENV["HOME"])/Data/TMIP/data/ACCESS-ESM1-5/historical/r1i1p1f1/Jan1990-Dec1999"
3434
# The path above is for my local machine. See test/onlinebuild.jl for an example using data from the cloud.
3535

3636
# Load datasets

src/extratools.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ where the lumping should occur.
3131
Outside of this region, no lumping.
3232
Default is `f=Returns(true)`, i.e. lump everywhere.
3333
"""
34-
function lump_and_spray(wet3D, volume; f=Returns(true), di=2, dj=2, dk=1)
34+
function lump_and_spray(wet3D, vol; f=Returns(true), di=2, dj=2, dk=1)
3535

3636
# extend the grid to avoid lumping cells outside of bounds
3737
nxyz = size(wet3D)
@@ -54,7 +54,7 @@ function lump_and_spray(wet3D, volume; f=Returns(true), di=2, dj=2, dk=1)
5454
c += 1
5555
end
5656
end
57-
LUMP = sparse(LUMPidx[:], 1:length(LUMPidx), 1)
57+
LUMP = sparse(LUMPidx[C][:], 1:length(C), 1)
5858

5959
# Find wet points in coarsened grid
6060
wet = wet3D[:]
@@ -66,15 +66,15 @@ function lump_and_spray(wet3D, volume; f=Returns(true), di=2, dj=2, dk=1)
6666
# Make the LUMP operator volume-conserving
6767
# by volume integrating on the right and dividing by the coarse
6868
# volume on the left
69-
volume_c = LUMP * volume
70-
LUMP = sparse(Diagonal(1 ./ volume_c)) * LUMP * sparse(Diagonal(volume))
69+
vol_c = LUMP * vol
70+
LUMP = sparse(Diagonal(1 ./ vol_c)) * LUMP * sparse(Diagonal(vol))
7171

7272
# The SPRAY operator just copies the values back
7373
# so it is sinply 1's with the transposed sparsity structure
7474
SPRAY = copy(LUMP')
7575
SPRAY.nzval .= 1
7676

77-
return LUMP, SPRAY, volume_c
77+
return LUMP, SPRAY, vol_c
7878
end
7979

8080

test/LocalBuiltMatrix.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# My local directory for input files
1717
model = "ACCESS-ESM1-5"
1818
member = "r1i1p1f1"
19-
inputdir = "/Users/benoitpasquier/Data/TMIP/data/$model/historical/$member/Jan1990-Dec1999"
19+
inputdir = "$(ENV["HOME"])/Data/TMIP/data/$model/historical/$member/Jan1990-Dec1999"
2020

2121
# and for output files
2222
@show version = "v$(pkgversion(OceanTransportMatrixBuilder))"
@@ -64,9 +64,9 @@
6464
thetao_ds = open_dataset(joinpath(inputdir, "thetao.nc"))
6565
so_ds = open_dataset(joinpath(inputdir, "so.nc"))
6666
# Load variables in memory
67-
thetao = readcubedata(thetao_ds.thetao)
67+
thetao = readcubedata(thetao_ds.thetao) |> Array
6868
@test 0 < nanmean(thetao) < 20
69-
so = readcubedata(so_ds.so)
69+
so = readcubedata(so_ds.so) |> Array
7070
@show 30 < nanmean(so) < 40
7171
# Convert thetao and so to density
7272
ct = gsw_ct_from_pt.(so, thetao)

test/interactive.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Pkg.instantiate()
44
using TestEnv
55
TestEnv.activate();
66

7+
using Revise
78

89
using Test
910
using OceanTransportMatrixBuilder
@@ -20,7 +21,7 @@ using LinearAlgebra
2021
# My local directory for input files
2122
model = "ACCESS-ESM1-5"
2223
member = "r1i1p1f1"
23-
inputdir = "/Users/benoitpasquier/Data/TMIP/data/$model/historical/$member/Jan1990-Dec1999"
24+
inputdir = "$(ENV["HOME"])/Data/TMIP/data/$model/historical/$member/Jan1990-Dec1999"
2425

2526
# and for output files
2627
@show version = "v$(pkgversion(OceanTransportMatrixBuilder))"
@@ -73,8 +74,8 @@ thetao = readcubedata(thetao_ds.thetao)
7374
so = readcubedata(so_ds.so)
7475
@show 30 < nanmean(so) < 40
7576
# Convert thetao and so to density
76-
ct = gsw_ct_from_pt.(so, thetao)
77-
ρ = gsw_rho.(so, ct, Z3D)
77+
ct = map(gsw_ct_from_pt, so, thetao)
78+
ρ = map(gsw_rho, so, ct, Z3D)
7879
# TODO: Check if this is correct usage of gsw functions!
7980
# Alternatively use a fixed density:
8081
# ρ = 1035.0 # kg/m^3

test/local_fast.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22

33

4-
@testitem "grid checks" tags = [:skipci] begin
4+
@testitem "grid checks" tags = [:skipci, :local_fast] begin
55

66
using Test
77
using OceanTransportMatrixBuilder
@@ -14,8 +14,10 @@
1414
using Unitful: m, km
1515

1616
# TODO fix this so that I don't have to track all members
17-
models = ("ACCESS-ESM1-5", "ACCESS-CM2", "ACCESS1-3", "ACCESS1-0")
18-
members = ("r1i1p1f1", "r1i1p1f1", "r1i1p1", "r1i1p1")
17+
# models = ("ACCESS-ESM1-5", "ACCESS-CM2", "ACCESS1-3", "ACCESS1-0")
18+
# members = ("r1i1p1f1", "r1i1p1f1", "r1i1p1", "r1i1p1")
19+
models = ("ACCESS-ESM1-5",)# "ACCESS-CM2", "ACCESS1-3", "ACCESS1-0")
20+
members = ("r1i1p1f1",)# "r1i1p1f1", "r1i1p1", "r1i1p1")
1921

2022
# models_untested = ("CMCC-CM2-HR4",)
2123
# members_untested = ("r1i1p1f1",)
@@ -39,7 +41,8 @@
3941
for (model, member) in zip(models, members)
4042

4143
# My local directory for input files
42-
inputdir = "/Users/benoitpasquier/Data/TMIP/data/$model/historical/$member/Jan1990-Dec1999"
44+
inputdir = "$(ENV["HOME"])/Data/TMIP/data/$model/historical/$member/Jan1990-Dec1999"
45+
@info "inputdir = $inputdir"
4346

4447
# Load datasets
4548
volcello_ds = open_dataset(joinpath(inputdir, "volcello.nc"))

test/local_full.jl

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44

5-
@testitem "velocities and mass transports" setup=[LocalBuiltMatrix] tags=[:skipci] begin
5+
@testitem "velocities and mass transports" setup=[LocalBuiltMatrix] tags=[:skipci, :local_full] begin
66

77
using NaNStatistics
88
using CairoMakie
@@ -15,7 +15,7 @@
1515

1616
# plot for sanity check
1717
# plot zonal average density
18-
ρ2D = dropdims(nansum.data .* v3D, dims = 1) ./ nansum(v3D, dims = 1), dims = 1)
18+
ρ2D = dropdims(nansum.* v3D, dims = 1) ./ nansum(v3D, dims = 1), dims = 1)
1919
fig = Figure()
2020
ax = Axis(fig[1,1], xlabel = "latitude (°)", ylabel = "depth (m)")
2121
# levels = 25:0.1:30
@@ -32,10 +32,6 @@
3232
@info "Saving density zonal average as image file:\n $(joinpath("test", outputfile))"
3333
save(outputfile, fig)
3434

35-
κGM = 600 # m^2/s
36-
maxslope = 0.01
37-
uGM, vGM = OceanTransportMatrixBuilder.bolus_GM_velocity(ρ, gridmetrics, indices; κGM, maxslope)
38-
3935
# Plot location of cell center for volcello, umo, vmo, uo, vo
4036
fig = Figure()
4137
ax = Axis(fig[1,1], xlabel = "lon", ylabel = "lat")
@@ -47,31 +43,37 @@
4743
text!(ax, vo_lon[1], vo_lat[1]; text="vo (i,j)", align = (:center, :bottom))
4844
fig
4945

46+
47+
κGM = 600 # m^2/s
48+
maxslope = 0.01
49+
uGM, vGM = OceanTransportMatrixBuilder.bolus_GM_velocity(ρ, gridmetrics, indices; κGM, maxslope)
50+
51+
5052
uo2, uo2_lon, uo2_lat, vo2, vo2_lon, vo2_lat = OceanTransportMatrixBuilder.interpolateontodefaultCgrid(uo, uo_lon, uo_lat, vo, vo_lon, vo_lat, gridmetrics)
5153
fig = Figure(size=(1500, 800))
5254
ax = Axis(fig[1,1], xlabel = "lon", ylabel = "lat", xgridvisible = false, ygridvisible = false)
5355
i = 85 .+ (-1:5); j = 2 .+ (-1:4); k = 1
5456
[poly!(ax, lon_vertices[:,i,j] |> vec, lat_vertices[:,i,j] |> vec, color = (:blue, 0.1)) for i in i for j in j if indices.wet3D[i,j,1]];
5557
[lines!(ax, lon_vertices[:,i,j] |> vec, lat_vertices[:,i,j] |> vec, color = (:black, 0.1)) for i in i for j in j];
5658
# lines!(ax, lon_vertices[1,i,j] |> Array, lat_vertices[1,i,j] |> Array, color = :black)
57-
arrows!(ax, uo_lon[i,j,k] |> vec, uo_lat[i,j,k] |> vec, uo[i,j,k] |> vec, 0uo[i,j,k] |> vec, arrowsize = 10, lengthscale = 10, arrowcolor = :darkblue, linecolor = :darkblue)
58-
arrows!(ax, vo_lon[i,j,k] |> vec, vo_lat[i,j,k] |> vec, 0vo[i,j,k] |> vec, vo[i,j,k] |> vec, arrowsize = 10, lengthscale = 10, arrowcolor = :darkred, linecolor = :darkred)
59-
arrows!(ax, uo2_lon[i,j,k] |> vec, uo2_lat[i,j,k] |> vec, uo2[i,j,k] |> vec, 0uo2[i,j,k] |> vec, arrowsize = 10, lengthscale = 10, arrowcolor = :blue, linecolor = :blue)
60-
arrows!(ax, vo2_lon[i,j,k] |> vec, vo2_lat[i,j,k] |> vec, 0vo2[i,j,k] |> vec, vo2[i,j,k] |> vec, arrowsize = 10, lengthscale = 10, arrowcolor = :red, linecolor = :red)
61-
arrows!(ax, uo2_lon[i,j,k] |> vec, uo2_lat[i,j,k] .+ 0.02 |> vec, umo[i,j,k] |> vec, 0umo[i,j,k] |> vec, arrowsize = 10, lengthscale = 3e-8, arrowcolor = (:blue, 0.3), linecolor = (:blue, 0.3))
62-
arrows!(ax, vo2_lon[i,j,k] .+ 0.02 |> vec, vo2_lat[i,j,k] |> vec, 0vmo[i,j,k] |> vec, vmo[i,j,k] |> vec, arrowsize = 10, lengthscale = 3e-8, arrowcolor = (:red, 0.3), linecolor = (:red, 0.3))
59+
arrows2d!(ax, uo_lon[i,j,k] |> vec, uo_lat[i,j,k] |> vec, uo[i,j,k] |> vec, 0(uo[i,j,k] |> vec), lengthscale = 10, tipcolor = :darkblue, shaftcolor = :darkblue)
60+
arrows2d!(ax, vo_lon[i,j,k] |> vec, vo_lat[i,j,k] |> vec, 0(vo[i,j,k] |> vec), vo[i,j,k] |> vec, lengthscale = 10, tipcolor = :darkred, shaftcolor = :darkred)
61+
arrows2d!(ax, uo2_lon[i,j,k] |> vec, uo2_lat[i,j,k] |> vec, uo2[i,j,k] |> vec, 0(uo2[i,j,k] |> vec), lengthscale = 10, tipcolor = :blue, shaftcolor = :blue)
62+
arrows2d!(ax, vo2_lon[i,j,k] |> vec, vo2_lat[i,j,k] |> vec, 0(vo2[i,j,k] |> vec), vo2[i,j,k] |> vec, lengthscale = 10, tipcolor = :red, shaftcolor = :red)
63+
arrows2d!(ax, uo2_lon[i,j,k] |> vec, uo2_lat[i,j,k] .+ 0.02 |> vec, umo[i,j,k] |> vec, 0(umo[i,j,k] |> vec), lengthscale = 3e-8, tipcolor = (:blue, 0.3), shaftcolor = (:blue, 0.3))
64+
arrows2d!(ax, vo2_lon[i,j,k] .+ 0.02 |> vec, vo2_lat[i,j,k] |> vec, 0(vmo[i,j,k] |> vec), vmo[i,j,k] |> vec, lengthscale = 3e-8, tipcolor = (:red, 0.3), shaftcolor = (:red, 0.3))
6365
fig
6466
ax = Axis(fig[1,2], xlabel = "lon", ylabel = "lat", xgridvisible = false, ygridvisible = false)
6567
i = 160 .+ (-3:3); j = 200 .+ (-2:2); k = 1
6668
[poly!(ax, lon_vertices[:,i,j] |> vec, lat_vertices[:,i,j] |> vec, color = (:blue, 0.1)) for i in i for j in j if indices.wet3D[i,j,1]];
6769
[lines!(ax, lon_vertices[:,i,j] |> vec, lat_vertices[:,i,j] |> vec, color = (:black, 0.1)) for i in i for j in j];
6870
# lines!(ax, lon_vertices[1,i,j] |> Array, lat_vertices[1,i,j] |> Array, color = :black)
69-
arrows!(ax, uo_lon[i,j,k] |> vec, uo_lat[i,j,k] |> vec, uo[i,j,k] |> vec, 0uo[i,j,k] |> vec, arrowsize = 10, lengthscale = 10, arrowcolor = :darkblue, linecolor = :darkblue)
70-
arrows!(ax, vo_lon[i,j,k] |> vec, vo_lat[i,j,k] |> vec, 0vo[i,j,k] |> vec, vo[i,j,k] |> vec, arrowsize = 10, lengthscale = 10, arrowcolor = :darkred, linecolor = :darkred)
71-
arrows!(ax, uo2_lon[i,j,k] |> vec, uo2_lat[i,j,k] |> vec, uo2[i,j,k] |> vec, 0uo2[i,j,k] |> vec, arrowsize = 10, lengthscale = 10, arrowcolor = :blue, linecolor = :blue)
72-
arrows!(ax, vo2_lon[i,j,k] |> vec, vo2_lat[i,j,k] |> vec, 0vo2[i,j,k] |> vec, vo2[i,j,k] |> vec, arrowsize = 10, lengthscale = 10, arrowcolor = :red, linecolor = :red)
73-
arrows!(ax, uo2_lon[i,j,k] |> vec, uo2_lat[i,j,k] .+ 0.02 |> vec, umo[i,j,k] |> vec, 0umo[i,j,k] |> vec, arrowsize = 10, lengthscale = 1e-8, arrowcolor = (:blue, 0.3), linecolor = (:blue, 0.3))
74-
arrows!(ax, vo2_lon[i,j,k] .+ 0.02 |> vec, vo2_lat[i,j,k] |> vec, 0vmo[i,j,k] |> vec, vmo[i,j,k] |> vec, arrowsize = 10, lengthscale = 1e-8, arrowcolor = (:red, 0.3), linecolor = (:red, 0.3))
71+
arrows2d!(ax, uo_lon[i,j,k] |> vec, uo_lat[i,j,k] |> vec, uo[i,j,k] |> vec, 0(uo[i,j,k] |> vec), lengthscale = 10, tipcolor = :darkblue, shaftcolor = :darkblue)
72+
arrows2d!(ax, vo_lon[i,j,k] |> vec, vo_lat[i,j,k] |> vec, 0(vo[i,j,k] |> vec), vo[i,j,k] |> vec, lengthscale = 10, tipcolor = :darkred, shaftcolor = :darkred)
73+
arrows2d!(ax, uo2_lon[i,j,k] |> vec, uo2_lat[i,j,k] |> vec, uo2[i,j,k] |> vec, 0(uo2[i,j,k] |> vec), lengthscale = 10, tipcolor = :blue, shaftcolor = :blue)
74+
arrows2d!(ax, vo2_lon[i,j,k] |> vec, vo2_lat[i,j,k] |> vec, 0(vo2[i,j,k] |> vec), vo2[i,j,k] |> vec, lengthscale = 10, tipcolor = :red, shaftcolor = :red)
75+
arrows2d!(ax, uo2_lon[i,j,k] |> vec, uo2_lat[i,j,k] .+ 0.02 |> vec, umo[i,j,k] |> vec, 0(umo[i,j,k] |> vec), lengthscale = 1e-8, tipcolor = (:blue, 0.3), shaftcolor = (:blue, 0.3))
76+
arrows2d!(ax, vo2_lon[i,j,k] .+ 0.02 |> vec, vo2_lat[i,j,k] |> vec, 0(vmo[i,j,k] |> vec), vmo[i,j,k] |> vec, lengthscale = 1e-8, tipcolor = (:red, 0.3), shaftcolor = (:red, 0.3))
7577
fig
7678

7779
fig = Figure()
@@ -143,6 +145,9 @@ end
143145
M_c = sparse(Diagonal(issrf_c))
144146
sΓ_c = LUMP *
145147
@time "Solving ideal mean age" Γ_c = (T_c + M_c) \ sΓ_c
148+
# Just some timings from machines I have used (ACCESS-ESM1-5 coarsened 2x2x1)
149+
# time machine proc. RAM
150+
# 3min MacBook Air 8 × M2 8GB
146151
Γ = SPRAY * Γ_c
147152
Γyr = ustrip.(yr, Γ .* s)
148153
Γ3D = OceanTransportMatrixBuilder.as3D(Γyr, wet3D)
@@ -220,6 +225,8 @@ end
220225
# Difference between the fluxes from velocities and mass transport
221226
(; uo, vo, umo, vmo, uo_lon, uo_lat, vo_lon, vo_lat, gridmetrics, ρ) = LocalBuiltMatrix
222227
umo_bis, vmo_bis = velocity2fluxes(uo, uo_lon, uo_lat, vo, vo_lon, vo_lat, gridmetrics, ρ)
228+
umo_arr = umo |> Array
229+
vmo_arr = vmo |> Array
223230
colorrange = 1e9 .* (-1, 1)
224231
colormap = cgrad(:RdBu, rev=true)
225232
Δcolorrange = (-5, 5)
@@ -239,22 +246,22 @@ end
239246
hidedecorations!(ax)
240247

241248
ax = Axis(fig[1,2], xlabel = "i", ylabel = "j")
242-
heatmap!(ax, umo[:,:,k]; colormap, colorrange)
249+
heatmap!(ax, umo_arr[:,:,k]; colormap, colorrange)
243250
text!(ax, 0, 1; text = "umo", align = (:left, :top), offset = (5, -5), space = :relative)
244251
hidedecorations!(ax)
245252

246253
ax = Axis(fig[2,2], xlabel = "i", ylabel = "j")
247-
hm = heatmap!(ax, vmo[:,:,k]; colormap, colorrange)
254+
hm = heatmap!(ax, vmo_arr[:,:,k]; colormap, colorrange)
248255
text!(ax, 0, 1; text = "vmo", align = (:left, :top), offset = (5, -5), space = :relative)
249256
hidedecorations!(ax)
250257

251258
ax = Axis(fig[1,3], xlabel = "i", ylabel = "j")
252-
heatmap!(ax, 100((umo_bis - umo) ./ umo)[:,:,k]; colormap = Δcolormap, colorrange = Δcolorrange)
259+
heatmap!(ax, 100((umo_bis - umo_arr) ./ umo_arr)[:,:,k]; colormap = Δcolormap, colorrange = Δcolorrange)
253260
text!(ax, 0, 1; text = "(umo_bis − umo) / umo", align = (:left, :top), offset = (5, -5), space = :relative)
254261
hidedecorations!(ax)
255262

256263
ax = Axis(fig[2,3], xlabel = "i", ylabel = "j")
257-
Δhm = heatmap!(ax, 100((vmo_bis - vmo) ./ vmo)[:,:,k]; colormap = Δcolormap, colorrange = Δcolorrange)
264+
Δhm = heatmap!(ax, 100((vmo_bis - vmo_arr) ./ vmo_arr)[:,:,k]; colormap = Δcolormap, colorrange = Δcolorrange)
258265
text!(ax, 0, 1; text = "(vmo_bis − vmo) / vmo", align = (:left, :top), offset = (5, -5), space = :relative)
259266
hidedecorations!(ax)
260267

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
using TestItemRunner
22

3-
@run_package_tests verbose=true filter=ti->!(:skipci in ti.tags)
3+
@run_package_tests verbose=true filter=test->(:skipci test.tags)

0 commit comments

Comments
 (0)