-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeteors.py
More file actions
56 lines (33 loc) · 1.3 KB
/
meteors.py
File metadata and controls
56 lines (33 loc) · 1.3 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
import math
import requests
def calc_dist(lat1, lon1, lat2, lon2):
lat1 = math.radians(lat1)
lon1 = math.radians(lon1)
lat2 = math.radians(lat2)
lon2 = math.radians(lon2)
h = math.sin((lat2 - lat1) / 2) ** 2 + \
math.cos(lat1) * \
math.cos(lat2) * \
math.sin((lon2 - lon1) / 2) ** 2
return 6372.8 * 2 * math.asin(math.sqrt(h))
def getMeteorCoordinates(meteor):
latitude = meteor.get('reclat')
longtitude = meteor.get('reclong')
coordinates = (latitude, longtitude)
return coordinates
def calculateAndAddDistancesOfMeteors():
global meteor_data
for meteor in meteor_data:
if 'reclat' not in meteor or 'reclong' not in meteor:
continue
meteor['distance'] = calc_dist(houseCoordinates[0], houseCoordinates[1],
float(getMeteorCoordinates(meteor)[0]), float(getMeteorCoordinates(meteor)[1]))
def get_distance(meteor):
return meteor.get('distance', math.inf)
if __name__ == '__main__':
houseCoordinates = (52.08673121780718, 5.049856391142839)
nasaResponse = requests.get('https://data.nasa.gov/resource/y77d-th95.json')
meteor_data = nasaResponse.json()
calculateAndAddDistancesOfMeteors()
meteor_data.sort(key=get_distance)
print(meteor_data[:10])