Skip to content
Snippets Groups Projects
Commit 29bcffde authored by Frisinghelli Daniel's avatar Frisinghelli Daniel
Browse files

Reproject and resample to target grid.

parent 3bdf91b7
No related branches found
No related tags found
No related merge requests found
...@@ -132,6 +132,10 @@ def preprocess_era5_parser(): ...@@ -132,6 +132,10 @@ def preprocess_era5_parser():
# positional arguments # positional arguments
# positional argument: path to the target grid file
parser.add_argument('grid', type=pathlib.Path,
help='Path to the target grid file.')
# positional argument: path to search for ERA5 NetCDF files # positional argument: path to search for ERA5 NetCDF files
parser.add_argument('source', type=pathlib.Path, parser.add_argument('source', type=pathlib.Path,
help='Path to search for ERA5 NetCDF files.') help='Path to search for ERA5 NetCDF files.')
...@@ -162,4 +166,10 @@ def preprocess_era5_parser(): ...@@ -162,4 +166,10 @@ def preprocess_era5_parser():
.format(default)), default=False, nargs='?', .format(default)), default=False, nargs='?',
const=True, metavar='') const=True, metavar='')
# optional argument: resampling mode
parser.add_argument('-m', '--mode', type=str,
help='Resampling mode {}.'.format(default),
default='bilinear', choices=CDO_RESAMPLING_MODES,
metavar='')
return parser return parser
...@@ -15,6 +15,7 @@ import xarray as xr ...@@ -15,6 +15,7 @@ import xarray as xr
# locals # locals
from climax.core.cli import preprocess_era5_parser from climax.core.cli import preprocess_era5_parser
from climax.core.constants import ERA5_VARIABLES from climax.core.constants import ERA5_VARIABLES
from climax.core.utils import reproject_cdo
from pysegcnn.core.logging import log_conf from pysegcnn.core.logging import log_conf
from pysegcnn.core.utils import search_files from pysegcnn.core.utils import search_files
from pysegcnn.core.trainer import LogConfig from pysegcnn.core.trainer import LogConfig
...@@ -41,6 +42,11 @@ if __name__ == '__main__': ...@@ -41,6 +42,11 @@ if __name__ == '__main__':
# check whether the source directory exists # check whether the source directory exists
if args.source.exists(): if args.source.exists():
# check whether the target grid file exists
if not args.grid.exists():
LOGGER.info('{} does not exist.'.format(args.grid))
sys.exit()
# check whether a single variable is specified # check whether a single variable is specified
variables = ERA5_VARIABLES variables = ERA5_VARIABLES
if args.variable is not None: if args.variable is not None:
...@@ -92,6 +98,10 @@ if __name__ == '__main__': ...@@ -92,6 +98,10 @@ if __name__ == '__main__':
LOGGER.info('Compressing NetCDF: {}'.format(filename)) LOGGER.info('Compressing NetCDF: {}'.format(filename))
ds.to_netcdf(filename, engine='h5netcdf') ds.to_netcdf(filename, engine='h5netcdf')
# reproject and resample to target grid
reproject_cdo(args.grid, filename, filename, mode=args.mode,
overwrite=args.overwrite)
else: else:
LOGGER.info('{} does not exist.'.format(str(args.source))) LOGGER.info('{} does not exist.'.format(str(args.source)))
sys.exit() sys.exit()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment