Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reading NetCDF files with incorrect dimensions #35

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
ClimaAnalysis.jl Release Notes
===============================

v0.5.5
------
- Fix reading `NetCDF` files with dimensions in incorrect order.

v0.5.4
------
- Added support for extraction dimension from functions, such as `times`.
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ClimaAnalysis"
uuid = "29b5916a-a76c-4e73-9657-3c8fd22e65e6"
authors = ["Gabriele Bozzola <[email protected]>"]
version = "0.5.4"
version = "0.5.5"

[deps]
NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
Expand Down
7 changes: 5 additions & 2 deletions src/Var.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,13 @@ read_var(simdir.variable_paths["hu"]["inst"])
"""
function read_var(path::String)
NCDatasets.NCDataset(path) do nc
dims = map(NCDatasets.dimnames(nc)) do dim_name
# First, we have to identify the name of the variable by finding what is
# not a dimension
unordered_dims = NCDatasets.dimnames(nc)
var_name = pop!(setdiff(keys(nc), unordered_dims))
dims = map(NCDatasets.dimnames(nc[var_name])) do dim_name
return dim_name => Array(nc[dim_name])
end |> OrderedDict
var_name = pop!(setdiff(keys(nc), keys(dims)))
attribs = Dict(k => v for (k, v) in nc[var_name].attrib)
dim_attribs = OrderedDict(
dim_name => Dict(nc[dim_name].attrib) for dim_name in keys(dims)
Expand Down