From 813aad6bd2f906a55ba23d709ad216f8e04cc721 Mon Sep 17 00:00:00 2001 From: "Morten W. Hansen" Date: Wed, 4 Jan 2023 22:16:12 +0000 Subject: [PATCH] #525: gdal adds its own Conventions attribute with value 'CF-1.5' which is obviously wrong. This is now deleted. Same goes for the history. That should also be handled in the processing software rather then by the gdal netcdf driver. --- nansat/exporter.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/nansat/exporter.py b/nansat/exporter.py index 810349ae..47a87d66 100644 --- a/nansat/exporter.py +++ b/nansat/exporter.py @@ -143,14 +143,19 @@ def rename_attributes(filename): rename_attrs = [] # Open new file to edit attribute names ds = Dataset(filename, 'r+') + """ The netcdf driver adds the Conventions attribute with + value CF-1.5. This may be wrong, so it is better to use the + Conventions metadata from the Nansat object. Other attributes + added by gdal that are already present in Nansat, should also + be deleted.""" for attr in ds.ncattrs(): if GDAL in attr: if attr.replace(GDAL, "") in ds.ncattrs(): - # Mark for deletion - del_attrs.append(attr) - else: - # Mark for renaming - rename_attrs.append(attr) + # Mark the attribute created by the netcdf driver + # for deletion - ref above comment + del_attrs.append(attr.replace(GDAL, "")) + # Mark for renaming + rename_attrs.append(attr) # Delete repeated attributes.. for attr in del_attrs: