|
| 1 | +# Standalone round-trip test for fluxes2velocity |
| 2 | +# Run with: julia --project test/test_fluxes2velocity.jl |
| 3 | + |
| 4 | +using Test |
| 5 | +using OceanTransportMatrixBuilder |
| 6 | +using NetCDF |
| 7 | +using YAXArrays |
| 8 | +using GibbsSeaWater |
| 9 | +using DimensionalData |
| 10 | +using NaNStatistics |
| 11 | + |
| 12 | +model = "ACCESS-ESM1-5" |
| 13 | +member = "r1i1p1f1" |
| 14 | +inputdir = "$(ENV["HOME"])/Data/TMIP/data/$model/historical/$member/Jan1990-Dec1999" |
| 15 | + |
| 16 | +# Load datasets |
| 17 | +uo_ds = open_dataset(joinpath(inputdir, "uo.nc")) |
| 18 | +vo_ds = open_dataset(joinpath(inputdir, "vo.nc")) |
| 19 | +volcello_ds = open_dataset(joinpath(inputdir, "volcello.nc")) |
| 20 | +areacello_ds = open_dataset(joinpath(inputdir, "areacello.nc")) |
| 21 | +thetao_ds = open_dataset(joinpath(inputdir, "thetao.nc")) |
| 22 | +so_ds = open_dataset(joinpath(inputdir, "so.nc")) |
| 23 | + |
| 24 | +areacello = readcubedata(areacello_ds.areacello) |
| 25 | +volcello = readcubedata(volcello_ds.volcello) |
| 26 | +lon = readcubedata(volcello_ds.lon) |
| 27 | +lat = readcubedata(volcello_ds.lat) |
| 28 | +lev = volcello_ds.lev |
| 29 | +lon_vertices = readcubedata(volcello_ds.lon_verticies) |
| 30 | +lat_vertices = readcubedata(volcello_ds.lat_verticies) |
| 31 | +uo = readcubedata(uo_ds.uo) |
| 32 | +vo = readcubedata(vo_ds.vo) |
| 33 | +uo_lon = readcubedata(uo_ds.lon) |
| 34 | +uo_lat = readcubedata(uo_ds.lat) |
| 35 | +vo_lon = readcubedata(vo_ds.lon) |
| 36 | +vo_lat = readcubedata(vo_ds.lat) |
| 37 | +thetao = readcubedata(thetao_ds.thetao) |> Array |
| 38 | +so = readcubedata(so_ds.so) |> Array |
| 39 | + |
| 40 | +gridmetrics = makegridmetrics(; areacello, volcello, lon, lat, lev, lon_vertices, lat_vertices) |
| 41 | +(; Z3D, v3D) = gridmetrics |
| 42 | +ct = gsw_ct_from_pt.(so, thetao) |
| 43 | +ρ = gsw_rho.(so, ct, Z3D) |
| 44 | +indices = makeindices(v3D) |
| 45 | +(; wet3D) = indices |
| 46 | + |
| 47 | +# Round-trip: velocity → flux → velocity |
| 48 | +u_cgrid, _, _, v_cgrid, _, _ = OceanTransportMatrixBuilder.interpolateontodefaultCgrid(uo, uo_lon, uo_lat, vo, vo_lon, vo_lat, gridmetrics) |
| 49 | +umo_bis, vmo_bis = velocity2fluxes(uo, uo_lon, uo_lat, vo, vo_lon, vo_lat, gridmetrics, ρ) |
| 50 | +u_rec, v_rec = fluxes2velocity(umo_bis, vmo_bis, gridmetrics, ρ) |
| 51 | + |
| 52 | +@test u_rec[wet3D] ≈ u_cgrid[wet3D] |
| 53 | +@test v_rec[wet3D] ≈ v_cgrid[wet3D] |
| 54 | + |
| 55 | +println("All tests passed!") |
0 commit comments