Path: blob/main/tests/complex/emissions/evaluateHBEFA3vsPHEM.py
169678 views
#!/usr/bin/env python1# -*- coding: utf-8 -*-2# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo3# Copyright (C) 2013-2025 German Aerospace Center (DLR) and others.4# This program and the accompanying materials are made available under the5# terms of the Eclipse Public License 2.0 which is available at6# https://www.eclipse.org/legal/epl-2.0/7# This Source Code may also be made available under the following Secondary8# Licenses when the conditions for such availability set forth in the Eclipse9# Public License 2.0 are satisfied: GNU General Public License, version 210# or later which is available at11# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html12# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later1314# @file evaluateHBEFA3vsPHEM.py15# @author Daniel Krajzewicz16# @author Michael Behrisch17# @date 2013-01-141819from __future__ import absolute_import20from __future__ import print_function2122import sys23import os24import collections25import matplotlib.pyplot as plt26sys.path.append(27os.path.join(os.path.dirname(sys.argv[0]), '..', '..', '..', "tools"))2829ec = None30hbefa = collections.defaultdict(lambda: collections.defaultdict(list))31phem = collections.defaultdict(lambda: collections.defaultdict(list))32maxVal = collections.defaultdict(float)33for line in open('nefz_hbefa3/output.complex'):34lh = line.split(":")35if line[:7] == "Running":36ec = line.split('/')[1][:-2]37elif len(lh) > 1:38val = float(lh[1])39hbefa[ec][lh[0]].append(val)40maxVal[lh[0]] = max(maxVal[lh[0]], val)41for line in open('nefz_phemlight/output.complex'):42lp = line.split(":")43if line[:7] == "Running":44ec = line.split('/')[1][:-2]45if ec[:3] == "PKW":46ec = "PC" + ec[3:]47if ec[:3] == "LNF":48ec = "LDV" + ec[3:ec.rfind("_")]49elif len(lp) > 1:50measure = lp[0]51val = float(lp[1])52phem[ec][measure].append(val)53if ec in hbefa and len(hbefa[ec][measure]) < len(phem[ec][measure]):54hbefa[ec][measure].append(hbefa[ec][measure][0])55maxVal[measure] = max(maxVal[measure], val)5657marker = {"PC_G_": "s", "PC_D_": "^", "LDV_G": "o", "LDV_D": "v"}58# color = {"0": "k", "1": "r", "2": "y", "3": "g", "4": "m", "5": "b", "6": "c"}59color = {"0": "0", "1": "0.3", "2": "0.45",60"3": "0.6", "4": "0.75", "5": "0.9", "6": "1"}61limit = {"CO": 100000, "CO2": 5e6, "HC": 30000, "PMx": 6000, "fuel": 1700}6263for emission in ["CO", "CO2", "HC", "PMx", "fuel"]:64print(emission)65fig = plt.figure()66ax1 = fig.add_subplot(111)67if emission in limit:68m = limit[emission]69else:70m = maxVal[emission]71if emission == "fuel":72plt.xlim(500, m)73plt.ylim(500, m)74else:75plt.xlim(0, m)76plt.ylim(0, m)77for ec in sorted(phem.keys()):78if ec in hbefa and hbefa[ec][emission][0] > 0:79print(ec, phem[ec][emission], hbefa[ec][emission])80ax1.scatter(phem[ec][emission], hbefa[ec][emission], s=80, c=color[81ec[-1]], marker=marker[ec[:5]], label=ec)82ax1.plot((0, m), (0, m))83plt.title(emission + (" [ml]" if emission == "fuel" else " [mg]"))84plt.xlabel("PHEMlight")85plt.ylabel("HBEFA3")86plt.legend(scatterpoints=1, fontsize=8, bbox_to_anchor=(871.05, 1), loc=2, borderaxespad=0.)88plt.savefig(emission + ".png", bbox_inches="tight")89plt.xlim(0, m / 5)90plt.ylim(0, m / 5)91plt.savefig(emission + "Zoom.png", bbox_inches="tight")929394