-
Notifications
You must be signed in to change notification settings - Fork 285
/
_geos_area.py
229 lines (179 loc) · 7.71 KB
/
_geos_area.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2019 Satpy developers
#
# This file is part of satpy.
#
# satpy 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.
#
# satpy 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
# satpy. If not, see <http://www.gnu.org/licenses/>.
"""Geostationary Projection / Area computations.
This module computes properties and area definitions for geostationary
satellites. It is designed to be a common module that can be called by
all geostationary satellite readers and uses commonly-included parameters
such as the CFAC/LFAC values, satellite position, etc, to compute the
correct area definition.
"""
import numpy as np
from pyresample import geometry
def get_xy_from_linecol(line, col, offsets, factors):
"""Get the intermediate coordinates from line & col.
Intermediate coordinates are actually the instruments scanning angles.
"""
loff, coff = offsets
lfac, cfac = factors
x__ = float(col - coff) / (float(cfac) / 2 ** 16)
y__ = float(line - loff) / (float(lfac) / 2 ** 16)
return x__, y__
def make_ext(ll_x, ur_x, ll_y, ur_y, h):
"""Create the area extent from computed ll and ur.
Args:
ll_x: The lower left x coordinate (m)
ur_x: The upper right x coordinate (m)
ll_y: The lower left y coordinate (m)
ur_y: The upper right y coordinate (m)
h: The satellite altitude above the Earth's surface
Returns:
aex: An area extent for the scene
"""
aex = (np.deg2rad(ll_x) * h, np.deg2rad(ll_y) * h,
np.deg2rad(ur_x) * h, np.deg2rad(ur_y) * h)
return aex
def get_area_extent(pdict):
"""Get the area extent seen by a geostationary satellite.
Args:
pdict: A dictionary containing common parameters:
nlines: Number of lines in image
ncols: Number of columns in image
cfac: Column scaling factor
lfac: Line scaling factor
coff: Column offset factor
loff: Line offset factor
scandir: 'N2S' for standard (N->S), 'S2N' for inverse (S->N)
Returns:
aex: An area extent for the scene
"""
# count starts at 1
cols = 1 - 0.5
if pdict['scandir'] == 'S2N':
lines = 0.5 - 1
scanmult = -1
else:
lines = 1 - 0.5
scanmult = 1
# Lower left x, y scanning angles in degrees
ll_x, ll_y = get_xy_from_linecol(lines * scanmult,
cols,
(pdict['loff'], pdict['coff']),
(pdict['lfac'], pdict['cfac']))
cols += pdict['ncols']
lines += pdict['nlines']
# Upper right x, y scanning angles in degrees
ur_x, ur_y = get_xy_from_linecol(lines * scanmult,
cols,
(pdict['loff'], pdict['coff']),
(pdict['lfac'], pdict['cfac']))
if pdict['scandir'] == 'S2N':
ll_y *= -1
ur_y *= -1
# Convert degrees to radians and create area extent
aex = make_ext(ll_x=ll_x, ur_x=ur_x, ll_y=ll_y, ur_y=ur_y, h=pdict['h'])
return aex
def get_area_definition(pdict, a_ext):
"""Get the area definition for a geo-sat.
Args:
pdict: A dictionary containing common parameters:
nlines: Number of lines in image
ncols: Number of columns in image
ssp_lon: Subsatellite point longitude (deg)
a: Earth equatorial radius (m)
b: Earth polar radius (m)
h: Platform height (m)
a_name: Area name
a_desc: Area description
p_id: Projection id
a_ext: A four element tuple containing the area extent (scan angle)
for the scene in radians
Returns:
a_def: An area definition for the scene
.. note::
The AreaDefinition `proj_id` attribute is being deprecated.
"""
proj_dict = {'a': float(pdict['a']),
'b': float(pdict['b']),
'lon_0': float(pdict['ssp_lon']),
'h': float(pdict['h']),
'proj': 'geos',
'units': 'm'}
a_def = geometry.AreaDefinition(
pdict['a_name'],
pdict['a_desc'],
pdict['p_id'],
proj_dict,
int(pdict['ncols']),
int(pdict['nlines']),
a_ext)
return a_def
def sampling_to_lfac_cfac(sampling):
"""Convert angular sampling to line/column scaling factor (aka LFAC/CFAC).
Reference: `MSG Ground Segment LRIT HRIT Mission Specific Implementation`_,
Appendix E.2.
.. _MSG Ground Segment LRIT HRIT Mission Specific Implementation:
https://www-cdn.eumetsat.int/files/2020-04/pdf_ten_05057_spe_msg_lrit_hri.pdf
Args:
sampling: float
Angular sampling (rad)
Returns:
Line/column scaling factor (deg-1)
"""
return 2.0 ** 16 / np.rad2deg(sampling)
def get_geos_area_naming(input_dict):
"""Get a dictionary containing formatted AreaDefinition naming.
Args:
input_dict: dict
Dictionary with keys `platform_name`, `instrument_name`, `service_name`, `service_desc`, `resolution` .
The resolution is expected in meters.
Returns:
area_naming_dict with `area_id`, `description` keys, values are strings.
.. note::
The AreaDefinition `proj_id` attribute is being deprecated and is therefore not formatted here.
An empty string is to be used until the attribute is fully removed.
"""
area_naming_dict = {}
resolution_strings = get_resolution_and_unit_strings(input_dict['resolution'])
area_naming_dict['area_id'] = '{}_{}_{}_{}{}'.format(input_dict['platform_name'].lower(),
input_dict['instrument_name'].lower(),
input_dict['service_name'].lower(),
resolution_strings['value'],
resolution_strings['unit']
)
area_naming_dict['description'] = '{} {} {} area definition ' \
'with {} {} resolution'.format(input_dict['platform_name'].upper(),
input_dict['instrument_name'].upper(),
input_dict['service_desc'],
resolution_strings['value'],
resolution_strings['unit']
)
return area_naming_dict
def get_resolution_and_unit_strings(resolution):
"""Get the resolution value and unit as strings.
If the resolution is larger than 1000 m, use kilometer as unit. If lower, use meter.
Args:
resolution: scalar
Resolution in meters.
Returns:
Dictionary with `value` and `unit` keys, values are strings.
"""
if resolution >= 1000:
return {'value': '{:.0f}'.format(resolution*1e-3),
'unit': 'km'}
return {'value': '{:.0f}'.format(resolution),
'unit': 'm'}