Commit 91b00ea7 authored by Kennedy, Joseph H's avatar Kennedy, Joseph H
Browse files

LEX-0.1-rc2

A second release candidate of the LIVVkit Extensions repository to
demonstrate our extensions functionality. It lincludes the CESM
Greenland analyses for cloud cover, energy balance, and surface mass
balance, as well the CISM-Albany dynamics analyses, which will be
documented in the Evans et al. (2018) LIVVkit validation paper.

This relase candidate:
    Improves the context of all plots and tables
    Fixes some display issues in plots and tables
parents 4c4655cf b4e536dd
# coding=utf-8
import os
import Ngl
import numpy as np
......@@ -8,7 +10,16 @@ from netCDF4 import Dataset
from livvkit.util import elements as el
describe = """CESM_RACMO23_lwsd plot."""
describe = """
Average of the annual average downward longwave radiation (W m^-2) over Greenland
for every summer (June-July-August; JJA) from 1980--1999
for CESM (left) and RACMO 2.3 (middle), and the difference between them (right; CESM -
RACMO 2.3). The black solid lines denote the 0, 1000, 2000, and 3000 meter
Greenland ice sheet elevation contours as seen by the models (CESM's contours
shown in the difference plot).
"""
title = "Summer downward longwave radiation"
def make_plot(config, out_path='.'):
......@@ -221,7 +232,7 @@ def make_plot(config, out_path='.'):
img_link = os.path.join(os.path.basename(out_path),
os.path.basename(wks_img + '.' + wks_type))
img_elem = el.image('CESM_RACMO23_lwsd',
img_elem = el.image(title,
' '.join(describe.split()),
img_link)
img_elem['Height'] = config['image_height']
......
# coding=utf-8
import os
import Ngl
import numpy as np
......@@ -8,7 +10,16 @@ from netCDF4 import Dataset
from livvkit.util import elements as el
describe = """CESM_RACMO23_lwsn plot."""
describe = """
Average of the annual average net longwave radiation (W m^-2) over Greenland
for every summer (June-July-August; JJA) from 1980--1999
for CESM (left) and RACMO 2.3 (middle), and the difference between them (right; CESM -
RACMO 2.3). The black solid lines denote the 0, 1000, 2000, and 3000 meter
Greenland ice sheet elevation contours as seen by the models (CESM's contours
shown in the difference plot).
"""
title = "Net summer longwave radiation"
def make_plot(config, out_path='.'):
......@@ -229,7 +240,7 @@ def make_plot(config, out_path='.'):
img_link = os.path.join(os.path.basename(out_path),
os.path.basename(wks_img + '.' + wks_type))
img_elem = el.image('CESM_RACMO23_lwsn',
img_elem = el.image(title,
' '.join(describe.split()),
img_link)
img_elem['Height'] = config['image_height']
......
# coding=utf-8
import os
import Ngl
import numpy as np
......@@ -8,7 +10,16 @@ from netCDF4 import Dataset
from livvkit.util import elements as el
describe = """CESM_RACMO23_rnet plot."""
describe = """
Average of the summer (June-July-August; JJA) average net radiation (W m^-2)
over Greenland for every summer (June-July-August; JJA) from 1980--1999
for CESM (left) and RACMO 2.3 (middle), and the difference between them (right; CESM -
RACMO 2.3). The black solid lines denote the 0, 1000, 2000, and 3000 meter
Greenland ice sheet elevation contours as seen by the models (CESM's contours
shown in the difference plot).
"""
title = "Net summer radiation"
def make_plot(config, out_path='.'):
......@@ -238,7 +249,7 @@ def make_plot(config, out_path='.'):
img_link = os.path.join(os.path.basename(out_path),
os.path.basename(wks_img + '.' + wks_type))
img_elem = el.image('CESM_RACMO23_rnet',
img_elem = el.image(title,
' '.join(describe.split()),
img_link)
img_elem['Height'] = config['image_height']
......
# coding=utf-8
import os
import Ngl
import numpy as np
......@@ -8,7 +10,16 @@ from netCDF4 import Dataset
from livvkit.util import elements as el
describe = """CESM_RACMO23_senf plot."""
describe = """
Average of the annual average sensible heat flux (W m^-2) over Greenland for
every summer (June-July-August; JJA) from 1980--1999 for CESM (left) and RACMO
2.3 (middle), and the difference between them (right; CESM - RACMO 2.3). The
black solid lines denote the 0, 1000, 2000, and 3000 meter Greenland ice sheet
elevation contours as seen by the models (CESM's contours shown in the
difference plot).
"""
title = "Net shortwave radiation"
def make_plot(config, out_path='.'):
......@@ -222,7 +233,7 @@ def make_plot(config, out_path='.'):
img_link = os.path.join(os.path.basename(out_path),
os.path.basename(wks_img + '.' + wks_type))
img_elem = el.image('CESM_RACMO23_senf',
img_elem = el.image(title,
' '.join(describe.split()),
img_link)
img_elem['Height'] = config['image_height']
......
# coding=utf-8
import os
import Ngl
......@@ -9,7 +11,15 @@ from netCDF4 import Dataset
from livvkit.util import elements as el
describe = """CESM_RACMO23_smb plot."""
describe = """
Average of the annual average surface mass balance (kg m^-2 a^-1) over Greenland for every
summer (June-July-August; JJA) from 1980--1999 for CESM (left) and RACMO 2.3 (middle),
and the difference between them (right; CESM - RACMO 2.3). The black solid lines denote
the 0, 1000, 2000, and 3000 meter Greenland ice sheet elevation contours as seen by
the models (CESM's contours shown in the difference plot).
"""
title = "Summer surface mass balance"
def make_plot(config, out_path='.'):
......@@ -244,7 +254,7 @@ def make_plot(config, out_path='.'):
img_link = os.path.join(os.path.basename(out_path),
os.path.basename(wks_img + '.' + wks_type))
img_elem = el.image('CESM_RACMO23_smb',
img_elem = el.image(title,
' '.join(describe.split()),
img_link)
img_elem['Height'] = config['image_height']
......
# coding=utf-8
import os
import Ngl
import numpy as np
......@@ -8,7 +10,15 @@ from netCDF4 import Dataset
from livvkit.util import elements as el
describe = """CESM_RACMO23_swsd plot."""
describe = """
Average of the annual average downward shortwave radiation (W m^-2) over Greenland
for every summer (June-July-August; JJA) from 1980--1999 for CESM (left) and
RACMO 2.3 (middle), and the difference between them (right; CESM - RACMO 2.3).
The black solid lines denote the 0, 1000, 2000, and 3000 meter Greenland ice sheet
elevation contours as seen by the models (CESM's contours shown in the difference plot).
"""
title = "Summer downward shortwave radiation"
def make_plot(config, out_path='.'):
......@@ -219,7 +229,7 @@ def make_plot(config, out_path='.'):
img_link = os.path.join(os.path.basename(out_path),
os.path.basename(wks_img + '.' + wks_type))
img_elem = el.image('CESM_RACMO23_swsd',
img_elem = el.image(title,
' '.join(describe.split()),
img_link)
img_elem['Height'] = config['image_height']
......
# coding=utf-8
import os
import Ngl
import numpy as np
......@@ -8,7 +10,15 @@ from netCDF4 import Dataset
from livvkit.util import elements as el
describe = """CESM_RACMO23_swsn plot."""
describe = """
Average of the average net shortwave radiation (W m^-2)
over Greenland for every summer (June-July-August; JJA) from 1980--1999 for CESM (left)
and RACMO 2.3 (middle), and the difference between them (right; CESM - RACMO 2.3).
The black solid lines denote the 0, 1000, 2000, and 3000 meter Greenland ice sheet
elevation contours as seen by the models (CESM's contours shown in the difference plot).
"""
title = "Net Summer shortwave radiation"
def make_plot(config, out_path='.'):
......@@ -223,7 +233,7 @@ def make_plot(config, out_path='.'):
img_link = os.path.join(os.path.basename(out_path),
os.path.basename(wks_img + '.' + wks_type))
img_elem = el.image('CESM_RACMO23_swsn',
img_elem = el.image(title,
' '.join(describe.split()),
img_link)
img_elem['Height'] = config['image_height']
......
# coding=utf-8
import os
import Ngl
import numpy as np
......@@ -8,7 +10,15 @@ from netCDF4 import Dataset
from livvkit.util import elements as el
describe = """CESM_RACMO23_t2m_ann plot."""
describe = """
Average of the annual average 2-meter air temperature (°C) over Greenland from 1980--1999
for CESM (left) and RACMO 2.3 (middle), and the difference between them (right; CESM -
RACMO 2.3). The black solid lines denote the 0, 1000, 2000, and 3000 meter
Greenland ice sheet elevation contours as seen by the models (CESM's contours
shown in the difference plot).
"""
title = "Annual 2-meter air temperature"
def make_plot(config, out_path='.'):
......@@ -212,7 +222,7 @@ def make_plot(config, out_path='.'):
img_link = os.path.join(os.path.basename(out_path),
os.path.basename(wks_img + '.' + wks_type))
img_elem = el.image('CESM_RACMO23_t2m_ann',
img_elem = el.image(title,
' '.join(describe.split()),
img_link)
img_elem['Height'] = config['image_height']
......
# coding=utf-8
import os
import Ngl
import numpy as np
......@@ -8,7 +10,15 @@ from netCDF4 import Dataset
from livvkit.util import elements as el
describe = """CESM_RACMO23_t2m_djf plot."""
describe = """
Average of the 2-meter air temperature (°C) over Greenland for every winter
(December-January-Feburary; DJF) from 1980--1999 for CESM (left) and RACMO 2.3 (middle), and the
difference between them (right; CESM - RACMO 2.3). The black solid lines denote
the 0, 1000, 2000, and 3000 meter Greenland ice sheet elevation contours as seen
by the models (CESM's contours shown in the difference plot).
"""
title = "Winter 2-meter air temperature"
def make_plot(config, out_path='.'):
......@@ -213,7 +223,7 @@ def make_plot(config, out_path='.'):
img_link = os.path.join(os.path.basename(out_path),
os.path.basename(wks_img + '.' + wks_type))
img_elem = el.image('CESM_RACMO23_t2m_djf',
img_elem = el.image(title,
' '.join(describe.split()),
img_link)
img_elem['Height'] = config['image_height']
......
# coding=utf-8
import os
import Ngl
import numpy as np
......@@ -8,7 +10,15 @@ from netCDF4 import Dataset
from livvkit.util import elements as el
describe = """CESM_RACMO23_t2m_jja plot."""
describe = """
Average of the 2-meter air temperature (°C) over Greenland for every summer
(June-July-August; JJA) from 1980--1999 for CESM (left) and RACMO 2.3 (middle), and the
difference between them (right; CESM - RACMO 2.3). The black solid lines denote
the 0, 1000, 2000, and 3000 meter Greenland ice sheet elevation contours as seen
by the models (CESM's contours shown in the difference plot).
"""
title = "Summer 2-meter air temperature"
def make_plot(config, out_path='.'):
......@@ -213,7 +223,7 @@ def make_plot(config, out_path='.'):
img_link = os.path.join(os.path.basename(out_path),
os.path.basename(wks_img + '.' + wks_type))
img_elem = el.image('CESM_RACMO23_t2m_jja',
img_elem = el.image(title,
' '.join(describe.split()),
img_link)
img_elem['Height'] = config['image_height']
......
# coding=utf-8
import os
import numpy as np
import numpy.ma as ma
from collections import OrderedDict
from netCDF4 import Dataset
......@@ -96,16 +99,16 @@ def calculate_area_weighted_averages(config):
gris_mask = ma.masked_equal(gris_mask, 0)
area_maskice = ma.masked_array(areaices, mask=gris_mask.mask)
aavgs = {
'Sw_d': (ma.average(sw_d, weights=area_maskice)),
'Sw_net': (ma.average(sw_net, weights=area_maskice)),
'Lw_d': (ma.average(lw_d, weights=area_maskice)),
'Lw_net': (ma.average(lw_net, weights=area_maskice)),
'Rnet': (ma.average(r_net, weights=area_maskice)),
'shf': (ma.average(shf, weights=area_maskice)),
'lhf': (ma.average(lhf, weights=area_maskice)),
'smb': (ma.average(smb_gt, weights=area_maskice)),
't2c': (ma.average(t2m_c, weights=area_maskice)),
}
aavgs = OrderedDict([
('Downward shortwave radiation (W m^-2)', '{:.1f}'.format(ma.average(sw_d, weights=area_maskice))),
('Net shortwave radiation (W m^-2)', '{:.1f}'.format(ma.average(sw_net, weights=area_maskice))),
('Downward longwave radiation (W m^-2)', '{:.1f}'.format(ma.average(lw_d, weights=area_maskice))),
('Net longwave radiation (W m^-2)', '{:.1f}'.format(ma.average(lw_net, weights=area_maskice))),
('Net surface radiation (W m^-2)', '{:.1f}'.format(ma.average(r_net, weights=area_maskice))),
('Sensible heat flux (W m^-2)', '{:.1f}'.format(ma.average(shf, weights=area_maskice))),
('Latent heat flux (W m^-2)', '{:.1f}'.format(ma.average(lhf, weights=area_maskice))),
('Surface mass balance (Gt a^-1)', '{:.1f}'.format(ma.average(qice, weights=area_maskice))),
('2-meter air temperature (°C)', '{:.1f}'.format(ma.average(t2m_c, weights=area_maskice))),
])
return aavgs
# coding=utf-8
import os
import numpy as np
import numpy.ma as ma
from collections import OrderedDict
from netCDF4 import Dataset
......@@ -78,16 +81,16 @@ def calculate_area_weighted_averages(config):
gris_mask = ma.masked_equal(gris_mask, 0)
area_maskice = ma.masked_array(areaices, mask=gris_mask.mask)
aavgs = {
'Sw_d': (ma.average(sw_d, weights=area_maskice)),
'Sw_net': (ma.average(sw_net, weights=area_maskice)),
'Lw_d': (ma.average(lw_d, weights=area_maskice)),
'Lw_net': (ma.average(lw_net, weights=area_maskice)),
'Rnet': (ma.average(r_net, weights=area_maskice)),
'shf': (ma.average(shf, weights=area_maskice)),
'lhf': (ma.average(lhf, weights=area_maskice)),
'smb': (ma.average(smb, weights=area_maskice)),
't2c': (ma.average(t2m_c, weights=area_maskice)),
}
aavgs = OrderedDict([
('Downward shortwave radiation (W m^-2)', '{:.1f}'.format(ma.average(sw_d, weights=area_maskice))),
('Net shortwave radiation (W m^-2)', '{:.1f}'.format(ma.average(sw_net, weights=area_maskice))),
('Downward longwave radiation (W m^-2)', '{:.1f}'.format(ma.average(lw_d, weights=area_maskice))),
('Net longwave radiation (W m^-2)', '{:.1f}'.format(ma.average(lw_net, weights=area_maskice))),
('Net surface radiation (W m^-2)', '{:.1f}'.format(ma.average(r_net, weights=area_maskice))),
('Sensible heat flux (W m^-2)', '{:.1f}'.format(ma.average(shf, weights=area_maskice))),
('Latent heat flux (W m^-2)', '{:.1f}'.format(ma.average(lhf, weights=area_maskice))),
('Surface mass balance (Gt a^-1)', '{:.1f}'.format(ma.average(smb, weights=area_maskice))),
('2-meter air temperature (°C)', '{:.1f}'.format(ma.average(t2m_c, weights=area_maskice))),
])
return aavgs
import os
import numpy as np
import matplotlib.pyplot as plt
from netCDF4 import Dataset
from livvkit.util import elements as el
describe = """TimeSeries_SMB and BoxPlot_SMB plot."""
def make_plot(config, out_path='.'):
# ---------------- Data source in rhea, the two files save the same data ------------------------
f_cesm_glc_acab_aavg = os.path.join(config['cesm_glc_climos'],
'b.e10.BG20TRCN.f09_g16.002.cism.h.acab_aavg.nc')
f_racmo_ts_smb_aavg = os.path.join(config['racmo_data'], 'racmo23_GRN_monthly.smb.ann_tseries_aavg.nc')
# --------------------------------------------------------------
img_list = []
# read f_cesm_glc_acab_aavg
# time from 100-255, both time and acab have 156 data
ncid1 = Dataset(f_cesm_glc_acab_aavg, mode='r')
time = ncid1.variables['time'][:]
acab = ncid1.variables['acab'][:] # m/yr
ncid1.set_auto_scale(True) # put the scale-factor in the time-series plot
# acab = acab #unit transfer
acab = acab * 1000 # unit transfer to kg/m2/yr
time = time + 1751 # time from 1851-2006
# read f_racmo_ts_smb_aavg
ncid2 = Dataset(f_racmo_ts_smb_aavg, mode='r')
time2 = ncid2.variables['time'][:]
smb = ncid2.variables['smb'][:] # mmWE = kg/m2/yr
ncid2.set_auto_scale(True) # put the scale-factor in the time-series plot
# NOTE: add months to make the full year, divide my motnhs to get years, add to get 1958
time2 = (time2 + 6.5) / 12 + 1957
# print(np.max(acab))
# print(np.min(acab))
# print(np.max(time))
# print(np.min(time))
# print(np.max(smb))
# print(np.min(smb))
# print(np.max(time2))
# print(np.min(time2))
# ------- Time Series PLOT --------
fig = plt.figure(figsize=(8, 4))
ax = fig.add_subplot(111)
ax.plot(time, acab, 'r-')
ax.plot(time2, smb, 'b-')
ax.set_ylim(-10, 250)
ax.set_xlim(1851, 2013)
ax.xaxis.set_ticks(np.arange(1851, 2013, 26))
ax.set_xticklabels(['1851', '1877', '1903', '1929', '1955', '1981', '2006'])
ax.set_ylabel('SMB (kg/m2/yr)', fontsize=14)
ax.set_xlabel('time', fontsize=14)
# ax.text(-12,5,'T-2m, JJA',fontsize=18)
# ax.legend([s1,s2],['>20%','>99%'],loc='lower right')
ts_img_path = os.path.join(out_path, 'TimeSeries_SMB.png')
plt.savefig(ts_img_path)
plt.close()
img_link = os.path.join(os.path.basename(out_path),
os.path.basename(ts_img_path))
img_elem = el.image('TimeSeries_SMB',
' '.join(describe.split()),
img_link)
if config:
img_elem['Height'] = config['image_height']
img_list.append(img_elem)
# ------ Box plot of statistics ---------
# If I have 3 sets of data, put them a matrix with 3 columns,
# then boxplot(matrix) in one figure data=[a1,a2,a3]
fig = plt.figure(figsize=(4.8, 4))
# --- the whisker shows [Q1-1.5IQR, Q3+1.5IQR] without outliners
# ax = fig.add_subplot(121)
# ax.boxplot(acab,0,'')
# ax.set_ylim([0,230])
# ax.set_ylabel('acab(kg/m2/yr)',fontsize=14)
# ax.set_xticklabels('')
# --- the whisker shows [Q1-1.5IQR, Q3+1.5IQR] with outliners
# --- where the Q1 is 25% percentile and Q3 is 75% percential, IQR=Q3-Q1
# --- the outlier is data point located outside the whiskers.
ax = fig.add_subplot(121)
ax.boxplot(acab, sym='gd')
ax.set_ylabel('SMB(km/m2/yr)', fontsize=14)
ax.set_ylim(0, 230)
ax.set_xticklabels('')
ax = fig.add_subplot(122)
ax.boxplot(smb, sym='gd')
ax.set_ylabel('SMB(km/m2/yr)', fontsize=14)
ax.set_ylim(0, 230)
ax.set_xticklabels('')
bx_img_path = os.path.join(out_path, 'BoxPlot_SMB.png')
plt.savefig(bx_img_path)
plt.close()
img_link = os.path.join(os.path.basename(out_path),
os.path.basename(bx_img_path))
img_elem = el.image('BoxPlot_SMB',
' '.join(describe.split()),
img_link)
img_elem['Height'] = config['image_height']
img_list.append(img_elem)
return img_list
import os
import numpy as np
import matplotlib.pyplot as plt
from netCDF4 import Dataset
from livvkit.util import elements as el
describe = """TimeSeries_QICE and BoxPlot_QICE plot."""
def make_plot(config, out_path='.'):
# ---------------- Data source in rhea, the two files save the same data ------------------------
f_cesm_lnd_ts_qice = os.path.join(config['cesm_lnd_climos'],
'b.e10.BG20TRCN.f09_g16.002.clm2.aavg.h0.yrly_ai.QICE.nc')
f_racmo_ts_smb_aavg = os.path.join(config['racmo_data'], 'racmo23_GRN_monthly.smb.ann_tseries_aavg.nc')
# --------------------------------------------------------------
img_list = []
# read f_cesm_lnd_ts_qice
# time from 100-255, both time and acab have 156 data
ncid1 = Dataset(f_cesm_lnd_ts_qice, mode='r')
time = ncid1.variables['time'][:]
acab = ncid1.variables['QICE'][:] # m/yr
# unit transfer
acab = acab * 3.156e7 # convert from mm/s to kg/m^2/yr
time = (time - time[1]) / 365 + 1851 # time from 1851-2006
# read f_racmo_ts_smb_aavg
ncid2 = Dataset(f_racmo_ts_smb_aavg, mode='r')
time2 = ncid2.variables['time'][:]
smb = ncid2.variables['smb'][:] # mmWE
# NOTE: add months to make the full year, divide my motnhs to get years, add to get 1958
time2 = (time2 + 6.5) / 12 + 1957
# maxacab = (np.max(acab))
# minacab = (np.min(acab))
# maxtime = (np.max(time))
# mintime = (np.min(time))
# maxsmb = (np.max(smb))
# minsmb = (np.min(smb))
# maxtime2 = (np.max(time2))
# mintime2 = (np.min(time2))
# print("Max QICE: {}".format(maxacab))
# print("Min QICE: {}".format(minacab))
# print("Max time: {}".format(maxtime))
# print("Min time: {}".format(mintime))
# print("Max sum smb: {}".format(maxsmb))
# print("Min sum smb: {}".format(minsmb))
# print("Max time2: {}".format(maxtime2))
# print("Min time2: {}".format(mintime2))
# ------- Time Series PLOT --------
fig = plt.figure(figsize=(8, 4))
ax = fig.add_subplot(111)
ax.plot(time, acab, 'r-')
ax.plot(time2, smb, 'b-')
ax.set_ylim(0, 1200)
ax.set_xlim(1850, 2013)
ax.xaxis.set_ticks(np.arange(1850, 2013, 26))
ax.set_xticklabels(['1850', '1876', '1902', '1928', '1954', '1980', '2006'])
ax.set_ylabel('SMB (kg/m2/yr)', fontsize=14)
ax.set_xlabel('time', fontsize=14)
# ax.text(-12,5,'T-2m, JJA',fontsize=18)
# ax.legend([s1,s2],['>20%','>99%'],loc='lower right')
ts_img_path = os.path.join(out_path, 'TimeSeries_QICE.png')
plt.savefig(ts_img_path)
plt.close()
img_link = os.path.join(os.path.basename(out_path),
os.path.basename(ts_img_path))
img_elem = el.image('TimeSeries_QICE',
' '.join(describe.split()),
img_link)
if config:
img_elem['Height'] = config['image_height']
img_list.append(img_elem)