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

@select not work for 4d array #214

Closed
kongdd opened this issue Jun 29, 2023 · 4 comments
Closed

@select not work for 4d array #214

kongdd opened this issue Jun 29, 2023 · 4 comments

Comments

@kongdd
Copy link

kongdd commented Jun 29, 2023

using NCDatasets


f = "http:https://esgf3.dkrz.de/thredds/dodsC/cmip6/CMIP/EC-Earth-Consortium/EC-Earth3/historical/r1i1p1f1/day/zg/gr/v20200310/zg_day_EC-Earth3_historical_r1i1p1f1_gr_20130101-20131231.nc"
plevs = [250, 500, 850] .* 100

in_plev(plev, plevs) = indexin(round.(Int, plev), plevs) .!== nothing


nc = NCDataset(f)
var = nc["zg"]
v = @select(var, in_plev(plev, $plevs))

v.var[:, :, 1:2, 1] # error
v.var[:, :, :, 1] # error
v.var[:] # error
julia> v.var[:, :, 1:2, 1] # error   
ERROR: type Variable has no field var
Stacktrace:
 [1] getproperty
   @ .\Base.jl:37 [inlined]
 [2] getindex(::NCDatasets.Variable{Float32, 4, NCDataset{Nothing}}, ::Colon, ::Colon, ::Vector{Int64}, ::Vararg{Union{Colon, Int64, AbstractRange{<:Integer}, Vector{Int64}}})
   @ NCDatasets C:\Users\hydro\.julia\packages\NCDatasets\st9Jz\src\cfvariable.jl:432
 [3] materialize
   @ C:\Users\hydro\.julia\packages\NCDatasets\st9Jz\src\subvariable.jl:44 [inlined]
 [4] getindex(::NCDatasets.SubVariable{Float32, 4, NCDatasets.Variable{Float32, 4, NCDataset{Nothing}}, Tuple{Colon, Colon, Vector{Int64}, Colon}, NCDatasets.Attributes{NCDataset{Nothing}}, Nothing}, ::Colon, ::Colon, ::UnitRange{Int64}, ::Vararg{Union{Colon, Int64, AbstractRange{<:Integer}}})
   @ NCDatasets C:\Users\hydro\.julia\packages\NCDatasets\st9Jz\src\subvariable.jl:98
 [5] top-level scope
   @ z:\Researches\CMIP6\nctools.jl\debug.qmd:1

julia> v.var[:, :, :, 1] # error     
ERROR: type Variable has no field var
Stacktrace:
 [1] getproperty
   @ .\Base.jl:37 [inlined]
 [2] getindex(::NCDatasets.Variable{Float32, 4, NCDataset{Nothing}}, ::Colon, ::Colon, ::Vector{Int64}, ::Vararg{Union{Colon, Int64, AbstractRange{<:Integer}, Vector{Int64}}})
   @ NCDatasets C:\Users\hydro\.julia\packages\NCDatasets\st9Jz\src\cfvariable.jl:432
 [3] materialize
   @ C:\Users\hydro\.julia\packages\NCDatasets\st9Jz\src\subvariable.jl:44 [inlined]
 [4] getindex(::NCDatasets.SubVariable{Float32, 4, NCDatasets.Variable{Float32, 4, NCDataset{Nothing}}, Tuple{Colon, Colon, Vector{Int64}, Colon}, NCDatasets.Attributes{NCDataset{Nothing}}, Nothing}, ::Colon, ::Colon, ::Colon, ::Vararg{Union{Colon, Int64, AbstractRange{<:Integer}}})
   @ NCDatasets C:\Users\hydro\.julia\packages\NCDatasets\st9Jz\src\subvariable.jl:98
 [5] top-level scope
   @ z:\Researches\CMIP6\nctools.jl\debug.qmd:1

julia> v.var[:] # error
ERROR: BoundsError: attempt to access Tuple{Colon} at index [2]
Stacktrace:
 [1] getindex
   @ .\tuple.jl:29 [inlined]
 [2] _subsub(::Tuple{Colon}, ::Tuple{Colon}, ::Int64, ::Colon, ::Vector{Int64}, ::Vararg{Any})
   @ NCDatasets C:\Users\hydro\.julia\packages\NCDatasets\st9Jz\src\subvariable.jl:33
 [3] _subsub(::Tuple{}, ::Tuple{Colon}, ::Int64, ::Colon, ::Function, ::Vararg{Any})
   @ NCDatasets C:\Users\hydro\.julia\packages\NCDatasets\st9Jz\src\subvariable.jl:33
 [4] subsub(parentindices::Tuple{Colon, Colon, Vector{Int64}, Colon}, indices::Tuple{Colon})
   @ NCDatasets C:\Users\hydro\.julia\packages\NCDatasets\st9Jz\src\subvariable.jl:42
 [5] view(v::NCDatasets.SubVariable{Float32, 4, NCDatasets.Variable{Float32, 4, NCDataset{Nothing}}, Tuple{Colon, Colon, Vector{Int64}, Colon}, NCDatasets.Attributes{NCDataset{Nothing}}, Nothing}, indices::Colon)    
   @ NCDatasets C:\Users\hydro\.julia\packages\NCDatasets\st9Jz\src\subvariable.jl:64
 [6] getindex(v::NCDatasets.SubVariable{Float32, 4, NCDatasets.Variable{Float32, 4, NCDataset{Nothing}}, Tuple{Colon, Colon, Vector{Int64}, Colon}, NCDatasets.Attributes{NCDataset{Nothing}}, Nothing}, indices::Colon)   @ NCDatasets C:\Users\hydro\.julia\packages\NCDatasets\st9Jz\src\subvariable.jl:98
 [7] top-level scope
   @ z:\Researches\CMIP6\nctools.jl\debug.qmd:1
@Alexander-Barth
Copy link
Owner

Alexander-Barth commented Jul 3, 2023 via email

@kongdd
Copy link
Author

kongdd commented Jul 3, 2023

It works.

@Alexander-Barth
Copy link
Owner

if you need un-scaled data you can now use (7a3c9c5):

using NCDatasets
f = "http:https://esgf3.dkrz.de/thredds/dodsC/cmip6/CMIP/EC-Earth-Consortium/EC-Earth3/historical/r1i1p1f1/day/zg/gr/v20200310/zg_day_EC-Earth3_historical_r1i1p1f1_gr_20130101-20131231.nc"
plevs = [250, 500, 850] .* 100

# plevs*100 -> plevs : an error in your example?
in_plev(plev, plevs) = indexin(round.(Int, plev), plevs) .!== nothing


nc = NCDataset(f)
v = NCDatasets.@select(nc["zg"].var, in_plev(plev, $plevs))
v[:,:,1:2,1] # works

If the error persists, please file a new issue and provide all information in the issue template.
Thanks!

@kongdd
Copy link
Author

kongdd commented Jul 4, 2023

Got it. Thank you.

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