Setup¶
Install the Signal Ocean SDK:
pip install signal-ocean
Set your subscription key acquired here: https://apis.signalocean.com/profile
In [1]:
Copied!
pip install signal-ocean
pip install signal-ocean
In [2]:
Copied!
signal_ocean_api_key = '' #replace with your subscription key
signal_ocean_api_key = '' #replace with your subscription key
Calculate a distance over 2 ports¶
Create a connections towards distances API. Then call the distance API to get a distance between Fuijairah and Singapore for a VLCC vessel (corresponding restrictions applied)
In [3]:
Copied!
from signal_ocean import Connection
from signal_ocean.distances import DistancesAPI, VesselClassFilter, PortFilter, LoadingCondition
connection = Connection(api_key=signal_ocean_api_key)
distances_api = DistancesAPI(connection)
load_port = distances_api.get_ports(PortFilter(name_like='Fujairah'))[0]
discharge_port = distances_api.get_ports(PortFilter(name_like='Singapore'))[0]
vessel_class = distances_api.get_vessel_classes(VesselClassFilter(name_like='vlcc'))[0]
distanceInNM = distances_api.get_port_to_port_distance(vessel_class, LoadingCondition.BALLAST, load_port, discharge_port)
print(distanceInNM)
from signal_ocean import Connection
from signal_ocean.distances import DistancesAPI, VesselClassFilter, PortFilter, LoadingCondition
connection = Connection(api_key=signal_ocean_api_key)
distances_api = DistancesAPI(connection)
load_port = distances_api.get_ports(PortFilter(name_like='Fujairah'))[0]
discharge_port = distances_api.get_ports(PortFilter(name_like='Singapore'))[0]
vessel_class = distances_api.get_vessel_classes(VesselClassFilter(name_like='vlcc'))[0]
distanceInNM = distances_api.get_port_to_port_distance(vessel_class, LoadingCondition.BALLAST, load_port, discharge_port)
print(distanceInNM)
3302.86
Create a distance matrix¶
Find distance in NM for a Aframax vessel from Trieste to every available port. Persist the output in an excel file.
In [4]:
Copied!
distancesFromTriesteDictionary = {}
port_from = distances_api.get_ports(PortFilter(name_like='Trieste'))[0]
ports_to_get_distance = ['Rotterdam','Singapore','Lome','Long Beach','Galveston','Pazflor','Bonny','Ras Tanura','Houston','Escravos']
for port_to_filter in ports_to_get_distance:
port_to = distances_api.get_ports(PortFilter(name_like=port_to_filter))[0]
distanceInNM = distances_api.get_port_to_port_distance(vessel_class, LoadingCondition.BALLAST, port_from, port_to)
distancesFromTriesteDictionary[port_to.name] = float(distanceInNM)
distancesFromTriesteDictionary = {}
port_from = distances_api.get_ports(PortFilter(name_like='Trieste'))[0]
ports_to_get_distance = ['Rotterdam','Singapore','Lome','Long Beach','Galveston','Pazflor','Bonny','Ras Tanura','Houston','Escravos']
for port_to_filter in ports_to_get_distance:
port_to = distances_api.get_ports(PortFilter(name_like=port_to_filter))[0]
distanceInNM = distances_api.get_port_to_port_distance(vessel_class, LoadingCondition.BALLAST, port_from, port_to)
distancesFromTriesteDictionary[port_to.name] = float(distanceInNM)
In [5]:
Copied!
import pandas as pd
import openpyxl
df = pd.DataFrame(data=distancesFromTriesteDictionary, index=[0])
pd.options.display.float_format = '{:,.2f}'.format
df = (df.T)
df.to_excel('simpleDistanceMatrix_Trieste_Aframax_Ballast.xlsx')
df
import pandas as pd
import openpyxl
df = pd.DataFrame(data=distancesFromTriesteDictionary, index=[0])
pd.options.display.float_format = '{:,.2f}'.format
df = (df.T)
df.to_excel('simpleDistanceMatrix_Trieste_Aframax_Ballast.xlsx')
df
Out[5]:
0 | |
---|---|
Rotterdam | 3,079.19 |
Singapore | 6,386.87 |
Lome | 4,688.84 |
Long Beach | 13,980.85 |
Galveston | 6,403.92 |
Pazflor | 5,500.45 |
Bonny | 5,027.66 |
Ras Tanura | 4,480.52 |
Houston | 6,430.57 |
Escravos | 4,884.11 |