Skip to content

FelipeSBarros/SailingAnalysis

Repository files navigation

from movingpandas.trajectory_utils import convert_time_ranges_to_segments

Sailing Analysis

Package under construction to automate data analysis from sailing boats.

Functionalities:

TODOs:

  • 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;

Using:

Configuring the environment variables

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.

Applying migrations

The following comando shound apply all migrations using alembic

alembic upgrade head

Exporting GPX to database

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.

Exporting GPX to database

todo

Weather data:

retriving and processing weather data from Open Weather Map

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)

saving OWM data to database

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)

Creating maps

Trajectory maps

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
)

Contributing

Migrations:

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 on upgrade();
  • remove a create case is included for the table ref_sys on downgrade();
  • remove spatial indexes created on upgrade();
  • import geoalchemy2 as it is used but not imported;

Applying migrations

To persist the change done in the models.py migrations should be applied:

alembic upgrade head

Wind barbs

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published