atmosfair.py
2.52 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import numpy as np
from geopy.distance import great_circle
class EmissionModel():
def __init__(self, config):
self.config = config
def __repr__(self):
return "Emission model\n" + \
"==============\n" + \
repr(self.config)
def compute_travel_footprint(
self,
origin_latitude, origin_longitude,
destination_latitude, destination_longitude):
footprint = 0
#############################################
# FIXME: find closest airport(s) and pick one
# We're going to need caching here as well.
from collections import namedtuple
origin_airport = namedtuple('Position', [
'latitude',
'longitude',
'address', # perhaps
])
origin_airport.latitude = origin_latitude
origin_airport.longitude = origin_longitude
destination_airport = namedtuple('Position', [
'latitude',
'longitude',
'address', # perhaps
])
destination_airport.latitude = destination_latitude
destination_airport.longitude = destination_longitude
#############################################
#############################################
footprint += self.compute_airplane_footprint(
origin_airport.latitude,
origin_airport.longitude,
destination_airport.latitude,
destination_airport.longitude
)
return footprint
def compute_airplane_footprint(
self,
origin_latitude, origin_longitude,
destination_latitude, destination_longitude):
footprint = 0
distance = self.get_distance_between(
origin_latitude, origin_longitude,
destination_latitude, destination_longitude
)
footprint += distance # FIXME
return footprint
def get_distance_between(
self,
origin_latitude, origin_longitude,
destination_latitude, destination_longitude):
"""
:param origin_latitude:
:param origin_longitude:
:param destination_latitude:
:param destination_longitude:
:return: Distance in meters between the two locations,
along Earth's great circles.
"""
gcd = great_circle(
(np.float(origin_latitude), np.float(origin_longitude)),
(np.float(destination_latitude), np.float(destination_longitude))
).m
return gcd