Preprocessing and Preparation of Plot VI in EchoRD


In [1]:
import numpy as np
import pandas as pd
import vG_conv as vG

Plot VI


In [2]:
#get soil data for plot
soilsamples=pd.read_csv('soilsamplesVI.dat')
soilsamples


Out[2]:
sample depth sand silt clay BD porosity Ks_estimate theta_sat theta_res alpha n tau Ks_meas
0 297.3 0.80 56.95 14.56 16.21 1.12 0.58 0.060194 0.568 0.019 4.13 1.512 -0.749 4.073330e-04
1 270.3 0.80 57.30 17.14 14.46 1.14 0.57 0.001194 0.554 0.026 4.40 1.582 -2.000 1.136670e-04
2 1025.3 0.80 57.90 15.48 15.77 1.11 0.58 0.085980 0.574 0.050 3.40 1.717 -0.376 1.190000e-04
3 250.3 1.10 50.70 15.76 15.47 1.20 0.55 0.095159 0.554 0.013 2.64 1.764 -0.027 6.476670e-05
4 276.3 1.10 57.39 16.25 15.97 1.09 0.59 0.141984 0.571 0.031 3.99 1.658 -0.109 1.203330e-04
5 291.3 1.40 39.31 25.58 28.96 1.51 0.43 0.109221 0.434 0.000 1.79 1.199 0.880 3.253330e-06
6 455.0 0.14 36.10 25.34 41.78 1.48 0.44 0.000431 0.437 0.000 0.48 1.262 10.000 6.700000e-05
7 280.0 0.25 33.55 24.44 42.28 1.30 0.51 0.000300 0.468 0.000 0.39 1.237 2.313 1.276670e-04
8 272.0 0.30 5.07 21.51 76.97 1.27 0.52 0.000116 0.556 0.000 0.13 1.237 10.000 1.000000e-10

9 rows × 14 columns


In [3]:
#van Genuchten retention functions with fixed m
#def theta_f(psi, theta_res, theta_sat, alpha, n):
#    m=1.-1./n
#    theta=theta_res+(theta_sat-theta_res)*(1./(1.+(alpha*psi)**n))**m
#    return theta

#def psi_f(theta, theta_res, theta_sat, alpha, n):
#    m=1.-1./n
#    psi=1./alpha * (1. / ((theta-theta_res)/(theta_sat-theta_res))**(1./m)-1.)**(1./n) 
#    return psi

In [4]:
def theta_ff(psi,sample,soilsamples):
    return vG.theta_psi(psi, soilsamples.theta_sat[sample], soilsamples.theta_res[sample], soilsamples.alpha[sample], soilsamples.n[sample])

def psi_ff(theta,sample,soilsamples):
    return vG.psi_theta(theta, soilsamples.theta_sat[sample], soilsamples.theta_res[sample], soilsamples.alpha[sample], soilsamples.n[sample])

In [5]:
psi = 10**np.arange(-3,8,0.1)

In [6]:
for i in soilsamples.index:
    plot(theta_ff(psi,i,soilsamples),psi,label=''.join(['soil',str(i)]))

yscale('log')
legend(loc=1,ncol=2)
title('Retention curves')
xlabel('Theta [m3/m3]')
ylabel('psi [m]')


Out[6]:
<matplotlib.text.Text at 0x111fefad0>

In [7]:
#round depth to integrate close values to one layer
soilsamples['rdepth']=soilsamples.depth.round(decimals=1)

#group by depth
soil_zmean=soilsamples.groupby(by='rdepth', axis=0).mean()

for i in soil_zmean.index:
    plot(theta_ff(psi,i,soil_zmean),psi,label=''.join([str(i),' m']))

yscale('log')
legend(loc=1,ncol=2)
title('Retention curves')
xlabel('Theta [m3/m3]')
ylabel('psi [m]')


Out[7]:
<matplotlib.text.Text at 0x1133152d0>

In [8]:
soil_zmean['rdepth']=soil_zmean.index
soil_zmean.index=np.arange(len(soil_zmean))
#rename columns according to EchoRD
dummy=soil_zmean[['Ks_meas','theta_sat','theta_res','alpha','n','BD','rdepth']].copy()
dummy.columns=['ks','ts','tr','alpha','n','roh','z']
dummy.index=dummy.index+1
dummy.z=-1.*dummy.z
#dummy.alpha=10000.*dummy.alpha
dummy.roh=dummy.roh*1000.
dummy.tr[dummy.tr<0.001]=0.001
#save to file
dummy.to_csv('matrix_VI.dat',float_format='%2.6f',sep=' ',index_label='no')

