-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZonalFunctions.py
87 lines (65 loc) · 2.5 KB
/
ZonalFunctions.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
77
78
79
80
81
82
83
84
85
86
import os
import datetime
import pandas as pd
# import seaborn as sns
import numpy as np
import scipy.signal as sps
# import xarray as xr
# %matplotlib inline
from matplotlib import pyplot as plt
import matplotlib.colors
# from cartopy import config
# import cartopy.crs as ccrs
from numpy import ma
# from tqdm.notebook import trange, tqdm
from time import time
from glob import glob
import matplotlib.lines as mlines
def readRFRfeatures(filename):
RAW_DATA = {}
f = open(filename,'r')
first = True
for line in f.readlines():
l = line.strip().split(',')
if first:
labels = [x[1:-1] for x in l]
for k in labels:
if k != 't':
RAW_DATA[k] = []
first = False
else:
for i,v in enumerate(l):
if i == 0:
continue
RAW_DATA[labels[i]].append(float(v))
return RAW_DATA
# def plotPredictions(INPUT,TARGET,ax,name,SUBSET):
# ax.plot(TARGET,label=name)
# ax.legend(loc=1)
# ax.plot(INPUT,label=name+"*",color='orange')
# ax.legend(loc=1)
# from sklearn.metrics import r2_score
# from sklearn.metrics import explained_variance_score
# from sklearn.metrics import mean_absolute_error
# from sklearn.metrics import mean_squared_error
# SCORE_r2 = r2_score(TARGET, INPUT)
# n = 1200 # days = samples, but this shouldn't be hardcoded, this is only for the daily max right now!
# p = len(SUBSET)+1 # input features + RV = independent variables, probably shouldn't hard code the addition of the RV
# SCORE_r2adj = 1-(1-SCORE_r2)*(n-1)/(n-p-1) ## calculate adjusted R2
# SCORE_expVar = explained_variance_score(TARGET, INPUT)
# SCORE_meanErr = mean_absolute_error(TARGET, INPUT)
# SCORE_RMSE = np.sqrt(mean_squared_error(TARGET, INPUT, squared=True))
# return SCORE_r2adj, SCORE_RMSE, SCORE_meanErr
def plotScatter(INPUT,TARGET,ax,name):
lmin = min(min(INPUT),max(INPUT),min(TARGET),max(TARGET))
lmax = max(min(INPUT),max(INPUT),min(TARGET),max(TARGET))
line = mlines.Line2D([lmin, lmax], [lmin, lmax], color='black')
ax.scatter(INPUT,TARGET,label=name, alpha = 0.15)
ax.add_line(line)
# ax.legend(loc=1)
from sklearn.metrics import r2_score
from sklearn.metrics import mean_squared_error
import math
SCORE_r2 = r2_score(TARGET, INPUT)
SCORE_RMSE = math.sqrt(mean_squared_error(TARGET, INPUT, squared=True))
# return SCORE_r2, SCORE_RMSE