travel_emission_lerp_fit.py
1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import numpy as np
from .travel_emission_linear_fit import EmissionModel as BaseEmissionModel
class EmissionModel(BaseEmissionModel):
def apply_scaling_law(self, distance, config):
assert config.points
assert len(config.points) > 0
footprint = None
sample_points = sorted(config.points, key=lambda p: float(p[0]))
# Numpy!
previous_point = [0, 0]
for i, sample_point in enumerate(sample_points):
if distance <= sample_point[0]:
t = 0
if sample_point[0] != previous_point[0]:
t = (distance - previous_point[0]) * 1.0 \
/ \
(sample_point[0] - previous_point[0])
footprint = previous_point[1] + t * (sample_point[1] - previous_point[1])
previous_point = sample_point
break
previous_point = sample_point
if footprint is None:
if len(config.points) == 1:
last = sample_points[0]
penu = [0, 0]
else:
last = sample_points[-1]
penu = sample_points[-2]
t = 0
if last[0] != penu[0]:
t = (distance - last[0]) * 1.0 / (last[0] - penu[0])
footprint = last[1] + t * (last[1] - penu[1])
return footprint