-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
37 lines (31 loc) · 1.13 KB
/
utils.py
File metadata and controls
37 lines (31 loc) · 1.13 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
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()
print(f"Colonnes disponibles dans le Google Sheet : {CSV_DATA.fieldnames}")
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