Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tests/complex/emissions/evaluateHBEFA3vsPHEM.py
169678 views
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
4
# Copyright (C) 2013-2025 German Aerospace Center (DLR) and others.
5
# This program and the accompanying materials are made available under the
6
# terms of the Eclipse Public License 2.0 which is available at
7
# https://www.eclipse.org/legal/epl-2.0/
8
# This Source Code may also be made available under the following Secondary
9
# Licenses when the conditions for such availability set forth in the Eclipse
10
# Public License 2.0 are satisfied: GNU General Public License, version 2
11
# or later which is available at
12
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
13
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
14
15
# @file evaluateHBEFA3vsPHEM.py
16
# @author Daniel Krajzewicz
17
# @author Michael Behrisch
18
# @date 2013-01-14
19
20
from __future__ import absolute_import
21
from __future__ import print_function
22
23
import sys
24
import os
25
import collections
26
import matplotlib.pyplot as plt
27
sys.path.append(
28
os.path.join(os.path.dirname(sys.argv[0]), '..', '..', '..', "tools"))
29
30
ec = None
31
hbefa = collections.defaultdict(lambda: collections.defaultdict(list))
32
phem = collections.defaultdict(lambda: collections.defaultdict(list))
33
maxVal = collections.defaultdict(float)
34
for line in open('nefz_hbefa3/output.complex'):
35
lh = line.split(":")
36
if line[:7] == "Running":
37
ec = line.split('/')[1][:-2]
38
elif len(lh) > 1:
39
val = float(lh[1])
40
hbefa[ec][lh[0]].append(val)
41
maxVal[lh[0]] = max(maxVal[lh[0]], val)
42
for line in open('nefz_phemlight/output.complex'):
43
lp = line.split(":")
44
if line[:7] == "Running":
45
ec = line.split('/')[1][:-2]
46
if ec[:3] == "PKW":
47
ec = "PC" + ec[3:]
48
if ec[:3] == "LNF":
49
ec = "LDV" + ec[3:ec.rfind("_")]
50
elif len(lp) > 1:
51
measure = lp[0]
52
val = float(lp[1])
53
phem[ec][measure].append(val)
54
if ec in hbefa and len(hbefa[ec][measure]) < len(phem[ec][measure]):
55
hbefa[ec][measure].append(hbefa[ec][measure][0])
56
maxVal[measure] = max(maxVal[measure], val)
57
58
marker = {"PC_G_": "s", "PC_D_": "^", "LDV_G": "o", "LDV_D": "v"}
59
# color = {"0": "k", "1": "r", "2": "y", "3": "g", "4": "m", "5": "b", "6": "c"}
60
color = {"0": "0", "1": "0.3", "2": "0.45",
61
"3": "0.6", "4": "0.75", "5": "0.9", "6": "1"}
62
limit = {"CO": 100000, "CO2": 5e6, "HC": 30000, "PMx": 6000, "fuel": 1700}
63
64
for emission in ["CO", "CO2", "HC", "PMx", "fuel"]:
65
print(emission)
66
fig = plt.figure()
67
ax1 = fig.add_subplot(111)
68
if emission in limit:
69
m = limit[emission]
70
else:
71
m = maxVal[emission]
72
if emission == "fuel":
73
plt.xlim(500, m)
74
plt.ylim(500, m)
75
else:
76
plt.xlim(0, m)
77
plt.ylim(0, m)
78
for ec in sorted(phem.keys()):
79
if ec in hbefa and hbefa[ec][emission][0] > 0:
80
print(ec, phem[ec][emission], hbefa[ec][emission])
81
ax1.scatter(phem[ec][emission], hbefa[ec][emission], s=80, c=color[
82
ec[-1]], marker=marker[ec[:5]], label=ec)
83
ax1.plot((0, m), (0, m))
84
plt.title(emission + (" [ml]" if emission == "fuel" else " [mg]"))
85
plt.xlabel("PHEMlight")
86
plt.ylabel("HBEFA3")
87
plt.legend(scatterpoints=1, fontsize=8, bbox_to_anchor=(
88
1.05, 1), loc=2, borderaxespad=0.)
89
plt.savefig(emission + ".png", bbox_inches="tight")
90
plt.xlim(0, m / 5)
91
plt.ylim(0, m / 5)
92
plt.savefig(emission + "Zoom.png", bbox_inches="tight")
93
94