Energy consumption, fuel use and emissions#

In this notebook, we set up a basic simulation where a vessel moves over a 1D netork path. We add some properties to the graph (depth, width) and the vessel (VesselProperties, ConsumesEnergy) in order to calculate resistance, required power, and emissions. OpenTNSim model run.

We take the following steps:

  1. Imports

  2. Create vessel

  3. Create graph

  4. Run simulation

  5. Inspect output

1. Imports#

We start with importing required libraries

# package(s) used for creating and geo-locating the graph
import networkx as nx  
import shapely.geometry
import pyproj
import warnings

# package(s) related to the simulation (creating the vessel, running the simulation)
import datetime, time
import simpy
import opentnsim

# package(s) needed for data handling and inspecting the output
import numpy as np
import pandas as pd

# package(s) needed for plotting
import matplotlib.pyplot as plt
import plotly.express as px
from plotly.subplots import make_subplots

import logging
#logging.basicConfig(level=logging.DEBUG) #turn on all the debug messages
logging.basicConfig(level=logging.INFO)# turn off all the debug messages

from shapely.errors import ShapelyDeprecationWarning
warnings.filterwarnings("ignore", category=ShapelyDeprecationWarning) 


print('This notebook is executed with OpenTNSim version {}'.format(opentnsim.__version__))
This notebook is executed with OpenTNSim version 1.1.2

2. Create vessel#

We start with creating a vessel class. We call this class a Vessel, and add a number of OpenTNSim mix-ins to this class. Each mix-in requires certain input parameters.

The following mix-ins are sufficient to create a vessel for our problem:

  • Identifiable - allows to give the vessel a name and a random ID,

  • Movable - allows the vessel to move, with a fixed speed, while logging this activity,

    • Movable in turn relies on the mix-ins: Locatable, Routeable, and Log

  • VesselProperties - allows to give the vessel specific properties,

  • ConsumesEnergy - enables calculation of resistance, required power and emissions

# Make your preferred class out of available mix-ins.
TransportResource = type(
    "Vessel",
    (
        opentnsim.core.Identifiable,
        opentnsim.core.Movable,
        opentnsim.core.VesselProperties,  # needed to add vessel properties
        opentnsim.energy.ConsumesEnergy,
        opentnsim.core.ExtraMetadata,
    ),
    {},
)  # needed to calculate resistances
# Create a dict with all important settings
# NB: set both "v" and "P_tot_given" to None, as they will be set later
# Note that we set "h_squat" as "True". 
# The squat effect makes a great difference for the actual water depth and resistance calculation in shallow water. 
# Here we need to calculate the water depth reduced by squat since what we give the ship is a route with undisturbed water depth h_0.

data_vessel = {"env": None,
               "name": None,
               "route": None,
               "geometry": None,
               "v": None,  # m/s
               "type":None,
               "B": 11.4,
               "L": 110,
               "H_e": None, 
               "H_f": None, 
               "T": 3.5,      # <=== here we should enter the value from the T strategy notebook
               "safety_margin": 0.2, # for tanker vessel with sandy bed the safety margin is recommended as 0.2 m
               "h_squat": True, # if consider the ship squatting while moving, set to True, otherwise set to False
               "P_installed": 1750.0,
               "P_tot_given": None, # kW
               "bulbous_bow": False, # if a vessel has no bulbous_bow, set to False; otherwise set to True.
               "P_hotel_perc": 0.05,
               "P_hotel": None, # None: calculate P_hotel from percentage
               "x": 2,# number of propellers
               "L_w": 3.0 ,
               "C_B":0.85, 
               "C_year":1990,
              }             

vessel = TransportResource(**data_vessel)

2. Create graph#

Next we create a 1D network (a graph) along which the vessel can move. A graph is made of nodes (blue dots in the plot below) and edges (red arrows between the nodes in the plot below). We use the python package networkx to do this.

For this example, we construct a network of 4 nodes linked by 3 edges. The edges are made bi-directional to allow for two-way traffic, which means that the graph in the end contains 6 edges.

# specify a number of coordinate along your route (coords are: lon, lat)
coords = [
    [0,0],
    [0.8983,0], 
    [1.7966,0], 
    [2.6949,0]] 

# for each edge (between above coordinates) specify the depth (m)
depths = [6, 4.5, 6]

# check of nr of coords and nr of depths align
assert len(coords) == len(depths) + 1, 'nr of depths does not correspond to nr of coords'
# create a graph 
FG = nx.DiGraph()
nodes = []
path = []

# make your preferred Site class out of available mix-ins.
Node = type('Site', (opentnsim.core.Identifiable, opentnsim.core.Locatable), {})

# add nodes
for index, coord in enumerate(coords):
    data_node = {"name": str(index), "geometry": shapely.geometry.Point(coord[0], coord[1])}
    nodes.append(Node(**data_node))
    
positions = {}
for node in nodes:
    positions[node.name] = (node.geometry.x, node.geometry.y)
    FG.add_node(node.name, geometry = node.geometry)

# add edges
path = [[nodes[i], nodes[i+1]] for i in range(len(nodes)-1)]

for index, edge in enumerate(path):
    # For the energy consumption calculation we add info to the graph. We need depth info for resistance.
    # NB: the CalculateEnergy routine expects the graph to have "Info" that contains "GeneralDepth" 
    FG.add_edge(edge[0].name, edge[1].name, weight = 1, Info = {"GeneralDepth": depths[index]})
# toggle to undirected and back to directed to make sure all edges are two way traffic
FG = FG.to_undirected() 
FG = FG.to_directed() 
# create a positions dict for the purpose of plotting
positions = {}
for node in FG.nodes:
    positions[node] = (FG.nodes[node]['geometry'].x, FG.nodes[node]['geometry'].y)
# collect node labels.
labels = {}
for node in FG.nodes:
    labels[node] = node
print('Number of nodes is {}:'.format(len(FG.nodes)))
print('Number of edges is {}:'.format(len(FG.edges)))

# draw edges, nodes and labels.
nx.draw_networkx_edges(FG,  pos=positions, width=3, edge_color="red", alpha=1, arrowsize=20)
nx.draw_networkx_nodes(FG,  pos=positions, node_color="darkblue", node_size=600)
nx.draw_networkx_labels(FG, pos=positions, labels=labels, font_size=15, font_weight='bold', font_color="white")

plt.axis("off")
plt.show()
Number of nodes is 4:
Number of edges is 6:
../_images/Example 14 - Energy consumption, fuel use and emissions_12_1.png
# This cell just shows that now a depth of 10 m is added to the edges. 
# You can use this to vary depths, e.g. make the middle edge shallower. Note that edges are bi-directional 
for edge in FG.edges:
    print('General depth for edge {} is {}'.format(edge, FG.get_edge_data(edge[0], edge[1])["Info"]["GeneralDepth"]))
General depth for edge ('0', '1') is 6
General depth for edge ('1', '0') is 6
General depth for edge ('1', '2') is 4.5
General depth for edge ('2', '1') is 4.5
General depth for edge ('2', '3') is 6
General depth for edge ('3', '2') is 6

4. Run simulation#

Now we can define the run. After we define the path that the vessel will sail, we make an environment and add the graph to the environment. Then we add one vessel, to which we will append the environment and the route. Lastly, we give the vessel the process of moving from the origin to the destination of the defined path and subsequently run the model.

# create a path along that the vessel needs to follow (in this case from the first node to the last node)
path = nx.dijkstra_path(FG, nodes[0].name, nodes[3].name)

Run simulation#

Now we can define the run. First, we make an environment and add the graph to the environment. Then we add one vessel, to which we will append the environment and the above route. Lastly, we give the vessel the process of moving from the origin to the destination of the defined path and subsequently run the model.

def run_simulation(V_s, P_tot_given):
    
    # Start simpy environment
    simulation_start = datetime.datetime.now()
    env = simpy.Environment(initial_time = time.mktime(simulation_start.timetuple()))
    env.epoch = time.mktime(simulation_start.timetuple())

    # Add graph to environment
    env.FG = FG

    # Add environment and path to the vessel
    # create a fresh instance of vessel
    vessel = TransportResource(**data_vessel)
    vessel.env = env                                        #the created environment
    vessel.name = 'Vessel No.1'                     
    vessel.route = path                                     #the route (the sequence of nodes, as stored as the second column in the path)
    vessel.geometry = env.FG.nodes[path[0]]['geometry']     #a shapely.geometry.Point(lon,lat) (here taken as the starting node of the vessel)
    vessel.v = V_s
    vessel.P_tot_given = P_tot_given
              
    # Start the simulation
    env.process(vessel.move())
    env.run()
    
    return vessel
input_data = {'V_s': [3.0, 3.5, 4.0, None, None, None], 'P_tot_given': [None, None, None, 333, 473, 707]}
input_data
{'V_s': [3.0, 3.5, 4.0, None, None, None],
 'P_tot_given': [None, None, None, 333, 473, 707]}
# create empty plot data
plot_data = {}

# loop through the various input data
for index, value in enumerate(input_data['V_s']):
    
    # Run a basic simulation with V_s and P_tot_given combi
    vessel = run_simulation(input_data['V_s'][index], input_data['P_tot_given'][index])
    
    # create an EnergyCalculation object and perform energy consumption calculation
    
    energycalculation = opentnsim.energy.EnergyCalculation(FG, vessel)
    
    energycalculation.calculate_energy_consumption()
    
    # create dataframe from energy calculation computation
    df = pd.DataFrame.from_dict(energycalculation.energy_use)
    
    # add/modify some comlums to suit our plotting needs
   
    df['fuel_kg_per_km'] = (df['total_diesel_consumption_ICE_mass'] / 1000) / (df['distance']/1000)
    df['CO2_g_per_km']   = (df['total_emission_CO2']) / (df['distance']/1000)
    df['PM10_g_per_km']  = (df['total_emission_PM10']) / (df['distance']/1000)
    df['NOx_g_per_km']   = (df['total_emission_NOX']) / (df['distance']/1000)
    
    label = 'V_s = ' + str(input_data['V_s'][index]) + ' P_tot_given = ' + str(input_data['P_tot_given'][index])

    # Note that we make a dict to collect all plot data. 
    # We use labels like ['V_s = None P_tot_given = 274 fuel_kg_km'] to organise the data in the dict
    # The [0, 0, 1, 1, 2, 2] below creates a list per section 
    plot_data[label + ' v'] = list(df.distance[[0, 0, 1, 1, 2, 2]]/df.delta_t[[0, 0, 1, 1, 2, 2]])
    plot_data[label + ' P_tot']   = list(df.P_tot[[0, 0, 1, 1, 2, 2]])
    plot_data[label + ' fuel_kg_per_km']   = list(df.fuel_kg_per_km[[0, 0, 1, 1, 2, 2]])
    plot_data[label + ' CO2_g_per_km'] = list(df.CO2_g_per_km[[0, 0, 1, 1, 2, 2]])
    plot_data[label + ' PM10_g_per_km']   = list(df.PM10_g_per_km[[0, 0, 1, 1, 2, 2]])
    plot_data[label + ' NOx_g_per_km']   = list(df.NOx_g_per_km[[0, 0, 1, 1, 2, 2]])
        
5.8671748390034
4.332320207590202
5.8671748390034
5.816966883951583
4.268937190266964
5.816966883964907
5.75836884873338
4.194962453046343
5.7583688487132765
5.807566542693429
4.369549130829329
5.807566542693429
5.778075912264108
4.319929394881336
5.778075912246384
5.610242193677174
4.2459962536241225
5.610242193677174

5. Inspect output#

We can now analyse the simulation output by inspecting the vessel.log. Note that the Log mix-in was included when we added Movable. The vessel.log keeps track of the moving activities of the vessel. For each discrete event OpenTNSim logs an event message, the start/stop time and the location. The vessel.log is of type dict. For convenient inspection it can be loaded into a Pandas dataframe.

# this is now in the plot data
plot_data
{'V_s = 3.0 P_tot_given = None v': [3.000000000017929,
  3.000000000017929,
  3.000000000017929,
  3.000000000017929,
  3.00000000001793,
  3.00000000001793],
 'V_s = 3.0 P_tot_given = None P_tot': [327.7886503400087,
  327.7886503400087,
  436.1968803360304,
  436.1968803360304,
  327.7886503400089,
  327.7886503400089],
 'V_s = 3.0 P_tot_given = None fuel_kg_per_km': [7.922823289319963,
  7.922823289319963,
  10.294310201288647,
  10.294310201288647,
  7.922823289319965,
  7.922823289319965],
 'V_s = 3.0 P_tot_given = None CO2_g_per_km': [24523.917406855177,
  24523.917406855177,
  31864.50131700698,
  31864.50131700698,
  24523.917406855184,
  24523.917406855184],
 'V_s = 3.0 P_tot_given = None PM10_g_per_km': [14.847608422852904,
  14.847608422852904,
  18.11093479107904,
  18.11093479107904,
  14.847608422852904,
  14.847608422852904],
 'V_s = 3.0 P_tot_given = None NOx_g_per_km': [342.6443872351659,
  342.6443872351659,
  432.64335760224463,
  432.64335760224463,
  342.644387235166,
  342.644387235166],
 'V_s = 3.5 P_tot_given = None v': [3.500000000038418,
  3.500000000038418,
  3.500000000038418,
  3.500000000038418,
  3.499999999915917,
  3.499999999915917],
 'V_s = 3.5 P_tot_given = None P_tot': [435.50938451244417,
  435.50938451244417,
  637.3575799612884,
  637.3575799612884,
  435.50938447663276,
  435.50938447663276],
 'V_s = 3.5 P_tot_given = None fuel_kg_per_km': [8.811012111768543,
  8.811012111768543,
  12.368440145532086,
  12.368440145532086,
  8.811012111416213,
  8.811012111416213],
 'V_s = 3.5 P_tot_given = None CO2_g_per_km': [27273.17338897245,
  27273.17338897245,
  38284.66109922486,
  38284.66109922486,
  27273.173387881863,
  27273.173387881863],
 'V_s = 3.5 P_tot_given = None PM10_g_per_km': [15.506795429498567,
  15.506795429498567,
  21.13029090907852,
  21.13029090907852,
  15.506795429162302,
  15.506795429162302],
 'V_s = 3.5 P_tot_given = None NOx_g_per_km': [370.36239826701177,
  370.36239826701177,
  524.7732827713122,
  524.7732827713122,
  370.36239825523523,
  370.36239825523523],
 'V_s = 4.0 P_tot_given = None v': [3.9999999999839053,
  3.9999999999839053,
  3.9999999999839053,
  3.9999999999839053,
  4.000000000143909,
  4.000000000143909],
 'V_s = 4.0 P_tot_given = None P_tot': [392.559203150767,
  392.559203150767,
  900.0657788046773,
  900.0657788046773,
  392.55920318785763,
  392.55920318785763],
 'V_s = 4.0 P_tot_given = None fuel_kg_per_km': [7.0096566895121954,
  7.0096566895121954,
  14.618160900384083,
  14.618160900384083,
  7.009656689841988,
  7.009656689841988],
 'V_s = 4.0 P_tot_given = None CO2_g_per_km': [21697.34644160693,
  21697.34644160693,
  45248.336037532594,
  45248.336037532594,
  21697.346442627746,
  21697.346442627746],
 'V_s = 4.0 P_tot_given = None PM10_g_per_km': [12.604995729187815,
  12.604995729187815,
  25.180223715863725,
  25.180223715863725,
  12.604995729551012,
  12.604995729551012],
 'V_s = 4.0 P_tot_given = None NOx_g_per_km': [297.5134798307196,
  297.5134798307196,
  631.2961365252651,
  631.2961365252651,
  297.51347984226055,
  297.51347984226055],
 'V_s = None P_tot_given = 333 v': [3.5852976149599396,
  3.5852976149599396,
  2.6588949693329997,
  2.6588949693329997,
  3.5852976149599405,
  3.5852976149599405],
 'V_s = None P_tot_given = 333 P_tot': [369.4675744031554,
  369.4675744031554,
  333.00000941231497,
  333.00000941231497,
  369.4675744031556,
  369.4675744031556],
 'V_s = None P_tot_given = 333 fuel_kg_per_km': [7.3944915209786615,
  7.3944915209786615,
  9.067332352573747,
  9.067332352573747,
  7.394491520978662,
  7.394491520978662],
 'V_s = None P_tot_given = 333 CO2_g_per_km': [22888.54524505452,
  22888.54524505452,
  28066.574451405028,
  28066.574451405028,
  22888.54524505452,
  22888.54524505452],
 'V_s = None P_tot_given = 333 PM10_g_per_km': [13.447273657401519,
  13.447273657401519,
  16.910978266477727,
  16.910978266477727,
  13.447273657401517,
  13.447273657401517],
 'V_s = None P_tot_given = 333 NOx_g_per_km': [315.4530711294918,
  315.4530711294918,
  391.28315874500436,
  391.28315874500436,
  315.4530711294918,
  315.4530711294918],
 'V_s = None P_tot_given = 473 v': [3.839691205787076,
  3.839691205787076,
  3.1046087557818742,
  3.1046087557818742,
  3.839691205934512,
  3.839691205934512],
 'V_s = None P_tot_given = 473 P_tot': [433.34387907548205,
  433.34387907548205,
  473.0000017078113,
  473.0000017078113,
  433.34387911539767,
  433.34387911539767],
 'V_s = None P_tot_given = 473 fuel_kg_per_km': [7.995079888254837,
  7.995079888254837,
  10.706460736249541,
  10.706460736249541,
  7.995079888619778,
  7.995079888619778],
 'V_s = None P_tot_given = 473 CO2_g_per_km': [24747.57692817352,
  24747.57692817352,
  33140.251805118605,
  33140.251805118605,
  24747.576929303144,
  24747.576929303144],
 'V_s = None P_tot_given = 473 PM10_g_per_km': [14.086374893942267,
  14.086374893942267,
  18.684905366998073,
  18.684905366998073,
  14.086374894298459,
  14.086374894298459],
 'V_s = None P_tot_given = 473 NOx_g_per_km': [336.2318399430648,
  336.2318399430648,
  449.61593431928816,
  449.61593431928816,
  336.23183995534725,
  336.23183995534725],
 'V_s = None P_tot_given = 707 v': [5.03370578009758,
  5.03370578009758,
  3.6629627493254864,
  3.6629627493254864,
  5.033705780097581,
  5.033705780097581],
 'V_s = None P_tot_given = 707 P_tot': [706.9999955107305,
  706.9999955107305,
  707.0000001929258,
  707.0000001929258,
  706.9999955107306,
  706.9999955107306],
 'V_s = None P_tot_given = 707 fuel_kg_per_km': [9.39958132885961,
  9.39958132885961,
  12.917064783212211,
  12.917064783212211,
  9.399581328859608,
  9.399581328859608],
 'V_s = None P_tot_given = 707 CO2_g_per_km': [29095.00158595066,
  29095.00158595066,
  39982.84681036775,
  39982.84681036775,
  29095.001585950657,
  29095.001585950657],
 'V_s = None P_tot_given = 707 PM10_g_per_km': [16.04911697866472,
  16.04911697866472,
  22.054969946606917,
  22.054969946606917,
  16.049116978664717,
  16.049116978664717],
 'V_s = None P_tot_given = 707 NOx_g_per_km': [401.614950815197,
  401.614950815197,
  551.9061071509126,
  551.9061071509126,
  401.6149508151969,
  401.6149508151969]}
fig, axs = plt.subplots(5, 1, figsize=(8, 10), sharex=True,constrained_layout=True)
fontsize=12

ax=plt.subplot(511)    # Longitudinal section of the waterway
plt.title('M8 vessel: L$_s$ = 110 m, B$_s$ = 11.40 m, T$_s$ = 3.5 m, payload = 2682 ton, P$_{installed}$= 1750 kW',y=1.05)
# these values you probably want to extract from the graph, or from the log (minimise the manual work!!)
dist=[0,100,100,200,200,300]
water_level=[2.5,2.5,1,1,2.5,2.5,]
bed_level=[1,1,2.5,2.5,1,1]
draft=[3.5,3.5,3.5,3.5,3.5,3.5,]

plt.stackplot(dist,bed_level,water_level,draft, labels=['bed','water','actual draught'],colors=['#7f7053','#75bbfd','#95d0fc'])
plt.ylabel('Longitudinal section \n of the waterway',fontsize=12,fontweight='bold',labelpad=22)
plt.xlim(0, 300)
plt.ylim(0, 14)
plt.xticks( weight = 'bold')
plt.yticks([1,3.5,7], weight = 'bold', fontsize=12)
ax.legend(loc='upper left')
ax.text(285, 12, '(a)', fontsize=12,weight = 'bold')

ax=plt.subplot(512)    #  fuel (diesel) consumption kg/km 

diesel_fv1=(plot_data['V_s = 3.0 P_tot_given = None fuel_kg_per_km']) # use values from the output_plot variable
diesel_fv2=(plot_data['V_s = 3.5 P_tot_given = None fuel_kg_per_km'])
diesel_fv3=(plot_data['V_s = 4.0 P_tot_given = None fuel_kg_per_km'])
diesel_fp1=(plot_data['V_s = None P_tot_given = 333 fuel_kg_per_km'])
diesel_fp2=(plot_data['V_s = None P_tot_given = 473 fuel_kg_per_km'])
diesel_fp3=(plot_data['V_s = None P_tot_given = 707 fuel_kg_per_km'])

plt.plot(dist, diesel_fv1,':',color='#f1da7a',linewidth='2',label='Vs=3 m/s')
plt.plot(dist, diesel_fv2,'-.',color='#bf9005',linewidth='2',label='Vs=3.5 m/s')
plt.plot(dist, diesel_fv3,'--',color='#7f4e1e',linewidth='2',label='Vs=4 m/s')
plt.plot(dist, diesel_fp1,color='#f1da7a',linewidth='2',label='P=333 kW')
plt.plot(dist, diesel_fp2,color='#bf9005',linewidth='2',label='P=473 kW')
plt.plot(dist, diesel_fp3,color='#7f4e1e',linewidth='2',label='P=707 kW')
plt.ylabel('Fuel use\n (kg/km)',fontsize=12,fontweight='bold',labelpad=26)
plt.ylim(0, 25)
plt.xlim(0, 300)
plt.xticks( weight = 'bold')
plt.yticks( weight = 'bold', fontsize=12)
ax.legend(loc='upper left')
ax.text(285, 25*11/13, '(b)', fontsize=12,weight = 'bold')

ax=plt.subplot(513)    #  CO2 emission rates g/km
ax.legend(loc='upper left')

EMrCO2_fv1=(plot_data['V_s = 3.0 P_tot_given = None CO2_g_per_km'])
EMrCO2_fv2=(plot_data['V_s = 3.5 P_tot_given = None CO2_g_per_km'])
EMrCO2_fv3=(plot_data['V_s = 4.0 P_tot_given = None CO2_g_per_km'])
EMrCO2_fp1=(plot_data['V_s = None P_tot_given = 333 CO2_g_per_km'])
EMrCO2_fp2=(plot_data['V_s = None P_tot_given = 473 CO2_g_per_km'])
EMrCO2_fp3=(plot_data['V_s = None P_tot_given = 707 CO2_g_per_km'])

plt.plot(dist, EMrCO2_fv1,':',color='yellow',linewidth='2',label='Vs=3 m/s')
plt.plot(dist, EMrCO2_fv2,'-.',color='orange',linewidth='2',label='Vs=3.5 m/s')
plt.plot(dist, EMrCO2_fv3,'--',color='red',linewidth='2',label='Vs=4 m/s')
plt.plot(dist, EMrCO2_fp1,color='yellow',linewidth='2',label='P=333 kW')
plt.plot(dist, EMrCO2_fp2,color='orange',linewidth='2',label='P=473 kW')
plt.plot(dist, EMrCO2_fp3,color='red',linewidth='2',label='P=707 kW')
ax.legend(loc='upper left')
plt.ylabel('CO2 emission \n rate (g/km)',fontsize=12,fontweight='bold',labelpad=2)
plt.ylim(0, 80000)
plt.xlim(0, 300)
plt.xticks( weight = 'bold')
plt.yticks( weight = 'bold', fontsize=12)
ax.text(285, 80000*11/13, '(c)', fontsize=12,weight = 'bold')

