-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #137 from JuliaClimate/dim_handling
[WIP] - Dimension handling
- Loading branch information
Showing
3 changed files
with
217 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
""" | ||
get_dimname(::NCDatasets.Dataset, dim::String) | ||
Scans dataset ds and extract the dimensions X, Y, Z and T. The dataset needs to be CF-compliant. See http://cfconventions.org/. | ||
""" | ||
function get_dimname(ds::NCDatasets.Dataset, dim::String) | ||
|
||
dimensions = keys(ds.dim) | ||
|
||
found_dim = "NA" | ||
|
||
# try finding with the "axis" attribute | ||
|
||
for idim in dimensions | ||
if idim != "bnds" && idim != "vertices" | ||
if haskey(ds[idim].attrib, "axis") | ||
if ds[idim].attrib["axis"] == dim | ||
found_dim = idim | ||
end | ||
end | ||
end | ||
end | ||
|
||
# if found_dim is still not found, try to find it with the standard_name | ||
|
||
if found_dim == "NA" | ||
|
||
dim_dict = Dict(["T" => ["time"], | ||
"Z" => ["pressure", "depth"], | ||
"X" => ["longitude"], | ||
"Y" => ["latitude"]]) | ||
|
||
for idim in dimensions | ||
if idim != "bnds" && idim != "vertices" | ||
attribs = ds[idim].attrib | ||
if haskey(attribs, "standard_name") | ||
name = "standard_name" | ||
elseif haskey(attribs, "long_name") | ||
name = "long_name" | ||
end | ||
if in(ds[idim].attrib[name], dim_dict[dim]) | ||
# ds[idim].attrib[name] == dim_dict[dim] | ||
found_dim = idim | ||
end | ||
end | ||
end | ||
end | ||
|
||
if found_dim == "NA" | ||
error(string("Unable to find the dimension ", dim, "!")) | ||
end | ||
|
||
return found_dim | ||
end | ||
|
||
""" | ||
get_calendar(ds::NCDataset) | ||
Returns the calendar type. See See http://cfconventions.org/. | ||
""" | ||
function get_calendar(ds::NCDataset, timename) | ||
caltype = "" | ||
try | ||
caltype = ds[timename].attrib["calendar"] | ||
catch | ||
caltype = "standard" | ||
end | ||
|
||
return caltype | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters