1
|
|
|
#!/usr/bin/env python |
2
|
|
|
|
3
|
|
|
import sys |
4
|
|
|
import optparse as op |
5
|
|
|
|
6
|
|
|
from sciapy.level1c import scia_limb_scan |
7
|
|
|
|
8
|
|
|
convert_options = [ |
9
|
|
|
op.make_option("-a", "--mpl-to-text", action="store_true", dest="mpl_to_text"), |
10
|
|
|
op.make_option("-A", "--netcdf-to-text", action="store_true", dest="netcdf_to_text"), |
11
|
|
|
op.make_option("-n", "--text-to-netcdf", action="store_true", dest="text_to_netcdf"), |
12
|
|
|
op.make_option("-N", "--mpl-to-netcdf", action="store_true", dest="mpl_to_netcdf"), |
13
|
|
|
op.make_option("-m", "--text-to-mpl", action="store_true", dest="text_to_mpl"), |
14
|
|
|
op.make_option("-M", "--netcdf-to-mpl", action="store_true", dest="netcdf_to_mpl"), |
15
|
|
|
] |
16
|
|
|
input_options = [ |
17
|
|
|
op.make_option("-f", "--from-type", dest="from_type", choices=["mpl", "netcdf", "text"], default="mpl"), |
18
|
|
|
op.make_option("-t", "--to-type", dest="to_type", choices=["mpl", "netcdf", "text"], default="text"), |
19
|
|
|
op.make_option("-i", "--input", dest="input", default=sys.stdin, metavar="FILE"), |
20
|
|
|
op.make_option("-o", "--output", dest="output", default=sys.stdout, metavar="FILE"), |
21
|
|
|
] |
22
|
|
|
manip_options = [ |
23
|
|
|
op.make_option("-u", "--multiply-by", type=float, dest="mult_factor", default=1.0, metavar="FACTOR"), |
24
|
|
|
op.make_option("-d", "--add", type=float, dest="add", default=0.0, metavar="NUMBER"), |
25
|
|
|
] |
26
|
|
|
|
27
|
|
|
def read_input(sls, rtype, filename): |
28
|
|
|
if rtype == "mpl": |
29
|
|
|
sls.read_from_mpl_binary(filename) |
30
|
|
|
elif rtype == "text": |
31
|
|
|
sls.read_from_textfile(filename) |
32
|
|
|
elif rtype == "netcdf": |
33
|
|
|
sls.read_from_netcdf(filename) |
34
|
|
|
|
35
|
|
|
def write_output(sls, wtype, filename): |
36
|
|
|
if wtype == "mpl": |
37
|
|
|
sls.write_to_mpl_binary(filename) |
38
|
|
|
elif wtype == "text": |
39
|
|
|
sls.write_to_textfile(filename) |
40
|
|
|
elif wtype == "netcdf": |
41
|
|
|
sls.write_to_netcdf(filename) |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
parser = op.OptionParser(option_list=input_options) |
45
|
|
|
convert_group = op.OptionGroup(parser, "Conversion options", |
46
|
|
|
"Instead of specifying --from-type and --to-type, these options allow" |
47
|
|
|
"direct conversions between the desired formats.") |
48
|
|
|
for opt in convert_options: |
49
|
|
|
convert_group.add_option(opt) |
50
|
|
|
parser.add_option_group(convert_group) |
51
|
|
|
|
52
|
|
|
manip_group = op.OptionGroup(parser, "Manipulation options", |
53
|
|
|
"Allows manipulation of the radiance data.") |
54
|
|
|
for opt in manip_options: |
55
|
|
|
manip_group.add_option(opt) |
56
|
|
|
parser.add_option_group(manip_group) |
57
|
|
|
|
58
|
|
|
(options, args) = parser.parse_args() |
59
|
|
|
|
60
|
|
|
if options.mpl_to_text: |
61
|
|
|
options.from_type = "mpl" |
62
|
|
|
options.to_type = "text" |
63
|
|
|
if options.netcdf_to_text: |
64
|
|
|
options.from_type = "netcdf" |
65
|
|
|
options.to_type = "text" |
66
|
|
|
if options.text_to_netcdf: |
67
|
|
|
options.from_type = "text" |
68
|
|
|
options.to_type = "netcdf" |
69
|
|
|
if options.mpl_to_netcdf: |
70
|
|
|
options.from_type = "mpl" |
71
|
|
|
options.to_type = "netcdf" |
72
|
|
|
if options.text_to_mpl: |
73
|
|
|
options.from_type = "text" |
74
|
|
|
options.to_type = "mpl" |
75
|
|
|
if options.netcdf_to_mpl: |
76
|
|
|
options.from_type = "netcdf" |
77
|
|
|
options.to_type = "mpl" |
78
|
|
|
|
79
|
|
|
slscan = scia_limb_scan() |
80
|
|
|
read_input(slscan, options.from_type, options.input) |
81
|
|
|
#slscan = sn.scia_nadir_scan() |
82
|
|
|
#read_input(slscan, options.from_type, options.input) |
83
|
|
|
|
84
|
|
|
if options.mult_factor != 1.0 or options.add != 0.: |
85
|
|
|
tmp_list = [] |
86
|
|
|
for rad in slscan.rad_list: |
87
|
|
|
tmp_list.append(rad * options.mult_factor + options.add) |
88
|
|
|
slscan.rad_list = tmp_list |
89
|
|
|
|
90
|
|
|
#slscan.average_spectra() |
91
|
|
|
|
92
|
|
|
write_output(slscan, options.to_type, options.output) |
93
|
|
|
|