forked from serapred/netcdf-to-zarr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.py
57 lines (44 loc) · 2.04 KB
/
parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# parser for netcdf_to_zarr
import argparse
def configure(args):
class toList(argparse.Action):
def __init__(self, option_strings, dest, nargs=None, **kwargs):
if nargs is not None:
raise ValueError("nargs not allowed")
super(toList, self).__init__(option_strings, dest, **kwargs)
def __call__(self, parser, namespace, values, option_string=None):
setattr(namespace, self.dest, values.split(' '))
desc = ('This script converts netCDF4 into zarr files\n'
'It is possible to specify a list of netCDF4 files\n'
'to merge them into a single zarr file.\n'
'to do so, the variables in the netCD4 file\n'
'must have a common shape and run along the same dimension.\n'
'\nExamples:\n'
' -convert.py src.nc dst.nc [-options]\n'
' -convert.py "src1.nc src2.nc src3.nc" dst.zarr [-options]\n')
parser = argparse.ArgumentParser(description=desc,
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('src',
help='source netCDF4 file/files',
action=toList,
default=[])
parser.add_argument('dst',
help='target zarr file',
default='')
parser.add_argument('-a',
'--axis',
metavar='axis',
help='axis name to append along',
default=None)
parser.add_argument('-n',
'--nested',
help='chunks are located into a nested path',
action='store_true',
default=False)
parser.add_argument('-m',
'--mode',
metavar='mode',
help='use processes or threads',
choices=('threads', 'processes'),
default='serial')
return parser.parse_args(args)