@@ -13,6 +13,8 @@ struct InterpolationsRegridder{
13
13
FIELD <: ClimaCore.Fields.Field ,
14
14
BC,
15
15
DT <: Tuple ,
16
+ DI <: Tuple ,
17
+ N,
16
18
} <: Regridders.AbstractRegridder
17
19
18
20
""" ClimaCore.Space where the output Field will be defined"""
@@ -27,6 +29,12 @@ struct InterpolationsRegridder{
27
29
""" Tuple of booleans signifying if the dimension is monotonically increasing. True for
28
30
dimensions that are monotonically increasing, false for dimensions that are monotonically decreasing."""
29
31
dim_increasing:: DT
32
+
33
+ """ Tuple of integers indicating which dimensions to reverse in data"""
34
+ decreasing_indices:: DI
35
+
36
+ " Number of dimensions of the target space"
37
+ num_space_dims:: N
30
38
end
31
39
32
40
# Note, we swap Lat and Long! This is because according to the CF conventions longitude
@@ -74,23 +82,32 @@ function Regridders.InterpolationsRegridder(
74
82
isnothing (extrapolation_bc) &&
75
83
(extrapolation_bc = (Intp. Periodic (), Intp. Flat ()))
76
84
isnothing (dim_increasing) && (dim_increasing = (true , true ))
85
+ num_space_dims = Val (2 )
77
86
elseif eltype (coordinates) <: ClimaCore.Geometry.LatLongZPoint
78
87
isnothing (extrapolation_bc) &&
79
88
(extrapolation_bc = (Intp. Periodic (), Intp. Flat (), Intp. Throw ()))
80
89
isnothing (dim_increasing) && (dim_increasing = (true , true , true ))
90
+ num_space_dims = Val (3 )
81
91
elseif eltype (coordinates) <: ClimaCore.Geometry.XYZPoint
82
92
isnothing (extrapolation_bc) &&
83
93
(extrapolation_bc = (Intp. Flat (), Intp. Flat (), Intp. Throw ()))
84
94
isnothing (dim_increasing) && (dim_increasing = (true , true , true ))
95
+ num_space_dims = Val (3 )
85
96
else
86
97
error (" Only lat-long, lat-long-z, and x-y-z spaces are supported" )
87
98
end
88
99
100
+ decreasing_indices =
101
+ ! all (dim_increasing) ?
102
+ Tuple ([i for (i, d) in enumerate (dim_increasing) if ! d]) : ()
103
+
89
104
return InterpolationsRegridder (
90
105
target_space,
91
106
coordinates,
92
107
extrapolation_bc,
93
108
dim_increasing,
109
+ decreasing_indices,
110
+ num_space_dims,
94
111
)
95
112
end
96
113
@@ -103,16 +120,17 @@ This function is allocating.
103
120
"""
104
121
function Regridders. regrid (regridder:: InterpolationsRegridder , data, dimensions)
105
122
FT = ClimaCore. Spaces. undertype (regridder. target_space)
106
- dimensions_FT = map (dimensions, regridder. dim_increasing) do dim, increasing
107
- ! increasing ? reverse (FT .(dim)) : FT .(dim)
108
- end
123
+ dimensions_FT = ntuple (
124
+ i ->
125
+ ! regridder. dim_increasing[i] ? reverse (FT .(dimensions[i])) :
126
+ FT .(dimensions[i]),
127
+ regridder. num_space_dims,
128
+ )
109
129
110
130
data_transformed = data
111
131
# Reverse the data if needed. This allocates, so ideally it should be done in preprocessing
112
132
if ! all (regridder. dim_increasing)
113
- decreasing_indices =
114
- Tuple ([i for (i, d) in enumerate (regridder. dim_increasing) if ! d])
115
- data_transformed = reverse (data, dims = decreasing_indices)
133
+ data_transformed = reverse (data, dims = regridder. decreasing_indices)
116
134
end
117
135
# Make a linear spline
118
136
itp = Intp. extrapolate (
0 commit comments