-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsession_4_time_series.py
More file actions
82 lines (62 loc) · 1.69 KB
/
session_4_time_series.py
File metadata and controls
82 lines (62 loc) · 1.69 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
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
# %%
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
# %%
t_min = pd.to_datetime("2013-08-25")
t_max = pd.to_datetime("2013-12-15")
# %%
df0 = pd.read_csv("data/water_level_example.csv", parse_dates=["Date", "Time"])
print(df0.head())
# %%
df0 = pd.read_csv("data/water_level_example.csv")
df0 = df0.set_index(pd.to_datetime(df0["Date"].astype(str) + " " + df0["Time"].astype(str)))
print(df0.head())
# %%
df0 = df0.drop(["Date", "Time", "ms"], axis=1)
print(df0.head())
# %%
df0['LEVEL'].plot()
# %%
ax = df0['LEVEL'].plot()
ax.set_xlim("2013-09-15", "2013-10-15")
# %%
df0 = df0.interpolate()
ax = df0['LEVEL'].plot()
ax.set_xlim("2013-09-15", "2013-10-15")
# %%
dfm = pd.read_excel("data/manual_readings.xlsx", index_col=0, parse_dates=True)
# df0['LEVEL'] = -df0['LEVEL']
df0['manual'] = dfm / -100.
fig, ax = plt.subplots()
ax.plot(df0.index, df0['LEVEL'])
ax.plot(df0.index, df0['manual'], 'o')
# %%
wl_offset = np.nanmean(df0['manual'] - df0['LEVEL'])
fig, ax = plt.subplots()
ax.plot(df0.index, wl_offset + df0['LEVEL'])
ax.plot(df0.index, df0['manual'], 'o')
# %%
sheets_dict = pd.read_excel(
"data/weather_data_by_month.xlsx",
index_col=0,
parse_dates=True,
sheet_name=None,
)
# %%
dfd = pd.DataFrame()
for sheet_name, df in sheets_dict.items():
dfd = pd.concat((dfd, df))
# %%
idx = (dfd.index >= t_min) & (dfd.index <= t_max)
dfd = dfd.loc[idx]
# %%
dfwl = wl_offset + df0["LEVEL"].resample('1D').mean()
dfd['wl'] = dfwl
# %%
p_func_V = np.poly1d(np.loadtxt("p_coef_V_linear.dat"))
p_func_A = np.poly1d(np.loadtxt("p_coef_A_linear.dat"))
dfd["volume"] = p_func_V(dfd["wl"])
dfd["area"] = p_func_A(dfd["wl"])
# %%
dfd.to_excel("daily_wl&meteo_data.xlsx")