-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmelt_composite.py
471 lines (432 loc) · 24 KB
/
melt_composite.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
# Define where the script is running
host = 'jasmin'
# Import packages
import iris
import iris.plot as iplt
import sys
import numpy as np
import pandas as pd
import os
import fnmatch
import scipy
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.ticker import FormatStrFormatter
import matplotlib.dates as mdates
from matplotlib import rcParams
from matplotlib.lines import Line2D
if host == 'jasmin':
sys.path.append('/gws/nopw/j04/bas_climate/users/ellgil82/scripts/Tools/')
elif host == 'bsl':
sys.path.append('/users/ellgil82/scripts/Tools/')
from tools import compose_date, compose_time, find_gridbox
from find_gridbox import find_gridbox
from rotate_data import rotate_data
from divg_temp_colourmap import shiftedColorMap
import time
from sklearn.metrics import mean_squared_error
import datetime
import metpy
import metpy.calc
# Set up filepath
if host == 'jasmin':
filepath = '/gws/nopw/j04/bas_climate/users/ellgil82/hindcast/output/alloutput/ceda_archive/'
elif host == 'bsl':
filepath = '/data/mac/ellgil82/hindcast/output/'
## Load data
def load_vars(year):
try:
melt_flux = iris.load_cube(filepath + year + '_land_snow_melt_flux.nc', 'Snow melt heating flux') # W m-2
melt_amnt = iris.load_cube(filepath + year + '_land_snow_melt_amnt.nc', 'Snowmelt') # kg m-2 TS-1 (TS = 100 s)
melt_amnt = iris.analysis.maths.multiply(melt_amnt, 108.) # 10800 s in 3 hrs / 100 s in a model timestep = 108 ==> melt amount per output timestep
melt_rate = iris.load_cube(filepath+year+'_land_snow_melt_rate.nc', 'Rate of snow melt on land')
orog = iris.load_cube(filepath + 'orog.nc')
orog = orog[0, 0, :, :]
LSM = iris.load_cube(filepath + 'new_mask.nc')
lsm = LSM[0, 0, :, :]
except iris.exceptions.ConstraintMismatchError:
print('Files not found')
var_list = [melt_rate, melt_amnt, melt_flux, lsm, orog]
for i in var_list:
real_lon, real_lat = rotate_data(i, np.ndim(i)-2, np.ndim(i)-1)
vars_yr = {'melt_flux': melt_flux[:-4,0,:,:], 'melt_rate': melt_rate[:-4,0,:,:], 'melt_amnt': melt_amnt[:-4,0,:,:],
'orog': orog, 'lsm': lsm,'lon': real_lon, 'lat': real_lat, 'year': year}
return vars_yr
full_srs = load_vars('1998-2017')
#full_srs = load_vars('2016')
## Set up plotting options
rcParams['font.family'] = 'sans-serif'
rcParams['font.sans-serif'] = ['Segoe UI', 'Helvetica', 'Liberation sans', 'Tahoma', 'DejaVu Sans', 'Verdana']
year_list = ['1998', '1999', '2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017']
def composite_plot(year_list):
fig, ax = plt.subplots(7, 3, figsize=(8, 18))
CbAx = fig.add_axes([0.25, 0.1, 0.5, 0.015])
ax = ax.flatten()
for axs in ax:
axs.axis('off')
total_melt = np.zeros((220,220))
plot = 0
for year in year_list:
vars_yr = load_vars(year)
c = ax[plot].pcolormesh(np.ma.masked_where(vars_yr['orog'].data > 50, a = np.cumsum(vars_yr['melt_amnt'].data, axis = 0)[-1]), vmin = 0, vmax = 300, cmap = 'Blues')
ax[plot].contour(vars_yr['lsm'].data, colors = '#222222', lw = 2)
ax[plot].contour(vars_yr['orog'].data, colors = '#222222', levels = [50])
total_melt = total_melt + (np.cumsum(vars_yr['melt_amnt'].data, axis = 0)[-1])
ax[plot].text(0.4, 1.1, s = year_list[plot], fontsize = 24, color='dimgrey', transform = ax[plot].transAxes)
plot = plot+1
mean_melt_composite = np.ma.masked_where(vars_yr['orog'].data > 50, a =total_melt/len(year_list))
ax[-1].contour(vars_yr['lsm'].data, colors='#222222', lw=2)
ax[-1].pcolormesh(mean_melt_composite)
ax[-1].contour(vars_yr['orog'].data, colors = '#222222', levels=[50])
ax[-1].text(0., 1.1, s = '20 year mean', fontsize = 24, color='dimgrey', transform = ax[-1].transAxes)
cb = plt.colorbar(c, orientation = 'horizontal', cax = CbAx, ticks = [0,150,300])
cb.solids.set_edgecolor("face")
cb.outline.set_edgecolor('dimgrey')
cb.ax.tick_params(which='both', axis='both', labelsize=24, labelcolor='dimgrey', pad=10, size=0, tick1On=False, tick2On=False)
cb.outline.set_linewidth(2)
cb.ax.xaxis.set_ticks_position('bottom')
#cb.ax.set_xticks([0,4,8])
cb.set_label('Annual snow melt amount (mm w.e.)', fontsize = 24, color='dimgrey', labelpad = 30)
plt.subplots_adjust(left = 0.05, right = 0.95, top = 0.95, bottom = 0.15, hspace = 0.3, wspace = 0.05)
if host == 'bsl':
plt.savefig('/users/ellgil82/figures/Hindcast/SMB/melt_all_years.png', transparent = True)
plt.savefig('/users/ellgil82/figures/Hindcast/SMB/melt_all_years.eps', transparent = True)
elif host == 'jasmin':
plt.savefig('/gws/nopw/j04/bas_climate/users/ellgil82/hindcast/figures/melt_all_years.png', transparent = True)
plt.savefig('/gws/nopw/j04/bas_climate/users/ellgil82/hindcast/figures/melt_all_years.eps', transparent = True)
plt.show()
#composite_plot(year_list)
def total_melt(srs):
total_melt = np.zeros((220, 220))
total_melt = total_melt + (np.cumsum(srs['melt_amnt'].data, axis=0)[-1])
#total_melt_masked = np.ma.masked_where(srs['orog'].data > 150, total_melt, copy = True)
totm = total_melt.sum()
return totm, total_melt#_masked
totm, totm_masked = total_melt(full_srs)
def totm_map(vars_yr, mean):
fig, ax = plt.subplots(figsize=(8, 8))
CbAx = fig.add_axes([0.27, 0.2, 0.5, 0.025])
ax.axis('off')
if mean == 'yes':
c = ax.pcolormesh(total_melt/18., vmin = 0,vmax = 400)
xticks = [0,200,400]
cb_lab = 'Annual cumulative snow \nmelt amount (kg m$^{-2}$ year$^{-1}$)'
elif mean == 'no':
Larsen_box = np.zeros((220,220))
Larsen_box[40:135,90:155] = 1.
c = ax.pcolormesh(np.ma.masked_where((Larsen_box == 0.),totm_masked), vmin=0,vmax=6000)
xticks = [0,3000, 6000]
cb_lab = 'Cumulative surface \nmelt amount (mm w.e.)'
ax.contour(vars_yr['lsm'].data, colors='#222222')
ax.contour(vars_yr['orog'].data, colors='#222222', levels=[50])
#plt.colorbar(c, cax = CbAx, orientation = 'horizontal')
cb = plt.colorbar(c, orientation='horizontal', cax=CbAx, ticks=xticks, extend = "max")
cb.solids.set_edgecolor("face")
cb.outline.set_edgecolor('dimgrey')
cb.ax.tick_params(which='both', axis='both', labelsize=24, labelcolor='dimgrey', pad=10, size=0, tick1On=False,tick2On=False)
cb.outline.set_linewidth(2)
cb.ax.xaxis.set_ticks_position('bottom')
# cb.ax.set_xticks([0,4,8])
cb.set_label(cb_lab, fontsize=24, color='dimgrey', labelpad=20)
plt.subplots_adjust(left=0.1, right=0.9, top=0.92, bottom=0.32, hspace=0.3, wspace=0.05)
if host == 'bsl':
if mean == 'yes':
plt.savefig('/users/ellgil82/figures/Hindcast/SMB/melt_cumulative_spatial_annual_mean.png', transparent=True)
plt.savefig('/users/ellgil82/figures/Hindcast/SMB/melt_cumulative_spatial_annual_mean.eps', transparent=True)
else:
plt.savefig('/users/ellgil82/figures/Hindcast/SMB/melt_cumulative_spatial.png', transparent=True)
plt.savefig('/users/ellgil82/figures/Hindcast/SMB/melt_cumulative_spatial.eps', transparent=True)
elif host == 'jasmin':
if mean == 'yes':
plt.savefig('/gws/nopw/j04/bas_climate/users/ellgil82/hindcast/figures/melt_cumulative_spatial_annual_mean.png', transparent=True)
plt.savefig('/gws/nopw/j04/bas_climate/users/ellgil82/hindcast/figures/melt_cumulative_spatial_annual_mean.eps', transparent=True)
else:
plt.savefig('/gws/nopw/j04/bas_climate/users/ellgil82/hindcast/figures/melt_cumulative_spatial.png',transparent=True)
plt.savefig('/gws/nopw/j04/bas_climate/users/ellgil82/hindcast/figures/melt_cumulative_spatial.eps',transparent=True)
plt.show()
#totm_map(full_srs, mean = 'yes')
totm_map(full_srs, mean = 'no')
def melt_srs():
if host == 'jasmin':
filepath = '/gws/nopw/j04/bas_climate/users/ellgil82/hindcast/output/alloutput/'
ancil_path = '/gws/nopw/j04/bas_climate/users/ellgil82/hindcast/output/'
lsm_name = 'land_binary_mask'
elif host == 'bsl':
filepath = '/data/mac/ellgil82/hindcast/output/'
ancil_path = filepath
lsm_name = 'LAND MASK (No halo) (LAND=TRUE)'
try:
orog = iris.load_cube(ancil_path + 'orog.nc', 'surface_altitude')
orog = orog[0, 0, :, :]
LSM = iris.load_cube(ancil_path + 'new_mask.nc', lsm_name)
LSM = LSM[0, 0, :, :]
except iris.exceptions.ConstraintMismatchError:
print('Files not found')
tot_melt = iris.load_cube('1998-2017_land_snow_melt_amnt.nc')
tot_melt = tot_melt[0]
real_lon, real_lat = rotate_data(tot_melt, 1, 2)
srs_vars = {'real_lon': real_lon, 'real_lat': real_lat, 'tot_melt': tot_melt, 'orog': orog, 'lsm': LSM}
return srs_vars
# Create geographic location dictionaries necessary for plotting etc.
srs_vars = full_srs
lon_index14, lat_index14, = find_gridbox(-67.01, -61.03, srs_vars['real_lat'], srs_vars['real_lon'])
lon_index15, lat_index15, = find_gridbox(-67.34, -62.09, srs_vars['real_lat'], srs_vars['real_lon'])
lon_index17, lat_index17, = find_gridbox(-65.93, -61.85, srs_vars['real_lat'], srs_vars['real_lon'])
lon_index18, lat_index18, = find_gridbox(-66.48272, -63.37105, srs_vars['real_lat'], srs_vars['real_lon'])
lat_dict = {'AWS14': -67.01,
'AWS15': -67.34,
'AWS17': -65.93,
'AWS18': -66.48272}
lon_dict = {'AWS14': -61.03,
'AWS15': -62.09,
'AWS17': -61.85,
'AWS18': -63.37105}
station_dict = {'AWS14_SEB_2009-2017_norp.csv': 'AWS14',
'AWS15_hourly_2009-2014.csv': 'AWS15',
'AWS17_SEB_2011-2015_norp.csv': 'AWS17',
'AWS18_SEB_2014-2017_norp.csv': 'AWS18'}
def calc_melt_days(melt_var):
melt = np.copy(melt_var)
melt[melt > 0.] = 1. # if melt is detected at a timestep, this is 1 (i.e. True)
out = melt.reshape(-1, 8, melt.shape[1], melt.shape[2]).sum(1)
out = melt.sum(0)
melt_days = np.count_nonzero(out, axis = 0)
melt_days = np.ma.masked_where((full_srs['lsm'].data == 0.), out)
#melt_days = np.ma.masked_where((full_srs['orog'].data > 50.), melt_days)
return melt_days
#melt_max = iris.load_cube('1998-2017_land_snow_melt_amnt_daymax.nc')
#melt_max = melt_max[:,0,:,:]
melt_days = calc_melt_days(full_srs['melt_flux'].data)
def calc_melt_duration(melt_var):
melt = np.copy(melt_var)
melt_periods = np.count_nonzero(melt, axis = 0)
melt_periods = melt_periods*3. # multiply by 3 to get number of hours per year (3-hourly data)
return melt_periods
year_list = range(1998,2018)
def chop_melt_yrs():
# second half of 1997 doesn't exist, so create empty array of zeros
second_half_melt = np.zeros((220,220))
melt_days_2 = np.zeros((220, 220))
for yr in year_list[:-1]:
print("\nChopping " + str(yr) + " in 'alf...")
df = pd.DataFrame()
df['Timesrs'] = pd.date_range(datetime.datetime(int(yr), 1, 1, 0, 0, 0),
datetime.datetime(int(yr), 12, 31, 23, 59, 59), freq='D')
months = [g for n,g in df.groupby(pd.Grouper(key = 'Timesrs', freq = 'M'))]
first_half = pd.concat(months[:7])
up_to = len(first_half) # find index to cut off at
then_from = up_to
melt_yr1 = iris.load_cube(filepath + str(int(yr)) + '_land_snow_melt_amnt_daysum.nc')
melt_yr1 = melt_yr1[:,0,:,:]*108. # convert from per ts
# find cumulative melt up to end of July
print("\nFinding number of melt days in first half of " + str(yr))
first_half_melt = np.cumsum(melt_yr1[:up_to, :,:].data, axis = 0)[-1]
melt_days_1 = np.count_nonzero(melt_yr1[:up_to, :,:].data, axis = 0)
print("\nAdding to the end of " + str(yr-1))
melt_seas = second_half_melt + first_half_melt
melt_days_seas = melt_days_2 + melt_days_1
# Save as a file
print("\nSaving files...")
melt_seas = iris.cube.Cube(melt_seas)
melt_days_seas = iris.cube.Cube(melt_days_seas)
iris.save(melt_seas, filepath + 'total_melt_amnt_during_' + str(yr)[-2:] + '-' + str(yr+1)[-2:]+ '_melt_season.nc')
iris.save(melt_days_seas, filepath + 'number_of_melt_days_during_' + str(yr)[-2:] + '-' + str(int(yr) + 1)[-2:] + '_melt_season.nc')
print("\nFinding number of melt days in second half of " + str(yr))
melt_yr2 = iris.load_cube(filepath + str(int(yr) + 1) + '_land_snow_melt_amnt_daysum.nc')
melt_yr2 = melt_yr2[:,0,:,:]*108.
# The second half of the year will then get added to the first half of the next year
second_half_melt = np.cumsum(melt_yr2[then_from:, :,:].data, axis = 0)[-1]
try:
melt_days_2 = np.count_nonzero(melt_yr2[then_from:, :, :].data, axis = 0)
except:
try:
melt_days_2 = calc_melt_days(melt_yr2[then_from+2:, :, :].data)
except:
melt_days_2 = calc_melt_days(melt_yr2[then_from+4:, :, :].data)
#chop_melt_yrs()
# Find all days where melt occurs during at least one timestep
#melt_duration = calc_melt_duration(full_srs['melt_amnt'].data)
full_srs = {}
orog = iris.load_cube(filepath + 'orog.nc')
full_srs['orog'] = orog[0, 0, :, :]
LSM = iris.load_cube(filepath + 'new_mask.nc')
full_srs['lsm'] = LSM[0, 0, :, :]
real_lon, real_lat = rotate_data(full_srs['lsm'], np.ndim(full_srs['lsm']) - 2, np.ndim(full_srs['lsm']) - 1)
def composite_melt_seasons(days_or_amnt):
fig, ax = plt.subplots(5, 4, figsize=(10, 18))
CbAx = fig.add_axes([0.25, 0.1, 0.5, 0.01])
ax = ax.flatten()
for axs in ax:
axs.axis('off')
file_list = []
if days_or_amnt == 'days':
for file in os.listdir(filepath):
if fnmatch.fnmatch(file, 'number_of_melt_days_during_??-??_melt_season.nc'):
file_list.append(file)
first_file = 'number_of_melt_days_during_98-99_melt_season.nc'
second_file = 'number_of_melt_days_during_99-00_melt_season.nc'
vmax = 100
vmin = 25
elif days_or_amnt == 'amnt':
for file in os.listdir(filepath):
if fnmatch.fnmatch(file, 'total_melt_amnt_during_??-??_melt_season.nc'):
file_list.append(file)
first_file = 'total_melt_amnt_during_98-99_melt_season.nc'
second_file = 'total_melt_amnt_during_99-00_melt_season.nc'
vmax = 350
vmin = 0
file_list = file_list[:-2]
file_list = [first_file] + [second_file] + file_list
total_melt = np.ma.masked_where((full_srs['lsm']== 0.), a = np.zeros((220,220)))
for i in range(len(file_list)):
Larsen_box = np.zeros((220,220))
Larsen_box[40:135,90:155] = 1.
melt = iris.load_cube(filepath + file_list[i])
#melt_masked = np.ma.masked_where((full_srs['orog'].data > 250), a =melt.data)
c = ax[i].pcolormesh(np.ma.masked_where((Larsen_box[40:135, 90:155] == 0.), melt[40:135, 90:155].data), vmin = vmin, vmax = vmax, cmap='Blues') #[0,:,:]), vmin = 0, vmax = 300)#, cmap = 'RdYlGn_r')
ax[i].contour(full_srs['lsm'][40:135, 90:155].data, colors = '#222222', lw = 2)
ax[i].contour(full_srs['orog'][40:135, 90:155].data, colors = '#222222', levels = [50])
ax[i].contour(full_srs['orog'][40:135, 90:155].data, colors='dimgrey', lw=0.1, levels=[500, 1000, 1500])
if days_or_amnt == 'amnt':
ax[i].text(0.4, 1.1, s= file_list[i][23:25]+'/'+file_list[i][26:28], fontsize=24, color='dimgrey', transform=ax[i].transAxes)
else:
ax[i].text(0.4, 1.1, s=file_list[i][27:29] + '/' + file_list[i][30:32], fontsize=24, color='dimgrey',
transform=ax[i].transAxes)
total_melt = total_melt + np.ma.masked_where(full_srs['lsm'] == 0., a= melt.data)
c = ax[-1].pcolormesh(np.ma.masked_where((Larsen_box[40:135, 90:155] == 0.), total_melt[40:135, 90:155]/19.), vmin = vmin, vmax = vmax, cmap = 'Blues')#, cmap = 'RdYlGn_r')np.ma.masked_where(full_srs['orog'].data > 250, a = np.ma.masked_where(full_srs['lsm'] == 0.,a =
ax[-1].contour(full_srs['lsm'][40:135, 90:155].data, colors='#222222', lw=2)
ax[-1].contour(full_srs['orog'][40:135, 90:155].data, colors='#222222', levels=[50])
ax[-1].contour(full_srs['orog'][40:135, 90:155].data, colors='dimgrey', lw=0.1, levels = [500, 1000, 1500])
ax[-1].text(0.3, 1.1, s='Mean', fontsize=24, color='dimgrey', transform=ax[-1].transAxes)
if days_or_amnt == 'days':
label = 'Number of melt days per year'
ticks = [0, 25, 50, 75, 100]
fig_str = 'days'
extend = 'both'
elif days_or_amnt == 'amnt':
label = 'Annual cumulative surface melt amount (mm w.e.)'
ticks = [0, 200, 350, 500]
fig_str = 'amnt'
extend = 'max'
cb = plt.colorbar(c, orientation = 'horizontal', cax = CbAx, ticks = ticks, extend = extend)
cb.solids.set_edgecolor("face")
cb.outline.set_edgecolor('dimgrey')
cb.ax.tick_params(which='both', axis='both', labelsize=24, labelcolor='dimgrey', pad=10, size=0, tick1On=False, tick2On=False)
cb.outline.set_linewidth(2)
cb.ax.xaxis.set_ticks_position('bottom')
cb.set_label(label, fontsize=24, color='dimgrey', labelpad=30)
plt.subplots_adjust(left = 0.05, right = 0.95, top = 0.95, bottom = 0.15, hspace = 0.3, wspace = 0.05)
if host == 'bsl':
plt.savefig('/users/ellgil82/figures/Hindcast/SMB/melt_all_years.png', transparent = True)
plt.savefig('/users/ellgil82/figures/Hindcast/SMB/melt_all_years.eps', transparent = True)
elif host == 'jasmin':
plt.savefig('/gws/nopw/j04/bas_climate/users/ellgil82/hindcast/figures/Total_melt_'+fig_str+'_per_year_blue.png', transparent = True)
plt.savefig('/gws/nopw/j04/bas_climate/users/ellgil82/hindcast/figures/Total_melt_'+fig_str+'_per_year_blue.eps', transparent = True)
plt.show()
return total_melt
#total_melt = composite_melt_seasons('amnt')
total_melt = composite_melt_seasons('days')
def mean_melt_dur(total_melt, vars_yr):
fig, ax = plt.subplots(figsize=(8, 8))
CbAx = fig.add_axes([0.25, 0.2, 0.5, 0.025])
plt.setp(ax.spines.values(), linewidth=0, color='dimgrey')
ax.tick_params(which='both', axis='both', labelsize=24, labelcolor='dimgrey', pad=10, size=0)
PlotLonMin = np.min(real_lon[90:155])
PlotLonMax = np.max(real_lon[90:155])
PlotLatMin = np.min(real_lat[40:135])
PlotLatMax = np.max(real_lat[40:135])
XTicks = np.linspace(PlotLonMin, PlotLonMax, 4)
XTickLabels = [None] * len(XTicks)
for i, XTick in enumerate(XTicks):
if XTick < 0:
XTickLabels[i] = '{:.0f}{:s}'.format(np.abs(XTick), '$^{\circ}$W')
else:
XTickLabels[i] = '{:.0f}{:s}'.format(np.abs(XTick), '$^{\circ}$E')
ax.set_xticks(XTicks, XTickLabels)
ax.set_xlim(PlotLonMin, PlotLonMax)
YTicks = np.linspace(PlotLatMin, PlotLatMax, 4)
YTickLabels = [None] * len(YTicks)
for i, YTick in enumerate(YTicks):
if YTick < 0:
YTickLabels[i] = '{:.0f}{:s}'.format(np.abs(YTick), '$^{\circ}$S')
else:
YTickLabels[i] = '{:.0f}{:s}'.format(np.abs(YTick), '$^{\circ}$N')
plt.yticks(YTicks, YTickLabels)
ax.set_ylim(PlotLatMin, PlotLatMax)
xlon, ylat = np.meshgrid(real_lon[90:155], real_lat[40:135])
cb_lab = 'Annual mean melt duration(days per year)'
c = ax.pcolormesh(xlon, ylat, (total_melt[40:135, 90:155] / 19.), vmin=0, vmax=100, cmap='RdYlGn_r')
ax.contour(xlon,ylat,vars_yr['lsm'][40:135, 90:155].data, colors='#222222')
ax.contour(xlon,ylat,vars_yr['orog'][40:135, 90:155].data, colors='#222222', levels=[50])
ax.contour(xlon,ylat,vars_yr['orog'][40:135, 90:155].data, colors='lightgrey', levels=[500,1000,1500], lw = 0.1)
plt.colorbar(c, cax = CbAx, orientation = 'horizontal')
cb = plt.colorbar(c, orientation='horizontal', cax=CbAx, ticks=[0,50,100], extend = "max")
cb.solids.set_edgecolor("face")
cb.outline.set_edgecolor('dimgrey')
cb.ax.tick_params(which='both', axis='both', labelsize=24, labelcolor='dimgrey', pad=10, size=0, tick1On=False,tick2On=False)
cb.outline.set_linewidth(2)
cb.ax.xaxis.set_ticks_position('bottom')
cb.set_label(cb_lab, fontsize=24, color='dimgrey', labelpad=30)
plt.subplots_adjust(left=0.15, right=0.95, top=0.92, bottom=0.3, hspace=0.3, wspace=0.05)
if host == 'jasmin':
plt.savefig('/gws/nopw/j04/bas_climate/users/ellgil82/hindcast/figures/melt_duration_cf_Luckman14_&_Bevan18.png',transparent=True)
plt.savefig('/gws/nopw/j04/bas_climate/users/ellgil82/hindcast/figures/melt_duration_cf_Luckman14_&_Bevan18.eps',transparent=True)
plt.show()
mean_melt_dur(total_melt, full_srs)
def melt_table():
df = pd.DataFrame(index = ['Annual ice shelf integrated melt', 'Maximum meltwater production', 'Minimum meltwater production'])
file_list = []
for file in os.listdir(filepath):
if fnmatch.fnmatch(file, 'total_melt_amnt_during_??-??_melt_season.nc'):
file_list.append(file)
first_file = ['total_melt_amnt_during_98-99_melt_season.nc', 'total_melt_amnt_during_99-00_melt_season.nc']
file_list = file_list[:-2]
file_list = first_file + file_list
for file in file_list:
melt = iris.load_cube(filepath + file)
mn_melt = np.mean(melt.data[40:135, 90:155]) # Larsen C average
max_melt = np.max(melt.data[40:135, 90:155]) # Larsen C average
min_melt = np.min(melt.data[40:135, 90:155])
df[file[23:28]] = [mn_melt, max_melt, min_melt]
df = df.transpose()
#print(df)
df.to_csv(filepath + 'Melt_season_integrated_ice_shelf_totals.csv')
return df
df = melt_table()
def boxplot():
fig, ax = plt.subplots(figsize = (14, 6))
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
plt.setp(ax.spines.values(), linewidth=3, color='dimgrey')
labels=['98/99', '99/00', '00/01', '01/02', '02/03', '03/04', '04/05', '05/06', '06/07', '07/08', '08/09', '09/10',
'10/11', '11/12', '12/113', '13/14', '14/15', '15/16', '16/17']
ax.boxplot(df, labels=labels, patch_artist=True, medianprops=dict(color="white",linewidth=2), boxprops=dict(color='k', lw=2), meanline=True)
[l.set_visible(False) for (i, l) in enumerate(ax.xaxis.get_ticklabels()) if i % 3 != 0]
ax.yaxis.set_label_coords(-0.22, 0.4)
ax.set_ylabel('Meltwater \nproduction \n(mm w.e. yr$^{-1}$)', rotation=0, fontname='SegoeUI semibold', color='dimgrey', fontsize=24, labelpad=80)
ax.tick_params(which='both', axis='both', labelsize=24, labelcolor='dimgrey', pad=10, size=8, color = 'dimgrey', width = 3, tick2On=False)
plt.subplots_adjust(left=0.25, right = 0.95, top = 0.95, bottom = 0.15)
plt.savefig('/gws/nopw/j04/bas_climate/users/ellgil82/hindcast/figures/Total_melt_Larsen_C_boxplot.png')
plt.savefig('/gws/nopw/j04/bas_climate/users/ellgil82/hindcast/figures/Total_melt_Larsen_C_boxplot.eps')
plt.show()
boxplot()
def plot_melt_trends():
fig, ax = plt.subplots(figsize = (10, 6))
ax.plot(df['Annual ice shelf integrated melt'], color = 'orange', label = 'Mean', lw = 4)
ax.plot(df['Maximum meltwater production'], color = 'darkred', label = 'Maximum', lw = 4)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
plt.setp(ax.spines.values(), linewidth=3, color='dimgrey')
ax.set_ylabel('\n\n\n\nLarsen C annual meltwater \nproduction (mm w.e year$^{-1}$)', fontname='SegoeUI semibold', color='dimgrey', fontsize=24, labelpad=20)
[l.set_visible(False) for (i, l) in enumerate(ax.xaxis.get_ticklabels()) if i % 4 != 0]
ax.set_yticks([0,500,1000])
lgd = plt.legend(bbox_to_anchor=(0.9, 0.85), borderaxespad=0., loc='best', prop={'size': 18})
for ln in lgd.get_texts():
plt.setp(ln, color='dimgrey')
lgd.get_frame().set_linewidth(0.0)
plt.tick_params(axis='both', which='both', labelsize=24, tick1On=False, tick2On=False, labelcolor='dimgrey', pad=5)
plt.subplots_adjust(left = 0.25, right = 0.95, top = 0.85)
plt.savefig('/gws/nopw/j04/bas_climate/users/ellgil82/hindcast/figures/Meltwater_production_trends_LarsenC.png')
plt.savefig('/gws/nopw/j04/bas_climate/users/ellgil82/hindcast/figures/Meltwater_production_trends_LarsenC.eps')
plt.show()
plot_melt_trends()