Skip to content

Commit

Permalink
update predicts parameter handling
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharyburnett committed Mar 5, 2022
1 parent fc3be0c commit b66a5f3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 28 deletions.
4 changes: 2 additions & 2 deletions packetraven/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from packetraven.packets import APRSPacket
from packetraven.packets.tracks import APRSTrack, LocationPacketTrack
from packetraven.packets.writer import write_packet_tracks
from packetraven.predicts import get_predictions, PredictionAPIURL, PredictionError
from packetraven.predicts import packet_track_predictions, PredictionAPIURL, PredictionError
from packetraven.utilities import (
ensure_datetime_timezone,
get_logger,
Expand Down Expand Up @@ -429,7 +429,7 @@ def main():
if prediction_filename is not None:
try:
predictions.update(
get_predictions(
packet_track_predictions(
packet_tracks,
**{
key.replace('prediction_', ''): value
Expand Down
4 changes: 2 additions & 2 deletions packetraven/gui/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from packetraven.packets import APRSPacket, LocationPacket
from packetraven.packets.tracks import LocationPacketTrack, PredictedTrajectory
from packetraven.packets.writer import write_packet_tracks
from packetraven.predicts import get_predictions, PredictionError
from packetraven.predicts import packet_track_predictions, PredictionError
from packetraven.utilities import get_logger


Expand Down Expand Up @@ -773,7 +773,7 @@ async def retrieve_packets(self):
if self.toggles['prediction_file']:
try:
self.__predictions.update(
get_predictions(
packet_track_predictions(
self.packet_tracks,
**{
key.replace('prediction_', ''): value
Expand Down
33 changes: 16 additions & 17 deletions packetraven/packets/tracks.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from copy import copy
from datetime import datetime, timedelta
from os import PathLike
from typing import Iterable, List, Union
from typing import Any, Dict, Iterable, List, Union

from dateutil.parser import parse as parse_date
import geojson
import numpy
from pandas import DataFrame
from pyproj import CRS
import typepigeon

from packetraven.model import (
FREEFALL_DESCENT_RATE,
Expand Down Expand Up @@ -425,34 +424,26 @@ class PredictedTrajectory(LocationPacketTrack):
def __init__(
self,
packets: List[LocationPacket],
prediction_time: datetime,
dataset_time: datetime,
parameters: Dict[str, Any],
metadata: Dict[str, Any],
crs: CRS = None,
**attributes,
):
"""
:param packets: iterable of packets
:param prediction_time: time of completed prediction
:param dataset_time: time of last dataset update
:param parameters: prediction parameters
:param metadata: prediction completion metadata
:param crs: coordinate reference system to use
"""

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

if not isinstance(prediction_time, datetime):
prediction_time = typepigeon.convert_value(prediction_time, datetime)

if not isinstance(dataset_time, datetime):
dataset_time = typepigeon.convert_value(dataset_time, datetime)
self.__parameters = parameters
self.__metadata = metadata

LocationPacketTrack.__init__(
self,
packets=packets,
prediction_time=prediction_time,
dataset_time=dataset_time,
crs=crs,
**attributes,
self, packets=packets, crs=crs, **attributes,
)

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

return tracks

@property
def parameters(self) -> Dict[str, Any]:
return self.__parameters

@property
def metadata(self) -> Dict[str, Any]:
return self.__metadata
16 changes: 9 additions & 7 deletions packetraven/predicts.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,10 @@ def get(self) -> Dict[str, Any]:
try:
error = response.json()['error']['description']
except:
error = ''
raise ConnectionError(f'connection raised error {response.status_code} for {response.url} - {error}')
error = 'no message'
raise ConnectionError(
f'connection raised error {response.status_code} for {response.url} - {error}'
)

@property
def predict(self) -> PredictedTrajectory:
Expand All @@ -305,8 +307,8 @@ def predict(self) -> PredictedTrajectory:
)
for point in points
],
prediction_time=response['metadata']['complete_datetime'],
dataset_time=response['request']['dataset'],
parameters=response['request'],
metadata=response['metadata'],
)
else:
raise PredictionError(response['error']['description'])
Expand Down Expand Up @@ -388,7 +390,7 @@ def query(self) -> Dict[str, Any]:
return query


def get_predictions(
def packet_track_predictions(
packet_tracks: Dict[str, LocationPacketTrack],
start_location: Tuple[float, float, float] = None,
start_time: datetime = None,
Expand Down Expand Up @@ -475,7 +477,7 @@ def get_predictions(
if float_altitude is not None and not packet_track.falling:
packets_at_float_altitude = packet_track[
numpy.abs(float_altitude - packet_track.altitudes) < float_altitude_uncertainty
]
]
if (
len(packets_at_float_altitude) > 0
and packets_at_float_altitude[-1].time == packet_track.times[-1]
Expand All @@ -485,7 +487,7 @@ def get_predictions(
elif packet_track.ascent_rates[-1] >= 0:
prediction_float_start_time = prediction_start_time + timedelta(
seconds=(float_altitude - prediction_start_location[2])
/ prediction_ascent_rate
/ prediction_ascent_rate
)
descent_only = False
else:
Expand Down

0 comments on commit b66a5f3

Please sign in to comment.