Skip to content

Commit

Permalink
Var.dim_units return a string
Browse files Browse the repository at this point in the history
  • Loading branch information
ph-kev committed Nov 15, 2024
1 parent a39b5a1 commit dd54614
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var_reversed = ClimaAnalysis.reverse_dim(var, "pressure_level")
is not specified. In particular, the vertical dimension is mapped to pressure levels by z
-> P0 * exp(-z / H_EARTH), where P0 = 10000 and H_EARTH = 7000.0, following a simple
hydrostatic model for the atmosphere.
- `Var.dim_units` returns a string even if the type of the units is Unitful.

v0.5.11
-------
Expand Down
2 changes: 1 addition & 1 deletion src/Var.jl
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ function dim_units(var::OutputVar, dim_name)
!haskey(var.dims, dim_name) &&
error("Var does not have dimension $dim_name, found $(keys(var.dims))")
# Double get because var.dim_attributes is a dictionry whose values are dictionaries
get(get(var.dim_attributes, dim_name, Dict()), "units", "")
string(get(get(var.dim_attributes, dim_name, Dict()), "units", ""))
end

"""
Expand Down
3 changes: 2 additions & 1 deletion test/test_Var.jl
Original file line number Diff line number Diff line change
Expand Up @@ -525,12 +525,13 @@ end
dims = OrderedDict(["time" => time, "x" => x, "y" => y])
dim_attributes = OrderedDict([
"time" => Dict("units" => "seconds"),
"x" => Dict("units" => "km"),
"x" => Dict("units" => u"km"),
])
attribs = Dict("long_name" => "hi")
var = ClimaAnalysis.OutputVar(attribs, dims, dim_attributes, data)

@test ClimaAnalysis.dim_units(var, "y") == ""
@test ClimaAnalysis.dim_units(var, "time") == "seconds"
@test ClimaAnalysis.dim_units(var, "x") == "km"
@test ClimaAnalysis.range_dim(var, "x") == (0.0, 180.0)
@test_throws ErrorException(
Expand Down

0 comments on commit dd54614

Please sign in to comment.