Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tests/complex/emissions/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("emissionsDrivingCycle", 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
with open("classes.txt") as fd:
41
emissionClasses = fd.readlines()
42
43
if emissionClasses[0].startswith("PHEMlight5"):
44
PHEMLIGHTp = os.path.join(PHEMLIGHTp, "V5")
45
46
# different outputs to avoid the pickup of the huge file by texttest
47
with open("HBEFAresults.csv" if emissionClasses[0].startswith("HBEFA4") else "results.csv", "w") as fdo:
48
for i, ec in enumerate(emissionClasses):
49
ec = ec.strip()
50
if len(ec) == 0:
51
continue
52
drivingCycle = sys.argv[1]
53
print("Running '%s'" % ec)
54
sys.stdout.flush()
55
sys.stderr.flush()
56
call = [EDC, "-e", ec, "-t", drivingCycle, "-o", "tmp.csv",
57
"--phemlight-path", PHEMLIGHTp, "--kmh", "--compute-a"]
58
if drivingCycle[-4:] == ".dri":
59
call += ["--timeline-file.skip", "3", "--timeline-file.separator", ","]
60
call += sys.argv[2:]
61
retCode = subprocess.call(call)
62
sys.stdout.flush()
63
sys.stderr.flush()
64
if retCode != 0:
65
print("Error on building PHEMlight measurements")
66
sys.exit(1)
67
fdo.write("%s\n" % ec)
68
with open("tmp.csv") as fd:
69
fdo.write(fd.read())
70
fdo.write("-----\n\n")
71
72