-
Notifications
You must be signed in to change notification settings - Fork 39
/
find_wavelengths_for_satpy.py
73 lines (61 loc) · 2.69 KB
/
find_wavelengths_for_satpy.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2020-2022 Pytroll developers
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Retrieve channel wavelength ranges for a given sensor."""
import argparse
from pyspectral.rsr_reader import RelativeSpectralResponse
from pyspectral.utils import get_wave_range
def _setup_argparse():
arg_parser = argparse.ArgumentParser(
description='Retrieve channel wavelength ranges for a given sensor.')
arg_parser.add_argument("platform_name",
help="The Platform name",
type=str)
arg_parser.add_argument("sensor",
help="The sensor/instrument name",
type=str)
arg_parser.add_argument("-r", "--minimum_response",
help=("Minimum response threshold: Defines the value "
"that the RSR must exceed in order to trigger"
"the minimum or maximum wavelengths."),
default=0.15, type=float)
arg_parser.add_argument("--bandname", '-b',
help="The sensor band name. Leave blank to return all bands.", type=str)
arg_parser.add_argument("--detector", '-d',
help="The sensor detector, if not passed will default to det-1",
default='det-1', type=str)
return arg_parser
def main(arguments):
"""Retrieve wavelength range based on user-supplied arguments."""
platform = arguments.platform_name
sensor = arguments.sensor
threshold = arguments.minimum_response
rsr = RelativeSpectralResponse(platform, sensor)
if arguments.bandname:
bands = [arguments.bandname]
else:
bands = rsr.band_names
det = arguments.detector
for bname in bands:
wvls = get_wave_range(rsr.rsr[bname][det], threshold)
print(f'name: {bname}')
print(f' wavelength: [{wvls[0]:5.3f}, {wvls[1]:5.3f}, {wvls[2]:5.3f}]')
if __name__ == "__main__":
parser = _setup_argparse()
args = parser.parse_args()
main(args)