Skip to content

Commit

Permalink
Add Var.has_dim
Browse files Browse the repository at this point in the history
Useful to see if a variable has a given dimension (e.g., `z`).
  • Loading branch information
Sbozzolo committed Aug 3, 2024
1 parent 982973c commit 2114df2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/outvar_dimensions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,18 @@ export times,
_dim_name(dim_names, allowed_names)
Return the `dim_name` within `dim_names` that is contained in `allowed_names`.
Return `nothing` is not available
Return `nothing` is not available.
Example
==========
```jldoctest
julia> ClimaAnalysis.Var._dim_name(["z", "lat", "lon"], ["lon", "long"])
1
```
"""
function _dim_name(dim_names, allowed_names)
return
findfirst(possible_name -> possible_name in dim_names, allowed_names)
return findfirst(possible_name -> possible_name in dim_names, allowed_names)
end

"""
Expand Down
2 changes: 1 addition & 1 deletion test/test_Var.jl
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ end
time = 0.0:10.0 |> collect
alt = 0.0:2.0 |> collect

data = reshape(1.0:(3 * 91 * 181 * 11), (3, 11, 181, 91))
data = reshape(1.0:(3 * 91 * 181 * 11), (11, 181, 91, 3))

dims =
OrderedDict(["time" => time, "lon" => long, "lat" => lat, "z" => alt])
Expand Down

0 comments on commit 2114df2

Please sign in to comment.