Skip to content

Commit 83951fc

Browse files
committed
Relax conditions for Var.arecompatible
1 parent 1eded67 commit 83951fc

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

NEWS.md

+5
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ sim_var = shift_to_start_of_previous_month(sim_var)
6060
`net_toa_flux`). ([#109](https://github.com/CliMA/ClimaAnalysis.jl/pull/109
6161
"PR109"))
6262

63+
## Minor changes
64+
65+
- Var.arecompatible only check for the units of the dimensions instead of checking that the
66+
dimension attributes fully match.
67+
6368
v0.5.9
6469
------
6570

src/Var.jl

+11-1
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,17 @@ We assume that:
840840
We also *do not* check units for `data`.
841841
"""
842842
function arecompatible(x::OutputVar, y::OutputVar)
843-
return (x.dims == y.dims) && (x.dim_attributes == y.dim_attributes)
843+
x_dims = collect(keys(x.dims))
844+
y_dims = collect(keys(y.dims))
845+
x_units = (dim_units(x, dim_name) for dim_name in x_dims)
846+
y_units = (dim_units(y, dim_name) for dim_name in y_dims)
847+
848+
for (x_dim, x_unit, y_dim, y_unit) in zip(x_dims, x_units, y_dims, y_units)
849+
x_unit == "" && @warn "Missing units for dimension $x_dim in x"
850+
y_unit == "" && @warn "Missing units for dimension $y_dim in y"
851+
x_unit != y_unit && return false
852+
end
853+
return x.dims == y.dims
844854
end
845855

846856
"""

test/test_Var.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,15 @@ end
170170

171171
dims = OrderedDict(["time" => time, "lon" => long, "lat" => lat])
172172
dim_attributes = OrderedDict([
173-
"time" => Dict(),
173+
"time" => Dict("units" => "s"),
174174
"lon" => Dict("b" => 2),
175175
"lat" => Dict("a" => 1),
176176
])
177177
attribs = Dict("short_name" => "bob", "long_name" => "hi")
178178
var1 = ClimaAnalysis.OutputVar(attribs, dims, dim_attributes, data1)
179179

180180
dim_attributes2 = OrderedDict([
181-
"time" => Dict(),
181+
"time" => Dict("units" => "m"),
182182
"lon" => Dict("lol" => 2),
183183
"lat" => Dict("a" => 1),
184184
])

0 commit comments

Comments
 (0)