neurogenomics / Kayaking

5 stars 0 forks source link

Write initial route planning algorithm #53

Closed NathanSkene closed 6 months ago

NathanSkene commented 7 months ago

We're going to need some ideas here on what kind of algorithms are most suitable.

We'll be getting the info from the route planning interface here: https://github.com/orgs/neurogenomics/projects/28?pane=issue&itemId=51305971

Initial steps:

3mily8rown commented 7 months ago

/ This query retrieves the coastline of the Isle of Wight. /

area["name"="Isle of Wight"]->.searchArea;

( way(area.searchArea)["natural"="coastline"]; );

out geom; code from https://overpass-turbo.eu/ for coastline

jamielewisturner commented 7 months ago

Or this [out:json][timeout:25];

way"natural"="coastline";

; node._; out;

3mily8rown commented 7 months ago
import math
import geopandas as gpd

def outland_direction(coor1, coor2):
    lon1, lat1 = coor1
    lon2, lat2 = coor2
    y = math.sin(lon2 - lon1) * math.cos(lat2)
    x = math.cos(lat1) * math.sin(lat2) - math.sin(lat1) * math.cos(lat2) * math.cos(lon2 - lon1)
    r = math.atan2(y, x)
    brng = ((r * 180 / math.pi + 360) % 360 + 90) % 360
    return "(" + str(lat1) + "," + str(lon1) + ") and (" + str(lat2) + "," + str(lon2) + ") make: " + str(brng) + "\n"

def coordinate_processing():
    # find sea direction for list of coordinates (between each pair)

    # the data file from overpass turbo https://overpass-turbo.eu/
    gdf = gpd.read_file('data.geojson')

    with open('outland.txt', 'w') as output:
        coors = gdf["geometry"].apply(lambda geom: list(geom.coords) if geom.is_empty is False else [])
        prev = coors[0][0]
        for i in range(1, len(coors)):
            for j in range(0, len(coors[i])):
                output.write(outland_direction(prev, coors[i][j]))
                prev = coors[i][j]

# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    coordinate_processing()

current code looking for bearings out to sea

jamielewisturner commented 7 months ago

@NathanSkene Would you be able to look over the following plan for a route planning algorithm to see if it matches what you may expect.

1. Displaying launch sites Find all launch sites - Points along the beach + slipways. The user can select one of the points to start from (Not sure if it might be better to allow the user to just pick a point on the map rather than forcing them to pick one of our points) image

2. Filter places that are unsuitable Colour areas that are unsuitable in a different colour. Unrealistic diagram showing which starting points may be bad given wind direction. Not sure what other factors need to be included. image We had a look at the coastline data and found all the normals out to sea. For the wind I think you'd want to check that the angle difference between the normal and wind direction is > 90. This would flag areas where you are blown out to sea. image Now the user can select a starting point using the knowledge of where is safe.

3. Make base route Get the coastline (red) and all routes go X meters out from it (purple). All routes will follow this line image Before we make the route line. We can use an algorithm to remove coves from the coastline - probably find an existing smoothing algorithm. This would remove the green part from the line and produce a smoother purple one. image

Now we have a starting point and a line to follow for the route.

4. Route planning In the case the user wants to do a non-circular loop, we could display how far they could get from the origin in M minutes. This could be calculated by constructing a function v(t) in terms of time from origin and output speed the user will travel along the line. The function would take into account how wind speed /currents etc will affect your speed at different times. Integrating the function at the time=duration will give you the distance you travel. Using the distance you can determine where you are along the long. Analytically integrating this would be difficult so instead it would be a good idea to make approximations in short intervals. v(t) will need to know the distance travelled to approximate the speed (since it needs to check the weather positions at this location) so both functions will need to be calculated at the same time. This isn't an issue as you could use the speed at the start position for the estimate of the first interval, then calculate the new position and calculate speed there and use that for the next interval. Then just repeat this until you reach the end time of the trip.

The case of a circular loop is similar. Analytically you would solve these equations to find the duration there and back. V1 is the speed leaving the origin and v2 is the speed returning to the origin. Again this can be approximated in a similar way rather than solving analytically. image

Now you have a route!

Please let me know what you think and if you think any steps should be modified. Thanks

NathanSkene commented 7 months ago

One initial response: I’ve imagined it suggesting routes from various start points, rather than the user selecting one. Strava lets you flick through a range of different possible routes, I think we want something like that.

In later iterations of the app, I think the app should show you which parts of a coastline you’ve explored before, and gives you options for how you can explore further bits.

Will reply about the rest in the morning.

Sent from Outlook for iOShttps://aka.ms/o0ukef


From: jamielewisturner @.> Sent: Tuesday, January 30, 2024 9:21:19 PM To: neurogenomics/Kayaking @.> Cc: Skene, Nathan G @.>; Mention @.> Subject: Re: [neurogenomics/Kayaking] Write initial route planning algorithm (Issue #53)

This email from @.*** originates from outside Imperial. Do not click on links and attachments unless you recognise the sender. If you trust the sender, add them to your safe senders listhttps://spam.ic.ac.uk/SpamConsole/Senders.aspx to disable email stamping for this address.

@NathanSkenehttps://github.com/NathanSkene Would you be able to look over the following plan for a route planning algorithm to see if it matches what you may expect.

  1. Displaying launch sites Find all launch sites - Points along the beach + slipways. The user can select one of the points to start from (Not sure if it might be better to allow the user to just pick a point on the map rather than forcing them to pick one of our points) image.png (view on web)https://github.com/neurogenomics/Kayaking/assets/19625407/e8ed0311-41d6-45cf-a703-a8e864c36f03

  2. Filter places that are unsuitable Colour areas that are unsuitable in a different colour. Unrealistic diagram showing which starting points may be bad given wind direction. Not sure what other factors need to be included. image.png (view on web)https://github.com/neurogenomics/Kayaking/assets/19625407/b032d026-7c40-4423-bce7-f1337bf86d73 We had a look at the coastline data and found all the normals out to sea. For the wind I think you'd want to check that the angle difference between the normal and wind direction is > 90. This would flag areas where you are blown out to sea. image.png (view on web)https://github.com/neurogenomics/Kayaking/assets/19625407/5e2d61c4-7f4d-456f-b59c-14b8ddd0e23c Now the user can select a starting point using the knowledge of where is safe.

  3. Make base route Get the coastline (red) and all routes go X meters out from it (purple). All routes will follow this line image.png (view on web)https://github.com/neurogenomics/Kayaking/assets/19625407/5e9c9cae-52cd-4fd4-938d-536224825416 Before we make the route line. We can use an algorithm to remove coves from the coastline - probably find an existing smoothing algorithm. This would remove the green part from the line and produce a smoother purple one. image.png (view on web)https://github.com/neurogenomics/Kayaking/assets/19625407/7820d798-91bb-4ccf-b8c1-7a8225b3f9b9

Now we have a starting point and a line to follow for the route.

  1. Route planning In the case the user wants to do a non-circular loop, we could display how far they could get from the origin in M minutes. This could be calculated by constructing a function v(t) in terms of time from origin and output speed the user will travel along the line. The function would take into account how wind speed /currents etc will affect your speed at different times. Integrating the function at the time=duration will give you the distance you travel. Using the distance you can determine where you are along the long. Analytically integrating this would be difficult so instead it would be a good idea to make approximations in short intervals. v(t) will need to know the distance travelled to approximate the speed (since it needs to check the weather positions at this location) so both functions will need to be calculated at the same time. This isn't an issue as you could use the speed at the start position for the estimate of the first interval, then calculate the new position and calculate speed there and use that for the next interval. Then just repeat this until you reach the end time of the trip.

The case of a circular loop is similar. Analytically you would solve these equations to find the duration there and back. V1 is the speed leaving the origin and v2 is the speed returning to the origin. Again this can be approximated in a similar way rather than solving analytically. image.png (view on web)https://github.com/neurogenomics/Kayaking/assets/19625407/8e736190-ee38-4255-9625-6b8f9b8b3a0e

Now you have a route!

Please let me know what you think and if you think any steps should be modified. Thanks

— Reply to this email directly, view it on GitHubhttps://github.com/neurogenomics/Kayaking/issues/53#issuecomment-1917914637, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AH5ZPE7CR3N7RFPUHZSSQY3YRFP47AVCNFSM6AAAAABCNEQZDCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJXHEYTINRTG4. You are receiving this because you were mentioned.Message ID: @.***>

NathanSkene commented 7 months ago

What do you mean by:

"We had a look at the coastline data and found all the normals out to sea"?

Sounds like you've got the gist though!

jamielewisturner commented 7 months ago

Hi Nathan, I think the first stage of suggesting a route from various starting points is to focus on creating routes from one point. Your end goal would not be possible in this iteration and we could run the algorithm multiple times removing the user input on the starting location. In my opinion, we should focus on this for this iteration and expand on it in the next.

By "We had a look at the coastline data and found all the normals out to sea", I meant we've checked we can find what direction the ocean from any point on a route. This is needed to check if the wind is pushing you into shore or out to sea.