ax1.set_ylabel(r"Depth $(cm)$") for tl in ax1.get_xticklabels(): tl.set_color('g') h2 = ax2.plot(X1,Y) ax2.set_xlabel(r"$\Delta14C$ ("+ u"\u2030)"+ "(solid line)") plt.gca().invert_yaxis() pylab.text(0.8, 0.1,orderlabel[i]+"\n"+"N = "+str(len(set(biomedataid))), horizontalalignment='center',verticalalignment='center', transform = ax1.transAxes,fontsize=16) dum = dum + 1 fig.tight_layout() # Or equivalently, "plt.tight_layout()" matplotlib.rcParams.update({'font.size': 14}) #fig.savefig('../figures/biome_profiles/withGCBdata/%s_%s.png'%(order[pltorder[0]],order[pltorder[1]])) #%% plot C-averaged D14C and depth/SOC content filename = 'Non_peat_data_synthesis.csv' Cave14C = prep.getCweightedD14C2(filename) fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(10,6)) nsmp = Cave14C[~np.isnan(Cave14C[:,4]),4].shape[0] axes[0].scatter(Cave14C[:,5],Cave14C[:,4]) axes[0].set_xlabel(r'Total C Content$(kg \ m^{-2})$') axes[0].set_ylabel(r'SOC averaged $\Delta 14C$ ('+ u"\u2030)") ylimm = axes[0].get_ylim() axes[0].plot(np.array([7.02,7.02]),ylimm,'r:',lw=2) axes[0].set_ylim(ylimm) axes[0].set_xlim(0,axes[0].get_xlim()[1]) axes[0].annotate('HadGEM equilibrium global mean',xy=(7.3,-750),xytext=(15,-750),\ arrowprops=dict(facecolor='black',shrink=0.05)) # global average SOC stock in HadGEM is 7.02 kg/m2 axes[0].text(100,0.8,'n = %d'%nsmp) axes[1].scatter(Cave14C[:,2],Cave14C[:,4]) axes[1].set_xlabel(r'Depth (cm)') axes[1].set_ylabel(r'SOC averaged $\Delta 14C$ ('+ u"\u2030)")
import D14Cpreprocess as prep import scipy.stats as stats import statsmodels.api as sm import mystats as mysm import myplot import pylab import random from collections import Counter #%% prepare data # get 14C and SOC of total profiles filename = 'Non_peat_data_synthesis.csv' data = pd.read_csv(filename,encoding='iso-8859-1',index_col='ProfileID', skiprows=[1]) layerbot = prep.getvarxls(data, 'Layer_bottom_norm', data.index.unique(), -1) plt.hist(layerbot, 60) cutdep = 40. Cave14C = prep.getCweightedD14C2(filename, cutdep=cutdep) nprof = Cave14C[(Cave14C[:,1]==0) & (Cave14C[:,2]==cutdep)].shape[0] # n = 138 totprofid = Cave14C[(Cave14C[:,1]==0) & (Cave14C[:,2]==cutdep), 3] totprof14C = Cave14C[(Cave14C[:,1]==0) & (Cave14C[:,2]==cutdep), 4] totprofSOC = Cave14C[(Cave14C[:,1]==0) & (Cave14C[:,2]==cutdep), 5] totprofveg = prep.getvarxls(data,'VegTypeCode_Local',totprofid,0) dum = list(totprofveg); Counter(dum) # get 14C and SOC of profiles selected for modeling pltorisitesonly = 0 filename = 'sitegridid2.txt' data = np.loadtxt(filename,unpack=True,delimiter=',')[:,:].T mdlprofid = data[:,2].astype(float) if pltorisitesonly == 0: # including extra sites filename = 'extrasitegridid.txt' data = np.loadtxt(filename,unpack=True,delimiter=',')[:,:].T
besttau.append(taufast[np.argmin(np.asarray(cost))]) else: # use prebomb_FM for n, tau in enumerate(tauslow): #print 'tauslow: %d, #%d'%(tau, n) dum = obs - FMtoD14C(cal_prebomb_FM(1./tau)) cost.append(dum**2) besttau.append(tauslow[np.argmin(np.asarray(cost))]) return besttau #%% test cal_tau import D14Cpreprocess as prep import pandas as pd import C14tools filename = 'Non_peat_data_synthesis.csv' Cave14C = prep.getCweightedD14C2(filename) data = pd.read_csv(filename,encoding='iso-8859-1',index_col='ProfileID', skiprows=[1]) profid = Cave14C[:,3] d14C = prep.getvarxls(data,'D14C_BulkLayer', profid, ':') sampleyr = prep.getvarxls(data, 'SampleYear', profid, ':') n0 = 40 nend = 60 %timeit tau, cost = C14tools.cal_tau(d14C[n0:nend], sampleyr[n0:nend]) #%% import numba as nb #@nb.jit(nb.f8(nb.f8[:])) #@nb.autojit def summ(arr): summ = 0.
import pylab from matplotlib.ticker import FuncFormatter # All profiles fromsitegrididfile = 1 if fromsitegrididfile == 1: filename = 'sitegridid2.txt' dum = np.loadtxt(filename, delimiter=',') proftotSOC = dum[:,6] profD14C= dum[:,5] proflon = dum[:,0] proflat = dum[:,1] else: filename = 'Non_peat_data_synthesis.csv' cutdep = 100. profdata = prep.getCweightedD14C2(filename,cutdep=cutdep) proftotSOC = profdata[profdata[:,2]==cutdep,5] profD14C = profdata[profdata[:,2]==cutdep,4] # HWSD sawtcfn = '..\\AncillaryData\\HWSD\\Regridded_ORNLDAAC\\AWT_S_SOC.nc4' tawtcfn = '..\\AncillaryData\\HWSD\\Regridded_ORNLDAAC\\AWT_T_SOC.nc4' ncfid = Dataset(sawtcfn, 'r') nc_attrs, nc_dims, nc_vars = mync.ncdump(ncfid) sawtc = ncfid.variables['SUM_s_c_1'][:] ncfid = Dataset(tawtcfn, 'r') nc_attrs, nc_dims, nc_vars = mync.ncdump(ncfid) hwsdlat = ncfid.variables['lat'][:] hwsdlon = ncfid.variables['lon'][:] tawtc = ncfid.variables['SUM_t_c_12'][:] hwsdsoc = sawtc + tawtc hwsdsoc = np.ravel(hwsdsoc)