In [9]:
dummy


Out[9]:
ks ts tr alpha n roh z
1 6.700000e-05 0.437000 0.001000 0.480000 1.262000 1480.000000 -0.1
2 1.276670e-04 0.468000 0.001000 0.390000 1.237000 1300.000000 -0.2
3 1.000000e-10 0.556000 0.001000 0.130000 1.237000 1270.000000 -0.3
4 2.133333e-04 0.565333 0.031667 3.976667 1.603667 1123.333333 -0.8
5 9.254985e-05 0.562500 0.022000 3.315000 1.711000 1145.000000 -1.1
6 3.253330e-06 0.434000 0.001000 1.790000 1.199000 1510.000000 -1.4

6 rows × 7 columns


In [10]:
#define soil type representation in matrixdef.dat manually - room for improvement

In [10]:


In [11]:
import scipy as sp
import matplotlib.pyplot as plt
import scipy.constants as const
import mcini_VI as mc
import dataread as dr

In [12]:
mc=dr.dataread_caos(mc)


/Library/Python/2.7/site-packages/numpy-override/numpy/ma/core.py:3847: UserWarning: Warning: converting a masked element to nan.
  warnings.warn("Warning: converting a masked element to nan.")
MODEL SETUP READY.

In [13]:
import mcpickle as mcp
mcp.mcpick_in(mc,'mc_dump_VI.pickle')


wrote mc to  mc_dump_VI.pickle

In [13]:


In [ ]:


In [ ]:

Plot XI


In [14]:
#get soil data for plot
soilsamples=pd.read_csv('soilsamplesXI.dat',na_values='NaN')
soilsamples


Out[14]:
sample depth sand silt clay BD porosity Ks_estimate theta_sat theta_res alpha n tau Ks_meas
0 300.3 0.01 1.71 45.43 31.99 0.88 0.67 0.170124 0.710 0.037 3.66 1.317 1.007 0.000035
1 453.3 0.01 1.96 46.63 39.04 0.74 0.72 1.155642 0.721 0.000 3.76 1.237 3.480 0.000097
2 257.3 0.02 0.86 50.00 32.16 0.95 0.64 1.643208 0.717 0.000 4.93 1.216 3.604 0.000021
3 248.3 0.10 1.10 56.87 40.26 0.91 0.66 1.500762 0.691 0.000 4.67 1.224 0.410 0.000436
4 465.3 0.11 1.12 56.98 40.15 1.09 0.59 0.781988 0.626 0.000 6.30 1.218 -0.991 0.000123
5 470.3 0.11 0.80 58.98 42.67 0.91 0.66 3.998630 0.668 0.000 11.55 1.207 -0.025 0.000300
6 460.3 0.21 1.56 50.90 40.76 0.90 0.66 1.374740 0.686 0.000 8.40 1.231 -0.861 0.000171
7 474.3 0.22 1.29 57.66 40.46 0.81 0.69 3.558207 0.623 0.000 11.37 1.222 0.098 0.002007
8 296.3 0.22 1.94 55.83 35.70 0.92 0.65 0.006532 0.602 0.000 5.98 1.220 -2.000 0.000449
9 246.3 0.32 1.42 55.89 39.87 1.27 0.52 0.002149 0.750 0.000 0.58 1.313 -1.322 0.000603
10 287.3 0.33 1.79 55.97 41.33 1.21 0.54 1.531581 0.513 0.000 12.82 1.162 -2.000 0.002530
11 254.3 0.39 1.40 55.66 42.47 1.26 0.52 8.201794 0.515 0.000 3.06 1.206 4.248 0.000223
12 252.3 0.39 2.66 58.72 43.37 1.17 0.56 0.356355 0.527 0.000 4.30 1.217 -2.000 0.000497
13 462.3 0.40 1.46 55.67 44.14 1.07 0.60 1.206361 0.540 0.000 7.17 1.189 -2.000 0.001016

14 rows × 14 columns


In [15]:
#round depth to integrate close values to one layer
soilsamples['rdepth']=soilsamples.depth.round(decimals=1)

In [16]:
#group by depth
soil_zmean=soilsamples[0:14].groupby(by='rdepth', axis=0).mean()

for i in soil_zmean.index:
    plot(theta_ff(psi,i,soil_zmean),psi,label=''.join([str(i),' m']))

yscale('log')
legend(loc=3,ncol=2)
title('Retention curves')
xlabel('Theta [m3/m3]')
ylabel('psi [m]')


