Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tests/complex/emissionsMap/runner.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 runner.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 subprocess
26
sys.path.append(os.path.join(os.environ["SUMO_HOME"], "tools"))
27
from sumolib import checkBinary # noqa
28
29
EDC = checkBinary("emissionsMap", os.path.join(
30
os.path.dirname(sys.argv[0]), '..', '..', '..', "bin"))
31
if len(sys.argv) > 2:
32
PHEMLIGHTp = sys.argv[2]
33
else:
34
PHEMLIGHTp = os.path.join(
35
os.environ["SUMO_HOME"], "data", "emissions", "PHEMlight")
36
if not os.path.exists(PHEMLIGHTp):
37
PHEMLIGHTp = os.path.join(os.path.dirname(
38
sys.argv[0]), '..', '..', '..', "data", "emissions", "PHEMlight")
39
40
fd = open("classes.txt")
41
emissionClasses = fd.readlines()
42
fd.close()
43
44
if emissionClasses[0].startswith("PHEMlight5"):
45
PHEMLIGHTp = os.path.join(PHEMLIGHTp, "V5")
46
47
if emissionClasses[0].startswith("HBEFA4"):
48
fdo = open("HBEFAresults.csv", "w") # just to avoid the pickup of the huge file by texttest
49
else:
50
fdo = open("results.csv", "w")
51
for i, ec in enumerate(emissionClasses):
52
ec = ec.strip()
53
if len(ec) == 0:
54
continue
55
print("Running '%s'" % ec)
56
sys.stdout.flush()
57
sys.stderr.flush()
58
call = [EDC, "-e", ec, "-o", "tmp.csv", "--phemlight-path", PHEMLIGHTp,
59
"--v-max", "30",
60
"--v-step", "5",
61
"--a-step", "1",
62
"--s-min", "0",
63
"--s-max", "0",
64
]
65
call += sys.argv[2:]
66
retCode = subprocess.call(call)
67
sys.stdout.flush()
68
sys.stderr.flush()
69
if retCode != 0:
70
print("Error on building PHEMlight measurements")
71
sys.exit(1)
72
fdo.write("%s\n" % ec)
73
with open("tmp.csv") as fd:
74
fdo.write(fd.read())
75
fdo.write("-----\n\n")
76
fdo.close()
77
78