from movingpandas.trajectory_utils import convert_time_ranges_to_segments
Package under construction to automate data analysis from sailing boats.
-
Get sailing track from GPX and save it on a spatially enabled database (using GeoAlchemy2:
-
For each sailing track, use MovingPandas to calculate:
-
Get weather forecast from the sailing date and save on the database:
- Get Weather Station and Weather data using meteostat Python API
- Open Weather Map
-
Generate automatic analysis (weather data?):
- Identifying
No-Go Zone
(45° from wind direction on both directions); - Identifying the Upwind, Beam Reaching and Downwind sailing segments of the trajectory;
- Identifying
-
Generate sailing map with:
- Trajectory segment for a specific date and time (start and end);
- Trajectory and wind conditions using wind brabs more info here;
- Identify
OK
andnot OK
tacks;
-
Generate sailing report with:
- General overview about:
- Weather conditions;
- Sailing;
- Maps;
- Join weather data on traj dataframe;
- Get timezone information automatically from machine;
- Create function to confirm if sailing track already exists. If exists, retrieve from database;
- Create function to retrieve sailing track from database;
In order to use sailing data analysis it is necessary to have set a .env
file:
# .env
OPENWEATHER_KEY='<your_key>'
DB_URL='postgresql+psycopg2://<user>:<password>@172.17.0.2/<db_name>'
if necessary, take a look on .env-example file.
The following comando shound apply all migrations using alembic
alembic upgrade head
Use export_gpx function to export a gpx file to the database:
from spatial_tools import export_gpx
track_df, trajectory = export_gpx(
gpx_path="path_to_the.gpx",
layer="track_points",
)
This function will get the track_point from gpx, convert datetime data to Buenos Aires timezone, calculate a acceleration, angular difference, direction, distance and speed for each track segment, save as point and linestring geometries in the data base and return both as GeoDataFrame.
Use process_OWM_data function to process weather data from Opwn Weather Map. This function will call get_OWM_data which, after confirming there is weather data already saved for that track, will get coordinates and datime for each step
parameter and retrieve the data (using OpenWeatherMap API) appending it to a jsonline.
from spatial_tools import process_OWM_data
owm_data = process_OWM_data(track_df)
Use save_OWM_data to save Open Weather Map data in the data base using pandas.to_sql;
from spatial_tools import save_OWM_data
save_OWM_data(owm_data)
create_traj_map creates the vizualization (A.K.A. map) of a trajectory data
from spatial_tools import create_traj_map
create_traj_map(
traj=trajectory,
map_title="REGATA INDEPENDENCIA: entire",
save=True)
Plot a section of a sailing track:
from datetime import datetime
create_traj_map(
traj=trajectory,
map_title="REGATA INDEPENDENCIA: 1ra boya",
save=True,
start=datetime(2023, 7, 30, 9, 30),
stop=datetime(2023, 7, 30, 10, 41),
)
Adding contra info
create_traj_map(
traj=trajectory,
map_title="REGATA INDEPENDENCIA: 1ra boya - contra",
save=True,
start=datetime(2023, 7, 30, 9, 30),
stop=datetime(2023, 7, 30, 10, 41),
contra=True
)
Adding wind direction and speed info:
create_traj_map(
traj=trajectory,
map_title="REGATA INDEPENDENCIA: 1ra boya - contra",
save=True,
start=datetime(2023, 7, 30, 9, 30),
stop=datetime(2023, 7, 30, 10, 41),
contra=True,
weather=owm_data
)
When ever a change is done in models.py, a migrations should be created:
alembic revision --autogenerate -m "msg"
After creating migration, make sure to review it as it is normal that it needs some improvements, like:
- remove a drop case is included for the table
ref_sys
onupgrade()
; - remove a create case is included for the table
ref_sys
ondowngrade()
; - remove spatial indexes created on
upgrade()
; - import
geoalchemy2
as it is used but not imported;
To persist the change done in the models.py migrations should be applied:
alembic upgrade head