@@ -231,6 +231,9 @@ The `Remapper` is designed to not be tied to any particular `Field`. You can use
231
231
232
232
If you want to quickly remap something, you can call directly `interpolate`.
233
233
234
+ By default, [`default_target_zcoords`](@ref) [`default_target_hcoords`](@ref) are used to
235
+ determine the coordinates.
236
+
234
237
Keyword arguments
235
238
=================
236
239
@@ -241,31 +244,51 @@ the work in sizes of `buffer_length`.
241
244
"""
242
245
function Remapper end
243
246
244
- # 3D case, everything passed as a keyword argument
247
+ # General case
248
+ #
249
+ # We have Union{AbstractArray, Nothing} because we want to allow for a single interface that
250
+ # capture every case.
245
251
Remapper (
246
252
space:: Spaces.AbstractSpace ;
247
- target_hcoords:: Union{AbstractArray, Nothing} = nothing ,
248
- target_zcoords:: Union{AbstractArray, Nothing} = nothing ,
253
+ target_hcoords:: Union{AbstractArray, Nothing} = default_target_hcoords (
254
+ space,
255
+ ),
256
+ target_zcoords:: Union{AbstractArray, Nothing} = default_target_zcoords (
257
+ space,
258
+ ),
249
259
buffer_length:: Int = 1 ,
250
260
) = _Remapper (space; target_zcoords, target_hcoords, buffer_length)
251
261
252
- # 3D case, horizontal coordinate passed as position argument (backward compatibility)
262
+ # General case, everything passed as positional
253
263
Remapper (
254
264
space:: Spaces.AbstractSpace ,
255
265
target_hcoords:: Union{AbstractArray, Nothing} ,
256
266
target_zcoords:: Union{AbstractArray, Nothing} ;
257
267
buffer_length:: Int = 1 ,
258
- ) = _Remapper (space; target_hcoords, target_zcoords, buffer_length)
259
-
268
+ ) = _Remapper (space; target_zcoords, target_hcoords, buffer_length)
260
269
261
270
# Purely vertical case
262
271
Remapper (
263
272
space:: Spaces.FiniteDifferenceSpace ;
264
- target_zcoords:: AbstractArray ,
273
+ target_zcoords:: AbstractArray = default_target_zcoords (space),
274
+ buffer_length:: Int = 1 ,
275
+ ) = _Remapper (space; target_zcoords, target_hcoords = nothing , buffer_length)
276
+
277
+ # Purely vertical, positional
278
+ Remapper (
279
+ space:: Spaces.FiniteDifferenceSpace ,
280
+ target_zcoords:: AbstractArray ;
265
281
buffer_length:: Int = 1 ,
266
282
) = _Remapper (space; target_zcoords, target_hcoords = nothing , buffer_length)
267
283
268
284
# Purely horizontal case
285
+ Remapper (
286
+ space:: Spaces.AbstractSpectralElementSpace ;
287
+ target_hcoords:: AbstractArray = default_target_hcoords (space),
288
+ buffer_length:: Int = 1 ,
289
+ ) = _Remapper (space; target_zcoords = nothing , target_hcoords, buffer_length)
290
+
291
+ # Purely horizontal case, positional
269
292
Remapper (
270
293
space:: Spaces.AbstractSpectralElementSpace ,
271
294
target_hcoords:: AbstractArray ;
@@ -922,13 +945,17 @@ end
922
945
"""
923
946
interpolate(field::ClimaCore.Fields;
924
947
hresolution = 180,
925
- zresolution = 50 ,
948
+ zresolution = nothing ,
926
949
target_hcoords = default_target_hcoords(space; hresolution),
927
- target_zcoords = default_target_vcoords (space; zresolution)
950
+ target_zcoords = default_target_zcoords (space; zresolution)
928
951
)
929
952
930
953
Interpolate the given fields on the Cartesian product of `target_hcoords` with
931
- `target_zcoords` (if not empty).
954
+ `target_zcoords`. For `Space`s without horizontal/vertical component, the relevant
955
+ `target_*coords` are ignored.
956
+
957
+ When `zresolution` is set to `nothing`, do not perform any interpolation in the vertical
958
+ direction. When `zresolution`, perform linear interpolation with uniformly spaced levels.
932
959
933
960
Coordinates have to be `ClimaCore.Geometry.Points`.
934
961
@@ -965,7 +992,7 @@ julia> interpolate(field, target_hcoords, target_zcoords)
965
992
```
966
993
967
994
If you need the array of coordinates, you can call `default_target_hcoords` (or
968
- `default_target_vcoords `) passing `axes(field)`. This will return an array of
995
+ `default_target_zcoords `) passing `axes(field)`. This will return an array of
969
996
`Geometry.Point`s. The functions `Geometry.Components` and `Geometry.Component`
970
997
can be used to extract the components as numeric values. For example,
971
998
```julia
@@ -990,115 +1017,45 @@ This can be used directly for plotting.
990
1017
"""
991
1018
function interpolate (
992
1019
field:: Fields.Field ;
993
- zresolution = 50 ,
1020
+ zresolution = nothing ,
994
1021
hresolution = 180 ,
995
1022
target_hcoords = default_target_hcoords (axes (field); hresolution),
996
1023
target_zcoords = default_target_zcoords (axes (field); zresolution),
997
1024
)
998
- return interpolate (field, axes (field); hresolution, zresolution )
1025
+ return interpolate (field, axes (field); target_hcoords, target_zcoords )
999
1026
end
1000
1027
1028
+ # interpolate, positional
1001
1029
function interpolate (field:: Fields.Field , target_hcoords, target_zcoords)
1002
- remapper = Remapper (axes (field), target_hcoords, target_zcoords)
1003
- return interpolate (remapper, field)
1004
- end
1005
-
1006
- """
1007
- default_target_hcoords(space::Spaces.AbstractSpace; hresolution)
1008
-
1009
- Return an Array with the Geometry.Points to interpolate uniformly the horizontal
1010
- component of the given `space`.
1011
- """
1012
- function default_target_hcoords (space:: Spaces.AbstractSpace ; hresolution = 180 )
1013
- return default_target_hcoords (Spaces. horizontal_space (space); hresolution)
1030
+ return interpolate (field, axes (field); target_hcoords, target_zcoords)
1014
1031
end
1015
1032
1016
- """
1017
- default_target_hcoords_as_vectors(space::Spaces.AbstractSpace; hresolution)
1018
-
1019
- Return an Vectors with the coordinate to interpolate uniformly the horizontal
1020
- component of the given `space`.
1021
- """
1022
- function default_target_hcoords_as_vectors (
1033
+ function interpolate (
1034
+ field:: Fields.Field ,
1023
1035
space:: Spaces.AbstractSpace ;
1024
- hresolution = 180 ,
1036
+ target_hcoords,
1037
+ target_zcoords,
1025
1038
)
1026
- return default_target_hcoords_as_vectors (
1027
- Spaces. horizontal_space (space);
1028
- hresolution,
1029
- )
1030
- end
1031
-
1032
- function default_target_hcoords (
1033
- space:: Spaces.SpectralElementSpace2D ;
1034
- hresolution = 180 ,
1035
- )
1036
- topology = Spaces. topology (space)
1037
- domain = Meshes. domain (topology. mesh)
1038
- xrange, yrange = default_target_hcoords_as_vectors (space; hresolution)
1039
- PointType =
1040
- domain isa Domains. SphereDomain ? Geometry. LatLongPoint :
1041
- Topologies. coordinate_type (topology)
1042
- return [PointType (x, y) for x in xrange, y in yrange]
1043
- end
1044
-
1045
- function default_target_hcoords_as_vectors (
1046
- space:: Spaces.SpectralElementSpace2D ;
1047
- hresolution = 180 ,
1048
- )
1049
- FT = Spaces. undertype (space)
1050
- topology = Spaces. topology (space)
1051
- domain = Meshes. domain (topology. mesh)
1052
- if domain isa Domains. SphereDomain
1053
- return FT .(range (- 180.0 , 180.0 , hresolution)),
1054
- FT .(range (- 90.0 , 90.0 , hresolution))
1055
- else
1056
- x1min = Geometry. component (domain. interval1. coord_min, 1 )
1057
- x2min = Geometry. component (domain. interval2. coord_min, 1 )
1058
- x1max = Geometry. component (domain. interval1. coord_max, 1 )
1059
- x2max = Geometry. component (domain. interval2. coord_max, 1 )
1060
- return FT .(range (x1min, x1max, hresolution)),
1061
- FT .(range (x2min, x2max, hresolution))
1062
- end
1039
+ remapper = Remapper (space; target_hcoords, target_zcoords)
1040
+ return interpolate (remapper, field)
1063
1041
end
1064
1042
1065
- function default_target_hcoords (
1066
- space:: Spaces.SpectralElementSpace1D ;
1067
- hresolution = 180 ,
1043
+ function interpolate (
1044
+ field:: Fields.Field ,
1045
+ space:: Spaces.FiniteDifferenceSpace ;
1046
+ target_zcoords,
1047
+ target_hcoords,
1068
1048
)
1069
- topology = Spaces. topology (space)
1070
- PointType = Topologies. coordinate_type (topology)
1071
- return PointType .(default_target_hcoords_as_vectors (space; hresolution))
1049
+ remapper = Remapper (space; target_zcoords)
1050
+ return interpolate (remapper, field)
1072
1051
end
1073
1052
1074
- function default_target_hcoords_as_vectors (
1075
- space:: Spaces.SpectralElementSpace1D ;
1076
- hresolution = 180 ,
1053
+ function interpolate (
1054
+ field:: Fields.Field ,
1055
+ space:: Spaces.AbstractSpectralElementSpace ;
1056
+ target_hcoords,
1057
+ target_zcoords,
1077
1058
)
1078
- FT = Spaces. undertype (space)
1079
- topology = Spaces. topology (space)
1080
- domain = Meshes. domain (topology. mesh)
1081
- xmin = Geometry. component (domain. coord_min, 1 )
1082
- xmax = Geometry. component (domain. coord_max, 1 )
1083
- return FT .(range (xmin, xmax, hresolution))
1084
- end
1085
-
1086
-
1087
- """
1088
- default_target_zcoords(space::Spaces.AbstractSpace; zresolution)
1089
-
1090
- Return an Array with the Geometry.Points to interpolate uniformly the vertical component of
1091
- the given `space`.
1092
- """
1093
- function default_target_zcoords (space; zresolution = 50 )
1094
- return Geometry. ZPoint .(
1095
- default_target_zcoords_as_vectors (space; zresolution)
1096
- )
1097
-
1098
- end
1099
-
1100
- function default_target_zcoords_as_vectors (space; zresolution = 50 )
1101
- return collect (
1102
- range (Domains. z_min (space), Domains. z_max (space), zresolution),
1103
- )
1059
+ remapper = Remapper (space; target_hcoords)
1060
+ return interpolate (remapper, field)
1104
1061
end
0 commit comments