-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1_local_effect_snow.py
73 lines (67 loc) · 2.95 KB
/
1_local_effect_snow.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
# -*- coding: utf-8 -*-
"""
@author: [email protected]
tip list:
%matplotlib inline
%matplotlib qt
import pdb; pdb.set_trace()
"""
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import numpy as np
from textwrap import wrap
plt.close('all')
notes = pd.read_csv('data/Michele/time lapse/notes.txt', skipinitialspace=True)
notes['time'] = pd.to_datetime(notes.time)
notes = notes.set_index(['site', 'time']).sort_index()
df_gst = pd.read_csv('data/GST_data.csv', skipinitialspace=True)
df_gst['time'] = pd.to_datetime(df_gst.time)
df_gst = df_gst.set_index(['site', 'time']).sort_index()
color_code = {'snow free': 'wheat',
'left side picture snow free': 'wheat',
'patchy snow on rest of picture': 'lightcyan',
'base snow free': 'lightcyan',
'logger melted out': 'lightcyan',
'logger out rest of picture snow covered': 'lightcyan',
'partial snow cover': 'lightblue',
'partially snow covered': 'lightblue',
'left side picture partially melted': 'lightblue',
'left side picture almost melted': 'lightblue',
'left side picture partially snow cover': 'lightblue',
'lower part snow covered': 'lightblue',
'snow cover': 'blue',
'snow covered': 'blue',
'snow cover except wall behind logger': 'blue',
'left side picture covered with snow while logger still exposed': 'blue',
'thick snow cover': 'steelblue',
'polar night': 'gray',
'camera covered': 'gray',
}
for site_id in notes.index.get_level_values('site').unique():
# site_id = 'ae1'
all_sites=df_gst.index.get_level_values('site').unique()
if len(all_sites[all_sites.str.lower().str.contains(site_id)])==0:
continue
site = all_sites[all_sites.str.lower().str.contains(site_id)].values[0]
print(site)
fig,ax = plt.subplots(1,1, figsize=(7,3.5))
plt.subplots_adjust(top=0.6)
df_gst.loc[site,'GST'].plot(ax=ax, label='_nolegend_')
site_notes = notes.loc[site_id,'note']
cmap = cm.get_cmap('tab20', len(site_notes.unique()))
for i in range(len(site_notes)-1):
ax.axvspan(site_notes.index[i].to_pydatetime(),
site_notes.index[i+1].to_pydatetime(),
alpha=0.5,color=color_code[site_notes.iloc[i]],
label='_nolegend_')
labels = [ '\n'.join(wrap(l, 20)) for l in site_notes.unique()]
for i in range(len(site_notes.unique())):
ax.axvspan(np.nan, np.nan,
alpha=0.5,color=color_code[site_notes.unique()[i]],
label=labels[i])
plt.legend(title=site, ncol=3, loc='lower center', bbox_to_anchor=(0.5,1.05))
plt.ylabel('GST ($^o$C)')
plt.xlim(site_notes.index[0], site_notes.index[-1])
# plt.tight_layout()
fig.savefig('plots/'+site+'_GST_labeled.png',bbox_inches='tight', dpi=300)