Giter VIP home page Giter VIP logo

libweatherrouting's Introduction

libweatherrouting

CI Status License: GPL v3 PyPI - Version

A 100% python weather routing library for sailing.

Reference

An introductory explanation (english, french, spanish and italian translations) of weather routing tools and methods can be find in: https://globalsolochallenge.com/weather-routing/

Install

pip install weatherrouting

Usage

For a comprehensive usage reference example pleace refer to wind_forecast_routing QGIS plugin or GWeatherRouting standalone application

Almost one external function has to be implemented as a preliminary requirement for library usage:

Wind direction and speed for a given location at specified time

A function that accept a datetime item, a float latitude and float longitude as parameters, performs a wind forecast analysis for the specified time and location (usually sampling a grib file) and returns a tuple with true wind direction (twd) expressed in radians and true wind speed (tws) expressed in meters per second or None if running out of temporal/geographic grib scope.

def getWindAt( t, lat, lon)
    # wind forecast analysys implementation
    ...
    return (twd, tws)

Point validity (Optional)

A function that accept a float latitude and float longitude as parameters, performs a test to check if the specified location is eligible as waypoint (i.e. lay or not on sea) and returns a boolean (True if valid, False if invalid)

def point_validity(lat, lon)
    # 
    ...
    return True/False

Line validity (Optional)

A function that accept a vector defined as four float parameters (latitude1, longitude1, latitude2, longitude2) performs a test to check whether the specified line between two waypoints is valid (i.e. lays completely or not on sea, or in other words is in line of sight) and returns a boolean (True if valid, False if invalid)

def line_validity(lat1, lon1, lat1, lon1)
    # 
    ...
    return True/False

Import weatherrouting module

from weatherrouting import Routing, Polar
from weatherrouting.routers.linearbestisorouter import LinearBestIsoRouter
from datetime import datetime

Define a track points list

Define a list of trackpoints as lat,long tuples (almost 2) that have to be reached by the route

track = ((5.1, 38.1), (5.2, 38.4), (5.7, 38.2))

Define a polar wrapper

Define the polar object from a polar file describing the performance of the boat at different wind speeds (tws) and different angles (twd)

polar_obj = Polar("polar_files/bavaria38.pol")

Define the start datetime

Define the polar object from a polar file describing the performance of the boat at different wind speeds (tws) and different angles (`twd~)

start = datetime.fromisoformat('2021-04-02T12:00:00')

Define routing object

routing_obj = Routing(
    LinearBestIsoRouter,            # specify a router type
    polar_obj,                      # the polar object for a specific sail boat
    track,                          # the list of track points (lat,lon)
    getWindAt,                      # the function that returns (twd,tws) for a specified (datetime, lat, lon)
    start,                          # the start datetime
    start_position = (4.8,37.8)     # the start location (lat lon, optional, the first track point if undefined)
    pointValidity = point_validity  # the point validity function (optional)
    lineValidity = line_validity    # the line validity function (optional)
)

Perform route calculation

Calculate subsequent steps until the end track point is reached

while not self.routing_obj.end:
    res = self.routing_obj.step()

the step method returns a RoutingResult object with the following informations during routing calculation:

res.time         # the datetime of step  
res.isochrones   # all points reached at a specified datetime
res.progress     # the calculation progress 

and after the end of the routing calculation contains a list of tuple containing the waypoints informations (lat,lon,datetime, twd, tws, speed, heading)

res.path         # the list of route waypoints

Export path as geojson

The path could be exported as a geojson object for cartographic representation

from weatherrouting.utils import pathAsGeojson
import json

json.dumps(pathAsGeojson(res.path))

License

Read the LICENSE file.

Credits

This work is partially based and inspired by Riccardo Apolloni Virtual Sailing Simulator.

libweatherrouting's People

Contributors

dakk avatar enricofer avatar pcav avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

libweatherrouting's Issues

Path not populated until routing ends & timedelta customization

Hi,

Thanks for your amazing work.
I'm looking at a way to define the number of steps to iterate to end routing from here rather than reaching the destination.
Is there an easy way to do that ?

The other thing (but it's maybe more a feat request) nice to have would be the possibility to have shorter steps the 1st 24h (say 20min) and 1 hour or more after.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.