-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow writing
Coord
containing data to NetCDF (#93)
* reorganize files * add `"cell"` as common name in dimensions * working code for saving Coord [needs tests] * fix `sametimespan` tests * move to NCDatasets 0.11 * allow string values for dimensions without errors TODO: Test it! * clarify docstring of `sametimespan` * file re-org, and bump version * add tests for writing coord stuff * final todo comments
- Loading branch information
Showing
11 changed files
with
249 additions
and
229 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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "ClimateBase" | ||
uuid = "35604d93-0fb8-4872-9436-495b01d137e2" | ||
authors = ["Datseris <[email protected]>", "Philippe Roy <[email protected]>"] | ||
version = "0.15.2" | ||
version = "0.16.0" | ||
|
||
[deps] | ||
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" | ||
|
@@ -17,7 +17,7 @@ StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" | |
[compat] | ||
DimensionalData = "0.20.1" | ||
Interpolations = "0.13.2" | ||
NCDatasets = "0.10, 0.11" | ||
NCDatasets = "0.11" | ||
Requires = "1" | ||
SignalDecomposition = "1" | ||
StaticArrays = "0.12, 1.0" | ||
|
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
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,69 @@ | ||
#= | ||
Code related with input output (IO) of .nc files directly to/from ClimArrays | ||
utilizing the NCDatasets.jl package and a buttload of convenience code. | ||
An initial version of parts of this code was taken from: | ||
https://github.com/rafaqz/GeoData.jl | ||
=# | ||
using NCDatasets: NCDatasets, NCDataset | ||
export NCDatasets, NCDataset | ||
export nckeys, ncdetails, globalattr, ncsize | ||
export ncread, ncwrite | ||
|
||
dim_to_commonname(::Lat) = "lat" | ||
dim_to_commonname(::Lon) = "lon" | ||
dim_to_commonname(::Time) = "time" | ||
dim_to_commonname(::Pre) = "level" | ||
dim_to_commonname(D::Dim) = string(DimensionalData.name(D)) | ||
dim_to_commonname(::Coord) = "cell" | ||
|
||
const POSSIBLE_CELL_NAMES = ("ncells", "cell", "rgrid", "grid") | ||
|
||
|
||
""" | ||
nckeys(file::String) | ||
Return all keys of the `.nc` file in `file`. | ||
""" | ||
function nckeys(path::String) | ||
NCDataset(path) do ds | ||
return keys(ds) | ||
end | ||
end | ||
nckeys(a::NCDataset) = keys(a) | ||
|
||
""" | ||
ncdetails(file, io = stdout) | ||
Print details about the `.nc` file in `file` on `io`. | ||
""" | ||
function ncdetails(file, io = stdout) | ||
NCDataset(file) do ds | ||
show(io, MIME"text/plain"(), ds) | ||
end | ||
end | ||
ncdetails(ds::NCDataset, io = stdout) = show(io, MIME"text/plain"(), ds) | ||
|
||
""" | ||
ncsize(file, var) | ||
Return the size of the variable of the `.nc` file without actually loading any data. | ||
""" | ||
function ncsize(file, var) | ||
NCDataset(file) do ds | ||
return size(ds[var]) | ||
end | ||
end | ||
|
||
|
||
""" | ||
globalattr(file::String) → Dict | ||
Return the global attributes of the .nc file. | ||
""" | ||
function globalattr(file::String) | ||
NCDataset(file) do ds | ||
return Dict(ds.attrib) | ||
end | ||
end | ||
|
||
######################################################################### | ||
# Imports | ||
######################################################################### | ||
include("netcdf_read.jl") | ||
include("netcdf_write.jl") |
Oops, something went wrong.