diff --git a/climax/core/cli.py b/climax/core/cli.py index 66214631be3ed3f6cb79724d1fc98c0820943478..eaed173c5a2e44ee1bdc8bff0992e30d92659045 100644 --- a/climax/core/cli.py +++ b/climax/core/cli.py @@ -168,6 +168,11 @@ def preprocess_era5_parser(): help='Overwrite existing files {}.'.format(default), default=False, nargs='?', const=True, metavar='') + # optional argument: whether to apply compression + parser.add_argument('-c', '--compress', type=bool, + help='Apply file compression {}.'.format(default), + default=False, nargs='?', const=True, metavar='') + # optional argument: dry run, print files which would be processed parser.add_argument('-d', '--dry-run', type=bool, help=('Print files which would be processed {}.' diff --git a/climax/main/preprocess/preprocess_ERA5.py b/climax/main/preprocess/preprocess_ERA5.py index 6a83c9137f9d31da6c427be28e001bdd3133c4eb..4f666d4f31ecb08b0830bbe617440fb2d1999d66 100644 --- a/climax/main/preprocess/preprocess_ERA5.py +++ b/climax/main/preprocess/preprocess_ERA5.py @@ -128,9 +128,10 @@ if __name__ == '__main__': ds = xr.open_mfdataset(target, parallel=True).compute() # set NetCDF file compression for each variable - for _, var in ds.data_vars.items(): - var.encoding['zlib'] = True - var.encoding['complevel'] = 5 + if args.compress: + for _, var in ds.data_vars.items(): + var.encoding['zlib'] = True + var.encoding['complevel'] = 5 # save aggregated netcdf file LOGGER.info('Compressing NetCDF: {}'.format(filename))