-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
223 additions
and
83 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
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
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,36 @@ | ||
using NCDatasets | ||
using DataStructures | ||
|
||
# same behaviour as Python's netCDF4 1.5.8 and XArray 0.21.1 | ||
|
||
filename = tempname() | ||
# The mode "c" stands for creating a new file (clobber) | ||
ds = NCDataset(filename,"c") | ||
|
||
|
||
ds.dim["dim"] = 3 | ||
|
||
# single missing value | ||
|
||
missing_value = 123. | ||
v = defVar(ds,"var1",Float64,("dim",), attrib = OrderedDict("missing_value" => missing_value)) | ||
data = [0., 1., 123.] | ||
v.var[:] = data | ||
@test isequal(v[:],[0.,1.,missing]) | ||
|
||
# 2 missing values | ||
missing_value = [123., 124.] | ||
v = defVar(ds,"var2",Float64,("dim",), attrib = OrderedDict("missing_value" => missing_value)) | ||
data = [0., 123., 124.] | ||
v.var[:] = data | ||
@test isequal(v[:],[0.,missing,missing]) | ||
|
||
|
||
# missing values of wrong type | ||
v = defVar(ds,"var3",Float64,("dim",), attrib = OrderedDict("missing_value" => "value of wrong type")) | ||
data = [0., 1., 2.] | ||
v.var[:] = data | ||
@test isequal(v[:],[0.,1.,2.]) | ||
|
||
close(ds) | ||
|
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,38 @@ | ||
using NCDatasets | ||
fname = tempname() | ||
|
||
|
||
NCDataset(fname,"c") do ds | ||
defVar(ds,"data",[10., 11., 12., 13.], ("time",), attrib = Dict( | ||
"add_offset" => 10., | ||
"scale_factor" => 0.2)) | ||
end | ||
|
||
# stored valued are [0., 5., 10., 15.] | ||
# since 0.2 .* [0., 5., 10., 15.] .+ 10 is [10., 11., 12., 13.] | ||
|
||
ds = NCDataset(fname); | ||
|
||
@test ds["data"].var[:] == [0., 5., 10., 15.] | ||
|
||
@test cfvariable(ds,"data")[:] == [10., 11., 12., 13.] | ||
|
||
# neither add_offset nor scale_factor are applied | ||
@test cfvariable(ds,"data", add_offset = nothing, scale_factor = nothing)[:] == [0, 5, 10, 15] | ||
|
||
# add_offset is applied but not scale_factor | ||
@test cfvariable(ds,"data", scale_factor = nothing)[:] == [10, 15, 20, 25] | ||
|
||
# 0 is declared a fill value (add_offset and scale_factor are applied as usual) | ||
@test isequal(cfvariable(ds,"data", fillvalue = 0)[:], [missing, 11., 12., 13.]) | ||
|
||
# 0 and 5 are declared a missing value | ||
@test isequal(cfvariable(ds,"data", missing_value = (0,5))[:], [missing, missing, 12., 13.]) | ||
|
||
|
||
@test cfvariable(ds,"data", units = "days since 2000-01-01")[:] == [ | ||
DateTime(2000,1,11), DateTime(2000,1,12), DateTime(2000,1,13), DateTime(2000,1,14)] | ||
|
||
close(ds) | ||
|
||
#rm(fname) |