tatc 3.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tatc/__init__.py +12 -0
- tatc/analysis/__init__.py +25 -0
- tatc/analysis/coverage.py +546 -0
- tatc/analysis/dop.py +137 -0
- tatc/analysis/latency.py +301 -0
- tatc/analysis/track.py +446 -0
- tatc/constants.py +42 -0
- tatc/generation/__init__.py +10 -0
- tatc/generation/cells.py +183 -0
- tatc/generation/points.py +336 -0
- tatc/resources/de421.bsp +0 -0
- tatc/schemas/__init__.py +15 -0
- tatc/schemas/architecture.py +32 -0
- tatc/schemas/instrument.py +131 -0
- tatc/schemas/orbit.py +628 -0
- tatc/schemas/point.py +74 -0
- tatc/schemas/satellite.py +389 -0
- tatc/utils.py +696 -0
- tatc-3.2.0.dist-info/LICENSE +29 -0
- tatc-3.2.0.dist-info/METADATA +158 -0
- tatc-3.2.0.dist-info/RECORD +23 -0
- tatc-3.2.0.dist-info/WHEEL +5 -0
- tatc-3.2.0.dist-info/top_level.txt +1 -0
tatc/__init__.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Defines analysis functions.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from .coverage import (
|
|
6
|
+
collect_observations,
|
|
7
|
+
collect_multi_observations,
|
|
8
|
+
aggregate_observations,
|
|
9
|
+
reduce_observations,
|
|
10
|
+
grid_observations,
|
|
11
|
+
)
|
|
12
|
+
from .track import (
|
|
13
|
+
collect_orbit_track,
|
|
14
|
+
collect_ground_track,
|
|
15
|
+
compute_ground_track,
|
|
16
|
+
OrbitCoordinate,
|
|
17
|
+
OrbitOutput,
|
|
18
|
+
)
|
|
19
|
+
from .latency import (
|
|
20
|
+
collect_downlinks,
|
|
21
|
+
compute_latencies,
|
|
22
|
+
reduce_latencies,
|
|
23
|
+
grid_latencies,
|
|
24
|
+
)
|
|
25
|
+
from .dop import compute_dop, DopMethod
|
|
@@ -0,0 +1,546 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Methods to perform coverage analysis.
|
|
4
|
+
|
|
5
|
+
@author: Paul T. Grogan <paul.grogan@asu.edu>
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from typing import List, Union
|
|
9
|
+
from datetime import datetime, timedelta
|
|
10
|
+
|
|
11
|
+
import pandas as pd
|
|
12
|
+
import numpy as np
|
|
13
|
+
import geopandas as gpd
|
|
14
|
+
from shapely import geometry as geo
|
|
15
|
+
from skyfield.api import wgs84, EarthSatellite
|
|
16
|
+
from skyfield.toposlib import GeographicPosition
|
|
17
|
+
|
|
18
|
+
from ..schemas.point import Point
|
|
19
|
+
from ..schemas.satellite import Satellite
|
|
20
|
+
from ..schemas.instrument import Instrument
|
|
21
|
+
|
|
22
|
+
from ..utils import (
|
|
23
|
+
compute_min_elevation_angle,
|
|
24
|
+
compute_max_access_time,
|
|
25
|
+
)
|
|
26
|
+
from ..constants import de421, timescale
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _get_visible_interval_series(
|
|
30
|
+
point: GeographicPosition,
|
|
31
|
+
satellite: EarthSatellite,
|
|
32
|
+
min_elevation_angle: float,
|
|
33
|
+
start: datetime,
|
|
34
|
+
end: datetime,
|
|
35
|
+
) -> pd.Series:
|
|
36
|
+
"""
|
|
37
|
+
Get the series of visible intervals based on altitude angle constraints.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
point (akyfield.toposlib.GeographicPosition): Point to observe.
|
|
41
|
+
satellite (skyfield.api.EarthSatellite): Satellite doing the observation.
|
|
42
|
+
min_elevation_angle (float): Minimum elevation angle (degrees) for valid observation.
|
|
43
|
+
start (datetime.datetime): Start of analysis period.
|
|
44
|
+
end (datetime.datetime): End of analysis period.
|
|
45
|
+
|
|
46
|
+
Returns:
|
|
47
|
+
pandas.Series: Series of observation intervals.
|
|
48
|
+
"""
|
|
49
|
+
# define starting and ending points
|
|
50
|
+
t_0 = timescale.from_datetime(start)
|
|
51
|
+
t_1 = timescale.from_datetime(end)
|
|
52
|
+
# compute the initial satellite altitude
|
|
53
|
+
satellite_altitude = wgs84.geographic_position_of(satellite.at(t_0)).elevation.m
|
|
54
|
+
# compute the maximum access time to filter bad data
|
|
55
|
+
max_access_time = timedelta(
|
|
56
|
+
seconds=compute_max_access_time(satellite_altitude, min_elevation_angle)
|
|
57
|
+
)
|
|
58
|
+
# find the set of observation events
|
|
59
|
+
times, events = satellite.find_events(
|
|
60
|
+
point, t_0, t_1, altitude_degrees=min_elevation_angle
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
# build the observation periods
|
|
64
|
+
obs_periods = []
|
|
65
|
+
if len(events) > 0 and np.all(events == 1):
|
|
66
|
+
# if all events are type 1 (culminate), create a period from start to end
|
|
67
|
+
obs_periods += [pd.Interval(left=pd.Timestamp(start), right=pd.Timestamp(end))]
|
|
68
|
+
elif len(events) > 0:
|
|
69
|
+
# otherwise, match rise/set events
|
|
70
|
+
rises = times[events == 0]
|
|
71
|
+
sets = times[events == 2]
|
|
72
|
+
if (
|
|
73
|
+
len(sets) > 0
|
|
74
|
+
and (len(rises) == 0 or sets[0].utc_datetime() < rises[0].utc_datetime())
|
|
75
|
+
and start < sets[0].utc_datetime()
|
|
76
|
+
):
|
|
77
|
+
# if first event is a set, create a period from the start
|
|
78
|
+
obs_periods += [
|
|
79
|
+
pd.Interval(
|
|
80
|
+
left=pd.Timestamp(start), right=pd.Timestamp(sets[0].utc_datetime())
|
|
81
|
+
)
|
|
82
|
+
]
|
|
83
|
+
# create an observation period to match with each rise event if
|
|
84
|
+
# there is a following set event within twice the maximum access time
|
|
85
|
+
obs_periods += [
|
|
86
|
+
pd.Interval(
|
|
87
|
+
left=pd.Timestamp(rise.utc_datetime()),
|
|
88
|
+
right=pd.Timestamp(
|
|
89
|
+
sets[
|
|
90
|
+
np.logical_and(
|
|
91
|
+
rise.utc_datetime() < sets.utc_datetime(),
|
|
92
|
+
sets.utc_datetime()
|
|
93
|
+
< rise.utc_datetime() + 2 * max_access_time,
|
|
94
|
+
)
|
|
95
|
+
][0].utc_datetime()
|
|
96
|
+
),
|
|
97
|
+
)
|
|
98
|
+
for rise in rises
|
|
99
|
+
if np.any(
|
|
100
|
+
np.logical_and(
|
|
101
|
+
rise.utc_datetime() < sets.utc_datetime(),
|
|
102
|
+
sets.utc_datetime() < rise.utc_datetime() + 2 * max_access_time,
|
|
103
|
+
)
|
|
104
|
+
)
|
|
105
|
+
]
|
|
106
|
+
if (
|
|
107
|
+
len(rises) > 0
|
|
108
|
+
and (len(sets) == 0 or rises[-1].utc_datetime() > sets[-1].utc_datetime())
|
|
109
|
+
and rises[-1].utc_datetime() < end
|
|
110
|
+
):
|
|
111
|
+
# if last event is a rise, create a period to the end
|
|
112
|
+
obs_periods += [
|
|
113
|
+
pd.Interval(
|
|
114
|
+
left=pd.Timestamp(rises[-1].utc_datetime()), right=pd.Timestamp(end)
|
|
115
|
+
)
|
|
116
|
+
]
|
|
117
|
+
return pd.Series(obs_periods, dtype="interval")
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _get_satellite_altaz_series(
|
|
121
|
+
observations: gpd.GeoDataFrame, satellite: EarthSatellite
|
|
122
|
+
) -> pd.Series:
|
|
123
|
+
"""
|
|
124
|
+
Get a series with the satellite altitude/azimuth for each observation.
|
|
125
|
+
|
|
126
|
+
Args:
|
|
127
|
+
observations (geopandas.GeoDataFrame): Data frame of observation records.
|
|
128
|
+
satellite (skyfield.api.EarthSatellite): Satellite doing the observation.
|
|
129
|
+
|
|
130
|
+
Returns:
|
|
131
|
+
pandas.Series: Series of altitude-azimuth objects associated with observations.
|
|
132
|
+
"""
|
|
133
|
+
sat_altaz = observations.apply(
|
|
134
|
+
lambda r: (satellite - wgs84.latlon(r.geometry.y, r.geometry.x, r.geometry.z))
|
|
135
|
+
.at(timescale.from_datetime(r.epoch))
|
|
136
|
+
.altaz(),
|
|
137
|
+
axis=1,
|
|
138
|
+
)
|
|
139
|
+
return pd.Series(sat_altaz, dtype="object")
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def _get_satellite_sunlit_series(
|
|
143
|
+
observations: gpd.GeoDataFrame, satellite: EarthSatellite
|
|
144
|
+
) -> pd.Series:
|
|
145
|
+
"""
|
|
146
|
+
Get a series with the satellite sunlit condition for each observation.
|
|
147
|
+
|
|
148
|
+
Args:
|
|
149
|
+
observations (geopandas.GeoDataFrame): Data frame of observation records.
|
|
150
|
+
satellite (EarthSatellite): Satellite doing the observation.
|
|
151
|
+
|
|
152
|
+
Returns:
|
|
153
|
+
pandas.Series: Series of booleans associated with observations.
|
|
154
|
+
"""
|
|
155
|
+
sat_sunlit = observations.apply(
|
|
156
|
+
lambda r: satellite.at(timescale.from_datetime(r.epoch)).is_sunlit(de421),
|
|
157
|
+
axis=1,
|
|
158
|
+
)
|
|
159
|
+
return pd.Series(sat_sunlit, dtype="bool")
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def _get_solar_altaz_series(observations: gpd.GeoDataFrame) -> pd.Series:
|
|
163
|
+
"""
|
|
164
|
+
Get a series with the solar altitude/azimuth for each observation.
|
|
165
|
+
|
|
166
|
+
Args:
|
|
167
|
+
observations (geopandas.GeoDataFrame): Data frame of observation records.
|
|
168
|
+
|
|
169
|
+
Returns:
|
|
170
|
+
pandas.Series: Series of altitude-azimuth objects associated with observations.
|
|
171
|
+
"""
|
|
172
|
+
sun_altaz = observations.apply(
|
|
173
|
+
lambda r: (
|
|
174
|
+
de421["earth"] + wgs84.latlon(r.geometry.y, r.geometry.x, r.geometry.z)
|
|
175
|
+
)
|
|
176
|
+
.at(timescale.from_datetime(r.epoch))
|
|
177
|
+
.observe(de421["sun"])
|
|
178
|
+
.apparent()
|
|
179
|
+
.altaz(),
|
|
180
|
+
axis=1,
|
|
181
|
+
)
|
|
182
|
+
return pd.Series(sun_altaz, dtype="object")
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def _get_solar_time_series(observations: gpd.GeoDataFrame) -> pd.Series:
|
|
186
|
+
"""
|
|
187
|
+
Get a series with the local solar time for each observation.
|
|
188
|
+
|
|
189
|
+
Args:
|
|
190
|
+
observations (geopandas.GeoDataFrame): Data frame of observation records.
|
|
191
|
+
|
|
192
|
+
Returns:
|
|
193
|
+
pandas.Series: Series of floats (local solar time in hours) associated with observations.
|
|
194
|
+
"""
|
|
195
|
+
solar_time = observations.apply(
|
|
196
|
+
lambda r: (
|
|
197
|
+
de421["earth"] + wgs84.latlon(r.geometry.y, r.geometry.x, r.geometry.z)
|
|
198
|
+
)
|
|
199
|
+
.at(timescale.from_datetime(r.epoch))
|
|
200
|
+
.observe(de421["sun"])
|
|
201
|
+
.apparent()
|
|
202
|
+
.hadec()[0]
|
|
203
|
+
.hours
|
|
204
|
+
+ 12,
|
|
205
|
+
axis=1,
|
|
206
|
+
)
|
|
207
|
+
return pd.Series(solar_time, dtype="float")
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def _get_access_series(observations: gpd.GeoDataFrame) -> pd.Series:
|
|
211
|
+
"""
|
|
212
|
+
Get a series with the access time for each observation.
|
|
213
|
+
|
|
214
|
+
Args:
|
|
215
|
+
observations (geopandas.GeoDataFrame): Data frame of observation records.
|
|
216
|
+
|
|
217
|
+
Returns:
|
|
218
|
+
pandas.Series: Series of timedeltas measuring access duration of each observation.
|
|
219
|
+
"""
|
|
220
|
+
# compute the access time for the observation (end - start)
|
|
221
|
+
return observations["end"] - observations["start"]
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def _get_revisit_series(observations: gpd.GeoDataFrame) -> pd.Series:
|
|
225
|
+
"""
|
|
226
|
+
Get a series with the revisit times for each observation.
|
|
227
|
+
|
|
228
|
+
Args:
|
|
229
|
+
observations (geopandas.GeoDataFrame): Data frame of observation records.
|
|
230
|
+
|
|
231
|
+
Returns:
|
|
232
|
+
pandas.Series: Series of timedeltas measuring revisit duration for each observation.
|
|
233
|
+
"""
|
|
234
|
+
# compute the revisit time for each observation (previous end - start)
|
|
235
|
+
return observations["start"] - observations["end"].shift()
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def _get_empty_coverage_frame(omit_solar: bool) -> gpd.GeoDataFrame:
|
|
239
|
+
"""
|
|
240
|
+
Gets an empty data frame for coverage analysis results.
|
|
241
|
+
|
|
242
|
+
Returns:
|
|
243
|
+
geopandas.GeoDataFrame: Empty data frame.
|
|
244
|
+
"""
|
|
245
|
+
columns = {
|
|
246
|
+
"point_id": pd.Series([], dtype="int"),
|
|
247
|
+
"geometry": pd.Series([], dtype="object"),
|
|
248
|
+
"satellite": pd.Series([], dtype="str"),
|
|
249
|
+
"instrument": pd.Series([], dtype="str"),
|
|
250
|
+
"start": pd.Series([], dtype="datetime64[ns, utc]"),
|
|
251
|
+
"epoch": pd.Series([], dtype="datetime64[ns, utc]"),
|
|
252
|
+
"end": pd.Series([], dtype="datetime64[ns, utc]"),
|
|
253
|
+
"sat_alt": pd.Series(dtype="float"),
|
|
254
|
+
"sat_az": pd.Series(dtype="float"),
|
|
255
|
+
}
|
|
256
|
+
if not omit_solar:
|
|
257
|
+
columns = {
|
|
258
|
+
**columns,
|
|
259
|
+
**{
|
|
260
|
+
"sat_sunlit": pd.Series(dtype="bool"),
|
|
261
|
+
"solar_alt": pd.Series(dtype="float"),
|
|
262
|
+
"solar_az": pd.Series(dtype="float"),
|
|
263
|
+
"solar_time": pd.Series(dtype="float"),
|
|
264
|
+
},
|
|
265
|
+
}
|
|
266
|
+
return gpd.GeoDataFrame(columns, crs="EPSG:4326")
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def collect_observations(
|
|
270
|
+
point: Point,
|
|
271
|
+
satellite: Satellite,
|
|
272
|
+
instrument: Instrument,
|
|
273
|
+
start: datetime,
|
|
274
|
+
end: datetime,
|
|
275
|
+
omit_solar: bool = True,
|
|
276
|
+
) -> gpd.GeoDataFrame:
|
|
277
|
+
"""
|
|
278
|
+
Collect single satellite observations of a geodetic point of interest.
|
|
279
|
+
|
|
280
|
+
Args:
|
|
281
|
+
point (Point): The ground point of interest.
|
|
282
|
+
satellite (Satellite): The observing satellite.
|
|
283
|
+
instrument (Instrument): The observing instrument.
|
|
284
|
+
start (datetime.datetime): Start of analysis period.
|
|
285
|
+
end (datetime.datetime): End of analysis period.
|
|
286
|
+
omit_solar (bool): `True`, to omit solar angles to improve
|
|
287
|
+
computational efficiency; otherwise `False`.
|
|
288
|
+
|
|
289
|
+
Returns:
|
|
290
|
+
geopandas.GeoDataFrame: The data frame with recorded observations.
|
|
291
|
+
"""
|
|
292
|
+
# build a topocentric point at the designated geodetic point
|
|
293
|
+
topos = wgs84.latlon(point.latitude, point.longitude, point.elevation)
|
|
294
|
+
# convert orbit to tle
|
|
295
|
+
orbit = satellite.orbit.to_tle()
|
|
296
|
+
# construct a satellite for propagation
|
|
297
|
+
sat = EarthSatellite(orbit.tle[0], orbit.tle[1], satellite.name)
|
|
298
|
+
# compute the initial satellite altitude
|
|
299
|
+
satellite_altitude = wgs84.geographic_position_of(
|
|
300
|
+
sat.at(timescale.from_datetime(start))
|
|
301
|
+
).elevation.m
|
|
302
|
+
# compute the minimum altitude angle required for observation
|
|
303
|
+
min_elevation_angle = compute_min_elevation_angle(
|
|
304
|
+
satellite_altitude,
|
|
305
|
+
instrument.field_of_regard,
|
|
306
|
+
)
|
|
307
|
+
records = [
|
|
308
|
+
{
|
|
309
|
+
"point_id": point.id,
|
|
310
|
+
"geometry": geo.Point(point.longitude, point.latitude, point.elevation),
|
|
311
|
+
"satellite": satellite.name,
|
|
312
|
+
"instrument": instrument.name,
|
|
313
|
+
"start": (
|
|
314
|
+
period.left
|
|
315
|
+
if not instrument.access_time_fixed
|
|
316
|
+
else period.mid - instrument.min_access_time / 2
|
|
317
|
+
),
|
|
318
|
+
"end": (
|
|
319
|
+
period.right
|
|
320
|
+
if not instrument.access_time_fixed
|
|
321
|
+
else period.mid + instrument.min_access_time / 2
|
|
322
|
+
),
|
|
323
|
+
"epoch": period.mid,
|
|
324
|
+
}
|
|
325
|
+
for period in _get_visible_interval_series(
|
|
326
|
+
topos, sat, min_elevation_angle, start, end
|
|
327
|
+
)
|
|
328
|
+
if (
|
|
329
|
+
instrument.min_access_time <= period.right - period.left
|
|
330
|
+
and instrument.is_valid_observation(
|
|
331
|
+
sat, timescale.from_datetime(period.mid)
|
|
332
|
+
)
|
|
333
|
+
)
|
|
334
|
+
]
|
|
335
|
+
|
|
336
|
+
# build the dataframe
|
|
337
|
+
if len(records) > 0:
|
|
338
|
+
gdf = gpd.GeoDataFrame(records, crs="EPSG:4326")
|
|
339
|
+
# append satellite altitude/azimuth columns
|
|
340
|
+
sat_altaz = _get_satellite_altaz_series(gdf, sat)
|
|
341
|
+
gdf["sat_alt"] = sat_altaz.apply(lambda r: r[0].degrees)
|
|
342
|
+
gdf["sat_az"] = sat_altaz.apply(lambda r: r[1].degrees)
|
|
343
|
+
if not omit_solar:
|
|
344
|
+
# append satellite sunlit column
|
|
345
|
+
gdf["sat_sunlit"] = _get_satellite_sunlit_series(gdf, sat)
|
|
346
|
+
# append solar altitude/azimuth columns
|
|
347
|
+
sun_altaz = _get_solar_altaz_series(gdf)
|
|
348
|
+
gdf["sun_alt"] = sun_altaz.apply(lambda r: r[0].degrees)
|
|
349
|
+
gdf["sun_az"] = sun_altaz.apply(lambda r: r[1].degrees)
|
|
350
|
+
# append local solar time column
|
|
351
|
+
gdf["solar_time"] = _get_solar_time_series(gdf)
|
|
352
|
+
else:
|
|
353
|
+
gdf = _get_empty_coverage_frame(omit_solar)
|
|
354
|
+
return gdf
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
def collect_multi_observations(
|
|
358
|
+
point: Point,
|
|
359
|
+
satellites: Union[Satellite, List[Satellite]],
|
|
360
|
+
start: datetime,
|
|
361
|
+
end: datetime,
|
|
362
|
+
omit_solar: bool = True,
|
|
363
|
+
) -> gpd.GeoDataFrame:
|
|
364
|
+
"""
|
|
365
|
+
Collect multiple satellite observations of a geodetic point of interest.
|
|
366
|
+
|
|
367
|
+
Args:
|
|
368
|
+
point (Point): The ground point of interest.
|
|
369
|
+
satellites (Satellite or List[Satellite]): The observing satellite(s).
|
|
370
|
+
start (datetime.datetime): Start of analysis period.
|
|
371
|
+
end (datetime.datetime): End of analysis period.
|
|
372
|
+
omit_solar (bool): `True`, to omit solar angles to improve
|
|
373
|
+
computational efficiency; otherwise `False`.
|
|
374
|
+
|
|
375
|
+
Returns:
|
|
376
|
+
geopandas.GeoDataFrame: The data frame with all recorded observations.
|
|
377
|
+
"""
|
|
378
|
+
gdfs = [
|
|
379
|
+
collect_observations(point, satellite, instrument, start, end, omit_solar)
|
|
380
|
+
for constellation in (
|
|
381
|
+
satellites if isinstance(satellites, list) else [satellites]
|
|
382
|
+
)
|
|
383
|
+
for satellite in (constellation.generate_members())
|
|
384
|
+
for instrument in satellite.instruments
|
|
385
|
+
]
|
|
386
|
+
# concatenate into one data frame, sort by start time, and re-index
|
|
387
|
+
return pd.concat(gdfs).sort_values("start").reset_index(drop=True)
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
def _get_empty_aggregate_frame() -> gpd.GeoDataFrame:
|
|
391
|
+
"""
|
|
392
|
+
Gets an empty data frame for aggregated coverage analysis results.
|
|
393
|
+
|
|
394
|
+
Returns:
|
|
395
|
+
geopandas.GeoDataFrame: Empty data frame.
|
|
396
|
+
"""
|
|
397
|
+
columns = {
|
|
398
|
+
"point_id": pd.Series([], dtype="int"),
|
|
399
|
+
"geometry": pd.Series([], dtype="object"),
|
|
400
|
+
"satellite": pd.Series([], dtype="str"),
|
|
401
|
+
"instrument": pd.Series([], dtype="str"),
|
|
402
|
+
"start": pd.Series([], dtype="datetime64[ns, utc]"),
|
|
403
|
+
"epoch": pd.Series([], dtype="datetime64[ns, utc]"),
|
|
404
|
+
"end": pd.Series([], dtype="datetime64[ns, utc]"),
|
|
405
|
+
}
|
|
406
|
+
return gpd.GeoDataFrame(columns, crs="EPSG:4326")
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
def aggregate_observations(observations: gpd.GeoDataFrame) -> gpd.GeoDataFrame:
|
|
410
|
+
"""
|
|
411
|
+
Aggregate constellation observations. Interleaves observations by multiple
|
|
412
|
+
satellites to compute aggregate performance metrics including access
|
|
413
|
+
(observation duration) and revisit (duration between observations).
|
|
414
|
+
|
|
415
|
+
Args:
|
|
416
|
+
observations (geopandas.GeoDataFrame): The collected observations.
|
|
417
|
+
|
|
418
|
+
Returns:
|
|
419
|
+
geopandas.GeoDataFrame: The data frame with aggregated observations.
|
|
420
|
+
"""
|
|
421
|
+
if observations.empty:
|
|
422
|
+
return _get_empty_aggregate_frame()
|
|
423
|
+
gdfs = []
|
|
424
|
+
# split into constituent data frames based on point_id
|
|
425
|
+
for _, gdf in observations.groupby("point_id"):
|
|
426
|
+
# sort the values by start datetime
|
|
427
|
+
gdf = gdf.sort_values("start")
|
|
428
|
+
# assign the observation group number based on overlapping start/end times
|
|
429
|
+
gdf["obs"] = (gdf["start"] > gdf["end"].shift().cummax()).cumsum()
|
|
430
|
+
# perform the aggregation to group overlapping observations
|
|
431
|
+
gdf = gdf.dissolve(
|
|
432
|
+
"obs",
|
|
433
|
+
aggfunc={
|
|
434
|
+
"point_id": "first",
|
|
435
|
+
"satellite": ", ".join,
|
|
436
|
+
"instrument": ", ".join,
|
|
437
|
+
"start": "min",
|
|
438
|
+
"epoch": "mean",
|
|
439
|
+
"end": "max",
|
|
440
|
+
},
|
|
441
|
+
)
|
|
442
|
+
# compute access and revisit metrics
|
|
443
|
+
gdf["access"] = _get_access_series(gdf)
|
|
444
|
+
gdf["revisit"] = _get_revisit_series(gdf)
|
|
445
|
+
# append to the list of data frames
|
|
446
|
+
gdfs.append(gdf)
|
|
447
|
+
# return a concatenated data frame and re-index
|
|
448
|
+
return pd.concat(gdfs).reset_index(drop=True)
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
def _get_empty_reduce_frame() -> gpd.GeoDataFrame:
|
|
452
|
+
"""
|
|
453
|
+
Gets an empty data frame for reduced coverage analysis results.
|
|
454
|
+
|
|
455
|
+
Returns:
|
|
456
|
+
geopandas.GeoDataFrame: Empty data frame.
|
|
457
|
+
"""
|
|
458
|
+
columns = {
|
|
459
|
+
"point_id": pd.Series([], dtype="int"),
|
|
460
|
+
"geometry": pd.Series([], dtype="object"),
|
|
461
|
+
"access": pd.Series([], dtype="timedelta64[ns]"),
|
|
462
|
+
"revisit": pd.Series([], dtype="timedelta64[ns]"),
|
|
463
|
+
"samples": pd.Series([], dtype="int"),
|
|
464
|
+
}
|
|
465
|
+
return gpd.GeoDataFrame(columns, crs="EPSG:4326")
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
def reduce_observations(aggregated_observations: gpd.GeoDataFrame) -> gpd.GeoDataFrame:
|
|
469
|
+
"""
|
|
470
|
+
Reduce constellation observations. Computes descriptive statistics for each
|
|
471
|
+
geodetic point of interest contained in aggregated observations.
|
|
472
|
+
|
|
473
|
+
Args:
|
|
474
|
+
aggregated_observations (geopandas.GeoDataFrame): The aggregated observations.
|
|
475
|
+
|
|
476
|
+
Returns:
|
|
477
|
+
geopandas.GeoDataFrame: The data frame with reduced observations.
|
|
478
|
+
"""
|
|
479
|
+
if aggregated_observations.empty:
|
|
480
|
+
return _get_empty_reduce_frame()
|
|
481
|
+
# operate on a copy of the data frame
|
|
482
|
+
gdf = aggregated_observations.copy()
|
|
483
|
+
# convert access and revisit to numeric values before aggregation
|
|
484
|
+
gdf["access"] = gdf["access"] / timedelta(seconds=1)
|
|
485
|
+
gdf["revisit"] = gdf["revisit"] / timedelta(seconds=1)
|
|
486
|
+
# assign each record to one observation
|
|
487
|
+
gdf["samples"] = 1
|
|
488
|
+
# perform the aggregation operation
|
|
489
|
+
gdf = gdf.dissolve(
|
|
490
|
+
"point_id",
|
|
491
|
+
aggfunc={
|
|
492
|
+
"access": "mean",
|
|
493
|
+
"revisit": "mean",
|
|
494
|
+
"samples": "sum",
|
|
495
|
+
},
|
|
496
|
+
).reset_index()
|
|
497
|
+
# convert access and revisit from numeric values after aggregation
|
|
498
|
+
gdf["access"] = gdf["access"].apply(lambda t: timedelta(seconds=t))
|
|
499
|
+
gdf["revisit"] = gdf["revisit"].apply(
|
|
500
|
+
lambda t: pd.NaT if pd.isna(t) else timedelta(seconds=t)
|
|
501
|
+
)
|
|
502
|
+
return gdf
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
def grid_observations(
|
|
506
|
+
reduced_observations: gpd.GeoDataFrame, cells: gpd.GeoDataFrame
|
|
507
|
+
) -> gpd.GeoDataFrame:
|
|
508
|
+
"""
|
|
509
|
+
Grid reduced observations to cells.
|
|
510
|
+
|
|
511
|
+
Args:
|
|
512
|
+
reduced_observations (geopandas.GeoDataFrame): The reduced observations.
|
|
513
|
+
cells (geopandas.GeoDataFrame): The cell specification.
|
|
514
|
+
|
|
515
|
+
Returns:
|
|
516
|
+
geopandas.GeoDataFrame: The data frame with gridded observations.
|
|
517
|
+
"""
|
|
518
|
+
if reduced_observations.empty:
|
|
519
|
+
gdf = cells.copy()
|
|
520
|
+
gdf["samples"] = 0
|
|
521
|
+
gdf["access"] = None
|
|
522
|
+
gdf["revisit"] = None
|
|
523
|
+
return gdf
|
|
524
|
+
# operate on a copy of the data frame
|
|
525
|
+
gdf = reduced_observations.copy()
|
|
526
|
+
# convert access and revisit to numeric values before aggregation
|
|
527
|
+
gdf["access"] = gdf["access"] / timedelta(seconds=1)
|
|
528
|
+
gdf["revisit"] = gdf["revisit"] / timedelta(seconds=1)
|
|
529
|
+
gdf = (
|
|
530
|
+
cells.sjoin(gdf, how="inner", predicate="contains")
|
|
531
|
+
.dissolve(
|
|
532
|
+
by="cell_id",
|
|
533
|
+
aggfunc={
|
|
534
|
+
"samples": "sum",
|
|
535
|
+
"access": lambda r: np.average(r, weights=gdf.loc[r.index, "samples"]),
|
|
536
|
+
"revisit": lambda r: np.average(r, weights=gdf.loc[r.index, "samples"]),
|
|
537
|
+
},
|
|
538
|
+
)
|
|
539
|
+
.reset_index()
|
|
540
|
+
)
|
|
541
|
+
# convert access and revisit from numeric values after aggregation
|
|
542
|
+
gdf["access"] = gdf["access"].apply(lambda t: timedelta(seconds=t))
|
|
543
|
+
gdf["revisit"] = gdf["revisit"].apply(
|
|
544
|
+
lambda t: pd.NaT if pd.isna(t) else timedelta(seconds=t)
|
|
545
|
+
)
|
|
546
|
+
return gdf
|