Skip to content

Commit

Permalink
Merge pull request #40 from UMDBPP/develop
Browse files Browse the repository at this point in the history
timezones
  • Loading branch information
zacharyburnett authored Jan 31, 2021
2 parents e4143a8 + 73640f0 commit 27417d2
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 39 deletions.
20 changes: 9 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ on:

jobs:
build_wheels:
name: build wheel on ${{ matrix.os }}
name: Python ${{ matrix.python-version }} wheel on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python-version: [3.8]
os: [ ubuntu-latest ]
python-version: [ 3.9 ]
steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand All @@ -24,8 +24,8 @@ jobs:
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ matrix.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py') }}
restore-keys: ${{ matrix.os }}-pip-${{ matrix.python-version }}-
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py') }}
restore-keys: ${{ runner.os }}-pip-${{ matrix.python-version }}-
- name: Install dependencies
run: pip install --upgrade pip setuptools wheel
- name: Build wheel
Expand All @@ -42,25 +42,23 @@ jobs:
uses: actions/checkout@v2
- name: Install Python
uses: actions/setup-python@v2
with:
python-version: '3.8'
- name: Package source
run: python setup.py sdist
- name: Save source package
uses: actions/upload-artifact@v2
with:
path: ./dist/*.tar.gz
upload_pypi:
name: publish wheel to PyPI
needs: [build_wheels, build_sdist]
name: publish to PyPI
needs: [ build_wheels, build_sdist ]
runs-on: ubuntu-latest
steps:
- name: Retrieve wheel
- name: Retrieve wheel(s) and source
uses: actions/download-artifact@v2
with:
name: artifact
path: dist
- name: Upload wheel
- name: Upload wheel(s) and source
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ on: [ push ]

jobs:
tests:
name: test with Python ${{ matrix.python-version }} on ${{ matrix.os }}
name: Python ${{ matrix.python-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest ]
python-version: [ 3.8 ]
python-version: [ 3.8, 3.9 ]
services:
postgres:
image: postgis/postgis:10-2.5
image: postgis/postgis:13-3.1
env:
POSTGRES_PASSWORD: test_password
POSTGRES_DB: test_database
Expand All @@ -32,9 +32,11 @@ jobs:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py') }}
restore-keys: ${{ runner.os }}-pip-${{ matrix.python-version }}-
- name: Update pip
run: python -m pip install --upgrade pip
- name: Install dependencies
run: |
pip install --upgrade pip
pip install wheel
pip install -e .[testing]
- name: Lint with flake8
run: |
Expand Down
2 changes: 1 addition & 1 deletion packetraven/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def __init__(self, hostname: str, database: str, table: str, **kwargs):
if 'primary_key' not in kwargs:
kwargs['primary_key'] = 'time'
kwargs['fields'] = {**self.__default_fields, **kwargs['fields']}
PostGresTable.__init__(self, hostname, database, table, **kwargs)
PostGresTable.__init__(self, hostname=hostname, database=database, name=table, **kwargs)
PacketSource.__init__(
self, f'postgresql://{self.hostname}:{self.port}/{self.database}/{self.name}'
)
Expand Down
28 changes: 17 additions & 11 deletions packetraven/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path

from geojson import Point
import numpy
from shapely.geometry import LineString

from .tracks import APRSTrack
Expand All @@ -21,21 +22,24 @@ def write_aprs_packet_tracks(packet_tracks: [APRSTrack], output_filename: PathLi
packets = sorted(packets)
lines = [f'{packet.time:%Y-%m-%d %H:%M:%S %Z}: {packet.frame}' for packet in packets]
with open(output_filename, 'w') as output_file:
output_file.writelines(lines)
output_file.write('\n'.join(lines))
elif output_filename.suffix == '.geojson':
import geojson

features = []
for packet_track in packet_tracks:
ascent_rates = numpy.round(packet_track.ascent_rates, 3)
ground_speeds = numpy.round(packet_track.ground_speeds, 3)

features.extend(
geojson.Feature(
geometry=geojson.Point(packet.coordinates.tolist()),
properties={
'time': f'{packet.time:%Y%m%d%H%M%S}',
'callsign': packet.from_callsign,
'altitude': packet.coordinates[2],
'ascent_rate': packet_track.ascent_rates[packet_index],
'ground_speed': packet_track.ground_speeds[packet_index],
'ascent_rate': ascent_rates[packet_index],
'ground_speed': ground_speeds[packet_index],
},
)
for packet_index, packet in enumerate(packet_track)
Expand All @@ -50,10 +54,9 @@ def write_aprs_packet_tracks(packet_tracks: [APRSTrack], output_filename: PathLi
'time': f'{packet_track.packets[-1].time:%Y%m%d%H%M%S}',
'callsign': packet_track.callsign,
'altitude': packet_track.coordinates[-1, -1],
'ascent_rate': packet_track.ascent_rates[-1],
'ground_speed': packet_track.ground_speeds[-1],
'seconds_to_ground': packet_track.time_to_ground
/ timedelta(seconds=1),
'ascent_rate': ascent_rates[-1],
'ground_speed': ground_speeds[-1],
'seconds_to_ground': packet_track.time_to_ground / timedelta(seconds=1),
},
)
)
Expand All @@ -72,14 +75,17 @@ def write_aprs_packet_tracks(packet_tracks: [APRSTrack], output_filename: PathLi
output_kml.append(document)

for packet_track_index, packet_track in enumerate(packet_tracks):
ascent_rates = numpy.round(packet_track.ascent_rates, 3)
ground_speeds = numpy.round(packet_track.ground_speeds, 3)

for packet_index, packet in enumerate(packet_track):
placemark = kml.Placemark(
KML_STANDARD,
f'1 {packet_track_index} {packet_index}',
f'{packet_track.callsign} {packet.time:%Y%m%d%H%M%S}',
f'altitude={packet.coordinates[2]} '
f'ascent_rate={packet_track.ascent_rates[packet_index]} '
f'ground_speed={packet_track.ground_speeds[packet_index]}',
f'ascent_rate={ascent_rates[packet_index]} '
f'ground_speed={ground_speeds[packet_index]}',
)
placemark.geometry = Point(packet.coordinates.tolist())
document.append(placemark)
Expand All @@ -89,8 +95,8 @@ def write_aprs_packet_tracks(packet_tracks: [APRSTrack], output_filename: PathLi
f'1 {packet_track_index}',
packet_track.callsign,
f'altitude={packet_track.coordinates[-1, -1]} '
f'ascent_rate={packet_track.ascent_rates[-1]} '
f'ground_speed={packet_track.ground_speeds[-1]} '
f'ascent_rate={ascent_rates[-1]} '
f'ground_speed={ground_speeds[-1]} '
f'seconds_to_ground={packet_track.time_to_ground / timedelta(seconds=1)}',
)
placemark.geometry = LineString(packet_track.coordinates)
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@
install_requires=[
'aprslib',
'haversine',
'numpy==1.19.3',
'numpy>=1.20.0',
'pyserial',
'geojson',
'fastkml',
'matplotlib',
'pyproj',
'psycopg2-binary',
'pyproj',
'requests',
'shapely',
'sshtunnel',
'tablecrow',
],
extras_require={'testing': ['flake8', 'pytest', 'pytest-cov'], 'development': ['oitnb']},
extras_require={'testing': ['flake8', 'pytest', 'pytest-cov', 'pytz'], 'development': ['oitnb']},
entry_points={'console_scripts': ['packetraven=client.cli:main']},
)
1 change: 1 addition & 0 deletions tests/reference/test_output.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type": "FeatureCollection", "features": [{"type": "Feature", "geometry": {"type": "Point", "coordinates": [-77.909211, 39.700356, 8201.8632]}, "properties": {"time": "20181111102013", "callsign": "W3EAX-8", "altitude": 8201.8632, "ascent_rate": 0.0, "ground_speed": 0.0}}, {"type": "Feature", "geometry": {"type": "Point", "coordinates": [-77.881058, 39.700099, 8645.652]}, "properties": {"time": "20181111102124", "callsign": "W3EAX-8", "altitude": 8645.652, "ascent_rate": 6.251, "ground_speed": 34.01}}, {"type": "Feature", "geometry": {"type": "Point", "coordinates": [-77.425253, 39.641857, 13130.784]}, "properties": {"time": "20190203143928", "callsign": "W3EAX-13", "altitude": 13130.784000000001, "ascent_rate": 0.001, "ground_speed": 0.005}}, {"type": "Feature", "geometry": {"type": "LineString", "coordinates": [[-77.909211, 39.700356, 8201.8632], [-77.881058, 39.700099, 8645.652], [-77.425253, 39.641857, 13130.784]]}, "properties": {"time": "20190203143928", "callsign": "W3EAX-13", "altitude": 13130.784000000001, "ascent_rate": 0.001, "ground_speed": 0.005, "seconds_to_ground": -1.0}}]}
1 change: 1 addition & 0 deletions tests/reference/test_output.kml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<kml:kml xmlns:kml="http://www.opengis.net/kml/2.2"><kml:Document id="1"><kml:name>root document</kml:name><kml:description>root document, containing geometries</kml:description><kml:visibility>1</kml:visibility><kml:Placemark id="1 0 0"><kml:name>W3EAX-13 20181111102013</kml:name><kml:description>altitude=8201.8632 ascent_rate=0.0 ground_speed=0.0</kml:description><kml:visibility>1</kml:visibility><kml:Point><kml:coordinates>-77.909211,39.700356,8201.863200</kml:coordinates></kml:Point></kml:Placemark><kml:Placemark id="1 0 1"><kml:name>W3EAX-13 20181111102124</kml:name><kml:description>altitude=8645.652 ascent_rate=6.251 ground_speed=34.01</kml:description><kml:visibility>1</kml:visibility><kml:Point><kml:coordinates>-77.881058,39.700099,8645.652000</kml:coordinates></kml:Point></kml:Placemark><kml:Placemark id="1 0 2"><kml:name>W3EAX-13 20190203143928</kml:name><kml:description>altitude=13130.784000000001 ascent_rate=0.001 ground_speed=0.005</kml:description><kml:visibility>1</kml:visibility><kml:Point><kml:coordinates>-77.425253,39.641857,13130.784000</kml:coordinates></kml:Point></kml:Placemark><kml:Placemark id="1 0"><kml:name>W3EAX-13</kml:name><kml:description>altitude=13130.784000000001 ascent_rate=0.001 ground_speed=0.005 seconds_to_ground=-1.0</kml:description><kml:visibility>1</kml:visibility><kml:LineString><kml:coordinates>-77.909211,39.700356,8201.863200 -77.881058,39.700099,8645.652000 -77.425253,39.641857,13130.784000</kml:coordinates></kml:LineString></kml:Placemark></kml:Document></kml:kml>
3 changes: 3 additions & 0 deletions tests/reference/test_output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
2018-11-11 10:20:13 EST: W3EAX-8>APRS,WIDE1-1,WIDE2-1,qAR,K3DO-11:!/:Gh=:j)#O /A=026909|!Q| /W3EAX,262,0,18'C,http://www.umd.edu
2018-11-11 10:21:24 EST: W3EAX-8>APRS,N3TJJ-12,WIDE1*,WIDE2-1,qAR,N3FYI-2:!/:GiD:jcwO /A=028365|!R| /W3EAX,267,0,18'C,http://www.umd.edu
2019-02-03 14:39:28 EST: W3EAX-13>APRS,KC3FIT-1,WIDE1*,WIDE2-1,qAR,KC3AWP-10:!/:JL2:u4wO /A=043080|!j| /W3EAX,326,0,20'C,nearspace.umd.edu
32 changes: 23 additions & 9 deletions tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,61 @@
from pathlib import Path
from tempfile import TemporaryDirectory

import pytz

from packetraven.packets import APRSPacket
from packetraven.tracks import APRSTrack
from packetraven.utilities import repository_root
from packetraven.writer import write_aprs_packet_tracks

REFERENCE_DIRECTORY = repository_root() / 'tests' / 'reference'

PACKET_TRACK = APRSTrack(
'W3EAX-13',
[
APRSPacket.from_frame(
"W3EAX-8>APRS,WIDE1-1,WIDE2-1,qAR,K3DO-11:!/:Gh=:j)#O /A=026909|!Q| /W3EAX,262,0,18'C,http://www.umd.edu",
packet_time=datetime(2018, 11, 11, 10, 20, 13),
packet_time=pytz.timezone("America/New_York").localize(datetime(2018, 11, 11, 10, 20, 13)),
),
APRSPacket.from_frame(
"W3EAX-8>APRS,N3TJJ-12,WIDE1*,WIDE2-1,qAR,N3FYI-2:!/:GiD:jcwO /A=028365|!R| /W3EAX,267,0,18'C,"
'http://www.umd.edu',
packet_time=datetime(2018, 11, 11, 10, 21, 24),
packet_time=pytz.timezone("America/New_York").localize(datetime(2018, 11, 11, 10, 21, 24)),
),
APRSPacket.from_frame(
"W3EAX-13>APRS,KC3FIT-1,WIDE1*,WIDE2-1,qAR,KC3AWP-10:!/:JL2:u4wO /A=043080|!j| /W3EAX,326,0,20'C,"
'nearspace.umd.edu',
packet_time=datetime(2019, 2, 3, 14, 39, 28),
packet_time=pytz.timezone("America/New_York").localize(datetime(2019, 2, 3, 14, 39, 28)),
),
],
)


def test_write_kml():
filename = 'test_output.kml'
reference_filename = REFERENCE_DIRECTORY / filename
with TemporaryDirectory() as temporary_directory:
output_filename = Path(temporary_directory) / 'test_output.kml'
output_filename = Path(temporary_directory) / filename
write_aprs_packet_tracks([PACKET_TRACK], output_filename)
assert output_filename.exists()
with open(output_filename) as output_file, open(reference_filename) as reference_file:
assert output_file.read() == reference_file.read()


def test_write_geojson():
filename = 'test_output.geojson'
reference_filename = REFERENCE_DIRECTORY / filename
with TemporaryDirectory() as temporary_directory:
output_filename = Path(temporary_directory) / 'test_output.geojson'
output_filename = Path(temporary_directory) / filename
write_aprs_packet_tracks([PACKET_TRACK], output_filename)
assert output_filename.exists()
with open(output_filename) as output_file, open(reference_filename) as reference_file:
assert output_file.read() == reference_file.read()


def test_write_txt():
filename = 'test_output.txt'
reference_filename = REFERENCE_DIRECTORY / filename
with TemporaryDirectory() as temporary_directory:
output_filename = Path(temporary_directory) / 'test_output.txt'
output_filename = Path(temporary_directory) / filename
write_aprs_packet_tracks([PACKET_TRACK], output_filename)
assert output_filename.exists()
with open(output_filename) as output_file, open(reference_filename) as reference_file:
assert output_file.read() == reference_file.read()

0 comments on commit 27417d2

Please sign in to comment.