Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Climax
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
earth_observation_public
Climax
Commits
9f25ab4b
Commit
9f25ab4b
authored
3 years ago
by
DanielFrisinghelli
Browse files
Options
Downloads
Patches
Plain Diff
Command line interfaces.
parent
d99519eb
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
climax/core/cli.py
+78
-0
78 additions, 0 deletions
climax/core/cli.py
with
78 additions
and
0 deletions
climax/core/cli.py
0 → 100644
+
78
−
0
View file @
9f25ab4b
"""
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment