Skip to content

Commit b66a5f3

Browse files
update predicts parameter handling
1 parent fc3be0c commit b66a5f3

File tree

4 files changed

+29
-28
lines changed

4 files changed

+29
-28
lines changed

packetraven/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from packetraven.packets import APRSPacket
2727
from packetraven.packets.tracks import APRSTrack, LocationPacketTrack
2828
from packetraven.packets.writer import write_packet_tracks
29-
from packetraven.predicts import get_predictions, PredictionAPIURL, PredictionError
29+
from packetraven.predicts import packet_track_predictions, PredictionAPIURL, PredictionError
3030
from packetraven.utilities import (
3131
ensure_datetime_timezone,
3232
get_logger,
@@ -429,7 +429,7 @@ def main():
429429
if prediction_filename is not None:
430430
try:
431431
predictions.update(
432-
get_predictions(
432+
packet_track_predictions(
433433
packet_tracks,
434434
**{
435435
key.replace('prediction_', ''): value

packetraven/gui/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from packetraven.packets import APRSPacket, LocationPacket
2222
from packetraven.packets.tracks import LocationPacketTrack, PredictedTrajectory
2323
from packetraven.packets.writer import write_packet_tracks
24-
from packetraven.predicts import get_predictions, PredictionError
24+
from packetraven.predicts import packet_track_predictions, PredictionError
2525
from packetraven.utilities import get_logger
2626

2727

@@ -773,7 +773,7 @@ async def retrieve_packets(self):
773773
if self.toggles['prediction_file']:
774774
try:
775775
self.__predictions.update(
776-
get_predictions(
776+
packet_track_predictions(
777777
self.packet_tracks,
778778
**{
779779
key.replace('prediction_', ''): value

packetraven/packets/tracks.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
from copy import copy
22
from datetime import datetime, timedelta
33
from os import PathLike
4-
from typing import Iterable, List, Union
4+
from typing import Any, Dict, Iterable, List, Union
55

66
from dateutil.parser import parse as parse_date
77
import geojson
88
import numpy
99
from pandas import DataFrame
1010
from pyproj import CRS
11-
import typepigeon
1211

1312
from packetraven.model import (
1413
FREEFALL_DESCENT_RATE,
@@ -425,34 +424,26 @@ class PredictedTrajectory(LocationPacketTrack):
425424
def __init__(
426425
self,
427426
packets: List[LocationPacket],
428-
prediction_time: datetime,
429-
dataset_time: datetime,
427+
parameters: Dict[str, Any],
428+
metadata: Dict[str, Any],
430429
crs: CRS = None,
431430
**attributes,
432431
):
433432
"""
434433
:param packets: iterable of packets
435-
:param prediction_time: time of completed prediction
436-
:param dataset_time: time of last dataset update
434+
:param parameters: prediction parameters
435+
:param metadata: prediction completion metadata
437436
:param crs: coordinate reference system to use
438437
"""
439438

440439
if 'name' not in attributes:
441440
attributes['name'] = 'predicted trajectory'
442441

443-
if not isinstance(prediction_time, datetime):
444-
prediction_time = typepigeon.convert_value(prediction_time, datetime)
445-
446-
if not isinstance(dataset_time, datetime):
447-
dataset_time = typepigeon.convert_value(dataset_time, datetime)
442+
self.__parameters = parameters
443+
self.__metadata = metadata
448444

449445
LocationPacketTrack.__init__(
450-
self,
451-
packets=packets,
452-
prediction_time=prediction_time,
453-
dataset_time=dataset_time,
454-
crs=crs,
455-
**attributes,
446+
self, packets=packets, crs=crs, **attributes,
456447
)
457448

458449
@property
@@ -470,3 +461,11 @@ def from_file(cls, filename: PathLike) -> List['PredictedTrajectory']:
470461
)
471462

472463
return tracks
464+
465+
@property
466+
def parameters(self) -> Dict[str, Any]:
467+
return self.__parameters
468+
469+
@property
470+
def metadata(self) -> Dict[str, Any]:
471+
return self.__metadata

packetraven/predicts.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,10 @@ def get(self) -> Dict[str, Any]:
278278
try:
279279
error = response.json()['error']['description']
280280
except:
281-
error = ''
282-
raise ConnectionError(f'connection raised error {response.status_code} for {response.url} - {error}')
281+
error = 'no message'
282+
raise ConnectionError(
283+
f'connection raised error {response.status_code} for {response.url} - {error}'
284+
)
283285

284286
@property
285287
def predict(self) -> PredictedTrajectory:
@@ -305,8 +307,8 @@ def predict(self) -> PredictedTrajectory:
305307
)
306308
for point in points
307309
],
308-
prediction_time=response['metadata']['complete_datetime'],
309-
dataset_time=response['request']['dataset'],
310+
parameters=response['request'],
311+
metadata=response['metadata'],
310312
)
311313
else:
312314
raise PredictionError(response['error']['description'])
@@ -388,7 +390,7 @@ def query(self) -> Dict[str, Any]:
388390
return query
389391

390392

391-
def get_predictions(
393+
def packet_track_predictions(
392394
packet_tracks: Dict[str, LocationPacketTrack],
393395
start_location: Tuple[float, float, float] = None,
394396
start_time: datetime = None,
@@ -475,7 +477,7 @@ def get_predictions(
475477
if float_altitude is not None and not packet_track.falling:
476478
packets_at_float_altitude = packet_track[
477479
numpy.abs(float_altitude - packet_track.altitudes) < float_altitude_uncertainty
478-
]
480+
]
479481
if (
480482
len(packets_at_float_altitude) > 0
481483
and packets_at_float_altitude[-1].time == packet_track.times[-1]
@@ -485,7 +487,7 @@ def get_predictions(
485487
elif packet_track.ascent_rates[-1] >= 0:
486488
prediction_float_start_time = prediction_start_time + timedelta(
487489
seconds=(float_altitude - prediction_start_location[2])
488-
/ prediction_ascent_rate
490+
/ prediction_ascent_rate
489491
)
490492
descent_only = False
491493
else:

0 commit comments

Comments
 (0)