This repository was archived by the owner on Jan 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
76 lines (68 loc) · 2.31 KB
/
main.py
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
import csv
import reverse_geocoder as rg
import cv2
import numpy as np
from picamera import PiCamera
from pathlib import Path
from time import sleep
from datetime import datetime, timedelta
from orbit import ISS, ephemeris
from skyfield.api import load
timescale = load.timescale()
base_folder = Path(__file__).parent.resolve()
#takes the images and stores them
def takeImages():
camera = PiCamera()
camera.resolution = (2592, 1944)
startTime = datetime.now()
timeNow = datetime.now()
i = 0
#runs f
while (timeNow < startTime + timedelta(minutes=160)):
try:
path = f'{base_folder}/images/image_{i:03d}.jpg'
#waits until the iss is in sunlight
t = timescale.now()
while ISS.at(t).is_sunlit(ephemeris) == False:
t = timescale.now()
point = ISS.coordinates()
coordinates = (point.latitude.degrees, point.longitude.degrees)
country = coordinateToCountry(coordinates)
camera.capture(path)
try:
#crops image
img = cv2.imread(path)
x1 = 390
x2 = 2200
y1 = 390
y2 = 1560
img_cropped = img[x1:x2, y1:y2]
cv2.imwrite(img_cropped, path)
except:
pass
#saves data to csv
with open('data.csv', 'w') as csvfile:
filewriter = csv.writer(csvfile)
filewriter.writerow([coordinates, path, country])
i = i + 1
#waits ten seconds between each photo
sleep(5)
timeNow = datetime.now()
except:
pass
return
#converts coordinates to the name of the country the coordinates correspond to
def coordinateToCountry(coordinates):
try:
results = rg.search(coordinates)
country = results[0]['cc']
except:
pass
return country
#writes the csv headers
with open('data.csv', 'w') as csvfile:
filewriter = csv.writer(csvfile)
filewriter.writerow(['raw-coordinate', 'image-path', 'country'])
#takes the images and saves them
takeImages()
#we will create ndvi images later in the analysis phase and compare that to the countries GDP.