ax=plt.subplot(514)    #  PM10 emission rates g/km

EMrPM10_fv1=(plot_data['V_s = 3.0 P_tot_given = None PM10_g_per_km'])
EMrPM10_fv2=(plot_data['V_s = 3.5 P_tot_given = None PM10_g_per_km'])
EMrPM10_fv3=(plot_data['V_s = 4.0 P_tot_given = None PM10_g_per_km'])
EMrPM10_fp1=(plot_data['V_s = None P_tot_given = 333 PM10_g_per_km'])
EMrPM10_fp2=(plot_data['V_s = None P_tot_given = 473 PM10_g_per_km'])
EMrPM10_fp3=(plot_data['V_s = None P_tot_given = 707 PM10_g_per_km'])

plt.plot(dist, EMrPM10_fv1,':',color='paleturquoise',linewidth='2',label='Vs=3 m/s')
plt.plot(dist, EMrPM10_fv2,'-.',color='mediumseagreen',linewidth='2',label='Vs=3.5 m/s')
plt.plot(dist, EMrPM10_fv3,'--',color='darkgreen',linewidth='2',label='Vs=4 m/s')
plt.plot(dist, EMrPM10_fp1,color='paleturquoise',linewidth='2',label='P=333 kW')
plt.plot(dist, EMrPM10_fp2,color='mediumseagreen',linewidth='2',label='P=473 kW')
plt.plot(dist, EMrPM10_fp3,color='darkgreen',linewidth='2',label='P=707 kW')
ax.legend(loc='upper left')
plt.ylabel('PM10 emission \n rate (g/km)',fontsize=12,fontweight='bold',labelpad=26)
plt.ylim(0, 50)
plt.xlim(0, 300)
plt.xticks( weight = 'bold')
plt.yticks( weight = 'bold', fontsize=12)
ax.text(285, 50*11/13, '(d)', fontsize=12,weight = 'bold')

ax=plt.subplot(515)     #  NOx emission rates g/km

EMrNOx_fv1=(plot_data['V_s = 3.0 P_tot_given = None NOx_g_per_km'])
EMrNOx_fv2=(plot_data['V_s = 3.5 P_tot_given = None NOx_g_per_km'])
EMrNOx_fv3=(plot_data['V_s = 4.0 P_tot_given = None NOx_g_per_km'])
EMrNOx_fp1=(plot_data['V_s = None P_tot_given = 333 NOx_g_per_km'])
EMrNOx_fp2=(plot_data['V_s = None P_tot_given = 473 NOx_g_per_km'])
EMrNOx_fp3=(plot_data['V_s = None P_tot_given = 707 NOx_g_per_km'])

plt.plot(dist, EMrNOx_fv1,':',color='pink',linewidth='2',label='Vs=3 m/s')
plt.plot(dist, EMrNOx_fv2,'-.',color='deeppink',linewidth='2',label='Vs=3.5 m/s')
plt.plot(dist, EMrNOx_fv3,'--',color='purple',linewidth='2',label='Vs=4 m/s')
plt.plot(dist, EMrNOx_fp1,color='pink',linewidth='2',label='P=333 kW')
plt.plot(dist, EMrNOx_fp2,color='deeppink',linewidth='2',label='P=473 kW')
plt.plot(dist, EMrNOx_fp3,color='purple',linewidth='2',label='P=707 kW')
plt.ylabel('NOx emission \n rate (g/km)',fontsize=12,fontweight='bold',labelpad=10)
plt.xlabel('distance (km)',fontsize=12,fontweight='bold',labelpad=3)
plt.ylim(0, 1200)
plt.xlim(0, 300)
ax.legend(loc='upper left')
plt.xticks([0,100,200,300], weight = 'bold', fontsize=12)
plt.yticks( weight = 'bold', fontsize=12)
ax.text(285, 1200*11/13, '(e)', fontsize=12,weight = 'bold')

plt.savefig('Fig_11.pdf',bbox_inches = 'tight', dpi=600, format='pdf')  
WARNING:matplotlib.legend:No artists with labels found to put in legend.  Note that artists whose label start with an underscore are ignored when legend() is called with no argument.
../_images/Example 14 - Energy consumption, fuel use and emissions_22_1.png