Skip to content
Snippets Groups Projects
Commit 9f25ab4b authored by DanielFrisinghelli's avatar DanielFrisinghelli
Browse files

Command line interfaces.

parent d99519eb
No related branches found
No related tags found
No related merge requests found
"""Command line argument parsers."""
# !/usr/bin/env python
# -*- coding: utf-8 -*-
# builtins
import argparse
import logging
import pathlib
# locals
from climax.core.constants import CORDEX_VARIABLES, CDO_RESAMPLING_MODES
# epilogue to display at the end of each parser
EPILOGUE = 'Author: Daniel Frisinghelli, daniel.frisinghelli@gmail.com'
# module level logger
LOGGER = logging.getLogger(__name__)
# parser to preprocess Cordex data: climax.main.preprocess.py
def preprocess_parser():
# define command line argument parser
parser = argparse.ArgumentParser(
description='Reproject and resample Cordex 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: name of the variable of interest
parser.add_argument('variable', type=str,
help='Name of the variable of interest.',
choices=CORDEX_VARIABLES)
# positional argument: path to search for Cordex NetCDF files
parser.add_argument('source', type=pathlib.Path,
help='Path to search for Cordex NetCDF files.')
# positional argument: path to save the reprojected NetCDF files
parser.add_argument('target', type=pathlib.Path,
help='Path to save the remapped Cordex NetCDF files.')
# optional arguments
# default values
default = '(default: %(default)s)'
# 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: file pattern to search for in source directory
parser.add_argument('-p', '--pattern', type=str,
help=('(Regex) file pattern to search for in the '
'source directory {}.'.format(default)),
default='(.*).nc$', 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: 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
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