forked from AZMP-NL/python-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
azmp_bottomT_mean_anomaly.py
112 lines (94 loc) · 3.79 KB
/
azmp_bottomT_mean_anomaly.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
'''
To generate AZMP score cards for bottom temperature
Uses pickled object generated by azmp_bottom_stats.py
'''
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import os
# plot tuning:
font = {'family' : 'sans-serif',
'weight' : 'normal',
'size' : 13}
plt.rc('font', **font)
width = 0.7
clim_year = [1981, 2010]
#### ------------- For fall ---------------- ####
# 1.
infile = 'stats_2J_fall.pkl'
df = pd.read_pickle(infile)
df.index = pd.to_datetime(df.index) # update index to datetime
df['area_colder0'] = df['area_colder0']/1000 # In 1000km
df_clim = df[(df.index.year>=clim_year[0]) & (df.index.year<=clim_year[1])]
std_anom = (df-df_clim.mean(axis=0))/df_clim.std(axis=0)
std_anom2J = std_anom[['Tmean', 'Tmean_sha200']]
# 2.
infile = 'stats_3K_fall.pkl'
df = pd.read_pickle(infile)
df.index = pd.to_datetime(df.index) # update index to datetime
df['area_colder0'] = df['area_colder0']/1000 # In 1000km
df_clim = df[(df.index.year>=clim_year[0]) & (df.index.year<=clim_year[1])]
std_anom = (df-df_clim.mean(axis=0))/df_clim.std(axis=0)
std_anom3K = std_anom[['Tmean', 'Tmean_sha300']]
# 3.
infile = 'stats_3LNO_fall.pkl'
df = pd.read_pickle(infile)
df.index = pd.to_datetime(df.index) # update index to datetime
df['area_colder0'] = df['area_colder0']/1000 # In 1000km
df_clim = df[(df.index.year>=clim_year[0]) & (df.index.year<=clim_year[1])]
std_anom = (df-df_clim.mean(axis=0))/df_clim.std(axis=0)
std_anom3LNO = std_anom[['Tmean', 'Tmean_sha100']]
# 4. plot all merged together
std_anom_all = pd.concat([std_anom2J, std_anom3K, std_anom3LNO], axis=1)
df = std_anom_all.mean(axis=1)
df.index = df.index.year
fig = plt.figure(4)
fig.clf()
sign=df>0
df.plot(kind='bar', color=sign.map({True: 'red', False: 'blue'}), width = width)
plt.ylabel('Mean Standardized Anomaly', weight='bold', fontsize=14)
#plt.xlabel('Year')
plt.title('Mean bottom temperature anomaly for 2J3KLNO - Fall', weight='bold', fontsize=14)
plt.grid()
plt.ylim([-2.5,2.5])
#plt.gca().set_xlim([pd.to_datetime('1979-01-01'), pd.to_datetime('2018-01-01')])
fig.set_size_inches(w=15,h=7)
fig_name = 'mean_anomalies_fall.png'
fig.savefig(fig_name)
os.system('convert -trim mean_anomalies_fall.png mean_anomalies_fall.png')
#### ------------- For Spring ---------------- ####
# 1.
infile = 'stats_3LNO_spring.pkl'
df = pd.read_pickle(infile)
df.index = pd.to_datetime(df.index) # update index to datetime
df['area_colder0'] = df['area_colder0']/1000 # In 1000km
df_clim = df[(df.index.year>=clim_year[0]) & (df.index.year<=clim_year[1])]
std_anom = (df-df_clim.mean(axis=0))/df_clim.std(axis=0)
std_anom3LNO = std_anom[['Tmean', 'Tmean_sha100']]
# 2.
infile = 'stats_3Ps_spring.pkl'
df = pd.read_pickle(infile)
df.index = pd.to_datetime(df.index) # update index to datetime
df['area_colder0'] = df['area_colder0']/1000 # In 1000km
df_clim = df[(df.index.year>=clim_year[0]) & (df.index.year<=clim_year[1])]
std_anom = (df-df_clim.mean(axis=0))/df_clim.std(axis=0)
std_anom3Ps = std_anom[['Tmean', 'Tmean_sha100']]
# 4. plot all merged together
std_anom_all = pd.concat([std_anom3LNO, std_anom3Ps], axis=1)
df = std_anom_all.mean(axis=1)
df.index = df.index.year
fig = plt.figure(5)
fig.clf()
sign=df>0
#df.plot(kind='bar', color=sign.map({True: 'darkorange', False: 'steelblue'}), width = width)
df.plot(kind='bar', color=sign.map({True: 'red', False: 'blue'}), width = width)
plt.ylabel('Mean Standardized Anomaly', weight='bold', fontsize=14)
#plt.xlabel('Year')
plt.title('Mean bottom temperature anomaly for 3LNOPs - Spring', weight='bold', fontsize=14)
plt.grid()
plt.ylim([-2.5,2.5])
#plt.gca().set_xlim([pd.to_datetime('1979-01-01'), pd.to_datetime('2018-01-01')])
fig.set_size_inches(w=15,h=7)
fig_name = 'mean_anomalies_spring.png'
fig.savefig(fig_name)
os.system('convert -trim mean_anomalies_spring.png mean_anomalies_spring.png')