-
Notifications
You must be signed in to change notification settings - Fork 186
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
Error when writing Field
s reduced over 3 dimensions to NetCDF
#2857
Comments
Huh. Is this a bug with I'm not sure what is desirable for NetCDF users. A field reduced in all dimensions is just a scalar. Right now we store this in a 0D array via Oceananigans.jl/src/OutputWriters/netcdf_output_writer.jl Lines 489 to 491 in 5d044fb
I don't know enough about NetCDF to say whether we should convert to a scalar in this case. |
And just to clarify, this is what julia> a = reshape([1], 1, 1, 1)
1×1×1 Array{Int64, 3}:
[:, :, 1] =
1
julia> dropdims(a, dims=(1, 2, 3))
0-dimensional Array{Int64, 0}:
1 A 0D array can only contain one value, but I guess it still cannot be automatically cast to a scalar: julia> b = dropdims(a, dims=(1, 2, 3))
0-dimensional Array{Int64, 0}:
1
julia> b[]
1
julia> Float32(b)
ERROR: MethodError: no method matching Float32(::Array{Int64, 0})
Closest candidates are:
(::Type{T})(::AbstractChar) where T<:Union{AbstractChar, Number} at char.jl:50
(::Type{T})(::Base.TwicePrecision) where T<:Number at twiceprecision.jl:266
(::Type{T})(::Complex) where T<:Real at complex.jl:44
...
Stacktrace:
[1] top-level scope
@ REPL[7]:1 |
Okay so this MWE reproduces the error: using NCDatasets
a = reshape([1.], 1, 1, 1)
b = dropdims(a, dims=(1, 2, 3))
ds = NCDataset("/tmp/test.nc","c")
time = defDim(ds,"time",Inf)
v = defVar(ds,"temp",Float32,("time",))
ds["temp"][1] = b
close(ds) However, if I create a variable without an unbouded dimension (i.e. without time) and do the same thing, it works properly: using NCDatasets
a = reshape([1.], 1, 1, 1)
b = dropdims(a, dims=(1, 2, 3))
ds = NCDataset("/tmp/test.nc","c")
v = defVar(ds,"temp",Float32,())
ds["temp"][] = b
close(ds) So I think this is an edge case that NCDatasets doesn't yet handle well. I'm gonna create an issue there and see what they say. |
When I try to write a
Field
that's reduced over 3 dimensions to a NetCDF file I get an error. For the example the MWE belowproduces this error:
Which I'm guessing has to do with a
1×1×1
Array being converted to a Float somewhere.The text was updated successfully, but these errors were encountered: