Skip to content

Commit

Permalink
Merge pull request #60 from TUDelft-CITG/feature/opentnsim-exercise-2023
Browse files Browse the repository at this point in the history
Exercise 2023 update.
  • Loading branch information
SiggyF committed Jun 1, 2023
2 parents 7871c14 + f93ac0c commit fbf9566
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,5 +1,6 @@
# generated files
fis_cache
fis_cache.sqlite
requests_cache.sqlite
# generated by example notebook
book/config.json
Expand Down
21 changes: 7 additions & 14 deletions notebooks/Example 13 - Path selection by vessel limits.ipynb

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions opentnsim/fis.py
@@ -0,0 +1,35 @@
import io
import pickle

import requests
import requests_cache
import shapely.geometry

# inject caching
requests_cache.install_cache("fis_cache")

urls = {
"0.2": "https://zenodo.org/record/4578289/files/network_digital_twin_v0.2.pickle",
"0.3": "https://zenodo.org/record/6673604/files/network_digital_twin_v0.3.pickle",
}


def load_network(version="0.3"):
"""load the pickle version of the fairway information system network"""
url = urls[version]
resp = requests.get(url)
# convert the response to a file
f = io.BytesIO(resp.content)

# read the graph
graph = pickle.load(f)

# convert the edges and nodes geometry to shapely objects
for e in graph.edges:
edge = graph.edges[e]
edge["geometry"] = shapely.geometry.shape(edge["geometry"])
for n in graph.nodes:
node = graph.nodes[n]
node["geometry"] = shapely.geometry.shape(node["geometry"])

return graph
20 changes: 2 additions & 18 deletions setup.cfg
Expand Up @@ -29,24 +29,8 @@ packages = find:
include_package_data = True
# DON'T CHANGE THE FOLLOWING LINE! IT WILL BE UPDATED BY PYSCAFFOLD!
setup_requires = pyscaffold>=3.1a0,<3.2a0
# Add here dependencies of your project (semicolon/line-separated), e.g.

install_requires =
Deprecated
simpy
networkx
halem
shapely>=2
scipy
plotly
pyscaffold
simplekml
matplotlib
click
nose
flask
flask_cors
tqdm

# Dependencies are installed in requires


# The usage of test_requires is discouraged, see `Dependency Management` docs
Expand Down
8 changes: 6 additions & 2 deletions setup.py
Expand Up @@ -24,7 +24,8 @@
"openclsim>=0.16",
"numpy",
"simpy",
"networkx<3",
"networkx>=3",
"geopandas",
"shapely>=2",
"scipy",
"click",
Expand All @@ -36,13 +37,17 @@
"plotly",
"simplekml",
"nose",
# downloading
"requests",
"requests-cache",
# web mode
"Flask>=1.0",
"Flask-cors",
"sphinx_rtd_theme",
"Dill",
# deprecate old functions
"Deprecated",
"tqdm",
]

setup_requirements = [
Expand Down Expand Up @@ -74,7 +79,6 @@
"ipywidgets==7.7",
"jsonschema==3.0",
"jupyterlab_widgets==3",
"tqdm",
]

with open("README.md", "r") as des:
Expand Down
13 changes: 13 additions & 0 deletions tests/test_fis.py
@@ -0,0 +1,13 @@
#!/usr/bin/env python3

import opentnsim.fis


def test_network_v2():
"""check if we can load the network"""
graph = opentnsim.fis.load_network(version="0.2")


def test_network_v3():
"""check if we can load the network"""
graph = opentnsim.fis.load_network(version="0.3")

0 comments on commit fbf9566

Please sign in to comment.