From 783cbdc081e86212f679a0552d31f46050dde4ce Mon Sep 17 00:00:00 2001 From: "Daniel.Frisinghelli" <daniel.frisinghelli@eurac.edu> Date: Tue, 25 May 2021 10:05:22 +0200 Subject: [PATCH] Added NetCDF file compression. --- climax/main/preprocess.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/climax/main/preprocess.py b/climax/main/preprocess.py index 726544d..e1b6944 100644 --- a/climax/main/preprocess.py +++ b/climax/main/preprocess.py @@ -179,9 +179,14 @@ if __name__ == '__main__': # set encoding of time: calendar ds.time.encoding = ds.time_bnds.encoding + # set NetCDF file compression for each variable + for _, var in ds.data_vars.items(): + var.encoding['zlib'] = True + var.encoding['complevel'] = 5 + # save aggregated netcdf file - LOGGER.info('Saving aggregated NetCDF: {}'.format(filename)) - ds.to_netcdf(filename) + LOGGER.info('Compressing NetCDF: {}'.format(filename)) + ds.to_netcdf(filename, engine='h5netcdf') # remove single netcdf files from disk if args.remove: -- GitLab