Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/emissions/nefz.py
169674 views
1
#!/usr/bin/env python
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2012-2025 German Aerospace Center (DLR) and others.
4
# This program and the accompanying materials are made available under the
5
# terms of the Eclipse Public License 2.0 which is available at
6
# https://www.eclipse.org/legal/epl-2.0/
7
# This Source Code may also be made available under the following Secondary
8
# Licenses when the conditions for such availability set forth in the Eclipse
9
# Public License 2.0 are satisfied: GNU General Public License, version 2
10
# or later which is available at
11
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
14
# @file nefz.py
15
# @author [email protected]
16
# @date 2014-01-14
17
18
"""
19
Generates a ';'-separated file that contains the time line of the NEFZ
20
driving cycle.
21
"""
22
from __future__ import print_function
23
24
NEFZ1 = [
25
[11, 0, 0],
26
[4, 1.04, -1], [0, 0, 15],
27
[8, 0, 15],
28
[2, -0.69, -1], [0, 0, 10],
29
[3, -.93, -1], [0, 0, 0],
30
[21, 0, 0],
31
32
[5, 0.83, -1], [0, 0, 15],
33
[2, 0, -1],
34
[5, 0.94, -1], [0, 0, 32],
35
[24, 0, 32],
36
[8, -.76, -1], [0, 0, 10],
37
[3, -.93, -1], [0, 0, 0],
38
[21, 0, 0],
39
40
[5, .83, -1], [0, 0, 15],
41
[2, 0, -1],
42
[9, .62, -1], [0, 0, 35],
43
[2, 0, -1],
44
[8, .52, -1], [0, 0, 50],
45
[12, 0, 50],
46
[8, -.52, -1], [0, 0, 35],
47
[13, 0, 35],
48
[2, 0, -1],
49
[7, -.87, -1], [0, 0, 10],
50
[3, -.93, -1], [0, 0, 0],
51
52
[7, 0, 0],
53
54
]
55
56
NEFZ2 = [
57
[20, 0, 0],
58
[5, .83, -1], [0, 0, 15],
59
[2, 0, -1],
60
[9, .62, -1], [0, 0, 35],
61
[2, 0, -1],
62
[8, .52, -1], [0, 0, 50],
63
[2, 0, -1],
64
[13, .43, -1], [0, 0, 70],
65
[50, 0, 70],
66
[8, -.69, -1], [0, 0, 50],
67
[69, 0, 50],
68
[13, .43, -1], [0, 0, 70],
69
[50, 0, 70],
70
[35, .24, -1], [0, 0, 100],
71
[30, 0, 100],
72
[20, .28, -1], [0, 0, 120],
73
[10, 0, 120],
74
[16, -.69, -1], [0, 0, 80],
75
[8, -1.04, -1], [0, 0, 50],
76
[10, -1.39, -1], [0, 0, 0],
77
[20, 0, 0]
78
]
79
80
81
def build(what):
82
t = 0
83
v = 0
84
a = 0
85
ts1 = []
86
vs1 = []
87
as1 = []
88
ts2 = []
89
vs2 = []
90
as2 = []
91
ts3 = []
92
vs3 = []
93
as3 = []
94
ct = 0
95
cv = 0
96
lv = 0
97
lt = 0
98
ts1.append(0)
99
as1.append(0)
100
vs1.append(0)
101
for tav in what:
102
[t, a, v] = tav[:3]
103
v = v / 3.6
104
if v >= 0:
105
# destination velocity
106
if a != 0:
107
print("ups %s" % tav)
108
ts1.append(ct + t)
109
as1.append(0)
110
vs1.append(v)
111
# via acceleration
112
for it in range(0, t):
113
ts2.append(ct + it)
114
as2.append(a)
115
mv = cv + a * float(it)
116
if mv < 0:
117
mv = 0
118
vs2.append(mv)
119
# via speed (if not None, otherwise "keep in mind")
120
if v >= 0:
121
dt = float((ct + t) - lt)
122
if dt != 0:
123
dv = float(v - lv)
124
a = dv / float(dt)
125
for it in range(lt, ct + t):
126
ts3.append(it)
127
as3.append(a)
128
vs3.append(lv + a * float(it - lt))
129
130
ct = ct + t
131
if v >= 0:
132
cv = v
133
lv = v
134
lt = ct
135
return [ts1, vs1, as1, ts2, vs2, as2, ts3, vs3, as3]
136
137
138
BASE = 3
139
ts = []
140
vs = []
141
ts1 = []
142
vs1 = []
143
ts2 = []
144
vs2 = []
145
ts3 = []
146
vs3 = []
147
t = 0
148
for c in [NEFZ1, NEFZ1, NEFZ1, NEFZ1, NEFZ2]:
149
tmp = build(c)
150
for i in range(0, len(tmp[BASE])):
151
ts.append(tmp[BASE][i] + t)
152
vs.append(tmp[BASE + 1][i])
153
# ts1.append(tmp[0][i]+t)
154
# vs1.append(tmp[0+1][i])
155
# ts2.append(tmp[3][i]+t)
156
# vs2.append(tmp[3+1][i])
157
# ts3.append(tmp[6][i]+t)
158
# vs3.append(tmp[6+1][i])
159
t = t + tmp[BASE][-1] + 1
160
161
fdo = open("nefz.csv", "w")
162
pv = 0
163
for i in range(0, len(ts)):
164
fdo.write("%s;%s;%s\n" % (ts[i], round(vs[i] * 3.6, 2), round(vs[i] - pv, 7)))
165
pv = vs[i]
166
fdo.close()
167
168