input_arguments.py 2.03 KB
Newer Older
1
"""
Eva Börgens's avatar
Eva Börgens committed
2
3
4
Module checking the input parameter
"""

Eva Börgens's avatar
Eva Börgens committed
5
from argparse import ArgumentParser, FileType, RawTextHelpFormatter
6
from .io import test_coordiantes
Eva Börgens's avatar
Eva Börgens committed
7
8

def arg_parser():
Eva Börgens's avatar
Eva Börgens committed
9
    """
Eva Börgens's avatar
Eva Börgens committed
10
    Argument parser of input line
11
12
13

    Returns:
        ArgumentParser.arguments
Eva Börgens's avatar
Eva Börgens committed
14
    """
Eva Börgens's avatar
Eva Börgens committed
15
16
17

    parser = ArgumentParser(
       prog="tws_covariances.sh",
Eva Börgens's avatar
Eva Börgens committed
18
19
20
       description="Programm to compute the covariances of given region and return the "
                   "standard deviation of the mean TWS of this region and/or the full "
                   "covariance matrix",
Eva Börgens's avatar
Eva Börgens committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
       formatter_class=RawTextHelpFormatter,
    )
    parser.add_argument(
       "-f",
       "--filename",
       required=True,
       type=FileType(),
       help="Filename of the netcdf TWS input file, as downloaded from gravis.gfz-potsdam.de"
    )
    parser.add_argument(
       "-r",
       "--region",
       required=True,
       type=FileType(),
Eva Börgens's avatar
Eva Börgens committed
35
36
       help="Filename of the ascii file defining the requested region. List of coordinates "
            "lon, lat, each line one coordinate."
Eva Börgens's avatar
Eva Börgens committed
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
            "Coordinates have to be on an even spaced grid. Comment lines have to start with '#'. "
    )
    parser.add_argument(
       "-o",
       "--output",
       required=True,
       type=str,
       help="Filename of the netcdf output file"
    )
    parser.add_argument(
       "-m",
       "--matrix",
       action="store_true",
       help="Return full covariance matrix"
    )
    parser.add_argument(
       "-u",
       "--uncertainty",
       action="store_true",
       help="Return time series of standard deviations for mean TWS time series"
    )
    parser.add_argument(
       "-t",
       "--timeseries",
       action="store_true",
       help="Return mean TWS time series"
    )

    args = parser.parse_args()
66
    if not args.matrix and not args.uncertainty and not args.timeseries:
Eva Börgens's avatar
Eva Börgens committed
67
68
        raise RuntimeError("Either covariance matrix (-m) or uncertainties (-u) or timeseries (-t) "
                           "have to be set for the output!")
Eva Börgens's avatar
Eva Börgens committed
69
70
    test_coordiantes(args.region.name)

Eva Börgens's avatar
Eva Börgens committed
71
    return args