Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1D variable with unlimited dimensions #123

Closed
Alexander-Barth opened this issue Oct 5, 2023 · 2 comments
Closed

1D variable with unlimited dimensions #123

Alexander-Barth opened this issue Oct 5, 2023 · 2 comments

Comments

@Alexander-Barth
Copy link
Contributor

Alexander-Barth commented Oct 5, 2023

While debugging an issue in NCDatasets using DiskArrays v0.3.20 ( Alexander-Barth/NCDatasets.jl#230 )
I found some behavior of NetCDF.jl with DiskArray with variables of unlimited dimensions that I could not understand.
While the following code with a 2D array (one unlimited) works without error:

import NetCDF
fname2 = tempname()
time_dim = NetCDF.NcDim("time",Int[],unlimited=true);
lon_dim = NetCDF.NcDim("lon",1:3);
v = NetCDF.NcVar("obs",[lon_dim,time_dim]);
NetCDF.create(fname2,v) do nc
   nc["obs"][:,1:3] = rand(3,3)
end;

The following code with a single unlimited dimensions fails:

import NetCDF
var = collect(1:4)
fname2 = tempname()
time_dim = NetCDF.NcDim("time",Int[],unlimited=true);
v = NetCDF.NcVar("var",[time_dim]);
NetCDF.create(fname2,v) do nc
    nc["var"][1:4] = var
end;

with the following error message:

ERROR: BoundsError: attempt to access 0-element CartesianIndices{1, Tuple{Base.OneTo{Int64}}} at index [1:4]                                                       
Stacktrace:
  [1] throw_boundserror(A::CartesianIndices{1, Tuple{Base.OneTo{Int64}}}, I::Tuple{UnitRange{Int64}})                                                                      
    @ Base ./abstractarray.jl:744
  [2] checkbounds
    @ ./abstractarray.jl:709 [inlined]
  [3] getindex
    @ ./multidimensional.jl:358 [inlined]
  [4] view
    @ ./multidimensional.jl:372 [inlined]
  [5] interpret_indices_disk
    @ ~/.julia/packages/DiskArrays/VLHvZ/src/diskarray.jl:137 [inlined]
  [6] setindex_disk!(a::NcVar{Float64, 1, 6}, v::UnitRange{Int64}, i::UnitRange{Int64})
    @ DiskArrays ~/.julia/packages/DiskArrays/VLHvZ/src/diskarray.jl:56
  [7] setindex!(a::NcVar{Float64, 1, 6}, v::UnitRange{Int64}, i::UnitRange{Int64})
    @ DiskArrays ~/.julia/packages/DiskArrays/VLHvZ/src/diskarray.jl:222
  [8] (::var"#15#16")(nc::NcFile)
    @ Main ./REPL[54]:2
  [9] create(::var"#15#16", ::String, ::Vararg{Any}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})                                     
    @ NetCDF ~/.julia/packages/NetCDF/7hOe9/src/NetCDF.jl:1022
 [10] create(::Function, ::String, ::NcVar{Float64, 1, 6})
    @ NetCDF ~/.julia/packages/NetCDF/7hOe9/src/NetCDF.jl:1019
 [11] top-level scope
    @ REPL[54]:1

NetCDF.jl and the equivalent NCDatasets.jl code both fail at the same line:

https://github.com/meggart/DiskArrays.jl/blob/v0.3.20/src/diskarray.jl#L137

Ref:
#53

@Alexander-Barth
Copy link
Contributor Author

If I comment-out the definition interpret_indices_disk(A, r::NTuple{1,AbstractVector}) so that the general method interpret_indices_disk(A, r::NTuple{N,Union{Integer,AbstractVector,Colon}}) where {N} is used instead, the example passes for NetCDF.jl and NCDatasets.jl but I see failure in this test:

https://github.com/meggart/DiskArrays.jl/blob/v0.3.20/test/runtests.jl#L105

Alexander-Barth added a commit to Alexander-Barth/DiskArrays.jl that referenced this issue Oct 5, 2023
Alexander-Barth added a commit to Alexander-Barth/DiskArrays.jl that referenced this issue Oct 6, 2023
rafaqz pushed a commit that referenced this issue Oct 6, 2023
rafaqz pushed a commit that referenced this issue Oct 6, 2023
@rafaqz
Copy link
Collaborator

rafaqz commented Oct 8, 2023

Fixed on master

@rafaqz rafaqz closed this as completed Oct 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants