@@ -126,29 +126,10 @@ function regrid_bathymetry(target_grid;
126126 close (dataset)
127127
128128 # Diagnose target grid information
129- arch = architecture (target_grid)
130- φ₁, φ₂ = y_domain (target_grid)
131- λ₁, λ₂ = x_domain (target_grid)
132-
133- if λ₁ < 0 || λ₂ > 360
134- throw (ArgumentError (" Cannot regrid bathymetry between λ₁ = $(λ₁) and λ₂ = $(λ₂) .
135- Bathymetry data is defined on longitudes spanning λ = (0, 360)." ))
136- end
137-
138- # Calculate limiting indices on the bathymetry grid
139- i₁ = searchsortedfirst (λ_data, λ₁)
140- i₂ = searchsortedfirst (λ_data, λ₂) - 1
141- ii = i₁: i₂
142-
143- j₁ = searchsortedfirst (φ_data, φ₁)
144- j₂ = searchsortedfirst (φ_data, φ₂) - 1
145- jj = j₁: j₂
146-
147- # Restrict bathymetry coordinate_data to region of interest
148- λ_data = λ_data[ii] |> Array{BigFloat}
149- φ_data = φ_data[jj] |> Array{BigFloat}
150- z_data = z_data[ii, jj]
151-
129+ arch = architecture (target_grid)
130+ λ_data = λ_data |> Array{BigFloat}
131+ φ_data = φ_data |> Array{BigFloat}
132+
152133 if ! isnothing (height_above_water)
153134 # Overwrite the height of cells above water.
154135 # This has an impact on reconstruction. Greater height_above_water reduces total
@@ -170,6 +151,7 @@ function regrid_bathymetry(target_grid;
170151 Nyn = length (φ_data)
171152 Nzn = 1
172153
154+
173155 native_grid = LatitudeLongitudeGrid (arch, Float32;
174156 size = (Nxn, Nyn, Nzn),
175157 latitude = (φ₁_data, φ₂_data),
@@ -179,7 +161,8 @@ function regrid_bathymetry(target_grid;
179161
180162 native_z = Field {Center, Center, Nothing} (native_grid)
181163 set! (native_z, z_data)
182-
164+ fill_halo_regions! (native_z)
165+
183166 target_z = interpolate_bathymetry_in_passes (native_z, target_grid;
184167 passes = interpolation_passes)
185168
@@ -206,9 +189,15 @@ function interpolate_bathymetry_in_passes(native_z, target_grid;
206189 Nλt, Nφt = Nt = size (target_grid)
207190 Nλn, Nφn = Nn = size (native_z)
208191
192+ resxt = minimum_xspacing (target_grid)
193+ resyt = minimum_yspacing (target_grid)
194+
195+ resxn = minimum_xspacing (native_z. grid)
196+ resyn = minimum_yspacing (native_z. grid)
197+
209198 # Check whether we are coarsening the grid in any directions.
210199 # If so, skip interpolation passes.
211- if Nλt > Nλn || Nφt > Nφn
200+ if resxt > resxn || resyt > resyn
212201 target_z = Field {Center, Center, Nothing} (target_grid)
213202 interpolate! (target_z, native_z)
214203 @info string (" Skipping passes for interpolating bathymetry of size $Nn " , ' \n ' ,
0 commit comments