Skip to content

Error when appending layer to netcdf still adds a layer to the file #971

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

Open
tiemvanderdeure opened this issue May 12, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@tiemvanderdeure
Copy link
Collaborator

MWE:

using Rasters, NCDatasets
write("myfile.nc", Raster(rand(X(1:10), Y(1:10))))
write("myfile.nc", Raster(rand(X(2:10), Y(1:10)), name = :ras2), append = true)
RasterStack("myfile.nc")

The second write errors because the dimensions don't match, but before that error occurs the layer is already initalized, so we end up with an extra layer that is filled with 9.96921e36.

Probably we need a try-catch block and delete the layer again if an error occurs.

┌ 10×10 RasterStack ┐
├───────────────────┴─────────────────────────────────────────────────────────────────────────────────── dims ┐
  ↓ X Mapped{Int64} [1, 2, …, 9, 10] ForwardOrdered Regular Points,
  → Y Mapped{Int64} [1, 2, …, 9, 10] ForwardOrdered Regular Points
├───────────────────────────────────────────────────────────────────────────────────────────────────── layers ┤
  :unnamed eltype: Union{Missing, Float64} dims: X, Y size: 10×10
  :ras2    eltype: Union{Missing, Float64} dims: X, Y size: 10×10
├─────────────────────────────────────────────────────────────────────────────────────────────────── metadata ┤
  Metadata{Rasters.NCDsource} of Dict{String, Any}()
├───────────────────────────────────────────────────────────────────────────────────────────────────── raster ┤
  missingval: missing
  extent: Extent(X = (1, 10), Y = (1, 10))
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
@tiemvanderdeure tiemvanderdeure added the bug Something isn't working label May 12, 2025
@tiemvanderdeure tiemvanderdeure changed the title Failing to append layer to netcfd still initializes the layer Error when appending layer to netcdf still adds a layer to the file May 12, 2025
@rafaqz
Copy link
Owner

rafaqz commented May 12, 2025

Yep, all checks should happen before we add any variables or dimensions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants