gher-uliege/Diva-Workshops

"conversion to pointer not defined for StepRangeLen..." in notebook "90-full-analysis".

ctroupin opened this issue · 4 comments

The cell

@time dbinfo = diva3d((lonr,latr,depthr,TS),
    (obslon,obslat,obsdepth,obstime), obsval,
    len, epsilon2,
    filename,varname,
    bathname=bathname,
    plotres = plotres,
    mask = mask_edit,
    fitcorrlen = false,
    niter_e = 2,
    ncvarattrib = ncvarattrib,
    ncglobalattrib = ncglobalattrib,
    surfextend = true
    );

yields this issue:

conversion to pointer not defined for StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}

Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:33
  [2] unsafe_convert(#unused#::Type{Ptr{Float64}}, a::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64})
    @ Base ./pointer.jl:67
  [3] unsafe_convert(#unused#::Type{Ptr{Nothing}}, a::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64})
    @ Base ./pointer.jl:66
  [4] nc_put_vara(ncid::Int32, varid::Int32, startp::Vector{Float64}, countp::Vector{Int64}, op::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64})
    @ NCDatasets ~/.julia/packages/NCDatasets/c8XyT/src/netcdf_c.jl:796
  [5] nc_put_var(ncid::Int32, varid::Int32, data::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64})
    @ NCDatasets ~/.julia/packages/NCDatasets/c8XyT/src/netcdf_c.jl:712
  [6] setindex!
    @ ~/.julia/packages/NCDatasets/c8XyT/src/variable.jl:342 [inlined]
  [7] setindex!(v::NCDatasets.CFVariable{Float64, 1, NCDatasets.Variable{Float64, 1, NCDataset{Nothing}}, NCDatasets.Attributes{NCDataset{Nothing}}, NamedTuple{(:fillvalue, :scale_factor, :add_offset, :calendar, :time_origin, :time_factor), NTuple{6, Nothing}}}, data::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, indexes::Colon)
    @ NCDatasets ~/.julia/packages/NCDatasets/c8XyT/src/cfvariable.jl:632
  [8] ncfile(ds::NCDataset{Nothing}, filename::String, xyi::Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, Vector{Float64}, Vector{DateTime}}, varname::String; ncvarattrib::OrderedDict{String, String}, ncglobalattrib::OrderedDict{String, String}, thresholds::Vector{Tuple{String, Float64}}, deflatelevel::Int64, chunksizes::Vector{Int64}, type_save::Type{Float32}, timeorigin::DateTime, checksum::Symbol, saveindex::Tuple{Colon, Colon, UnitRange{Int64}}, kwargs::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol}, NamedTuple{(:climatology_bounds, :relerr), Tuple{Matrix{DateTime}, Bool}}})
    @ DIVAnd ~/ULiege/Tools/DIVAnd.jl/src/DIVAnd_save.jl:322
  [9] (::DIVAnd.var"#447#463"{Vector{Float64}, OrderedDict{String, String}, OrderedDict{String, String}, typeof(DIVAnd.distfun_m), Nothing, Int64, Bool, Bool, Dict{Any, Any}, Dict{Any, Any}, Int64, Float64, Int64, Float64, Float64, Tuple{}, Bool, Vector{Tuple{String, Float64}}, typeof(DIVAndgo), Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, Tuple{Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{DateTime}}, Vector{Float64}, String, String, Bool, Matrix{DateTime}, Dict{Symbol, Any}, Tuple{Array{Float64, 3}, Array{Float64, 3}, Array{Float64, 3}}, Tuple{Array{Float64, 3}, Array{Float64, 3}, Array{Float64, 3}}, Vector{Float64}, Vector{Float64}, Int64, Tuple{Int64, Int64, Int64}, Tuple{Array{Float64, 3}, Array{Float64, 3}, Array{Float64, 3}}, Tuple{Array{Float64, 3}, Array{Float64, 3}, Array{Float64, 3}}, DIVAnd.Anam.var"#invtrans#5"{DIVAnd.Anam.var"#invtrans#2#6"}, DIVAnd.Anam.var"#trans#3"{DIVAnd.Anam.var"#trans#1#4"}, Vector{DateTime}, TimeSelectorYearListMonthList{Vector{UnitRange{Int64}}, Vector{Vector{Int64}}}, Vector{Float64}, Int64})(ds::NCDataset{Nothing})
    @ DIVAnd ~/ULiege/Tools/DIVAnd.jl/src/diva.jl:376
 [10] NCDataset(::DIVAnd.var"#447#463"{Vector{Float64}, OrderedDict{String, String}, OrderedDict{String, String}, typeof(DIVAnd.distfun_m), Nothing, Int64, Bool, Bool, Dict{Any, Any}, Dict{Any, Any}, Int64, Float64, Int64, Float64, Float64, Tuple{}, Bool, Vector{Tuple{String, Float64}}, typeof(DIVAndgo), Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, Tuple{Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{DateTime}}, Vector{Float64}, String, String, Bool, Matrix{DateTime}, Dict{Symbol, Any}, Tuple{Array{Float64, 3}, Array{Float64, 3}, Array{Float64, 3}}, Tuple{Array{Float64, 3}, Array{Float64, 3}, Array{Float64, 3}}, Vector{Float64}, Vector{Float64}, Int64, Tuple{Int64, Int64, Int64}, Tuple{Array{Float64, 3}, Array{Float64, 3}, Array{Float64, 3}}, Tuple{Array{Float64, 3}, Array{Float64, 3}, Array{Float64, 3}}, DIVAnd.Anam.var"#invtrans#5"{DIVAnd.Anam.var"#invtrans#2#6"}, DIVAnd.Anam.var"#trans#3"{DIVAnd.Anam.var"#trans#1#4"}, Vector{DateTime}, TimeSelectorYearListMonthList{Vector{UnitRange{Int64}}, Vector{Vector{Int64}}}, Vector{Float64}, Int64}, ::String, ::Vararg{String}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ NCDatasets ~/.julia/packages/NCDatasets/c8XyT/src/dataset.jl:220
 [11] NCDataset(::Function, ::String, ::Vararg{String})
    @ NCDatasets ~/.julia/packages/NCDatasets/c8XyT/src/dataset.jl:218
 [12] diva3d(xi::Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, Vector{Float64}, TimeSelectorYearListMonthList{Vector{UnitRange{Int64}}, Vector{Vector{Int64}}}}, x::Tuple{Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{DateTime}}, value::Vector{Float64}, len::Tuple{Array{Float64, 3}, Array{Float64, 3}, Array{Float64, 3}}, epsilon2::Float64, filename::String, varname::String; datadir::String, bathname::String, bathisglobal::Bool, plotres::typeof(plotres), timeorigin::DateTime, moddim::Vector{Float64}, zlevel::Symbol, ncvarattrib::OrderedDict{String, String}, ncglobalattrib::OrderedDict{String, String}, transform::Tuple{DIVAnd.Anam.var"#trans#3"{DIVAnd.Anam.var"#trans#1#4"}, DIVAnd.Anam.var"#invtrans#5"{DIVAnd.Anam.var"#invtrans#2#6"}}, distfun::typeof(DIVAnd.distfun_m), mask::BitArray{3}, background::Nothing, background_epsilon2_factor::Nothing, background_lenz::Nothing, background_len::Nothing, background_lenz_factor::Int64, filterbackground::Int64, fitcorrlen::Bool, fithorzcorrlen::Bool, fitvertcorrlen::Bool, fithorz_param::Dict{Any, Any}, fitvert_param::Dict{Any, Any}, memtofit::Int64, overlapfactor::Float64, niter_e::Int64, minfield::Float64, maxfield::Float64, surfextend::Bool, velocity::Tuple{}, stat_per_timeslice::Bool, error_thresholds::Vector{Tuple{String, Float64}}, divamethod::typeof(DIVAndgo), kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ DIVAnd ~/ULiege/Tools/DIVAnd.jl/src/diva.jl:375
 [13] top-level scope
    @ ./timing.jl:220 [inlined]
 [14] top-level scope
    @ ./In[41]:0
 [15] eval
    @ ./boot.jl:373 [inlined]
 [16] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
    @ Base ./loading.jl:1196
Julia Version 1.7.0
Commit 3bf9d17731 (2021-11-30 12:12 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 4

Solution:

using Pkg
Pkg.update()

(just reporting the issue for the record, in case others get it)

It now works in the notebook 90 but still had an issue in another application, using the same domain configuration but different data.

Replacing lonr by collect(lonr) etc. solves the issue, but why?

@time dbinfo = diva3d((collect(lonr), collect(latr), collect(depthr), TS),
    (obslon, obslat, obsdepth, obstime), obsval,
    len, eps2,
    outputfile, varname,
    bathname=bathname,
    mask = mask,
    fitcorrlen = false,
    niter_e = 2,
    ncvarattrib = ncvarattrib,
    ncglobalattrib = ncglobalattrib,
    surfextend = true
    );

Package versions

julia> Pkg.status()
      Status `~/.julia/environments/v1.7/Project.toml`
  [336ed68f] CSV v0.10.4
  [052768ef] CUDA v3.12.0
  [8be319e6] Chain v0.5.0
  [8f4d0f93] Conda v1.7.0
  [0d879ee6] DINCAE v2.0.1
  [f57bf84d] DINCAE_utils v0.1.0 `https://github.com/gher-ulg/DINCAE_utils.jl#main`
  [efc8151c] DIVAnd v2.7.8 `~/ULiege/Tools/DIVAnd.jl`
  [1b7aed40] DIVAndNN v0.1.0 `https://github.com/gher-ulg/DIVAndNN.jl#master`
  [7f46824f] DIVAnd_HFRadar v0.1.0 `https://github.com/gher-ulg/DIVAnd_HFRadar.jl#master`
  [864edb3b] DataStructures v0.18.13
  [b4f34e82] Distances v0.10.7
  [31c24e10] Distributions v0.25.66
  [2fb1d81b] GeoArrays v0.7.8
  [855c05df] GeoMapping v0.0.0 `git@github.com:Alexander-Barth/GeoMapping.jl.git#master`
  [0ef565a4] Geodesy v1.1.0
  [c27321d9] Glob v1.3.0
  [cd3eb016] HTTP v0.9.17
  [7073ff75] IJulia v1.23.3
  [a98d9a8b] Interpolations v0.13.6
  [682c06a0] JSON v0.21.3
  [1902f260] Knet v1.4.10
  [23992714] MAT v0.10.3
  [e1d29d7a] Missings v1.0.2
  [0db19996] NBInclude v2.3.0
  [85f8d34a] NCDatasets v0.12.6 `git@github.com:Alexander-Barth/NCDatasets.jl.git#master`
  [b946abbf] NaNStatistics v0.6.14
  [626c502c] Parquet v0.8.4
  [3725be50] PhysOcean v0.6.5
  [f3e62ec7] PkgCleanup v0.1.0 `https://github.com/giordano/PkgCleanup.jl#main`
  [eebad327] PkgVersion v0.2.0
  [c3e4b0f8] Pluto v0.19.9
  [438e738f] PyCall v1.93.1
  [d330b81b] PyPlot v2.10.0
  [6f49c342] RCall v0.13.13
  [295af30f] Revise v3.4.0
  [276daf66] SpecialFunctions v2.1.7
  [860ef19b] StableRNGs v1.0.0
  [90137ffa] StaticArrays v1.5.2
  [fd094767] Suppressor v0.2.1
  [0a941bbe] Zarr v0.7.2
  [7243133f] NetCDF_jll v400.802.103+0 `https://github.com/JuliaBinaryWrappers/NetCDF_jll.jl#main`
  [10745b16] Statistics
  • Within notebook 90 can you also run in a new cell Pkg.status() and paste the output here?

  • Can you check if you have in notebook (or its parent directory) a Manifest.toml file ?

(for context: You will probably see old version of NCDatasets. Starting the kernel IJulia is equivalent to julia --project=@..

https://github.com/JuliaLang/IJulia.jl/blob/1cdaf7e5e65c1221b4a3fac86f63253bea65a0c5/docs/src/manual/usage.md#julia-projects

Pkg.update() updates only your current environment (per default the global environment is used /home/USER/.julia/environments/vVERSION/).

Here is some explanation of @.:

https://stackoverflow.com/a/53624158/3801401

)

Sorry, I forgot to close that one.
I now works and I'm not sure why it was failing at some point.