public.py 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  1. import pandas as pd
  2. import numpy as np
  3. # 这里写所有表格的判断规则 按顺序每个表格一个函数 方便后续修改
  4. pd.set_option('display.max_columns', 1000)
  5. pd.set_option('display.width', 1000)
  6. pd.set_option('display.max_colwidth', 1000)
  7. # 表1 土壤容重机械组成数据 为了方便做具体修改
  8. def soil_bulk_density(arr): #arr为计算过的数组
  9. # (1)土壤容重不在[0.8, 1.6]范围以内的,存疑
  10. shenHeList=[] # 定义一个数组存放容重存疑的数据
  11. shenHeTarget = [] # 存放每条数据 有问题的指标
  12. try:
  13. for i in arr['土壤容重平均值(g/cm3)(计算)']:
  14. if i > 1.6 or i < 0.8:
  15. shenHeList.append('土壤容重:复核数据合理性。')
  16. shenHeTarget.append('土壤容重平均值。')
  17. else:
  18. shenHeList.append('')
  19. shenHeTarget.append('')
  20. except Exception as err:
  21. print('土壤容重判断出错!请检查soil_bulk_density中判断土壤容重内容',err)
  22. # (2)土壤利用类型→耕地、园地→相对极差>15 %,存疑;土壤利用类型→林地、草地→相对极差>20 %,存疑
  23. tRTypeList = [] # 定义一个数组存放土壤利用类型存疑的数据
  24. tRTypeTarget= [] # 定义一个数组存放土壤利用类型存疑的数据指标名称
  25. try:
  26. for i in arr['相对极差(%)']:
  27. # TODO 此处土地利用类型应从原样品编码提取7-8位两位数组,01代表耕地,02代表园地,03代表林地,04代表草地
  28. if i > 15 and arr.loc[arr['相对极差(%)'] == i, '土地利用类型'].iloc[0] == '耕地园地':
  29. tRTypeList.append('存疑:耕地园地相对极差>15%。')
  30. tRTypeTarget.append('耕地园地极差。')
  31. elif i > 20 and arr.loc[arr['相对极差(%)'] == i, '土地利用类型'].iloc[0] == '林地草地':
  32. tRTypeList.append('存疑:林地草地相对极差>20%。')
  33. tRTypeTarget.append('林地草地极差。')
  34. else:
  35. tRTypeList.append('')
  36. tRTypeTarget.append('')
  37. except Exception as err:
  38. print('相对极差判断、土壤利用类型判断出错!请检查soil_bulk_density中判断相对极差判断、土壤利用类型内容',err)
  39. # (3)加和不在[99, 101]范围内的,存疑
  40. plusShenHeList = [] # 定义一个数组存放加和存疑的数据
  41. plusShenHeTarget = [] # 保存土壤颗粒加和存疑的指标
  42. try:
  43. for i in arr['加和%']:
  44. if float(i) > 101 or float(i) < 99:
  45. plusShenHeList.append('土壤颗粒加和:复核数据合理性。')
  46. plusShenHeTarget.append('土壤颗粒含量加和。')
  47. else:
  48. plusShenHeList.append('')
  49. plusShenHeTarget.append('')
  50. except Exception as err:
  51. print('颗粒含量加和判断出错!请检查soil_bulk_density中判断颗粒含量加和内容',err)
  52. # 根据国际土壤质地类型三角形编程实现对质地的分类→判断质地分类和质地名称是否正确
  53. # 判断土壤类型逻辑:
  54. # soilList = [] # 定义一个数组存放土地类型的数据
  55. # soilContent = []
  56. # soilContentTarget = [] # 存放土壤质地异常的指标名称
  57. xSLErr = [] # 存放ph>7 洗失量为空的异常数据
  58. xSLTarget = [] # 存放异常数据 指标名称
  59. try:
  60. # # 按行循环读取所有数据
  61. # for index, row in arr.iterrows():
  62. # # 1.将0.02-0.2,0.2-2两列加起来
  63. # plusSoil = row['0.2-0.02mm颗粒含量%'] + row['2-0.2mm颗粒含量%']
  64. # small_002_list = row['0.02-0.002mm颗粒含量%']
  65. # small_0002_list = row['0.002mm以下颗粒含量%']
  66. # if np.isnan(plusSoil) or np.isnan(small_002_list) or np.isnan(small_0002_list):
  67. # soilList.append('')
  68. # # 具体判断 这里为了方便看 减少了嵌套逻辑
  69. # elif small_0002_list >=65 and small_0002_list <100: # 2. <0.002含量 65-100 ->重黏土
  70. # soilList.append('重黏土')
  71. # elif small_0002_list >= 45 and small_0002_list <65: # 3.<0.002含量 45-65 ->黏土
  72. # soilList.append('黏土')
  73. # elif small_0002_list >= 25 and small_0002_list <45 and small_002_list >= 45 and small_002_list <75: # 4. <0.002含量 25-45 and 0.002-0.02含量 45-75 -> 粉(砂)质黏土
  74. # soilList.append('粉(砂)质黏土')
  75. # elif small_0002_list >= 25 and small_0002_list<45 and small_002_list>=0 and small_002_list<45 and plusSoil>=10 and plusSoil <55: # 5. <0.002含量 25-45 and 0.002-0.02含量 0-45 and 0.02-2含量 10-55-> 壤质黏土
  76. # soilList.append('壤质黏土')
  77. # elif small_0002_list >= 25 and small_0002_list<45 and small_002_list>=0 and small_002_list<20 and plusSoil>=55 and plusSoil <75:# 6. <0.002含量 25-45 and 0.002-0.02含量 0-20 and 0.02-2含量 55-75-> 砂质黏土
  78. # soilList.append('砂质黏土')
  79. # elif small_0002_list >= 15 and small_0002_list<25 and small_002_list>=45 and small_002_list<85: # 7.<0.002含量 15-25 and 0.002-0.02含量 45-85 -> 粉(砂)质黏壤土
  80. # soilList.append('粉(砂)质黏壤土')
  81. # elif small_0002_list >= 15 and small_0002_list<25 and small_002_list>=20 and small_002_list<45 and plusSoil>=30 and plusSoil <55:# 8.<0.002含量 15-25 and 0.002-0.02含量 20-45 and 0.02-2含量 30-55-> 黏壤土
  82. # soilList.append('黏壤土')
  83. # elif small_0002_list >= 15 and small_0002_list<25 and small_002_list>=0 and small_002_list<30 and plusSoil>=55 and plusSoil <85:# 9.<0.002含量 15-25 and 0.002-0.02含量 0-30 and 0.02-2含量 55-85-> 砂质黏壤土
  84. # soilList.append('砂质黏壤土')
  85. # elif small_0002_list >= 0 and small_0002_list<15 and small_002_list>=45 and small_002_list<100:#10.<0.002含量 0-15 and 0.002-0.02含量 45-100 ->粉(砂)质壤土
  86. # soilList.append('粉(砂)质壤土')
  87. # elif small_0002_list >= 0 and small_0002_list<15 and small_002_list>=30 and small_002_list<45 and plusSoil>=40 and plusSoil <55: # 11.<0.002含量 0-15 and 0.002-0.02含量 30-45 and 0.02-2含量 40-55-> 壤土
  88. # soilList.append('壤土')
  89. # elif small_0002_list >= 0 and small_0002_list<15 and small_002_list>=0 and small_002_list<45 and plusSoil>=55 and plusSoil <85: # 12.<0.002含量 0-15 and 0.002-0.02含量 0-45 and 0.02-2含量 55-85-> 砂质壤土
  90. # soilList.append('砂质壤土')
  91. # elif small_0002_list >= 0 and small_0002_list<15 and small_002_list>=0 and small_002_list<15 and plusSoil>=85 and plusSoil <100: # 13.<0.002含量 0-15 and 0.002-0.02含量 0-15 and 0.02-2含量 85-100-> 砂土及壤质砂土
  92. # soilList.append('砂土及壤质砂土')
  93. # else:
  94. # soilList.append('') # 除所有情况外 还有空值
  95. #
  96. # # 比较和原有数据是否一致
  97. # arr['土壤质地(判断)'] = soilList
  98. for index, row in arr.iterrows():
  99. # if (row['土壤质地(判断)'] != row['土壤质地']) and (not pd.isna(row['土壤质地'])):
  100. # soilContent.append('存疑:土壤质地填报与判断不一致')
  101. # soilContentTarget.append('土壤质地。')
  102. # else:
  103. # soilContent.append('')
  104. # soilContentTarget.append('')
  105. # 如果pH>7,则洗失量数据不能为空;
  106. if (not pd.isna(row['pH']) and row['pH'] > 7 and pd.isna(row['洗失量(吸管法需填)%']) and ((not pd.isna(row['0.2-0.02mm颗粒含量%']) or ( not pd.isna(row['0.02-0.002mm颗粒含量%'])) )) ):
  107. xSLErr.append('洗失量:机械组成存在,ph>7但洗失量未检测。')
  108. xSLTarget.append('洗失量。')
  109. else:
  110. xSLErr.append('')
  111. xSLTarget.append('')
  112. except Exception as err:
  113. print('土壤洗失量判断出错!请检查soil_bulk_density中判断洗失量内容', err)
  114. # 把存疑数据组合并返回
  115. # print('shenHeList--',shenHeList,len(shenHeList))
  116. # print('plusShenHeList--', plusShenHeList, len(plusShenHeList))
  117. # print('tRTypeList--', tRTypeList, len(tRTypeList))
  118. # print('soilContent--', soilContent, len(soilContent))
  119. # print('soilList--', soilList, len(soilList))
  120. pdData = pd.DataFrame({
  121. '审核结果': pd.Series(shenHeList) + pd.Series(tRTypeList) + pd.Series(plusShenHeList),
  122. #'土壤质地(判断)': soilList,
  123. '异常指标': pd.Series(shenHeTarget) + pd.Series(tRTypeTarget) + pd.Series(plusShenHeTarget),
  124. })
  125. return pdData
  126. # 这是一个判断范围的函数 如果需要修改范围 修改start end值就行
  127. # def is_not_in_range(value):
  128. # return value <30 or value > 90
  129. # 表3 水稳性大团聚体规则判断函数
  130. def water_stable(arr):
  131. # (1)不在[30, 90]范围以内的,存疑
  132. shenHeList = [] # 定义一个数组存放团聚体存疑的数据
  133. shenHeTar = [] # 存放水稳异常指标
  134. # (2)总和超过90,存疑;耕地和园地>80,提示关注;林地和草地>90,提示关注
  135. plusList = []
  136. plusTar = [] # 水稳总和异常指标名称
  137. soilType = []
  138. # (3)>5mm指标占比超过10 %,存疑,应回溯
  139. rateList = []
  140. rateTar = [] # >5mm占比异常指标
  141. try:
  142. for index, row in arr.iterrows():
  143. # 规则1判断 先判断值是否存在
  144. # if (not pd.isna(row['>5mm%']) and is_not_in_range(row['>5mm%'])) or (
  145. # not pd.isna(row['3-5mm%']) and is_not_in_range(row['3-5mm%'])) or (
  146. # not pd.isna(row['2-3mm%']) and is_not_in_range(row['2-3mm%'])) or (
  147. # not pd.isna(row['1-2mm%']) and is_not_in_range(row['1-2mm%'])) or (
  148. # not pd.isna(row['0.5-1mm%']) and is_not_in_range(row['0.5-1mm%'])) or (
  149. # not pd.isna(row['0.25-0.5mm%']) and is_not_in_range(row['0.25-0.5mm%'])):
  150. # shenHeList.append('存疑:团聚体百分比不在范围以内。')
  151. # shenHeTar.append('水稳分项指标。')
  152. # else:
  153. # shenHeList.append('')
  154. # shenHeTar.append('')
  155. # 规则2判断
  156. if pd.isna(row['总和(%)']) and row['总和(%)'] > 90 or row['总和(%)'] < 30:
  157. plusList.append('水稳性大团聚体:总和复核数据合理性。')
  158. plusTar.append('水稳总和。')
  159. else:
  160. plusList.append('')
  161. plusTar.append('')
  162. # if (row['土地利用类型'] == '耕地园地' and row['总和(%)'] > 80) or (row['土地利用类型'] == '林地草地' and row['总和(%)'] > 90):
  163. # soilType.append('关注:耕地园地团聚体总和大于80或林地草地团聚体总和大于90。')
  164. # else:
  165. # soilType.append('')
  166. if row['>5mm%'] > 10:
  167. rateList.append('存疑:>5mm占比超过10%应回溯。')
  168. rateTar.append('水稳>5mm。')
  169. else:
  170. rateList.append('')
  171. rateTar.append('')
  172. resData = pd.DataFrame({
  173. '审核结果': pd.Series(plusList) + pd.Series(rateList),
  174. '异常指标': pd.Series(plusTar) + pd.Series(rateTar),
  175. })
  176. return resData
  177. except Exception as err:
  178. print('大团聚体判断出错!请检查water_stable中判断大团聚体内容', err)
  179. # 表5 pH、阳离子交换量、交换性盐基基础数据判断
  180. # 判断土壤类型和阳离子交换量 盐基饱和度的范围
  181. def soilTypeValue(row): # 传入一行数据
  182. strValue = row['土壤类型']
  183. soilType = ''
  184. if isinstance(strValue, str):
  185. # print('type---', strValue.split('_'))
  186. # print('strValue',strValue)
  187. if len(strValue.split('_')) > 1:
  188. soilType = strValue.split('_')[1] # 获取到土壤类型
  189. cationChange = row['阳离子交换量Cmol(+)/kg'] # 获取到阳离子交换量
  190. bHValue = (row['交换性盐总量Cmol(+)/kg']/row['阳离子交换量Cmol(+)/kg'] )*100# 计算出的盐基饱和度
  191. # 判断三者范围是否合理
  192. res = ''
  193. if soilType == '黄红壤':
  194. if (not pd.isna(cationChange)) and (cationChange > 10 and cationChange<24) and (not pd.isna(bHValue)) and (bHValue > 30 and bHValue<50):
  195. res = ''
  196. else:
  197. res = '存疑:该土壤类型的阳离子交换量或盐基饱和度范围存疑。'
  198. elif soilType == '棕红壤':
  199. if (not pd.isna(cationChange)) and (cationChange > 6 and cationChange < 15) and (not pd.isna(bHValue)) and (
  200. bHValue > 25 and bHValue < 70):
  201. res = ''
  202. else:
  203. res = '存疑:该土壤类型的阳离子交换量或盐基饱和度范围存疑。'
  204. elif soilType == '红壤性土':
  205. if (not pd.isna(cationChange)) and (cationChange > 5 and cationChange < 15) and (not pd.isna(bHValue)) and (
  206. bHValue > 10 and bHValue < 50):
  207. res = ''
  208. else:
  209. res = '存疑:该土壤类型的阳离子交换量或盐基饱和度范围存疑。'
  210. elif soilType == '典型黄壤':
  211. if (not pd.isna(cationChange)) and (cationChange > 5 and cationChange < 15) and not(pd.isna(bHValue)) and (
  212. bHValue < 30):
  213. res = ''
  214. else:
  215. res = '该土壤类型的阳离子交换量或盐基饱和度范围存疑。'
  216. elif soilType == '黄壤性土':
  217. if (not pd.isna(cationChange)) and (cationChange > 10 and cationChange < 18) and (not pd.isna(bHValue)) and (
  218. bHValue < 45):
  219. res = ''
  220. else:
  221. res = '存疑:该土壤类型的阳离子交换量或盐基饱和度范围存疑。'
  222. elif soilType == '典型黄棕壤' or soilType == '暗黄棕壤' or soilType == '黄棕壤性土':
  223. if (not pd.isna(cationChange)) and (cationChange > 8 and cationChange < 22) and (not pd.isna(bHValue)) and (
  224. bHValue > 30 and bHValue < 60):
  225. res = ''
  226. else:
  227. res = '存疑:该土壤类型的阳离子交换量或盐基饱和度范围存疑。'
  228. elif soilType == '典型黄褐土' or soilType == '黏盘黄褐土' or soilType == '粘盘黄褐土' or soilType == '粘盘黄褐土' or soilType=='白浆化黄褐土' or soilType=='黄褐土性土':
  229. if (not pd.isna(cationChange)) and (cationChange > 15 and cationChange < 25) and (not pd.isna(bHValue)) and (
  230. bHValue > 60 and bHValue < 85):
  231. res = ''
  232. else:
  233. res = '存疑:该土壤类型的阳离子交换量或盐基饱和度范围存疑。'
  234. elif soilType == '粘盘黄褐土':
  235. if (not pd.isna(cationChange)) and (cationChange > 10 and cationChange < 30) and (not pd.isna(bHValue)) and (
  236. bHValue > 75 and bHValue < 95):
  237. res = ''
  238. else:
  239. res = '存疑:该土壤类型的阳离子交换量或盐基饱和度范围存疑。'
  240. elif soilType == '典型棕壤' or soilType == '白浆化棕壤' or soilType == '潮棕壤' or soilType == '棕壤性土' or soilType == '棕壤性土':
  241. if (not pd.isna(cationChange)) and (cationChange > 5 and cationChange < 20) and (not pd.isna(bHValue)) and (
  242. cationChange > 25 and cationChange < 65):
  243. res = ''
  244. else:
  245. res = '存疑:该土壤类型的阳离子交换量或盐基饱和度范围存疑。'
  246. elif soilType == '典型山地草甸土' or soilType == '山地草原草甸土' or soilType == '山地灌丛草甸土':
  247. if (not pd.isna(cationChange)) and (cationChange > 10 and cationChange < 20) and (not pd.isna(bHValue)) and (
  248. bHValue > 15 and bHValue < 30):
  249. res = ''
  250. else:
  251. res = '存疑:该土壤类型的阳离子交换量或盐基饱和度范围存疑。'
  252. elif soilType == '酸性紫色土' or soilType == '中性紫色土' or soilType == '石灰性紫色土':
  253. if (not pd.isna(cationChange)) and (cationChange > 10 and cationChange < 20) and (not pd.isna(bHValue)) and (
  254. bHValue > 50 and bHValue < 70):
  255. res = ''
  256. else:
  257. res = '存疑:该土壤类型的阳离子交换量或盐基饱和度范围存疑。'
  258. elif soilType == '红色石灰土' or soilType == '黑色石灰土' or soilType == '棕色石灰土' or soilType == '黄色石灰土' :
  259. if (not pd.isna(cationChange)) and (cationChange > 15 and cationChange < 30) and (not pd.isna(bHValue)) and (
  260. bHValue > 70 and bHValue < 100):
  261. res = ''
  262. else:
  263. res = '存疑:该土壤类型的阳离子交换量或盐基饱和度范围存疑。'
  264. elif soilType == '酸性石质土' or soilType == '中性石质土' or soilType == '钙质石质土' or soilType == '含盐石质土':
  265. if (not pd.isna(cationChange)) and (cationChange > 10 and cationChange < 15) and (not pd.isna(bHValue)) and (
  266. bHValue > 45 and bHValue < 65):
  267. res = ''
  268. else:
  269. res = '存疑:该土壤类型的阳离子交换量或盐基饱和度范围存疑。'
  270. elif soilType == '酸性粗骨土' or soilType == '中性粗骨土' or soilType == '钙质粗骨土' or soilType == '硅质盐粗骨土':
  271. if (not pd.isna(cationChange)) and (cationChange > 5 and cationChange < 15) and (not pd.isna(bHValue)) and (
  272. bHValue > 20 and bHValue < 50):
  273. res = ''
  274. else:
  275. res = '存疑:该土壤类型的阳离子交换量或盐基饱和度范围存疑。'
  276. elif soilType == '典型潮土' or soilType == '灰潮土' or soilType == '脱潮土' or soilType == '湿潮土' or soilType == '盐化潮土' or soilType == '碱化潮土' or soilType == '灌於潮土':
  277. if (not pd.isna(cationChange)) and (cationChange > 10 and cationChange < 30) and (not pd.isna(bHValue)) and (
  278. bHValue > 70 and bHValue < 100):
  279. res = ''
  280. else:
  281. res = '存疑:该土壤类型的阳离子交换量或盐基饱和度范围存疑。'
  282. elif soilType == '典型砂姜黑土' or soilType == '石灰性砂姜黑土' or soilType == '盐化砂姜黑土' or soilType == '碱化砂姜黑土' or soilType == '黑粘土':
  283. if (not pd.isna(cationChange)) and (cationChange > 18 and cationChange < 35) and (not pd.isna(bHValue)) and (
  284. bHValue > 90 and bHValue < 100):
  285. res = ''
  286. else:
  287. res = '存疑:该土壤类型的阳离子交换量或盐基饱和度范围存疑。'
  288. elif soilType == '淹育水稻土':
  289. if (not pd.isna(cationChange)) and (cationChange > 20 and cationChange < 30) and (not pd.isna(bHValue)) and (
  290. bHValue > 85 and bHValue < 90):
  291. res = ''
  292. else:
  293. res = '存疑:该土壤类型的阳离子交换量或盐基饱和度范围存疑。'
  294. elif soilType == '潴育水稻土':
  295. if (not pd.isna(cationChange)) and (cationChange > 12 and cationChange < 20) and (not pd.isna(bHValue)) and (
  296. bHValue > 60 and bHValue < 80):
  297. res = ''
  298. else:
  299. res = '存疑:该土壤类型的阳离子交换量或盐基饱和度范围存疑。'
  300. elif soilType == '潜育水稻土':
  301. if (not pd.isna(cationChange)) and (cationChange > 15 and cationChange < 25) and (not pd.isna(bHValue)) and (
  302. bHValue > 75 and bHValue < 90):
  303. res = ''
  304. else:
  305. res = '存疑:该土壤类型的阳离子交换量或盐基饱和度范围存疑。'
  306. elif soilType == '漂洗水稻土':
  307. if (not pd.isna(cationChange)) and (cationChange > 10 and cationChange < 20) and (not pd.isna(bHValue)) and (
  308. bHValue > 65 and bHValue < 80):
  309. res = ''
  310. else:
  311. res = '存疑:该土壤类型的阳离子交换量或盐基饱和度范围存疑。'
  312. return res
  313. def cation_value(arr):
  314. phList = [] # 保存ph存疑数据
  315. cationList = [] # 保存阳离子存疑数据
  316. exchangeableSalt = [] # 保存交换性盐基总量存疑数据
  317. exchangeableCa = [] # 保存交换性钙总量存疑数据
  318. exchangeableMg = [] # 保存交换性镁总量存疑数据
  319. exchangeableK = [] # 保存交换性钾总量存疑数据
  320. exchangeableNa = [] # 保存交换性钠总量存疑数据
  321. summaryList = [] # 保存ph 离子和 盐基饱和度范围存疑数据
  322. soilTypeList = [] # 保存土壤类型 阳离子交换量cmol(+)/kg 和盐基饱和度范围存疑数据
  323. waterMount = [] # 保存含水量存疑数据 含水量应小于10%
  324. phTar = [] # 保存ph异常指标
  325. cationTar = [] # 保存阳离子异常指标
  326. exchangeableSaltTar = [] # 保存交换性盐基总量异常指标
  327. exchangeableCaTar = [] # 保存交换性钙异常指标
  328. exchangeableMgTar = [] # 保存交换性镁异常指标
  329. exchangeableKTar = [] # 保存交换性钾异常指标
  330. exchangeableNaTar = [] # 保存交换性钠异常指标
  331. summaryListTar = [] # 保存ph 离子和 盐基饱和度异常指标
  332. soilTypeListTar = [] # 保存土壤类型 阳离子交换量cmol(+)/kg 和盐基饱和度异常数据
  333. waterMountTar = [] # 保存含水量异常指标
  334. try:
  335. for index, row in arr.iterrows():
  336. # 风干样含水量 0.5-5,存疑
  337. if pd.isna(row['含水量']) or row['含水量'] > 5 or row['含水量'] < 0.5:
  338. waterMount.append('风干试样含水量(分析基):复核数据合理性。')
  339. waterMountTar.append('风干试样含水量(分析基)。')
  340. else:
  341. waterMount.append('')
  342. waterMountTar.append('')
  343. # (1)pH在[4, 9]范围之外的,存疑;
  344. if pd.isna(row['pH']) or row['pH'] < 4 or row['pH'] > 9:
  345. phList.append('pH:复核数据合理性。')
  346. phTar.append('pH。')
  347. else:
  348. phList.append('')
  349. phTar.append('')
  350. # (2)阳离子交换量在[6, 38]范围之外的,存疑;
  351. if row['阳离子交换量Cmol(+)/kg'] < 6 or row['阳离子交换量Cmol(+)/kg'] > 38:
  352. cationList.append('阳离子交换量:复核数据合理性。')
  353. cationTar.append('阳离子交换量。')
  354. else:
  355. cationList.append('')
  356. cationTar.append('')
  357. # (3)交换性盐基总量在[3, 30]范围之外的,存疑;
  358. if row['交换性盐总量Cmol(+)/kg'] <3 or row['交换性盐总量Cmol(+)/kg'] > 30:
  359. exchangeableSalt.append('交换性盐基总量:复核数据合理性。')
  360. exchangeableSaltTar.append('交换性盐总量。')
  361. else:
  362. exchangeableSalt.append('')
  363. exchangeableSaltTar.append('')
  364. # (4)交换性钙在[1, 25]范围之外的,存疑;
  365. if row['交换性钙Cmol(1/2Ca2+)/kg'] < 1 or row['交换性钙Cmol(1/2Ca2+)/kg'] > 25:
  366. exchangeableCa.append('交换性钙:交换性钙复核数据合理性。')
  367. exchangeableCaTar.append('交换性钙。')
  368. else:
  369. exchangeableCa.append('')
  370. exchangeableCaTar.append('')
  371. # (5)交换性镁在[0.5, 12.5]范围之外的,存疑;
  372. if row['交换性镁cmol(1/2Mg2+)/kg'] < 0.5 or row['交换性镁cmol(1/2Mg2+)/kg'] > 12.5:
  373. exchangeableMg.append('交换性镁:复核数据合理性。')
  374. exchangeableMgTar.append('交换性镁。')
  375. else:
  376. exchangeableMg.append('')
  377. exchangeableMgTar.append('')
  378. # (6)交换性钾在[0.1, 1.5]范围之外的,存疑;
  379. if row['交换性钾Cmol(+)/kg'] < 0.1 or row['交换性钾Cmol(+)/kg'] > 1.5:
  380. exchangeableK.append('交换性钾:复核数据合理性。')
  381. exchangeableKTar.append('交换性钾。')
  382. else:
  383. exchangeableK.append('')
  384. exchangeableKTar.append('')
  385. # (7)交换性钠在[0.1, 2]范围之外的,存疑;
  386. if row['交换性钠cmol(+)/kg'] < 0.1 or row['交换性钠cmol(+)/kg'] > 2:
  387. if row['交换性钠cmol(+)/kg'] > 2:
  388. exchangeableNa.append('交换性钠:复核数据合理性,关联pH审核。')
  389. exchangeableNaTar.append('交换性钠。')
  390. else:
  391. exchangeableNa.append('交换性钠:复核数据合理性。')
  392. exchangeableNaTar.append('交换性钠。')
  393. else:
  394. exchangeableNa.append('')
  395. exchangeableNaTar.append('')
  396. # (8)pH<7.5,阳离子交换量>交换性盐总量>四大离子之和,且盐基饱和度小于100 %;违反则存疑;pH≥7.5,交换性盐总量 = 四大离子之和,盐基饱和度范围在80~120 %;违反则存疑;
  397. if ((not pd.isna(row['pH']) and row['pH']<6 and (row['阳离子交换量Cmol(+)/kg']>row['交换性盐总量Cmol(+)/kg']) and (row['交换性盐总量Cmol(+)/kg']>row['四大离子之和']) and row['盐基饱和度%']*100 <60 ) or
  398. ((not pd.isna(row['pH']) and row['pH']>=7.5 and row['交换性盐总量Cmol(+)/kg']==row['四大离子之和'] and (row['盐基饱和度%']*100 <120 and row['盐基饱和度%']*100 >80 )))or
  399. ((not pd.isna(row['pH']) and row['pH']>=6 and row['pH']<7.5 and (row['阳离子交换量Cmol(+)/kg']>row['交换性盐总量Cmol(+)/kg']) and (row['交换性盐总量Cmol(+)/kg']>row['四大离子之和']) and row['盐基饱和度%']*100 < 85))
  400. ):
  401. summaryList.append('')
  402. summaryListTar.append('')
  403. else:
  404. summaryList.append('存疑:pH值、阳离子交换量、交换性盐总量、离子总和、盐基饱和度之间关系存疑。')
  405. summaryListTar.append('盐基饱和度。')
  406. soilRes = soilTypeValue(row)
  407. soilTypeList.append(soilRes)
  408. # print('pd.Series(phList)',pd.Series(phList) + pd.Series(cationList)+pd.Series(exchangeableSalt))
  409. # print('pd.Series(cationList)', pd.Series(exchangeableSalt))
  410. # print('res---', pd.Series(phList)+pd.Series(cationList)+pd.Series(exchangeableSalt)+pd.Series(exchangeableCa)+pd.Series(exchangeableMg)+pd.Series(exchangeableK)+pd.Series(exchangeableNa)+pd.Series(summaryList))
  411. checkData = pd.DataFrame({
  412. '审核结果': pd.Series(phList)+pd.Series(cationList)+pd.Series(exchangeableSalt)+pd.Series(exchangeableCa)+pd.Series(exchangeableMg)+pd.Series(exchangeableK)+pd.Series(exchangeableNa)+pd.Series(summaryList)+pd.Series(soilTypeList)+pd.Series(waterMount),
  413. '异常指标': pd.Series(phTar)+pd.Series(cationTar)+pd.Series(exchangeableSaltTar)+pd.Series(exchangeableCaTar)+pd.Series(exchangeableMgTar)+pd.Series(exchangeableKTar)+pd.Series(exchangeableNaTar)+pd.Series(summaryListTar)+pd.Series(waterMountTar)
  414. })
  415. return checkData
  416. except Exception as err:
  417. print('阳离子量判断出错!请检查cation_value中判断阳离子量内容', err)
  418. # 表8 8大离子基础数据判断
  419. def eight_ion_coun(arr, summary):
  420. try:
  421. allArr = [] # 存储水溶性盐总量存疑数据
  422. conductivity = [] # 存储电导率存疑数据
  423. naArr = [] # 存储钠离子存疑数据
  424. kArr = [] # 存储钾离子存疑数据
  425. caArr = [] # 存储钙离子存疑数据
  426. mgArr = [] # 存储镁离子存疑数据
  427. coArr = [] # 存储碳酸根离子存疑数据
  428. cohArr = [] # 存储碳酸氢根离子存疑数据
  429. soArr = [] # 存储硫酸根离子存疑数据
  430. clArr = [] # 氯离子存疑数据
  431. totalCom = [] # 全盐量小于八大离子和存疑数据
  432. phCoArr = [] # ph 碳酸根存疑数据
  433. changeComArr = [] #交换性离子高于水溶性离子存疑数据
  434. rateArr = [] # (水溶性全盐量-八大离子加和)/八大离子加和×100 存疑数据
  435. subtractionArr=[] #阳离子-阴离子 不在范围内
  436. # 存放异常指标
  437. allArrTar = [] # 存储水溶性盐总量异常指标
  438. conductivityTar = [] # 存储电导率异常指标
  439. naArrTar = [] # 存储钠离子异常指标
  440. kArrTar = [] # 存储钾离子异常指标
  441. caArrTar = [] # 存储钙离子异常指标
  442. mgArrTar = [] # 存储镁离子异常指标
  443. coArrTar = [] # 存储碳酸根离子异常指标
  444. cohArrTar = [] # 存储碳酸氢根离子异常指标
  445. soArrTar = [] # 存储硫酸根离子异常指标
  446. clArrTar = [] # 氯离子异常指标
  447. totalComTar = [] # 全盐量小于八大离子和异常指标
  448. phCoArrTar = [] # ph 碳酸根异常指标
  449. changeComArrTar = [] # 交换性离子高于水溶性离子异常指标
  450. rateArrTar = [] # (水溶性全盐量-八大离子加和)/八大离子加和×100 异常指标
  451. subtractionArrTar = [] # 阳离子-阴离子 异常指标
  452. #(2)水溶性盐总量在[0.1, 2]范围之外的,存疑;
  453. for index, row in arr.iterrows():
  454. if (not pd.isna(row['水溶性全盐量g/kg']) and row['水溶性全盐量g/kg'] < 0.1) or (not pd.isna(row['水溶性全盐量g/kg']) and row['水溶性全盐量g/kg'] > 2):
  455. allArr.append('全盐量:复核数据合理性。')
  456. allArrTar.append('全盐量。')
  457. else:
  458. allArr.append('')
  459. allArrTar.append('')
  460. #(3)电导率在[0.01, 2]范围之外的,存疑;
  461. if ( not pd.isna(row['电导率ms/cm']) and row['电导率ms/cm'] < 0.01) or (not pd.isna(row['电导率ms/cm']) and row['电导率ms/cm'] > 2):
  462. conductivity.append('电导率:复核数据合理性。')
  463. conductivityTar.append('电导率。')
  464. else:
  465. conductivity.append('')
  466. conductivityTar.append('')
  467. #(4)水溶性钠在[0.05, 0.5]范围之外的,存疑;
  468. if (not pd.isna(row['水溶性钠离子含量Cmol(Na+)/kg']) and row['水溶性钠离子含量Cmol(Na+)/kg'] <0.05) or (pd.isna(row['水溶性钠离子含量Cmol(Na+)/kg']) and row['水溶性钠离子含量Cmol(Na+)/kg'] > 0.5):
  469. naArr.append('水溶性钠离子:水溶性钠离子复核数据合理性。')
  470. naArrTar.append('水溶性钠离子。')
  471. else:
  472. naArr.append('')
  473. naArrTar.append('')
  474. #(5)水溶性钾在[0.01, 0.5]范围之外的,存疑;
  475. if (not pd.isna(row['水溶性钾离子含量Cmol(K+)/kg']) and row['水溶性钾离子含量Cmol(K+)/kg'] <0.01) or ( not pd.isna(row['水溶性钾离子含量Cmol(K+)/kg']) and row['水溶性钾离子含量Cmol(K+)/kg'] > 0.5):
  476. kArr.append('水溶性钾离子:复核数据合理性。')
  477. kArrTar.append('水溶性钾离子。')
  478. else:
  479. kArr.append('')
  480. kArrTar.append('')
  481. #(6)水溶性钙在[0.25, 5]范围之外的,存疑;
  482. if (not pd.isna(row['水溶性钙离子含量cmol(1/2Ca2+)/kg']) and row['水溶性钙离子含量cmol(1/2Ca2+)/kg'] <0.25) or (not pd.isna(row['水溶性钙离子含量cmol(1/2Ca2+)/kg']) and row['水溶性钙离子含量cmol(1/2Ca2+)/kg'] > 0.5):
  483. caArr.append('水溶性钙离子:复核数据合理性。')
  484. caArrTar.append('水溶性钙离子。')
  485. else:
  486. caArr.append('')
  487. caArrTar.append('')
  488. #(7)水溶性镁在[0.125, 2.5]范围之外的,存疑;
  489. if (not pd.isna(row['水溶性镁离子Cmol(1/2Mg2+)/kg']) and row['水溶性镁离子Cmol(1/2Mg2+)/kg'] <0.125) or (not pd.isna(row['水溶性镁离子Cmol(1/2Mg2+)/kg']) and row['水溶性镁离子Cmol(1/2Mg2+)/kg'] > 2.5):
  490. mgArr.append('水溶性镁离子:复核数据合理性。')
  491. mgArrTar.append('水溶性镁离子。')
  492. else:
  493. mgArr.append('')
  494. mgArrTar.append('')
  495. #(8)水溶性碳酸根在[0.01, 2.5]范围之外的,存疑;
  496. if (not pd.isna(row['水溶性碳酸根离子含量cmol(1/2CO32+)/kg']) and row['水溶性碳酸根离子含量cmol(1/2CO32+)/kg'] <0.01) or (not pd.isna(row['水溶性碳酸根离子含量cmol(1/2CO32+)/kg']) and row['水溶性碳酸根离子含量cmol(1/2CO32+)/kg'] > 2.5):
  497. coArr.append('水溶性碳酸根:复核数据合理性。')
  498. coArrTar.append('水溶性碳酸根。')
  499. else:
  500. coArr.append('')
  501. coArrTar.append('')
  502. #(9)水溶性碳酸氢根在[0.05, 5]范围之外的,存疑;
  503. if (not pd.isna(row['水溶性碳酸氢离子含量cmol(1/2HCO3-)/kg']) and row['水溶性碳酸氢离子含量cmol(1/2HCO3-)/kg'] <0.05) or (not pd.isna(row['水溶性碳酸氢离子含量cmol(1/2HCO3-)/kg']) and row['水溶性碳酸氢离子含量cmol(1/2HCO3-)/kg'] > 5):
  504. cohArr.append('水溶性碳酸氢根:复核数据合理性。')
  505. cohArrTar.append('水溶性碳酸氢根。')
  506. else:
  507. cohArr.append('')
  508. cohArrTar.append('')
  509. #(10)水溶性硫酸根在[0.25, 2.5]范围之外的,存疑;
  510. if (not pd.isna(row['水溶性硫酸根离子含量cmol(1/2SO42-)/kg']) and row['水溶性硫酸根离子含量cmol(1/2SO42-)/kg'] <0.25) or (not pd.isna(row['水溶性硫酸根离子含量cmol(1/2SO42-)/kg']) and row['水溶性硫酸根离子含量cmol(1/2SO42-)/kg'] > 2.5):
  511. soArr.append('水溶性硫酸根:复核数据合理性。')
  512. soArrTar.append('水溶性硫酸根。')
  513. else:
  514. soArr.append('')
  515. soArrTar.append('')
  516. #(11)水溶性氯根在[0.5, 5]范围之外的,存疑;
  517. if (not pd.isna(row['水溶性氯离子含量cmol(Cl-)/kg']) and row['水溶性氯离子含量cmol(Cl-)/kg'] <0.5) or (not pd.isna(row['水溶性氯离子含量cmol(Cl-)/kg']) and row['水溶性氯离子含量cmol(Cl-)/kg'] > 5):
  518. clArr.append('水溶性氯根:复核数据合理性。')
  519. clArrTar.append('水溶性氯根。')
  520. else:
  521. clArr.append('')
  522. clArrTar.append('')
  523. #(12)水溶性盐总量大于等于八大离子之和,违背则存疑;土地利用类型为菜地的,可能不符合这个规律;
  524. if (not pd.isna( row['水溶性全盐量g/kg']) and not pd.isna(row['八大离子加和g/kg']) and row['水溶性全盐量g/kg'] < row['八大离子加和g/kg']):
  525. totalCom.append('存疑:水溶性全盐量小于八大离子之和。')
  526. totalComTar.append('水溶性全盐量。')
  527. else:
  528. totalCom.append('')
  529. totalComTar.append('')
  530. #(13)水溶性八大离子换算为g / kg,如水溶性钠离子g / kg = 水溶性钠离子cmol(Na +) / kg×23g / mol×10 - 2; 这里在计算离子和时已转换
  531. #(14)pH<8,碳酸根基本为0
  532. if row['pH'] <8 and not pd.isna(row['水溶性碳酸根离子含量cmol(1/2CO32+)/kg']) and row['水溶性碳酸根离子含量cmol(1/2CO32+)/kg'] != 0:
  533. phCoArr.append('水溶性碳酸根:pH<8水溶性碳酸根不为0。')
  534. phCoArrTar.append('水溶性碳酸根。')
  535. else:
  536. phCoArr.append('')
  537. phCoArrTar.append('')
  538. #(15)交换性四大盐离子均要高于水溶性四大盐离子(钙镁钾钠)
  539. naBool = not pd.isna(row['水溶性钠离子含量Cmol(Na+)/kg'])
  540. kBool = not pd.isna(row['水溶性钾离子含量Cmol(K+)/kg'])
  541. caBool = not pd.isna(row['水溶性钙离子含量cmol(1/2Ca2+)/kg'])
  542. mgBool = not pd.isna(row['水溶性镁离子Cmol(1/2Mg2+)/kg'])
  543. sumNa = not pd.isna(summary.loc[index,'交换性钠'])
  544. sumK = not pd.isna(summary.loc[index, '交换性钾'])
  545. sumCa = not pd.isna(summary.loc[index, '交换性钙'])
  546. sumMg = not pd.isna(summary.loc[index, '交换性镁'])
  547. if (naBool and sumNa and row['水溶性钠离子含量Cmol(Na+)/kg']>summary.loc[index,'交换性钠']) or (
  548. kBool and sumK and row['水溶性钾离子含量Cmol(K+)/kg']>summary.loc[index,'交换性钾']) or (
  549. caBool and sumCa and row['水溶性钙离子含量cmol(1/2Ca2+)/kg']>summary.loc[index,'交换性钙']) or (
  550. mgBool and sumMg and row['水溶性镁离子Cmol(1/2Mg2+)/kg']>summary.loc[index,'交换性镁']):
  551. changeComArr.append('存疑:交换性盐基总量低于于水溶性盐离子。')
  552. else:
  553. changeComArr.append('')
  554. #(16)(全盐量-水溶性八大离子加和)x2/(全盐量+水溶性八大离子加和)*100,不超过±20 %
  555. if not pd.isna(row['(全盐量-水溶性八大离子加和)x2/(全盐量+水溶性八大离子加和)*100']) and (row['(全盐量-水溶性八大离子加和)x2/(全盐量+水溶性八大离子加和)*100'] < -0.2 or row['(全盐量-水溶性八大离子加和)x2/(全盐量+水溶性八大离子加和)*100'] > 0.2) :
  556. rateArr.append('存疑:全盐量与水溶性八大离子加和的相对相差超过±20%,复核合理性。')
  557. else:
  558. rateArr.append('')
  559. #(17)阳离子总量 - 阴离子总量应基本相等,超过±0.5则提示异常
  560. if not pd.isna(row['阳离子总量-阴离子总量']) and (row['阳离子总量-阴离子总量'] < -0.5 or row['阳离子总量-阴离子总量'] > 0.5) :
  561. subtractionArr.append('存疑:阳离子总量 - 阴离子总量复核数据合理性。')
  562. else:
  563. subtractionArr.append('')
  564. resData = pd.DataFrame({
  565. '审核结果': pd.Series(allArr) + pd.Series(conductivity) + pd.Series(naArr) +
  566. pd.Series(kArr) + pd.Series(caArr) + pd.Series(mgArr) + pd.Series(coArr) + pd.Series(
  567. cohArr) + pd.Series(soArr) + pd.Series(clArr) + pd.Series(totalCom) + pd.Series(
  568. phCoArr) + pd.Series(changeComArr) + pd.Series(rateArr) + pd.Series(subtractionArr),
  569. '异常指标': pd.Series(allArrTar) + pd.Series(conductivityTar) + pd.Series(naArrTar) +
  570. pd.Series(kArrTar) + pd.Series(caArrTar) + pd.Series(mgArrTar) + pd.Series(coArrTar) + pd.Series(
  571. cohArrTar) + pd.Series(soArrTar) + pd.Series(clArrTar) + pd.Series(totalComTar) + pd.Series(
  572. phCoArrTar)
  573. })
  574. return resData
  575. except Exception as err:
  576. print('八大离子判断出错!请检查eight_ion_coun中判断离子内容', err)
  577. # 表10 有机质、全氮、全磷、全钾数据
  578. def nutrient_data(arr):
  579. try:
  580. organicMatter = [] # 有机质存疑数据
  581. NArr = [] # 全氮存疑数据
  582. PArr = [] # 全磷存疑数据
  583. KArr = [] # 全钾存疑数据
  584. availableP = [] # 有效磷存疑数据
  585. availablek = [] #速效钾存疑数据
  586. slowlyK= [] #缓效钾存疑数据
  587. organicRate = [] #有机质 / 全氮比值存疑数据
  588. availablePCom = [] #有效磷<3和大于60,提示异常;
  589. availableTxt = [] # 速效钾<50提示异常
  590. availablekCom = [] # 速效钾>缓效钾 存疑数据
  591. sKErr = [] # 保存交换性钾不等于速效钾
  592. # 异常指标
  593. organicMatterTar = [] # 有机质异常指标
  594. NArrTar = [] # 全氮异常指标
  595. PArrTar = [] # 全磷异常指标
  596. KArrTar = [] # 全钾异常指标
  597. availablePTar = [] # 有效磷异常指标
  598. availablekTar = [] # 速效钾异常指标
  599. slowlyKTar = [] # 缓效钾异常指标
  600. sKErrTar = [] # 保存交换性钾不等于速效钾
  601. for index, row in arr.iterrows():
  602. # 交换性钾 == 速效钾
  603. if not pd.isna(row['速效钾mg/kg']) and not pd.isna(row['交换性钾']) and (2*(row['速效钾mg/kg'] - row['交换性钾']*391) / (row['速效钾mg/kg'] + row['交换性钾']*391) > 0.2 or 2*(row['速效钾mg/kg'] - row['交换性钾']*391)/ (row['速效钾mg/kg'] + row['交换性钾']*391) < -0.2):
  604. sKErr.append('存疑:交换性钾和速效钾相对相差超过±20%,复核合理性。')
  605. sKErrTar.append('交换性钾、速效钾。')
  606. else:
  607. sKErr.append('')
  608. sKErrTar.append('')
  609. #(2)有机质在[2, 50]范围之外的,存疑;有机质<5提示异常;
  610. if row['有机质g/kg'] < 2 or row['有机质g/kg'] >50:
  611. organicMatter.append('有机质:复核数据合理性。')
  612. organicMatterTar.append('有机质。')
  613. else:
  614. organicMatter.append('')
  615. organicMatterTar.append('')
  616. #(3)全氮在[0.1, 2.5]范围之外的;存疑;
  617. if row['全氮g/kg'] < 0.1 or row['全氮g/kg'] > 2.5:
  618. NArr.append('全氮:复核数据合理性。')
  619. NArrTar.append('全氮。')
  620. else:
  621. NArr.append('')
  622. NArrTar.append('')
  623. #(4)全磷在[0.18, 1.5]范围之外的;存疑;
  624. if row['全磷g/kg'] < 0.18 or row['全磷g/kg'] > 1.5:
  625. PArr.append('全磷:复核数据合理性。')
  626. PArrTar.append('全磷。')
  627. else:
  628. PArr.append('')
  629. PArrTar.append('')
  630. #(5)全钾在[10, 29]范围之外的;存疑;
  631. if row['全钾g/kg'] < 10 or row['全钾g/kg'] > 29:
  632. KArr.append('全钾:复核数据合理性。')
  633. KArrTar.append('全钾。')
  634. else:
  635. KArr.append('')
  636. KArrTar.append('')
  637. #(6)有效磷在[1, 50]范围之外的;存疑; 耕地 超过80存疑
  638. if (row['pH'] >= 6.5 and (row['有效磷g/kg'] < 3 or row['有效磷g/kg'] > 60)) or (row['pH'] < 6.5 and (row['有效磷g/kg'] <1 or row['有效磷g/kg'] > 50)) :
  639. if (row['pH'] >= 6.5 and row['有效磷g/kg'] > 60) or (row['pH'] < 6.5 and row['有效磷g/kg'] > 50):
  640. availableP.append('有效磷:复核数据合理性。回溯土地利用类型是否为设施农业。')
  641. else:
  642. availableP.append('有效磷:复核数据合理性。')
  643. availablePTar.append('有效磷。')
  644. else:
  645. availableP.append('')
  646. availablePTar.append('')
  647. # if row['有效磷g/kg'] < 1 or row['有效磷g/kg'] > 60 or ((row['编号'][6:11] == '0101' or row['编号'][6:11] == '0102' or row['编号'][6:11] == '0103') and row['有效磷g/kg'] > 60):
  648. # availableP.append('存疑:有效磷复核数据合理性。')
  649. # else:
  650. # availableP.append('')
  651. #(7)速效钾在[30, 300] 范围之外的;存疑; 耕地超过300存疑
  652. if row['速效钾mg/kg'] < 30 or row['速效钾mg/kg'] > 300 or ((row['编号'][6:10] == '0101' or row['编号'][6:10] == '0102' or row['编号'][6:10] == '0103') and row['速效钾mg/kg'] > 300):
  653. availablek.append('速效钾:复核数据合理性。')
  654. availablekTar.append('速效钾。')
  655. else:
  656. availablek.append('')
  657. availablekTar.append('')
  658. #(8)缓效钾在[100, 2000]范围之外的;存疑;
  659. if row['缓效钾mg/kg'] < 100 or row['缓效钾mg/kg'] > 2000:
  660. slowlyK.append('缓效钾:复核数据合理性。')
  661. slowlyKTar.append('缓效钾。')
  662. else:
  663. slowlyK.append('')
  664. slowlyKTar.append('')
  665. #(9)有机质 / 全氮比值≥20和≤13,提示存疑
  666. if row['有机质g/kg']/row['全氮g/kg'] >=20 or row['有机质g/kg']/row['全氮g/kg'] <=13 :
  667. organicRate.append('存疑:有机质/全氮比值复核数据合理性。')
  668. else:
  669. organicRate.append('')
  670. #(10)有机质、全氮含量异常高,但速效养分特低,提示异常 无法量化不处理
  671. #(11)母岩为片麻岩,但全钾、速效缓效钾含量低,提示异常 无法量化不处理
  672. #(12)有效磷<3和大于60,提示异常;速效钾<50提示异常
  673. # if row['有效磷g/kg'] < 3 or row['有效磷g/kg'] > 60:
  674. # availablePCom.append('有效磷:复核数据合理性。')
  675. # else:
  676. # availablePCom.append('')
  677. # if row['速效钾mg/kg'] < 50:
  678. # availableTxt.append('速效钾:复核数据合理性。')
  679. # else:
  680. # availableTxt.append('')
  681. #(13)速效钾>缓效钾,提示异常
  682. if row['速效钾mg/kg'] > row['缓效钾mg/kg']:
  683. availablekCom.append('异常:速效钾大于缓效钾。')
  684. else:
  685. availablekCom.append('')
  686. resData = pd.DataFrame({
  687. '审核结果': pd.Series(organicMatter) + pd.Series(NArr) + pd.Series(PArr) +
  688. pd.Series(KArr) + pd.Series(availableP) + pd.Series(availablek) + pd.Series(slowlyK) + pd.Series(
  689. organicRate) + pd.Series(availablekCom) + pd.Series(sKErr),
  690. '异常指标': pd.Series(organicMatterTar) + pd.Series(NArrTar) + pd.Series(PArrTar) +
  691. pd.Series(KArrTar) + pd.Series(availablePTar) + pd.Series(availablekTar) + pd.Series(slowlyKTar) + pd.Series(sKErrTar)
  692. })
  693. return resData
  694. except Exception as err:
  695. print('有机质、全氮、全磷、全钾数据判断出错!请检查nutrient_data中判断内容', err)
  696. # 表12 土壤指标判断规则
  697. def soil_metal(arr):
  698. try:
  699. effectiveL = [] # 有效硫存疑数据
  700. effectiveG = [] # 有效硅存疑数据
  701. effectiveT = [] # 有效铁存疑数据
  702. effectiveM = [] # 有效锰存疑数据
  703. effectiveCu = [] # 有效铜存疑数据
  704. effectiveX = [] # 有效锌存疑数据
  705. effectiveP = [] # 有效硼存疑数据
  706. effectiveMu = [] # 有效钼存疑数据
  707. # 存疑指标
  708. effectiveLTar = [] # 有效硫
  709. effectiveGTar = [] # 有效硅
  710. effectiveTTar = [] # 有效铁
  711. effectiveMTar = [] # 有效锰
  712. effectiveCuTar = [] # 有效铜
  713. effectiveXTar = [] # 有效锌
  714. effectivePTar = [] # 有效硼
  715. effectiveMutar = [] # 有效钼
  716. for index, row in arr.iterrows():
  717. #(1)有效硫在[2, 60]范围之外的,存疑;
  718. if (not pd.isna(row['有效硫mg/kg']) and row['有效硫mg/kg'] <2) or (not pd.isna(row['有效硫mg/kg']) and row['有效硫mg/kg'] >60):
  719. effectiveL.append('有效硫:复核数据合理性。')
  720. effectiveLTar.append('有效硫。')
  721. else:
  722. effectiveL.append('')
  723. effectiveLTar.append('')
  724. #(2)有效硅在[10, 500]范围之外的,存疑;
  725. if ( not pd.isna(row['有效硅mg/kg']) and row['有效硅mg/kg'] <10) or (not pd.isna(row['有效硅mg/kg']) and row['有效硅mg/kg'] >500):
  726. effectiveG.append('有效硅:复核数据合理性。')
  727. effectiveGTar.append('有效硅。')
  728. else:
  729. effectiveG.append('')
  730. effectiveGTar.append('')
  731. #(3)有效铁在[5, 300]范围之外的,存疑;
  732. if ( not pd.isna(row['有效铁mg/kg']) and row['有效铁mg/kg'] <5) or (not pd.isna(row['有效铁mg/kg']) and row['有效铁mg/kg'] >300):
  733. effectiveT.append('有效铁:复核数据合理性。')
  734. effectiveTTar.append('有效铁。')
  735. else:
  736. effectiveT.append('')
  737. effectiveTTar.append('')
  738. #(4)有效锰在[5, 200]范围之外的,存疑;
  739. if (not pd.isna(row['有效锰mg/kg']) and row['有效锰mg/kg'] <5) or (not pd.isna(row['有效锰mg/kg']) and row['有效锰mg/kg'] >200) :
  740. effectiveM.append('有效锰:复核数据合理性。')
  741. effectiveMTar.append('有效锰。')
  742. else:
  743. effectiveM.append('')
  744. effectiveMTar.append('')
  745. #(5)有效铜在[0.1, 8]范围之外的,存疑;
  746. if ( not pd.isna(row['有效铜mg/kg']) and row['有效铜mg/kg'] <0.1) or (not pd.isna(row['有效铜mg/kg']) and row['有效铜mg/kg'] >8):
  747. effectiveCu.append('有效铜:复核数据合理性。')
  748. effectiveCuTar.append('有效铜。')
  749. else:
  750. effectiveCu.append('')
  751. effectiveCuTar.append('')
  752. #(6)有效锌在[0.1, 10] 范围之外的,存疑;
  753. if (not pd.isna(row['有效锌mg/kg']) and row['有效锌mg/kg'] <0.1) or (not pd.isna(row['有效锌mg/kg']) and row['有效锌mg/kg'] >10):
  754. effectiveX.append('有效锌:复核数据合理性。')
  755. effectiveXTar.append('有效锌。')
  756. else:
  757. effectiveX.append('')
  758. effectiveXTar.append('')
  759. #(7)有效硼在[0.1, 2] 范围之外的,存疑;
  760. if (not pd.isna(row['有效硼mg/kg']) and row['有效硼mg/kg'] <0.1) or (not pd.isna(row['有效硼mg/kg']) and row['有效硼mg/kg'] >2):
  761. effectiveP.append('有效硼:复核数据合理性。')
  762. effectivePTar.append('有效硼。')
  763. else:
  764. effectiveP.append('')
  765. effectivePTar.append('')
  766. #(8)有效钼在[0.03, 1]范围之外的,存疑。
  767. if (not pd.isna(row['有效钼mg/kg']) and row['有效钼mg/kg'] <0.03) or (not pd.isna(row['有效钼mg/kg']) and row['有效钼mg/kg'] >1):
  768. effectiveMu.append('有效钼:复核数据合理性。')
  769. effectiveMutar.append('有效钼。')
  770. else:
  771. effectiveMu.append('')
  772. effectiveMutar.append('')
  773. resData = pd.DataFrame({
  774. '审核结果': pd.Series(effectiveL) + pd.Series(effectiveT) + pd.Series(effectiveG) +
  775. pd.Series(effectiveM) + pd.Series(effectiveCu) + pd.Series(effectiveX) + pd.Series(effectiveP) + pd.Series(
  776. effectiveMu),
  777. '异常指标': pd.Series(effectiveLTar) + pd.Series(effectiveTTar) + pd.Series(effectiveGTar) +
  778. pd.Series(effectiveMTar) + pd.Series(effectiveCuTar) + pd.Series(effectiveXTar) + pd.Series(effectivePTar) + pd.Series(
  779. effectiveMutar)
  780. })
  781. return resData
  782. except Exception as err:
  783. print('土壤指标数据判断出错!请检查soil_metal中判断内容', err)
  784. # 表14 土壤重金属判断
  785. # 这里风险值和管控值判断 单独写两个函数
  786. # 风险值
  787. def risk_value(arr):
  788. unnormalValue = []
  789. for index, row in arr.iterrows():
  790. str = ''
  791. if row['编号'][6:10] == '0101': # 水田
  792. # 镉
  793. if (row['pH'] <= 5.5 and row['镉mg/kg'] > 0.3) or (
  794. row['pH'] > 5.5 and row['pH']<= 6.5 and row['镉mg/kg'] > 0.4) or (
  795. row['pH'] >6.5 and row['pH'] <=7.5 and row['镉mg/kg'] > 0.6) or (
  796. row['pH'] > 7.5 and row['镉mg/kg'] > 0.8):
  797. str += '镉超污染风险值筛选值。'
  798. # 汞
  799. if (row['pH'] <= 5.5 and row['汞mg/kg'] > 0.5) or (
  800. row['pH'] > 5.5 and row['pH'] <= 6.5 and row['汞mg/kg'] > 0.5) or (
  801. row['pH'] > 6.5 and row['pH'] <= 7.5 and row['汞mg/kg'] > 0.6) or (
  802. row['pH'] > 7.5 and row['汞mg/kg'] > 1):
  803. str += '汞超污染风险值筛选值。'
  804. # 砷
  805. if (row['pH'] <= 5.5 and row['砷mg/kg'] >30) or (
  806. row['pH'] > 5.5 and row['pH'] <= 6.5 and row['砷mg/kg'] > 30) or (
  807. row['pH'] > 6.5 and row['pH'] <= 7.5 and row['砷mg/kg'] > 25) or (
  808. row['pH'] > 7.5 and row['砷mg/kg'] > 20):
  809. str += '砷超污染风险值筛选值。'
  810. # 铅
  811. if (row['pH'] <= 5.5 and row['铅mg/kg'] > 80) or (
  812. row['pH'] > 5.5 and row['pH'] <= 6.5 and row['铅mg/kg'] > 100) or (
  813. row['pH'] > 6.5 and row['pH'] <= 7.5 and row['铅mg/kg'] > 140) or (
  814. row['pH'] > 7.5 and row['铅mg/kg'] > 240):
  815. str += '铅超污染风险值筛选值。'
  816. # 铬
  817. if (row['pH'] <= 5.5 and row['铬mg/kg'] > 250) or (
  818. row['pH'] > 5.5 and row['pH'] <= 6.5 and row['铬mg/kg'] > 250) or (
  819. row['pH'] > 6.5 and row['pH'] <= 7.5 and row['铬mg/kg'] > 300) or (
  820. row['pH'] > 7.5 and row['铬mg/kg'] >350):
  821. str += '铬超污染风险值筛选值。'
  822. else:
  823. # 镉
  824. if (row['pH'] <= 5.5 and row['镉mg/kg'] > 0.3) or (
  825. row['pH'] > 5.5 and row['pH']<= 6.5 and row['镉mg/kg'] > 0.3) or (
  826. row['pH'] >6.5 and row['pH'] <=7.5 and row['镉mg/kg'] > 0.3) or (
  827. row['pH'] > 7.5 and row['镉mg/kg'] > 0.6):
  828. str += '镉超污染风险值筛选值。'
  829. # 汞
  830. if (row['pH'] <= 5.5 and row['汞mg/kg'] > 1.3) or (
  831. row['pH'] > 5.5 and row['pH'] <= 6.5 and row['汞mg/kg'] > 1.8) or (
  832. row['pH'] > 6.5 and row['pH'] <= 7.5 and row['汞mg/kg'] > 2.4) or (
  833. row['pH'] > 7.5 and row['汞mg/kg'] > 3.4):
  834. str += '汞超污染风险值筛选值。'
  835. # 砷
  836. if (row['pH'] <= 5.5 and row['砷mg/kg'] > 40) or (
  837. row['pH'] > 5.5 and row['pH'] <= 6.5 and row['砷mg/kg'] > 40) or (
  838. row['pH'] > 6.5 and row['pH'] <= 7.5 and row['砷mg/kg'] > 30) or (
  839. row['pH'] > 7.5 and row['砷mg/kg'] > 25):
  840. str += '砷超污染风险值筛选值。'
  841. # 铅
  842. if (row['pH'] <= 5.5 and row['铅mg/kg'] > 70) or (
  843. row['pH'] > 5.5 and row['pH'] <= 6.5 and row['铅mg/kg'] > 90) or (
  844. row['pH'] > 6.5 and row['pH'] <= 7.5 and row['铅mg/kg'] > 120) or (
  845. row['pH'] > 7.5 and row['铅mg/kg'] > 170):
  846. str += '铅超污染风险值筛选值。'
  847. # 铬
  848. if (row['pH'] <= 5.5 and row['铬mg/kg'] > 150) or (
  849. row['pH'] > 5.5 and row['pH'] <= 6.5 and row['铬mg/kg'] > 150) or (
  850. row['pH'] > 6.5 and row['pH'] <= 7.5 and row['铬mg/kg'] > 200) or (
  851. row['pH'] > 7.5 and row['铬mg/kg'] > 250):
  852. str += '铬超污染风险值筛选值。'
  853. if (row['pH'] <= 5.5 and row['镍mg/kg'] > 60) or (
  854. row['pH'] > 5.5 and row['pH'] <= 6.5 and row['镍mg/kg'] > 70) or (
  855. row['pH'] > 6.5 and row['pH'] <= 7.5 and row['镍mg/kg'] > 100) or (
  856. row['pH'] > 7.5 and row['镍mg/kg'] > 190):
  857. str += '镍超污染风险值筛选值。'
  858. unnormalValue.append(str)
  859. return unnormalValue
  860. # 管制值
  861. def control_value(arr):
  862. unnormalValue = []
  863. for index, row in arr.iterrows():
  864. str = ''
  865. # 镉
  866. if (row['pH'] <= 5.5 and row['镉mg/kg'] > 1.5) or (
  867. row['pH'] > 5.5 and row['pH'] <= 6.5 and row['镉mg/kg'] > 2) or (
  868. row['pH'] > 6.5 and row['pH'] <= 7.5 and row['镉mg/kg'] > 3) or (
  869. row['pH'] > 7.5 and row['镉mg/kg'] > 4):
  870. str += '镉超污染风险值管制值。'
  871. # 汞
  872. if (row['pH'] <= 5.5 and row['汞mg/kg'] > 2) or (
  873. row['pH'] > 5.5 and row['pH'] <= 6.5 and row['汞mg/kg'] > 2.5) or (
  874. row['pH'] > 6.5 and row['pH'] <= 7.5 and row['汞mg/kg'] > 4) or (
  875. row['pH'] > 7.5 and row['汞mg/kg'] > 6):
  876. str += '汞超污染风险值管制值。'
  877. # 砷
  878. if (row['pH'] <= 5.5 and row['砷mg/kg'] > 200) or (
  879. row['pH'] > 5.5 and row['pH'] <= 6.5 and row['砷mg/kg'] > 150) or (
  880. row['pH'] > 6.5 and row['pH'] <= 7.5 and row['砷mg/kg'] > 120) or (
  881. row['pH'] > 7.5 and row['砷mg/kg'] > 100):
  882. str += '砷超污染风险值管制值。'
  883. # 铅
  884. if (row['pH'] <= 5.5 and row['铅mg/kg'] >400) or (
  885. row['pH'] > 5.5 and row['pH'] <= 6.5 and row['铅mg/kg'] > 500) or (
  886. row['pH'] > 6.5 and row['pH'] <= 7.5 and row['铅mg/kg'] > 700) or (
  887. row['pH'] > 7.5 and row['铅mg/kg'] > 1000):
  888. str += '铅超污染风险值管制值。'
  889. # 铬
  890. if (row['pH'] <= 5.5 and row['铬mg/kg'] > 800) or (
  891. row['pH'] > 5.5 and row['pH'] <= 6.5 and row['铬mg/kg'] > 850) or (
  892. row['pH'] > 6.5 and row['pH'] <= 7.5 and row['铬mg/kg'] > 1000) or (
  893. row['pH'] > 7.5 and row['铬mg/kg'] > 1300):
  894. str += '铬超污染风险值管制值。'
  895. unnormalValue.append(str)
  896. return unnormalValue
  897. def last_metal(arr):
  898. try:
  899. totalGe = [] # 总镉在范围之外
  900. totalGo = [] # 总汞在范围之外
  901. totalShen = [] # 总砷在范围之外
  902. totalPb = [] # 总铅在范围之外
  903. totalG = [] # 总铬在范围之外
  904. totalN = [] # 总镍在范围之外
  905. # 异常指标
  906. totalGeTar = [] # 总镉
  907. totalGoTar = [] # 总汞
  908. totalShenTar = [] # 总砷
  909. totalPbTar = [] # 总铅
  910. totalGTar = [] # 总铬
  911. totalNTar = [] # 总镍
  912. # (1)超过风险筛选值,提示关注
  913. overValue = risk_value(arr) # 超过风险筛选值
  914. # (2)超过风险管控值,提示重点关注
  915. overLimit = control_value(arr) # 超过风险管控值
  916. for index, row in arr.iterrows():
  917. # (3)总镉在[0.03, 0.3]范围之外的,存疑
  918. if row['镉mg/kg'] < 0.03 or row['镉mg/kg'] > 0.3:
  919. totalGe.append('总镉:复核数据合理性。')
  920. totalGeTar.append('总镉。')
  921. else:
  922. totalGe.append('')
  923. totalGeTar.append('')
  924. # (4)总汞在[0.01, 0.3]范围之外的,存疑
  925. if row['汞mg/kg'] < 0.01 or row['汞mg/kg'] > 0.3:
  926. totalGo.append('总汞:复核数据合理性。')
  927. totalGoTar.append('总汞。')
  928. else:
  929. totalGo.append('')
  930. totalGoTar.append('')
  931. # (5)总砷在[0.5, 30]范围之外的,存疑
  932. if row['砷mg/kg'] < 0.5 or row['砷mg/kg'] > 30:
  933. totalShen.append('总砷:复核数据合理性。')
  934. totalShenTar.append('总砷。')
  935. else:
  936. totalShen.append('')
  937. totalShenTar.append('')
  938. # (6)总铅在[2, 100]范围之外的,存疑
  939. if row['铅mg/kg'] < 2 or row['铅mg/kg'] > 100:
  940. totalPb.append('总铅:复核数据合理性。')
  941. totalPbTar.append('总铅。')
  942. else:
  943. totalPb.append('')
  944. totalPbTar.append('')
  945. # (7)总铬在[0.4, 200]范围之外的,存疑
  946. if row['铬mg/kg'] < 0.4 or row['铬mg/kg'] > 200:
  947. totalG.append('总铬:复核数据合理性。')
  948. totalGTar.append('总铬。')
  949. else:
  950. totalG.append('')
  951. totalGTar.append('')
  952. # (8)总镍在[0.3, 100]范围之外的,存疑
  953. if row['镍mg/kg'] < 0.3 or row['镍mg/kg'] > 100:
  954. totalN.append('总镍:复核数据合理性。')
  955. totalNTar.append('总镍。')
  956. else:
  957. totalN.append('')
  958. totalNTar.append('')
  959. resData = pd.DataFrame({
  960. '审核结果': pd.Series(overValue) + pd.Series(overLimit) + pd.Series(totalGe) +
  961. pd.Series(totalGo) + pd.Series(totalShen) + pd.Series(totalPb) + pd.Series(
  962. totalG) + pd.Series(totalN),
  963. '异常指标': pd.Series(totalGeTar) + pd.Series(totalGoTar) + pd.Series(totalShenTar) + pd.Series(totalPbTar) + pd.Series(
  964. totalGTar) + pd.Series(totalNTar)
  965. })
  966. return resData
  967. except Exception as err:
  968. print('土壤重金属指标数据判断出错!请检查last_metal中判断内容', err)