Commit 1e2ab2c1 authored by Ingrid Luijkx's avatar Ingrid Luijkx
Browse files

Several adjustments in analysis scripts to produce plots, maps, tables etc. as on the new website

parent 4e690ce5
......@@ -735,18 +735,38 @@ def save_weekly_avg_agg_data(dacycle, region_aggregate='olson'):
for j in range(19):
regionnames.append("%s_%s" % (tc.transnams[i], tc.olsonnams[j],))
regionnames.extend(tc.oifnams)
xform = False
for i, name in enumerate(regionnames):
lab = 'Aggregate_Region_%03d' % (i + 1,)
setattr(ncf, lab, name)
elif region_aggregate == "olson_extended":
regionmask = tc.olson_ext_mask
dimname = 'olson_ext'
dimregs = ncf.add_dim(dimname, regionmask.max())
xform = False
for i, name in enumerate(tc.olsonextnams):
lab = 'Aggreate_Region_%03d'%(i+1)
setattr(ncf, lab, name)
elif region_aggregate == "transcom":
regionmask = tc.transcommask
dimname = 'tc'
dimregs = ncf.add_region_dim(type='tc')
xform = False
elif region_aggregate == "transcom_extended":
regionmask = tc.transcommask
dimname = 'tc_ext'
dimregs = ncf.add_region_dim(type='tc_ext')
xform = True
elif region_aggregate == "country":
xform = False
countrydict = ct.get_countrydict()
selected = ['Russia', 'Canada', 'China', 'United States', 'EU27', 'Brazil', 'Australia', 'India'] #,'G8','UNFCCC_annex1','UNFCCC_annex2']
regionmask = np.zeros((180, 360,), 'float')
......@@ -857,10 +877,28 @@ def save_weekly_avg_agg_data(dacycle, region_aggregate='olson'):
regiondata.append(aggdata)
regiondata = np.array(regiondata)
try:
regioncov = regiondata.transpose().dot(regiondata) / (data.shape[0] - 1)
except:
regioncov = np.dot(regiondata.transpose(), regiondata) / (data.shape[0] - 1) # Huygens fix
if xform:
regiondata = ExtendedTCRegions(regiondata,cov=False)
regioncov = ExtendedTCRegions(regioncov,cov=True)
savedict = ncf.standard_var(varname=vname)
savedict['name'] = vname.replace('ensemble','covariance')
savedict['units'] = '[mol/region/s]^2'
savedict['dims'] = dimdate + dimregs + dimregs
savedict['count'] = index
savedict['values'] = regioncov
ncf.add_data(savedict)
savedict = ncf.standard_var(varname=vname)
savedict['name'] = vname
savedict['units'] = 'mol/region/s'
savedict['dims'] = dimdate + dimensemble + dimregs
elif 'flux' in vname:
......@@ -868,6 +906,9 @@ def save_weekly_avg_agg_data(dacycle, region_aggregate='olson'):
regiondata = state_to_grid(data * area, regionmask, reverse=True, mapname=region_aggregate)
if xform:
regiondata = ExtendedTCRegions(regiondata)
savedict = ncf.standard_var(varname=vname)
savedict['dims'] = dimdate + dimregs
savedict['units'] = 'mol/region/s'
......@@ -876,6 +917,8 @@ def save_weekly_avg_agg_data(dacycle, region_aggregate='olson'):
data = ncf_in.get_variable(vname)[:]
regiondata = state_to_grid(data, regionmask, reverse=True, mapname=region_aggregate)
if xform:
regiondata = ExtendedTCRegions(regiondata)
savedict = ncf.standard_var(varname=vname)
savedict['dims'] = dimdate + dimregs
......@@ -1040,7 +1083,9 @@ if __name__ == "__main__":
save_weekly_avg_tc_data(dacycle, statevector)
save_weekly_avg_ext_tc_data(dacycle)
save_weekly_avg_agg_data(dacycle, region_aggregate='olson')
save_weekly_avg_agg_data(dacycle, region_aggregate='olson_extended')
save_weekly_avg_agg_data(dacycle, region_aggregate='transcom')
save_weekly_avg_agg_data(dacycle, region_aggregate='transcom_extended')
save_weekly_avg_agg_data(dacycle, region_aggregate='country')
dacycle.advance_cycle_times()
......
No preview for this file type
......@@ -44,14 +44,14 @@ ts_y2 = 0.72
ts_yspan = ts_y2 - ts_y1
markersize = 2
fontsize = 9
fontsize = 16
"""
Three routines that provide loops around the number of sites. These also create the rundirs and such and make sure the
figures that were created are stamped and saved properly
"""
def site_timeseries(analysisdir):
def site_timeseries(analysisdir,option='final'):
"""***************************************************************************************
Call example:
......@@ -75,8 +75,6 @@ def site_timeseries(analysisdir):
# Loop over site and sitefiles
#
for sitefile in sitelist:
logging.debug('Making timeseries figures for %s: ' % sitefile)
#
# Create filename and extract site codes for the sites that had day/night data separated
#
......@@ -84,10 +82,11 @@ def site_timeseries(analysisdir):
saveas = os.path.join(mrdir, sitefile[:-3] + '_timeseries')
if not os.path.exists(saveas+'.pdf'):
logging.debug('Making timeseries figures for %s: ' % sitefile)
#
# Create a figure instance to hold plot
#
fig = plt.figure(1, figsize=(15, 6,))#,frameon=False)
fig = plt.figure(1, figsize=(15, 7,))#,frameon=False)
#
# Make plot
#
......@@ -95,27 +94,31 @@ def site_timeseries(analysisdir):
#
# Save image
#
fig.savefig(saveas, dpi=100)
fig.savefig(saveas+'.pdf', dpi=100)
fig.savefig(saveas+'.png', dpi=50)
fig.savefig(saveas+'.large.png', dpi=150)
#
plt.close(fig)
#
# Residuals next
#
logging.debug('Making residuals figures for %s: ' % sitefile)
saveas = os.path.join(mrdir, sitefile[:-3] + '_residuals')
if not os.path.exists(saveas+'.pdf'):
logging.debug('Making residuals figures for %s: ' % sitefile)
#
# Create a figure instance to hold plot
#
fig = plt.figure(1, figsize=(15, 6,))#,frameon=False)
fig = plt.figure(1, figsize=(15, 7,))#,frameon=False)
#
# Make plot
#
fig = residuals_new(fig, filename)
fig = residuals_new(fig, filename, option)
#
# Save image
#
fig.savefig(saveas, dpi=100)
fig.savefig(saveas+'.pdf', dpi=100)
fig.savefig(saveas+'.png', dpi=50)
fig.savefig(saveas+'.large.png', dpi=150)
#
# next in loop over sites
#
......@@ -123,34 +126,75 @@ def site_timeseries(analysisdir):
#
# histograms next
#
logging.debug('Making histograms figures for %s: ' % sitefile)
saveas = os.path.join(mrdir, sitefile[:-3] + '_histograms')
if not os.path.exists(saveas+'.pdf'):
logging.debug('Making histograms figures for %s: ' % sitefile)
#
# Create a figure instance to hold plot
#
fig = plt.figure(1, figsize=(15, 6,))#,frameon=False)
fig = plt.figure(1, figsize=(15, 7,))#,frameon=False)
#
# Make plot
#
fig = timehistograms_new(fig, filename)
fig = timehistograms_new(fig, filename, option)
#
# Save image
#
fig.savefig(saveas, dpi=100)
fig.savefig(saveas+'.pdf', dpi=100)
fig.savefig(saveas+'.png', dpi=50)
fig.savefig(saveas+'.large.png', dpi=150)
#
# next in loop over sites
#
plt.close(fig)
def timehistograms_new(fig, infile):
#
# html table next
#
saveas = os.path.join(mrdir, sitefile[:-3] + '.html')
if not os.path.exists(saveas):
logging.debug('Making html info table for %s' % sitefile)
f = io.CT_CDF(filename, 'read')
with open(saveas, "wt") as fout:
with open("sitetable.html", "rt") as fin:
for lineout in fin:
lineout = lineout.replace('site_name',f.site_name)
lineout = lineout.replace('site_country',f.site_country)
lineout = lineout.replace('site_latitude',nice_lat(f.site_latitude,'html'))
lineout = lineout.replace('site_longitude',nice_lon(f.site_longitude,'html'))
lineout = lineout.replace('site_elevation',str(f.site_elevation))
lineout = lineout.replace('intake_height',str(f.variables['intake_height'][:].max()))
if 'co2_hip' in sitefile:
lineout = lineout.replace('site_map','http://carbontracker.eu/development/data/ct_europe/timeseries_molefractions/co2_hip_map.jpg')
else: lineout = lineout.replace('site_map',str(f.site_map))
lineout = lineout.replace('lab_abbr',f.lab_abbr)
lineout = lineout.replace('lab_name',f.lab_name)
lineout = lineout.replace('lab_country',f.lab_country)
if 'lab_provider' in lineout:
if 'Morgui' in f.provider_1_name:
lineout = lineout.replace('lab_provider','J.A. Morgui / M. Ramonet')
else: lineout = lineout.replace('lab_provider',f.provider_1_name)
if 'lab_url' in lineout:
if f.lab_url <> '':
lineout = lineout.replace('lab_url',f.lab_url)
else: lineout = ''
lineout = lineout.replace('lab_logo',f.lab_logo)
lineout = lineout.replace('dataset_selection',f.dataset_selection_tag)
lineout = lineout.replace('dataset_project',f.dataset_project)
lineout = lineout.replace('dataset_calibration_scale',f.dataset_calibration_scale)
if f.variables['modeldatamismatch'][:].max() > 0.0009:
lineout = lineout.replace('assimilated','No')
else: lineout = lineout.replace('assimilated','Yes')
fout.write(lineout)
f.close()
def timehistograms_new(fig, infile, option='final'):
"""
This routine makes two side-by-side histograms representing summer and winter PDFs of the residuals. It uses the special
x-axis and y-axis definitions from above. Note that currently, the PDFs are based on forecast-observed CO2, and not on
optimized-observed CO2.
"""
fontsize = 12
fontsize = 17
#
# Get data
#
......@@ -169,11 +213,14 @@ def timehistograms_new(fig, infile):
obs = f.get_variable('value') * molefac
mdm = f.get_variable('modeldatamismatch') * molefac
hphtr = f.get_variable('totalmolefractionvariance_forecast') * molefac * molefac
simulated = f.get_variable('modelsamplesmean_forecast') * molefac
if option == 'final':
simulated = f.get_variable('modelsamplesmean') * molefac
if option == 'forecast':
simulated = f.get_variable('modelsamplesmean_forecast') * molefac
flags = f.get_variable('flag_forecast')
longsitestring = f.site_name + ', ' + f.site_country
location = nice_lat(f.site_latitude) + ', ' + nice_lon(f.site_longitude) + ', ' + nice_alt(f.site_elevation)
location = nice_lat(f.site_latitude,'python') + ', ' + nice_lon(f.site_longitude,'python') + ', ' + nice_alt(f.site_elevation)
SDSInfo = {}
for k in f.ncattrs():
......@@ -197,15 +244,18 @@ def timehistograms_new(fig, infile):
flags = flags.compress(sampled)
residual = simulated - obs
chisquared = (residual ** 2) / hphtr
if option == 'final':
chisquared = (residual ** 2) / mdm
elif option == 'forecast':
chisquared = (residual ** 2) / hphtr
rejected = (flags == 2.0)
notused = (flags == 99.0)
if notused.all():
return fig
else:
obslabel = 'Residual'
#if notused.all():
# return fig
#else:
obslabel = 'Residual'
sd = pydates[0]
ed = pydates[-1]
......@@ -236,8 +286,13 @@ def timehistograms_new(fig, infile):
# Calculate residual and chi squared values
res = sel_fc - sel_obs
chi = res / np.sqrt(sel_hqhr)
#res = sel_fc - sel_obs
if option == 'final':
res = sel_fc.compress(sel_flags != 2) - sel_obs.compress(sel_flags != 2)
chi = res / np.sqrt(sel_mdm.compress(sel_flags != 2))
elif option == 'forecast':
res = sel_fc - sel_obs
chi = res / np.sqrt(sel_hqhr)
# Get a scaling factor for the x-axis range. Now we will include 5 standard deviations
......@@ -265,20 +320,31 @@ def timehistograms_new(fig, infile):
#
# Add a legend, not as a legend object but simply as text labels
#
labs = [
'%.2f $\pm$ %.2f' % (res.mean(), res.std()) , \
'N = %d' % sel_obs.shape[0], \
'Inn. $\chi^2$= %.2f' % (chi ** 2).mean()
]
if option == 'final':
strX = ''
elif option == 'forecast':
strX = 'Inn. '
if chi.mean() != chi.mean() or mdm.mean() < 900:
labs = [
'%.2f $\pm$ %.2f' % (res.mean(), res.std()) , \
'N = %d' % sel_obs.shape[0], \
'%s$\chi^2$= %.2f'%(strX, (chi**2).mean())
]
else:
labs = [
'%.2f $\pm$ %.2f' % (res.mean(), res.std()) , \
'N = %d' % sel_obs.shape[0]
]
# print the above labels onto the figure. Note that I use relative coordinates for their position by specifying the transform=ax.transAxes
for i, l in enumerate(labs):
ax.text(0.75, 0.6 - 0.07 * i, l, transform=ax.transAxes, fontsize=fontsize, horizontalalignment='center', color='blue')
ax.text(0.75, 0.9 - 0.07 * i, l, transform=ax.transAxes, fontsize=fontsize, horizontalalignment='center', color='blue')
#
# Set Tick Font Size on x and y labels
#
dummy = [lab.set_fontsize(0.9 * fontsize) for lab in ax.get_xticklabels()]
dummy = [lab.set_fontsize(0.9 * fontsize) for lab in ax.get_yticklabels()]
#dummy = [lab.set_fontsize(20) for lab in ax.get_xticklabels()]
#dummy = [lab.set_fontsize(20) for lab in ax.get_yticklabels()]
# set limits on x-axis and get limits on y-axis to determine the position of the x-axis labels (offset keyword to make_yaxis)
......@@ -295,14 +361,15 @@ def timehistograms_new(fig, infile):
ax.spines['bottom'].set_linewidth(1.5)
ax.spines['bottom'].set_position(('outward', 10))
matplotlib.rcParams.update({'font.size': 18})
ax.xaxis.set_ticks_position('bottom')
ax.set_xlabel('[%s]'%units)
ax.set_xlabel('[%s]'%units,size=16)
#
# All custom titles and auxiliary info are placed onto the figure directly (fig.text) in relative coordinates
#
fig.text(0.5, 0.02, 'Simulated - Observed %s [%s]\nData from %s to %s' %(species,units,pydates[0].strftime('%d-%b-%Y'), pydates[-1].strftime('%d-%b-%Y')), horizontalalignment='center', fontsize=fontsize - 1)
fig.text(0.5, 0.02, 'Simulated - Observed %s [%s]\nData from %s to %s' %(species,units,pydates[0].strftime('%d-%b-%Y'), pydates[-1].strftime('%d-%b-%Y')), horizontalalignment='center', fontsize=fontsize)
#fig.text(0.75,0.02,'Simulated - Observed\n CO$_2$ ($\mu$mol/mol)',horizontalalignment='center',fontsize=fontsize)
fig.text(0.5, 0.35, 'model-data\nmismatch:\n%.2f %s' % (sel_mdm[0], units), horizontalalignment='center', fontsize=fontsize, color='green')
fig.text(0.12, 0.75, 'NH Summer\n(Jun-Sep)', horizontalalignment='center', fontsize=fontsize)
......@@ -311,14 +378,19 @@ def timehistograms_new(fig, infile):
# Title
#
plt.suptitle('%s [%s]\n%s, %s, %s ' % (longsitestring, location , SDSInfo['dataset_project'], SDSInfo['lab_name'], SDSInfo['lab_country'],), fontsize=fontsize + 2)
plt.suptitle('%s [%s]\n%s, %s, %s ' % (longsitestring, location , SDSInfo['dataset_project'], SDSInfo['lab_name'], SDSInfo['lab_country'],), fontsize=fontsize + 4)
#
# Add info to plot
#
now = dt.datetime.today()
str1 = 'CTDAS2012\n' + now.strftime('%d/%m/%y')
fig.text(0.93, 0.95, str1, fontsize=0.75 * fontsize, color='0.5')
font0= FontProperties(size=15,style='italic',weight='bold')
txt='CarbonTracker Europe\n $\copyright$ Wageningen University'
clr='green'
fig.text(0.82,0.01,txt,ha='left',font_properties = font0, color=clr )
#now = dt.datetime.today()
#str1 = 'CTDAS2012\n' + now.strftime('%d/%m/%y')
#fig.text(0.93, 0.95, str1, fontsize=0.75 * fontsize, color='0.5')
#str1 = 'data provided by %s'%SDSInfo['provider_1_name']
#fig.text(0.12,0.16,str1,fontsize=0.8*fontsize,color='0.75')
......@@ -346,7 +418,7 @@ def timehistograms_new(fig, infile):
return fig
def timevssite_new(fig, infile):
fontsize = 17
#
# Get data
#
......@@ -367,7 +439,7 @@ def timevssite_new(fig, infile):
flags = f.get_variable('flag_forecast')
longsitestring = f.site_name + ', ' + f.site_country
location = nice_lat(f.site_latitude) + ', ' + nice_lon(f.site_longitude) + ', ' + nice_alt(f.site_elevation)
location = nice_lat(f.site_latitude,'python') + ', ' + nice_lon(f.site_longitude,'python') + ', ' + nice_alt(f.site_elevation)
SDSInfo = {}
for k in f.ncattrs():
......@@ -401,8 +473,8 @@ def timevssite_new(fig, infile):
sd = pydates[0]
ed = pydates[-1]
ax1 = fig.add_axes([0.1, 0.15, 0.7, 0.75])
ax2 = fig.add_axes([0.85, 0.15, 0.12, 0.75])
ax1 = fig.add_axes([0.1, 0.12, 0.7, 0.75])
ax2 = fig.add_axes([0.85, 0.12, 0.12, 0.75])
ax1.spines['right'].set_color('none')
ax1.spines['top'].set_color('none')
......@@ -419,7 +491,7 @@ def timevssite_new(fig, infile):
ax2.spines['bottom'].set_position(('outward', 10))
markersize = 8
fontsize = 12
fontsize = 16
p = ax1.plot(pydates, obs, marker='o', markeredgewidth=1, linestyle='None', markerfacecolor='None', \
markeredgecolor='k', label=obslabel , markersize=markersize)
......@@ -438,51 +510,61 @@ def timevssite_new(fig, infile):
#
# Set up x axis labels
#
dummy = [lab.set_fontsize(0.9 * fontsize) for lab in ax1.get_xticklabels()]
dummy = [lab.set_fontsize(0.9 * fontsize) for lab in ax1.get_yticklabels()]
#dummy = [lab.set_fontsize(0.9 * fontsize) for lab in ax1.get_xticklabels()]
#dummy = [lab.set_fontsize(0.9 * fontsize) for lab in ax1.get_yticklabels()]
#
# Location and format of xticks
#
ax1.xaxis.set_minor_locator(pltdt.MonthLocator([1,7],bymonthday=1))
ax1.xaxis.set_minor_formatter(pltdt.DateFormatter('%b'))
ax1.xaxis.set_major_locator(pltdt.YearLocator())
ax1.xaxis.set_major_formatter(pltdt.DateFormatter('\n\n%Y'))
ax1.xaxis.set_major_locator(pltdt.MonthLocator([7],bymonthday=7))
ax1.xaxis.set_major_formatter(pltdt.DateFormatter('%Y'))
#
# Legend
#
leg = ax1.legend(prop=FontProperties(size=(0.75 * fontsize)), borderpad=0.1, loc='upper left')
#leg.get_frame().set_visible(False)
leg.set_zorder(20)
leg.get_frame().set_color('0.9')
dummy = [lab.set_fontsize(12) for lab in leg.get_texts()]
leg.get_frame().set_color('1.0')
dummy = [lab.set_fontsize(16) for lab in leg.get_texts()]
#
# include grid
#
ax1.grid(True, axis='y')
ax1.grid(True, ls='-', color='0.75', axis='y')
ax1.autoscale(enable=True, axis='y', tight=False)
#ax1.set_ylim(obs.min()-3*residual.std(),obs.max()+5*residual.std())
#ax1.set_xlim(pltdt.date2num(dt.datetime(sd.year, 1, 1)), pltdt.date2num(dt.datetime(ed.year + 1, 1, 1)))
ax1.set_xlim(pltdt.date2num(dt.datetime(sd.year, 1, 1)), pltdt.date2num(dt.datetime(ed.year + 1, 1, 1)))
#ax1.set_ylim(360,430) #LUT
ym = ax1.get_ylim()
ymin=ym[0] ; ymax =ym[1]
for yr in range(sd.year,ed.year+1,2):
x1=dt.datetime(yr,1,1)
x2=dt.datetime(yr+1,1,1)
ax1.fill([x1,x2,x2,x1],[ymin,ymin,ymax,ymax],color='0.9',zorder=1)
ax1.set_ylim(ymin,ymax)
#
#
# Set Tick Font Size
#
dummy = [lab.set_fontsize(0.9 * fontsize) for lab in ax1.get_xticklabels()]
dummy = [lab.set_fontsize(0.9 * fontsize) for lab in ax1.get_yticklabels()]
#matplotlib.rcParams.update({'font.size': 30})
ax1.xaxis.set_ticks_position('bottom')
#dummy = [lab.set_fontsize(0.9 * fontsize) for lab in ax1.get_xticklabels()]
#dummy = [lab.set_fontsize(0.9 * fontsize) for lab in ax1.get_yticklabels()]
#xtitle='Time'
#ax1.set_xlabel(xtitle, fontsize=fontsize) # label x axis
ax1.set_ylabel(r"%s [%s]"% (species,units), fontsize=fontsize) # label y-axis
ax1.set_ylabel(r"%s [%s]"% (species,units), fontsize=fontsize + 5) # label y-axis
#
# Axes 2
#
residual = residual.compress(flags != 2)
offset = 0.0
n, bins, patches = ax2.hist(residual, max(residual.shape[0] / 15, 15), normed=1, orientation='horizontal')
p = plt.setp(patches, 'facecolor', 'tan' , 'edgecolor', 'tan', label='None', alpha=0.25)
# Create normal distributions for the line plots over the interval of the x-axis
sc = residual.std()
bins = np.arange(-4 * sc, 4 * sc, 0.1)
n = normpdf(bins, residual.mean(), residual.std())
......@@ -495,7 +577,7 @@ def timevssite_new(fig, infile):
]
# print the above labels onto the figure. Note that I use relative coordinates for their position by specifying the transform=ax.transAxes
ax2.text(0.6, 0.35 + offset, labs[0], transform=ax2.transAxes, fontsize=1.1 * fontsize, horizontalalignment='center', color='k')
ax2.text(0.6, 0.01 + offset, labs[0], transform=ax2.transAxes, fontsize=1.1 * fontsize, horizontalalignment='center', color='k')
offset += -0.05
ax2.set_ylim(-4 * sc, 4 * sc)
......@@ -512,27 +594,34 @@ def timevssite_new(fig, infile):
ax2.spines['bottom'].set_linewidth(1.5)
ax2.spines['bottom'].set_position(('outward', 10))
matplotlib.rcParams.update({'font.size': 18})
ax2.yaxis.set_ticks_position('left')
ax2.xaxis.set_ticklabels([])
#ax2.set_ylabel(r"CO$_2$ [ppm]", fontsize=fontsize) # label y-axis
#ax2.set_xlabel("frequency", fontsize=fontsize) # label x-axis
ax2.grid(True, axis='y')
#ax2.grid(True, axis='y')
ax2.grid(True, ls='-', color='0.75', axis='y')
#
# Title
#
plt.suptitle('%s [%s]\n%s, %s, %s ' % (longsitestring, location , SDSInfo['dataset_project'], SDSInfo['lab_name'], SDSInfo['lab_country'],), fontsize=fontsize + 2)
plt.suptitle('%s [%s]\n%s, %s, %s ' % (longsitestring, location , SDSInfo['dataset_project'], SDSInfo['lab_name'], SDSInfo['lab_country'],), fontsize=fontsize + 5)
#
# Add info to plot
#
now = dt.datetime.today()
str1 = 'CTDAS2012\n' + now.strftime('%d/%m/%y')
fig.text(0.93, 0.95, str1, fontsize=0.75 * fontsize, color='0.5')
str1 = 'data provided by %s' % SDSInfo['provider_1_name']
fig.text(0.12, 0.16, str1, fontsize=0.8 * fontsize, color='0.75')
font0= FontProperties(size=15,style='italic',weight='bold')
txt='CarbonTracker Europe\n $\copyright$ Wageningen University'
clr='green'
fig.text(0.82,0.01,txt,ha='left',font_properties = font0, color=clr )
#now = dt.datetime.today()
#str1 = 'CTDAS2012\n' + now.strftime('%d/%m/%y')
#fig.text(0.93, 0.95, str1, fontsize=0.75 * fontsize, color='0.5')
#str1 = 'data provided by %s' % SDSInfo['provider_1_name']
#fig.text(0.12, 0.16, str1, fontsize=0.8 * fontsize, color='0.75')
try:
img = urllib2.urlopen(SDSInfo['lab_logo']).read()
......@@ -557,8 +646,9 @@ def timevssite_new(fig, infile):
return fig
def residuals_new(fig, infile):
def residuals_new(fig, infile, option):
fontsize = 17
#
# Get data
#
......@@ -575,12 +665,15 @@ def residuals_new(fig, infile):
date = f.get_variable('time')
obs = f.get_variable('value') * molefac
mdm = f.get_variable('modeldatamismatch') * molefac
simulated = f.get_variable('modelsamplesmean_forecast') * molefac
if option == 'final':
simulated = f.get_variable('modelsamplesmean') * molefac
if option == 'forecast':
simulated = f.get_variable('modelsamplesmean_forecast') * molefac
hphtr = f.get_variable('totalmolefractionvariance_forecast') * molefac * molefac
flags = f.get_variable('flag_forecast')
longsitestring = f.site_name + ', ' + f.site_country
location = nice_lat(f.site_latitude) + ', ' + nice_lon(f.site_longitude) + ', ' + nice_alt(f.site_elevation)
location = nice_lat(f.site_latitude,'python') + ', ' + nice_lon(f.site_longitude,'python') + ', ' + nice_alt(f.site_elevation)
SDSInfo = {}
for k in f.ncattrs():
......@@ -602,22 +695,20 @@ def residuals_new(fig, infile):
hphtr = hphtr.compress(sampled)
flags = flags.compress(sampled)
residual = simulated - obs
chisquared = (residual ** 2) / hphtr
rejected = (flags == 2.0)
notused = (flags == 99.0)
if notused.all():
return fig
else:
obslabel = 'Residual'
residual = simulated - obs