Skip to content

Commit

Permalink
Bugfix set!ting ECCO FTS with cycling boundaries (#290)
Browse files Browse the repository at this point in the history
* add test

* cycling test

* fix ecco cycling

* no need for a memory index

* correct tests

* Import update_state!

* timesteppers

* correct tests

---------

Co-authored-by: Gregory L. Wagner <[email protected]>
  • Loading branch information
simone-silvestri and glwagner authored Dec 11, 2024
1 parent c6fe6a0 commit 3db2d25
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/DataWrangling/ECCO/ECCO_restoring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,10 @@ cache_inpainted_data(::ECCONetCDFBackend{native, cache_data}) where {native, cac

function set!(fts::ECCONetCDFFTS)
backend = fts.backend
start = backend.start
inpainting = backend.inpainting
cache_data = cache_inpainted_data(backend)
len = backend.length

for t in start:start+len-1
for t in time_indices(fts)
# Set each element of the time-series to the associated file
metadatum = @inbounds backend.metadata[t]
set!(fts[t], metadatum; inpainting, cache_inpainted_data=cache_data)
Expand Down
51 changes: 50 additions & 1 deletion test/test_ecco.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ using ClimaOcean
using ClimaOcean.ECCO
using ClimaOcean.ECCO: ECCO_field, metadata_path, ECCO_times
using ClimaOcean.DataWrangling: NearestNeighborInpainting

using Oceananigans.Grids: topology
using Oceananigans.OutputReaders: time_indices
using Oceananigans.TimeSteppers: update_state!
using Oceananigans.Units

using CUDA: @allowscalar

Expand Down Expand Up @@ -174,7 +178,8 @@ end

@testset "Setting temperature and salinity to ECCO" begin
for arch in test_architectures
grid = LatitudeLongitudeGrid(size=(10, 10, 10),
grid = LatitudeLongitudeGrid(arch;
size=(10, 10, 10),
latitude=(-60, -40),
longitude=(10, 15),
z=(-200, 0),
Expand All @@ -185,3 +190,47 @@ end
set!(ocean.model, T=ECCOMetadata(:temperature, date), S=ECCOMetadata(:salinity, date))
end
end

@testset "ECCO dataset cycling boundaries" begin
for arch in test_architectures
grid = LatitudeLongitudeGrid(arch;
size=(10, 10, 10),
latitude=(-60, -40),
longitude=(10, 15),
z=(-200, 0),
halo = (7, 7, 7))

start_date = DateTimeProlepticGregorian(1993, 1, 1)
end_date = DateTimeProlepticGregorian(1993, 5, 1)
dates = start_date : Month(1) : end_date

t_restoring = ECCORestoring(arch, :temperature;
dates,
rate = 1 / 1000.0,
inpainting)

times = ECCO_times(t_restoring.field_time_series.backend.metadata)
ocean = ocean_simulation(grid, forcing = (; T = t_restoring))

ocean.model.clock.time = times[3] + 2 * Units.days
update_state!(ocean.model)

@test t_restoring.field_time_series.backend.start == 3

# Compile
time_step!(ocean)

# Try stepping out of the ECCO dataset bounds
ocean.model.clock.time = last(times) + 2 * Units.days

update_state!(ocean.model)

@test begin
time_step!(ocean)
true
end

# The backend has cycled to the end
@test time_indices(t_restoring.field_time_series) == (5, 1)
end
end

0 comments on commit 3db2d25

Please sign in to comment.