From a693fd8afe4241bc89a0b3cd3aea2adca17a5099 Mon Sep 17 00:00:00 2001 From: "Daniel.Frisinghelli" <daniel.frisinghelli@eurac.edu> Date: Tue, 22 Jun 2021 15:34:33 +0200 Subject: [PATCH] Adjusted constant parameters. --- climax/core/cli.py | 67 ++++++++++++++++++++++++++++++++++++++-- climax/core/constants.py | 4 +++ climax/main/config.py | 3 ++ 3 files changed, 71 insertions(+), 3 deletions(-) diff --git a/climax/core/cli.py b/climax/core/cli.py index 84474ec..d2eaf8f 100644 --- a/climax/core/cli.py +++ b/climax/core/cli.py @@ -11,7 +11,7 @@ import pathlib # locals from climax.core.constants import (CORDEX_VARIABLES, CORDEX_EXPERIMENTS, EUROCORDEX_GCMS, EUROCORDEX_RCMS, - CDO_RESAMPLING_MODES) + CDO_RESAMPLING_MODES, ERA5_VARIABLES) # epilogue to display at the end of each parser EPILOGUE = 'Author: Daniel Frisinghelli, daniel.frisinghelli@gmail.com' @@ -20,8 +20,8 @@ EPILOGUE = 'Author: Daniel Frisinghelli, daniel.frisinghelli@gmail.com' LOGGER = logging.getLogger(__name__) -# parser to preprocess Cordex data: climax.main.preprocess.py -def preprocess_parser(): +# parser to preprocess Cordex data: climax.main.preprocess_CORDEX.py +def preprocess_cordex_parser(): # define command line argument parser parser = argparse.ArgumentParser( @@ -118,3 +118,64 @@ def preprocess_parser(): .format(default)), default=None, metavar='') return parser + + +# parser to preprocess ERA5 data: climax.main.preprocess_ERA5.py +def preprocess_era5_parser(): + + # define command line argument parser + parser = argparse.ArgumentParser( + description='Reproject and resample ERA5 data to a target grid.', + epilog=EPILOGUE, + formatter_class=lambda prog: argparse.RawDescriptionHelpFormatter( + prog, max_help_position=50, indent_increment=2)) + + # 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 Cordex NetCDF files + parser.add_argument('source', type=pathlib.Path, + help='Path to search for ERA5 NetCDF files.') + + # positional argument: path to save the reprojected NetCDF files + parser.add_argument('target', type=pathlib.Path, + help='Path to save the remapped ERA5 NetCDF files.') + + # optional arguments + + # default values + default = '(default: %(default)s)' + + # optional argument: name of the variable of interest + parser.add_argument('-var', '--variable', type=str, + help='Name of the variable of interest.', + choices=ERA5_VARIABLES, default=None, nargs='+', + metavar='') + + # optional argument: resampling mode + parser.add_argument('-m', '--mode', type=str, + help='Resampling mode {}.'.format(default), + default='bilinear', choices=CDO_RESAMPLING_MODES, + metavar='') + + # optional argument: whether to overwrite files + parser.add_argument('-o', '--overwrite', type=bool, + help='Overwrite existing files {}.'.format(default), + default=False, nargs='?', const=True, metavar='') + + # optional argument: whether to aggregate time periods of simulations + parser.add_argument('-a', '--aggregate', type=bool, + help=('Aggregate time periods of ERA5 to a ' + 'single NetCDF file {}.'.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 {}.' + .format(default)), default=False, nargs='?', + const=True, metavar='') + + return parser diff --git a/climax/core/constants.py b/climax/core/constants.py index 4f53fc0..30aa7a6 100644 --- a/climax/core/constants.py +++ b/climax/core/constants.py @@ -30,3 +30,7 @@ EUROCORDEX_RCMS = ['SMHI-RCA4', 'CLMcom-CCLM4-8-17', # climate data operator (cdo) resampling modes CDO_RESAMPLING_MODES = ['bilinear', 'conservative'] + +# ERA5 variables to use for the downscaling +ERA5_VARIABLES = ['geopotential', 'temperature', 'u_component_of_wind', + 'v_component_of_wind', 'specific_humidity'] diff --git a/climax/main/config.py b/climax/main/config.py index d0bf233..3c4be18 100644 --- a/climax/main/config.py +++ b/climax/main/config.py @@ -13,3 +13,6 @@ HERE = pathlib.Path(__file__).parent # calibration period P_CAL = (datetime.datetime.strptime('1970-01-01', '%Y-%m-%d').date(), datetime.datetime.strptime('2000-01-01', '%Y-%m-%d').date()) + +# path to ERA5 reanalysis data +ERA5_PATH = pathlib.Path('/mnt/CEPH_PROJECTS/FACT_CLIMAX/REANALYSIS/') -- GitLab