forked from hygeos/polymer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
polymer_cli.py
executable file
·40 lines (31 loc) · 1.23 KB
/
polymer_cli.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
A basic command line interface for Polymer
'''
import argparse
from polymer.main import run_atm_corr
from polymer.level1 import Level1
from polymer.level2 import Level2
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description='''Polymer atmospheric correction, simple command line interface.
To pass additional parameters, it is advised to execute the
function run_atm_corr in a python script''')
parser.add_argument('input_file')
parser.add_argument('output_file')
parser.add_argument('-fmt', choices=['hdf4', 'netcdf4', 'autodetect'],
default='autodetect',
help='Output file format')
args = parser.parse_args()
if args.fmt == 'autodetect':
if args.output_file.endswith('.nc'):
args.fmt = 'netcdf4'
elif args.output_file.endswith('.hdf'):
args.fmt = 'hdf4'
else:
print('Error, cannot detect file format from output file "{}"'.format(
args.output_file))
exit()
run_atm_corr(Level1(args.input_file),
Level2(filename=args.output_file, fmt=args.fmt))