Out[16]:
<matplotlib.text.Text at 0x113e80490>

In [17]:
soil_zmean['rdepth']=soil_zmean.index
soil_zmean.index=np.arange(len(soil_zmean))
#rename columns according to EchoRD
dummy=soil_zmean[['Ks_meas','theta_sat','theta_res','alpha','n','BD','rdepth']]
dummy.columns=['ks','ts','tr','alpha','n','roh','z']
dummy.index=dummy.index+1
dummy.z=-dummy.z.values
dummy.alpha=dummy.alpha.values
dummy.roh=dummy.roh.values*1000
dummy.tr[dummy.tr<0.001]=0.001
#save to file
dummy.to_csv('matrix_XI.dat',float_format='%2.6f',sep=' ',index_label='no')


/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/generic.py:1830: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_index,col_indexer] = value instead
  self[name] = value
/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/series.py:635: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame
  self.where(~key, value, inplace=True)

In [18]:
import mcini_XI as mcXI
mcXI=dr.dataread_caos(mcXI)


MODEL SETUP READY.

In [19]:
mcp.mcpick_in(mcXI,'mc_dump_XI.pickle')


wrote mc to  mc_dump_XI.pickle

Some testing


In [24]:
D=np.empty((101,mc.soilmatrix.no.size))
Dcalc=np.empty(101)
ku=np.empty(101)
ku1=np.empty(101)
psi=np.empty(101)
psi1=np.empty(101)
theta=np.empty(101)
theta1=np.empty(101)
cH2O=np.empty(101)

i=1
for j in np.arange(101):
    thetaS=float(j)/100.
    ku1[j]=mc.soilmatrix.ks[i]*thetaS**0.5*(1.-(1.-thetaS**(1./mc.soilmatrix.m[i]))**mc.soilmatrix.m[i])**2.
    psi[j]=vG.psi_theta(thetaS,mc.soilmatrix.ts[i],mc.soilmatrix.tr[i],mc.soilmatrix.alpha[i],mc.soilmatrix.n[i],mc.soilmatrix.m[i])
    ku[j]=vG.ku_psi(psi[j], mc.soilmatrix.ks[i], mc.soilmatrix.alpha[i], mc.soilmatrix.n[i], mc.soilmatrix.m[i])
    psi1[j]= -1 * ( (1-thetaS**(1./mc.soilmatrix.m[i])) / (thetaS**(1./mc.soilmatrix.m[i]) ))**(1./mc.soilmatrix.n[i]) / mc.soilmatrix.alpha[i]
    psi[0]=-1.0e+11
    psi1=psi/100. #convert to [m]
    theta1[j]=thetaS*(mc.soilmatrix.ts[i]-mc.soilmatrix.tr[i])+mc.soilmatrix.tr[i]
    theta[j]=vG.theta_thst(thetaS,mc.soilmatrix.ts[i],mc.soilmatrix.tr[i])
    cH2O[j]=vG.c_psi(psi[j],mc.soilmatrix.ts[i],mc.soilmatrix.tr[i],mc.soilmatrix.alpha[i], mc.soilmatrix.n[i], mc.soilmatrix.m[i])
    dummy=-mc.soilmatrix.m[i]*(1./(1.+np.abs((psi[j])*mc.soilmatrix.alpha[i])**mc.soilmatrix.n[i]))**(mc.soilmatrix.m[i]+1) *mc.soilmatrix.n[i]*(abs(psi[j])*mc.soilmatrix.alpha[i])**(mc.soilmatrix.n[i]-1.)*mc.soilmatrix.alpha[i]
    cH2O[j]=-1.*(mc.soilmatrix.ts[i]-mc.soilmatrix.tr[i])*dummy
    Dcalc[j]=vG.D_psi(psi[j],mc.soilmatrix.ks[i],mc.soilmatrix.ts[i],mc.soilmatrix.tr[i],mc.soilmatrix.alpha[i], mc.soilmatrix.n[i], mc.soilmatrix.m[i])

theta[theta<0.01]=0.01
DI=(ku[:-1]+(np.diff(ku)/2.))*np.diff(psi)/np.diff(theta)
DI[0]=0 #define very low diffusion at zero
D[:,i]=Dcalc#/10000. # convert cm2/s -> m2/s
D[-1,:]=D[-2,:]

In [27]:
plot(ku)
plot(ku1)


Out[27]:
[<matplotlib.lines.Line2D at 0x113f1e110>]

In [ ]: