@@ -8,7 +8,6 @@ import Thermodynamics as TD
88import ClimaOcean. EN4: download_dataset
99using KernelAbstractions: @kernel , @index , @inbounds
1010using XESMF # to load Oceananigans regridding extension
11- using PythonCall
1211
1312OceananigansXESMFExt = Base. get_extension (OC, :OceananigansXESMFExt ). OceananigansXESMFExt;
1413
@@ -195,6 +194,10 @@ function construct_remappers(grid, boundary_space)
195194 coords_oc =
196195 OceananigansXESMFExt. xesmf_coordinates (grid, OC. Center (), OC. Center (), OC. Center ())
197196 coords_oc = Dict (k => Array (v) for (k, v) in coords_oc)
197+ if grid. underlying_grid isa OC. TripolarGrid
198+ # TripolarGrid is defined on [0, 360], so we to convert to [-180, 180] to match ClimaCore
199+ coords_oc[" lon" ] .- = 180
200+ end
198201
199202 # Get the latitude and longitude of each node on the boundary space
200203 climacore_coords = CC. Fields. coordinate_field (boundary_space)
@@ -205,20 +208,9 @@ function construct_remappers(grid, boundary_space)
205208
206209 coords_climacore = Dict (" lat" => climacore_lat, " lon" => climacore_lon)
207210
208- # Make arrays F-contiguous (column major) using `np.asfortranarray` to reduce memory footprint and
209- # prevent segfaults since XESMF works more efficiently with F-contiguous arrays.
210- np = pyimport (" numpy" )
211- coords_oc_contiguous =
212- Dict (k => pyconvert (Array, np. asfortranarray (v)) for (k, v) in coords_oc)
213- coords_climacore_contiguous =
214- Dict (k => pyconvert (Array, np. asfortranarray (v)) for (k, v) in coords_climacore)
215-
216211 # Construct the XESMF regridder object
217- regridder_oceananigans_to_climacore = XESMF. Regridder (
218- coords_oc_contiguous,
219- coords_climacore_contiguous;
220- method = " bilinear" ,
221- )
212+ regridder_oceananigans_to_climacore =
213+ XESMF. Regridder (coords_oc, coords_climacore; method = " bilinear" )
222214
223215 # Allocate space for source an destination vectors to use as intermediate storage
224216 src_vec_oc = Array (vec (OC. Field {OC.Center, OC.Center, Nothing} (grid))) # 2D field on Center/Center
@@ -242,9 +234,12 @@ function construct_remappers(grid, boundary_space)
242234
243235 # For a LatitudeLongitudeGrid, latitude and longitude are 1D collections,
244236 # so we reshape them to 2D arrays.
245- if grid isa OC. LatitudeLongitudeGrid
237+ if grid. underlying_grid isa OC. LatitudeLongitudeGrid
246238 long_oc = reshape (long_oc, length (long_oc), 1 )
247239 lat_oc = reshape (lat_oc, 1 , length (lat_oc))
240+ else
241+ # TripolarGrid is defined on [0, 360], so we to convert to [-180, 180] to match ClimaCore
242+ long_oc .- = 180
248243 end
249244 target_points_oc = @. CC. Geometry. LatLongPoint (lat_oc, long_oc)
250245
0 commit comments