0

I am using xarray and rioxarray to compute values from an existing dataset, the existing dataset as band like red, blue and green so I have something like this:

import xarray as xr

dataset: xr.Dataset = ...

red, blue, green = dataset["red"], dataset["blue"], dataset["green"]
gray = (red + blue + green) / 3.0

I then save three files:

red.to_netcdf("red.nc")
gray.to_netcdf("gray.nc")
gray.rio.to_raster("gray.tif")

I then open these files in QGIS: the red.nc and gray.tif files are at the right location, the gray.nc file is at the location (0, 0).

I tried to compare everything in the red and gray variables but I could not find any difference in term of attributes, etc.

How can I save gray as an NC file so that QGIS can open it properly?

1
  • That's most likely an issue with the attributes and/or .encoding. During calculation attributes/encoding might get dropped/changed. This get's fixed when writing out via rioxarray. Compare attributes/encoding between red/gray first, to check for differences. Commented Aug 22 at 8:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.