-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
54 lines (38 loc) · 1.62 KB
/
utils.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
import csv
import sys
import numpy as np
import requests
from scipy import interpolate
import matplotlib.pyplot as plt
def get_data_from_google_sheet(google_sheet_id):
print(f'google_sheet_id {google_sheet_id}')
url = f'https://docs.google.com/spreadsheets/d/{google_sheet_id}/export?format=csv'
response = requests.get(url)
if response.status_code == 200:
decoded_content = response.content.decode('utf-8')
CSV_DATA = csv.DictReader(decoded_content.splitlines(), delimiter=',')
else :
print(f"Google sheet \n{url} is not available")
sys.exit()
colonnes_requises = ['VIDEO_PATH','NUMERO','commentaires','VITESSE_MAX_CLASSES_VITESSES',
'DATE_VIDEO', 'ALTI_ABS_LAC','ALTI_ABS_DRONE','SENSOR_DATA',
'GSD_HAUTEUR', 'DIAMETRE_DETECTION','DIAMETRE_INTERPOLATION',
'CENTRE_ZONE_DE_DETECTION', 'CENTRE_INTERPOLATION']
# Vérification des colonnes
for column in colonnes_requises:
if column not in CSV_DATA.fieldnames:
raise ValueError(f"{column} is missing in the google sheet or in the csv file.")
return CSV_DATA
def extrapolate_nans(x, y, v):
if x.size == 0 or y.size == 0:
# nothing to do
return np.array([[]])
if np.ma.is_masked(v):
nans = v.mask
else:
nans = np.isnan(v)
notnans = np.logical_not(nans)
v[nans] = interpolate.griddata((x[notnans], y[notnans]), v[notnans],
(x[nans], y[nans]),
method='nearest', rescale=True)
return v