Skip to content

Commit 0ac7132

Browse files
committed
Fix type instabilities
1 parent 70a2536 commit 0ac7132

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

ext/DataHandlingExt.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,6 @@ function DataHandling.regridded_snapshot(
581581
end
582582

583583
regridder_type = nameof(typeof(data_handler.regridder))
584-
regrid_args = ()
585584

586585
# Check if the regridded field at this date is already in the cache
587586
return get!(data_handler._cached_regridded_fields, date) do

ext/InterpolationsRegridderExt.jl

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ struct InterpolationsRegridder{
1313
FIELD <: ClimaCore.Fields.Field,
1414
BC,
1515
DT <: Tuple,
16+
DI <: Tuple,
17+
N,
1618
} <: Regridders.AbstractRegridder
1719

1820
"""ClimaCore.Space where the output Field will be defined"""
@@ -27,6 +29,12 @@ struct InterpolationsRegridder{
2729
"""Tuple of booleans signifying if the dimension is monotonically increasing. True for
2830
dimensions that are monotonically increasing, false for dimensions that are monotonically decreasing."""
2931
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
3038
end
3139

3240
# Note, we swap Lat and Long! This is because according to the CF conventions longitude
@@ -74,23 +82,32 @@ function Regridders.InterpolationsRegridder(
7482
isnothing(extrapolation_bc) &&
7583
(extrapolation_bc = (Intp.Periodic(), Intp.Flat()))
7684
isnothing(dim_increasing) && (dim_increasing = (true, true))
85+
num_space_dims = Val(2)
7786
elseif eltype(coordinates) <: ClimaCore.Geometry.LatLongZPoint
7887
isnothing(extrapolation_bc) &&
7988
(extrapolation_bc = (Intp.Periodic(), Intp.Flat(), Intp.Throw()))
8089
isnothing(dim_increasing) && (dim_increasing = (true, true, true))
90+
num_space_dims = Val(3)
8191
elseif eltype(coordinates) <: ClimaCore.Geometry.XYZPoint
8292
isnothing(extrapolation_bc) &&
8393
(extrapolation_bc = (Intp.Flat(), Intp.Flat(), Intp.Throw()))
8494
isnothing(dim_increasing) && (dim_increasing = (true, true, true))
95+
num_space_dims = Val(3)
8596
else
8697
error("Only lat-long, lat-long-z, and x-y-z spaces are supported")
8798
end
8899

100+
decreasing_indices =
101+
!all(dim_increasing) ?
102+
Tuple([i for (i, d) in enumerate(dim_increasing) if !d]) : ()
103+
89104
return InterpolationsRegridder(
90105
target_space,
91106
coordinates,
92107
extrapolation_bc,
93108
dim_increasing,
109+
decreasing_indices,
110+
num_space_dims,
94111
)
95112
end
96113

@@ -103,16 +120,17 @@ This function is allocating.
103120
"""
104121
function Regridders.regrid(regridder::InterpolationsRegridder, data, dimensions)
105122
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+
)
109129

110130
data_transformed = data
111131
# Reverse the data if needed. This allocates, so ideally it should be done in preprocessing
112132
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)
116134
end
117135
# Make a linear spline
118136
itp = Intp.extrapolate(

0 commit comments

Comments
 (0)