Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lazarusA committed Sep 16, 2024
1 parent 4d21127 commit 84eecb0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ MultivariateStats = "6f286f6a-111f-5878-ab1e-185364afe411"
NetCDF = "30363a11-5582-574a-97bb-aa9a979735b9"
OnlineStats = "a15396b6-48d5-5d58-9928-6d29437db91e"
PlotUtils = "995b91a9-d308-5afd-9ec6-746e21dbc043"
Rasters = "a3a2b9e3-a471-40c9-b274-f788e487c689"
SkipNan = "aed68c70-c8b0-4309-8cd1-d392a74f991a"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
TimeSeries = "9e3dc215-6440-5c97-bce1-76c03772f85e"
Expand Down
58 changes: 34 additions & 24 deletions test/Datasets/datasets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -413,47 +413,57 @@ end
@testset "Saving, OutDims" begin
using YAXArrays, Zarr, NetCDF, ArchGDAL
using Dates

flolat(lo, la, t) = (lo + la + Dates.dayofyear(t))
flola(lo, la) = lo + la + 1

function g(xout, lo, la, t)
xout .= flolat.(lo, la, t)
end

function g2d(xout, lo, la)
xout .= flola.(lo, la)
end

lon = YAXArray(Dim{:lon}(range(1, 15)))
lat = YAXArray(Dim{:lat}(range(1, 10)))
tspan = Date("2022-01-01"):Day(1):Date("2022-01-30")
time = YAXArray(Dim{:time}(tspan))

gen_cube = mapCube(g, (lon, lat, time);
indims = (InDims(), InDims(), InDims("time")),
outdims = OutDims("time",
outtype = Float32)
# max_cache=1e9
)
indims = (InDims(), InDims(), InDims("time")),
outdims = OutDims("time",
outtype = Float32)
# max_cache=1e9
)

gen_cube2d = mapCube(g2d, (lon, lat);
indims = (InDims(), InDims()),
outdims = OutDims(outtype = Float32)
# max_cache=1e9
)

# test saves, zarr
gen_zarr = mapCube(g, (lon, lat, time);
indims = (InDims(), InDims(), InDims("time")),
outdims = OutDims("time", overwrite=true, path="my_gen_cube.zarr",
outtype = Float32)
# max_cache=1e9
)
indims = (InDims(), InDims(), InDims("time")),
outdims = OutDims("time", overwrite=true, path="my_gen_cube.zarr",
outtype = Float32)
# max_cache=1e9
)
ds_zarr = open_dataset("my_gen_cube.zarr")
# test saves, nc
gen_nc = mapCube(g, (lon, lat, time);
indims = (InDims(), InDims(), InDims("time")),
outdims = OutDims("time", overwrite=true, path="my_gen_cube.nc",
outtype = Float32)
# max_cache=1e9
)
indims = (InDims(), InDims(), InDims("time")),
outdims = OutDims("time", overwrite=true, path="my_gen_cube.nc",
outtype = Float32)
# max_cache=1e9
)
ds_nc = open_dataset("my_gen_cube.nc")
# test saves, tif, once we update to YAXArrayBase 0.7.3
# gen_zarr = mapCube(g, (lon, lat, time);
# indims = (InDims(), InDims(), InDims("time")),
# outdims = OutDims("time", overwrite=true, path="my_gen_cube.tif",
# outtype = Float32)
# # max_cache=1e9
# )
@test gen_cube.data[:,:] == ds_zarr["layer"].data[:,:]
@test gen_cube.data[:,:] == ds_nc["layer"].data[:,:]

# TODO: fix tif for general inputs, so that writing also works.

@test gen_cube.data[:,:,:] == ds_zarr["layer"].data[:,:,:]
@test gen_cube.data[:,:,:] == ds_nc["layer"].data[:,:,:]
end

@testset "Caching" begin
Expand Down

0 comments on commit 84eecb0

Please sign in to comment.