Skip to content

Commit 8bb1adf

Browse files
authored
Merge pull request #14 from JuliaDataCubes/fix_noncontig
read into non-contig memory
2 parents 9663704 + 3911151 commit 8bb1adf

File tree

6 files changed

+33
-5
lines changed

6 files changed

+33
-5
lines changed

.github/workflows/CI.yml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
matrix:
1515
version:
1616
- '1.6'
17+
- '1'
1718
os:
1819
- ubuntu-latest
1920
- macOS-latest

src/axisarrays/axisindices.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using .AxisIndices: AbstractAxis,AxisIndices
1+
using .AxisIndices: AbstractAxis,AxisIndicesArray
22

33
valfromaxis(ax::AbstractAxis) = keys(ax)
44

src/datasets/netcdf.jl

+12-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,19 @@ for m in [:haschunks, :eachchunk]
3030
end
3131
))
3232
end
33+
function check_contig(x)
34+
isa(x,Array) || (isa(x,SubArray) && Base.iscontiguous(x))
35+
end
3336
writeblock!(v::NetCDFVariable, aout, r::AbstractUnitRange...) = NetCDF.open(a->writeblock!(a,aout,r...), v.filename, v.varname, mode=NC_WRITE)
34-
readblock!(v::NetCDFVariable, aout, r::AbstractUnitRange...) = NetCDF.open(a->readblock!(a,aout,r...), v.filename, v.varname)
37+
function readblock!(v::NetCDFVariable, aout, r::AbstractUnitRange...)
38+
if check_contig(aout)
39+
NetCDF.open(a->readblock!(a,aout,r...), v.filename, v.varname)
40+
else
41+
aouttemp = Array(aout)
42+
NetCDF.open(a->readblock!(a,aouttemp,r...), v.filename, v.varname)
43+
aout .= aouttemp
44+
end
45+
end
3546
iscompressed(v::NetCDFVariable) = NetCDF.open(v->v.compress > 0, v.filename, v.varname)
3647

3748
Base.size(v::NetCDFVariable) = v.size

test/Artifacts.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[ncar]
2+
git-tree-sha1 = "b3ad9125b25731444e8118c0a808aa2d3fc0eb1e"

test/Project.toml

+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ DimensionalData = "0703355e-b756-11e9-17c0-8b28908087d0"
77
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
88
NamedDims = "356022a1-0364-5f58-8944-0da4b18d706f"
99
NetCDF = "30363a11-5582-574a-97bb-aa9a979735b9"
10+
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
1011
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1112
Zarr = "0a941bbe-ad1d-11e8-39d9-ab76183a1d99"

test/datasets.jl

+16-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,24 @@ end
55

66
using NetCDF, Zarr
77

8-
@testset "Reading NetCDF" begin
8+
using Pkg.Artifacts
99
import Downloads
10-
p = Downloads.download("https://www.unidata.ucar.edu/software/netcdf/examples/sresa1b_ncar_ccsm3-example.nc")
10+
# This is the path to the Artifacts.toml we will manipulate
11+
artifact_toml = joinpath(@__DIR__,"Artifacts.toml")
12+
ncar_hash = artifact_hash("ncar", artifact_toml)
13+
if ncar_hash == nothing || !artifact_exists(ncar_hash)
14+
oldhash = ncar_hash
15+
ncar_hash = create_artifact() do artifact_dir
16+
Downloads.download("https://www.unidata.ucar.edu/software/netcdf/examples/sresa1b_ncar_ccsm3-example.nc",joinpath(artifact_dir,"ncar.nc"))
17+
end
18+
if oldhash !== nothing
19+
unbind_artifact!(artifact_toml, "ncar")
20+
end
21+
bind_artifact!(artifact_toml, "ncar", ncar_hash)
22+
end
23+
p2 = joinpath(artifact_path(ncar_hash),"ncar.nc")
1124

12-
p2 = mv(p,string(tempname(),".nc"))
25+
@testset "Reading NetCDF" begin
1326

1427
ds_nc = YAXArrayBase.to_dataset(p2)
1528
vn = get_varnames(ds_nc)

0 commit comments

Comments
 (0)