Problems adding attributes to NetCDF files created with SNAP/GPT

Hi All,

I’m using Snap6 to do C2RCC processing on S3 L1 scenes and write to NetCDF4-BEAM or NetCDF4-CF format files.

I need to add attributes to these nc files afterwards. This is usually quite easy in python-NetCDF4: Open Dataset in r+ mode, setncattr(), close(), done.
However this does not work on these C2RCC processed files from SNAP (and other S3 nc products from SNAP).

I can open the file in python, add global attributes, but when I do sync() or close() I get:

Traceback (most recent call last):
File “”, line 1, in
File “netCDF4.pyx”, line 1554, in netCDF4.Dataset.close (netCDF4.c:21176)
RuntimeError: NetCDF: Can’t open HDF5 attribute

the file is closed, but the changes are not written. Despite adding attributes does not work, I can do delncattr() in python and delete an attribute from the file! Strange.

I’m pretty stuck at this point. I tried it with various files (subsets, converted nc files), but always get the same error.
I also tried python HDF5 and pure command line with NCO’s ncatted, all with the same error.

Has anyone successfully added data or metadata to nc files created by SNAP? Or does anyone know another way than described above to give a try?

I also tried snappy to do the C2RCC processing, but instead of taking 15 minutes in SNAP I killed the job after it was not further than 60% after 20 hours (config already optimised)… But thats another problem (maybe someone has a solution for why snappy is so slow?)

I dont really want to copy the content in python and write a new file. Thats too much IO stuff for just adding a few attributes.

Any ideas welcome, many thanks!


Hi Daniel,

I experienced the same problem. I was able to bypass it by first using nccopy from the netCDF tools and then adding the attributes to the copied file.


We are doing nothing special to prevent changing the nc file after it was written by SNAP.
I have no idea why the SNAP NetCDF files should be special, and if nccopy works, the files seem to be valid in gerneral. Could it be a strange conflict between the files and the python-NetCDf4 library?

It seems that the attribute issue is related to the one discussed here:

So, also adding attributes should be possible after an update has been released.