Skip to content

Commit 2b7f3c4

Browse files
committed
Update Var.resampled_as to use Var.reordered_as
This commit also removes the tests for checking whether the order of dimensions are the same when resampling.
1 parent 6273f0a commit 2b7f3c4

File tree

3 files changed

+3
-31
lines changed

3 files changed

+3
-31
lines changed

NEWS.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ v0.5.9
99
### Reorder dimensions
1010
Before, resampling requires that the order of the dimensions is the same between the two
1111
`OutputVar`s. This feature adds the functionality of reordering the dimensions in a
12-
`OutputVar` to match the ordering of dimensions in another `OutputVar`. See the example
13-
below of this functionality.
12+
`OutputVar` to match the ordering of another `OutputVar`. The function `resampled_as` is
13+
updated to use `reordered_as`. See the example below of this functionality.
1414

1515
```julia
1616
julia> src_var.dims |> keys |> collect

src/Var.jl

+1
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,7 @@ Resample `data` in `src_var` to `dims` in `dest_var`.
838838
The resampling performed here is a 1st-order linear resampling.
839839
"""
840840
function resampled_as(src_var::OutputVar, dest_var::OutputVar)
841+
src_var = reordered_as(src_var, dest_var)
841842
_check_dims_consistent(src_var, dest_var)
842843

843844
src_resampled_data =

test/test_Var.jl

-29
Original file line numberDiff line numberDiff line change
@@ -1205,35 +1205,6 @@ end
12051205
var_missing_dim_units,
12061206
)
12071207

1208-
# Mismatch in ordering of dims
1209-
lon = collect(range(-179.5, 179.5, 360))
1210-
lat = collect(range(-89.5, 89.5, 180))
1211-
data_ones = ones(length(lon), length(lat))
1212-
dims = OrderedDict(["lon" => lon, "lat" => lat])
1213-
attribs =
1214-
Dict("long_name" => "idk", "short_name" => "short", "units" => "kg")
1215-
dim_attribs = OrderedDict([
1216-
"lon" => Dict("units" => "deg"),
1217-
"lat" => Dict("units" => "deg"),
1218-
])
1219-
var_lonlat = ClimaAnalysis.OutputVar(attribs, dims, dim_attribs, data_ones)
1220-
lon = collect(range(-179.5, 179.5, 360))
1221-
lat = collect(range(-89.5, 89.5, 180))
1222-
data_ones = ones(length(lat), length(lon))
1223-
dims = OrderedDict(["lat" => lat, "lon" => lon])
1224-
attribs =
1225-
Dict("long_name" => "idk", "short_name" => "short", "units" => "kg")
1226-
dim_attribs = OrderedDict([
1227-
"lat" => Dict("units" => "deg"),
1228-
"lon" => Dict("units" => "deg"),
1229-
])
1230-
var_latlon = ClimaAnalysis.OutputVar(attribs, dims, dim_attribs, data_ones)
1231-
@test_throws ErrorException ClimaAnalysis.bias(var_lonlat, var_latlon)
1232-
@test_throws ErrorException ClimaAnalysis.squared_error(
1233-
var_lonlat,
1234-
var_latlon,
1235-
)
1236-
12371208
# Missing dims
12381209
lon = collect(range(-179.5, 179.5, 360))
12391210
data_missing_dim = ones(length(lon))

0 commit comments

Comments
 (0)