-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeneralSoilPhys_Funky.py
executable file
·182 lines (137 loc) · 5.63 KB
/
GeneralSoilPhys_Funky.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
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 28 13:11:50 2015
@author: Administrator
"""
#==============================================================================
# General Soil Physics functions
#==============================================================================
import numpy
import pylab
#==============================================================================
# Textuur
#==============================================================================
def DefineTexClassPolygons():
#==============================================================================
# define polygon
#==============================================================================
## Draw polygons: Sand / Clay coordinates
poly_U = numpy.array([[0.0 ,100.0],
[65.0 ,35.0 ],
[10.0 ,35.0 ],
[0.0 ,45.0 ],
[0.0 ,100.0]])
poly_E = numpy.array([[65.0 ,35.0 ],
[10.0 ,35.0 ],
[0.0 ,45.0 ],
[0.0 ,30.0 ],
[25.0 ,17.5 ],
[82.5 ,17.5 ],
[65.0 ,35.0 ]])
poly_A = numpy.array([[0.0 ,30.0 ],
[15.0 ,22.5 ],
[15.0 ,0.0 ],
[0.0 ,0.0 ],
[0.0 ,30.0 ]])
poly_L = numpy.array([[15.0 ,22.5 ],
[25.0 ,17.5 ],
[67.5 ,17.5 ],
[67.5 ,12.5 ],
[50.0 ,12.5 ],
[50.0 ,0.0 ],
[15.0 ,0.0 ],
[15.0 ,22.5 ]])
poly_P = numpy.array([[50.0 ,0.0 ],
[67.5 ,0.0 ],
[67.5 ,12.5 ],
[50.0 ,12.5 ],
[50.0 ,0.0 ]])
poly_S = numpy.array([[67.5 ,0.0 ],
[67.5 ,17.5 ],
[82.5 ,17.5 ],
[92.5 ,7.5 ],
[82.5 ,7.5 ],
[82.5 ,0.0 ],
[67.5 ,0.0 ]])
poly_Z = numpy.array([[82.5 ,0.0 ],
[82.5 ,7.5 ],
[92.5 ,7.5 ],
[100.0,0.0 ],
[82.5 ,0.0 ]])
Poly_All_Labels=['U','E','A','L','P','S','Z']
Poly_All=[poly_U,poly_E,poly_A,poly_L,poly_P,poly_S,poly_Z]
Poly_All=map(lambda x : x/100.0,Poly_All)
nP=len(Poly_All)
Poly_Dict={}
for iP in range(nP):
Poly_Dict.update({Poly_All_Labels[iP] : Poly_All[iP]})
return Poly_Dict
def GetTexture(Sand,Clay,DoPlot=False):
import matplotlib.path as mplPath
import matplotlib.patches as mplPatches
Poly_Dict=DefineTexClassPolygons()
Poly_All_Labels=Poly_Dict.keys()
nP=len(Poly_Dict)
#==============================================================================
# Get Texture
#==============================================================================
if numpy.size(Sand)<1:
Sand=numpy.array([Sand,])
Clay=numpy.array([Clay,])
nTex=Sand.size
TexClass=numpy.zeros(nTex,dtype='S3')
TexClass[:]='nan'
if numpy.size(Sand)>1:
for iP in range(nP):
TexLabel=Poly_All_Labels[iP]
bbPath = mplPath.Path(Poly_Dict[TexLabel])
TexClass[bbPath.contains_points(numpy.array([Sand,Clay]).transpose())]=TexLabel
else:
TexClass=['nan',]
#==============================================================================
# Draw
#==============================================================================
if DoPlot:
fig=pylab.figure()
ax=fig.add_subplot(111)
for iP in range(nP):
TexLabel=Poly_All_Labels[iP]
bbPath = mplPath.Path(Poly_Dict[TexLabel])
patch=mplPatches.PathPatch(bbPath,facecolor='w', lw=2)
ax.add_patch(patch)
ax.text(Poly_Dict[TexLabel].mean(axis=0)[0],Poly_Dict[TexLabel].mean(axis=0)[1],TexLabel)
ax.plot(Sand,Clay,'r+')
ax.set_aspect('equal')
ax.set_xlabel('Sand (kg/kg)')
ax.set_ylabel('Clay (kg/kg)')
return TexClass,fig
else:
return TexClass
def DrawTexTriangle(Poly_Dict,fig=-1,ax=-1):
import matplotlib.path as mplPath
import matplotlib.patches as mplPatches
if ax==-1:
if fig==-1:
fig=pylab.figure()
ax=fig.add_subplot(111)
Poly_All_Labels=Poly_Dict.keys()
nP=len(Poly_Dict)
for iP in range(nP):
TexLabel=Poly_All_Labels[iP]
bbPath = mplPath.Path(Poly_Dict[TexLabel])
patch=mplPatches.PathPatch(bbPath,facecolor=None,fill=False, lw=2)
ax.add_patch(patch)
ax.text(Poly_Dict[TexLabel].mean(axis=0)[0],Poly_Dict[TexLabel].mean(axis=0)[1],TexLabel)
ax.set_aspect('equal')
ax.set_xlabel('Sand (kg/kg)')
ax.set_ylabel('Clay (kg/kg)')
return fig,ax
def TexCode2Name(TexCode):
TexCode=numpy.array(TexCode)
TexName=numpy.zeros_like(TexCode).astype('S16')
TexCode_unique=numpy.array(['U','E','A','L','P','S','Z'])
TexName_unique=numpy.array(['Zware Klei','Klei','Leem','Zandleem','Lichte Zandleem','Lemig Zand','Zand'])
nTex=len(TexCode_unique)
for iT in range(nTex):
TexName[TexCode==[TexCode_unique[iT]]]=TexName_unique[iT]
return TexName