diff --git a/nansat/exporter.py b/nansat/exporter.py index 47a87d66..28b126f2 100644 --- a/nansat/exporter.py +++ b/nansat/exporter.py @@ -129,14 +129,18 @@ def export(self, filename='', bands=None, rm_metadata=None, add_geolocation=True # Rename variable names to get rid of the band numbers self.rename_variables(filename) # Rename attributes to get rid of "GDAL_" added by gdal - self.rename_attributes(filename) + self.correct_attributes(filename, history=self.vrt.dataset.GetMetadata()['history']) self.logger.debug('Export - OK!') @staticmethod - def rename_attributes(filename): + def correct_attributes(filename, history=None): """ Rename global attributes to get rid of the "GDAL_"-string - added by gdal. + added by gdal, remove attributes added by gdal that are + already present in the Nansat object, and correct the history + attribute (the latter may be reduced in length because + gdal.GetDriverByName(driver).CreateCopy limits the string + lenght to 161 characters). """ GDAL = "GDAL_" del_attrs = [] @@ -144,10 +148,10 @@ def rename_attributes(filename): # 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.""" + value CF-1.5. This in most cases 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(): @@ -163,6 +167,9 @@ def rename_attributes(filename): # Rename attributes: for attr in rename_attrs: ds.renameAttribute(attr, attr.replace(GDAL, "")) + # Correct the history + if history is not None: + ds.history = history ds.close() @staticmethod