Cannot `convert` an object of type Missing to an object of type Float64

I’m trying to read some data out of a NetCDF file and then convert it to Float64. Below is my code. Would you please help me address this error?

My code:

using NCDatasets
ds1 = NCDataset("test.nc");
Var0 = ds1["Variable0"][:,:,:]
close(ds1);
Var0 = convert(Array{Float64}, Var0);

The error I got:

ERROR: LoadError: MethodError: Cannot `convert` an object of type Missing to an object of type Float64
Closest candidates are:
  convert(::Type{T}, ::Base.TwicePrecision) where T<:Number at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/base/twiceprecision.jl:262
  convert(::Type{T}, ::AbstractChar) where T<:Number at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/base/char.jl:185
  convert(::Type{T}, ::CartesianIndex{1}) where T<:Number at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/base/multidimensional.jl:136

eh, what do you want to do with missing value?

1 Like

If you want to interpret the missings as NaNs, you could do:

using NCDatasets
ds1 = NCDataset("test.nc");
Var0 = ds1["Variable0"][:,:,:]
close(ds1);
Var0 = nomissing(Var0,NaN)
1 Like

Many thanks for the solution. This is exactly what I want.