Skip to content
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ keywords = ["netcdf", "GRIB", "climate and forecast conventions", "oceanography"
license = "MIT"
desc = "CommonDataModel is a module that defines types common to NetCDF and GRIB data"
authors = ["Alexander Barth <barth.alexander@gmail.com>"]
version = "0.4.0"
version = "0.4.1"

[deps]
CFTime = "179af706-886a-5703-950a-314cd64e0468"
Expand Down
3 changes: 3 additions & 0 deletions src/CommonDataModel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import DiskArrays:
AbstractDiskArray,
AbstractSubDiskArray,
subarray,
view_disk,
writeblock!,
readblock!,
ChunkStyle,
Expand All @@ -36,6 +37,8 @@ import Base:
reduce,
show,
size,
vec,
view,
write

import Statistics
Expand Down
11 changes: 3 additions & 8 deletions src/subvariable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,11 @@ close(ds)

"""
function Base.view(a::AbstractVariable,i...)
i2 = DiskArrays._replace_colon.(size(a), i) # TODO improve
return SubVariable(SubArray(a, i2))
disk_sub_array = DiskArrays.view_disk(a, i...)
return SubVariable(DiskArrays.subarray(disk_sub_array))
end

# copied from https://github.com/JuliaIO/DiskArrays.jl/blob/6522ba32759f81945396890ebba5525d33342244/src/subarray.jl#L28
# this is done to not depend on DiskArray Internals.
_replace_colon(s, ::Colon) = Base.OneTo(s)
_replace_colon(s, r) = r

Base.view(a::AbstractVariable, i::CartesianIndices) = view(a, i.indices...)
Base.vec(a::AbstractVariable) = view(a, :)

dimnames(ds::SubDataset) = dimnames(ds.ds)
defDim(ds::SubDataset,name::SymbolOrString,len) = defDim(ds.ds,name,len)
Expand Down
11 changes: 11 additions & 0 deletions test/test_subvariable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,14 @@ v = select(sst_view,
@test size(v) == (4,3,8)
@test all(v[:,1,1] .≈ 2:5)
@test all(v[1,:,2] .≈ [3,5,7])


## regression test for https://github.com/JuliaGeo/NCDatasets.jl/issues/287
fname = tempname()
ds = TDS(fname, "c")
v = defVar(ds, "temperature", zeros(10,11), ("lon", "lat"))
m = iseven.(reshape(1:(10*11),(10,11)))

@test size(view(v,m)) == (count(m),)
v[m] .= 1
@test Array(v) == m
Loading