-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
retrieve_bathymetry
fails on a 1 degree grid
#205
Comments
I'm confused why the |
It looks like a precision error. The latitude-longitude grid to load the bathymetry wants to be at latitudes julia> grid = LatitudeLongitudeGrid(size = (100, 100, 1), z = (0, 1), latitude = (-85, 90), longitude = (0, 360))
100×100×1 LatitudeLongitudeGrid{Float64, Periodic, Bounded, Bounded} on CPU with 3×3×1 halo and with precomputed metrics
├── longitude: Periodic λ ∈ [0.0, 360.0) regularly spaced with Δλ=3.6
├── latitude: Bounded φ ∈ [-85.0, 90.0] regularly spaced with Δφ=1.75
└── z: Bounded z ∈ [0.0, 1.0] regularly spaced with Δz=1.0
julia> bathymetry = retrieve_bathymetry(grid, dir = "./")
[ Info: Regridding bathymetry from existing file ./ETOPO_2022_v1_60s_N90W180_surface.nc.
(φ_data[end], φ_data[end - 1], Δφ) = (89.99166666666667, 89.975, 0.01666666666667993)
(φ₁_data, φ₂_data) = (-85.00000000000001, 90.00000000000001)
ERROR: ArgumentError: The northern latitude cannot be less than -90 degrees.
Stacktrace:
[1] validate_lat_lon_grid_args
@ ~/.julia/packages/Oceananigans/s1DfC/src/Grids/latitude_longitude_grid.jl:281 [inlined]
[2] LatitudeLongitudeGrid(architecture::CPU, FT::DataType; size::Tuple{…}, longitude::Tuple{…}, latitude::Tuple{…}, z::Tuple{…}, radius::Float64, topology::Nothing, precompute_metrics::Bool, halo::Tuple{…})
@ Oceananigans.Grids ~/.julia/packages/Oceananigans/s1DfC/src/Grids/latitude_longitude_grid.jl:189
[3] LatitudeLongitudeGrid
@ ~/.julia/packages/Oceananigans/s1DfC/src/Grids/latitude_longitude_grid.jl:174 [inlined]
[4] regrid_bathymetry(target_grid::LatitudeLongitudeGrid{…}; height_above_water::Nothing, minimum_depth::Int64, dir::String, url::String, filename::String, interpolation_passes::Int64, major_basins::Float64)
@ ClimaOcean.Bathymetry ~/development/ClimaOcean.jl/src/Bathymetry.jl:173
[5] regrid_bathymetry
@ ~/development/ClimaOcean.jl/src/Bathymetry.jl:80 [inlined]
[6] #retrieve_bathymetry#13
@ ~/development/ClimaOcean.jl/src/Bathymetry.jl:366 [inlined]
[7] top-level scope
@ REPL[44]:1
Some type information was truncated. Use `show(err)` to see complete types.
julia> I wonder how we did not have hit this error before or if something did not change in the bathymetry. |
This error happens because the last element in ClimaOcean.jl/src/Bathymetry.jl Line 114 in 69a111a
is 89.99166666666667 While it should be 89.99166666666666 to have the face of the last element at |
Yeah weird that it somehow depends on the grid? But maybe the constructor for the lat lon grid should be allowed to fudge the bounds by very small amounts to ensure correctness? |
It seems like changing ClimaOcean.jl/src/Bathymetry.jl Lines 114 to 115 in 69a111a
to φ_data = dataset["lat"][:] |> Array{BigFloat}
λ_data = dataset["lon"][:] |> Array{BigFloat} ClimaOcean.jl/src/Bathymetry.jl Lines 160 to 165 in 69a111a
to
solves the issue. |
Agreed, we can do something like this: φ₂ <= 90 + tolerance || throw(ArgumentError("The northern latitude cannot be less than -90 degrees."))
φ₂ = φ₂ > 90 ? 90 : φ₂ (and the same for the southern boundary) |
However I am wondering how ClimaOcean.jl/test/test_simulations.jl Lines 8 to 30 in 69a111a
manages to run without errors |
I think directly / manually fixing the rounding issue might be preferred to BigFloat, but it does seem like BigFloat will work for bathymetry at least, because we always interpolate to a new field on the model grid? For other situations where we need to interpolate on the fly, we'd need a different solution. |
MWE:
The text was updated successfully, but these errors were encountered: