forked from utah-geological-survey/WellApplication
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
198 lines (166 loc) · 6.15 KB
/
test.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# -*- coding: utf-8 -*-
"""
Created on Sat Jan 23 13:03:00 2016
@author: p
"""
from __future__ import absolute_import, division, print_function, unicode_literals
import wellapplication as wa
import pandas as pd
import matplotlib
import sys
sys.path.append('../')
import numpy as np
m = wa.Meso(token='demotoken')
def test_getelev():
print('Testing getelev')
x = [-111.21, 41.4]
m = wa.get_elev(x)
assert m > 100.0
def test_gethuc():
print('Testing gethuc')
x = [-111.21, 41.4]
huc_data = wa.get_huc(x)
assert len(huc_data[0])>0
def test_USGSID():
print('Testing USGSID')
x = [-111.21, 41.4]
usgs_id = wa.USGSID(x)
assert usgs_id == '412400111123601'
def test_nwis():
nw = wa.nwis('dv', '01585200', 'sites')
assert len(nw.sites) == 1
def test_nwis_gw():
nw = wa.nwis('gwlevels','16010204','huc',siteStatus='all')
df = nw.avg_wl()
assert len(df) > 5
def test_fdc():
d16 = wa.nwis('dv','01659500','sites')
ci = wa.fdc(d16.data,'value',1900,2016)
assert type(ci[0]) == list
def test_mktest():
x = range(0,100)
trend = wa.MannKendall.mk_test(x,0.05)
assert trend.trend == 'increasing'
#def test_pipe():
# Chem = {'Type':[1,2,2,3], 'Cl':[1.72,0.90,4.09,1.52], 'HCO3':[4.02,1.28,4.29,3.04],
# 'SO4':[0.58,0.54,0.38,0.46], 'NaK':[1.40,0.90,3.38,2.86], 'Ca':[4.53,None,4.74,1.90],
# 'Mg':[0.79,0.74,0.72,0.66], 'EC':[672.0,308.0,884.0,542.0], 'NO3':[0.4,0.36,0.08,0.40],
# 'Sicc':[0.21,0.56,None,-0.41]}
# chem = pd.DataFrame(Chem)
# pipr = wa.piper(chem)
# assert type(pipr.plot) == matplotlib.figure.Figure
def test_new_xle_imp():
xle = 'test/20160919_LittleHobble.xle'
xle_df = wa.new_xle_imp(xle)
assert len(xle_df) > 0
def test_xle_head_table():
xle_dir = 'test/'
dir_df = wa.xle_head_table(xle_dir)
assert len(xle_dir) > 0
def test_dataendclean():
xle = 'test/20160919_LittleHobble.xle'
df = wa.new_xle_imp(xle)
x = 'Level'
xle1 = wa.dataendclean(df, x)
assert len(xle1) > 1
def test_smoother():
xle = 'test/20160919_LittleHobble.xle'
df = wa.new_xle_imp(xle)
x = 'Level'
xle1 = wa.smoother(df, x, sd=1)
assert len(xle1) > 1
def test_hourly_resample():
xle = 'test/20160919_LittleHobble.xle'
df = wa.new_xle_imp(xle)
xle1 = wa.hourly_resample(df, minutes=30)
# Basic Function Tests
def testvars():
var_list = m.variables()
def testmetadata():
stations = m.metadata(radius=['wbb', 5])
def test_WQP():
wqq = wa.WQP('16010204','huc')
wqq.results = wqq.massage_results()
pivchem = wqq.piv_chem()
assert 'Alk' in pivchem.columns
def test_WQ2():
wqq = wa.WQP('16010204','huc')
wqq.stations = wqq.massage_stations()
df = wqq.stations
assert "OrgId" in list(df.columns)
#def test_imp_new_well():
# inputfile = "test/ag13c 2016-08-02.xle"
# manualwls = "test/All tape measurements.csv"
# manual = pd.read_csv(manualwls, index_col="DateTime", engine="python")
# barofile = "test/baro.csv"
# baro = pd.read_csv(barofile,index_col=0, parse_dates=True)
# wellinfo = pd.read_csv("test/wellinfo4.csv")
# g, drift, wellname = wa.fix_well(wellinfo,inputfile, manual, baro)
# assert wellname == 'ag13c'
def test_well_baro_merge():
xle = "test/ag13c 2016-08-02.xle"
xle_df = wa.new_xle_imp(xle)
barofile = "test/baro.csv"
baro = pd.read_csv(barofile,index_col=0, parse_dates=True)
baro['Level'] = baro['pw03']
assert len(wa.well_baro_merge(xle_df, baro, sampint=60)) > 10
#def test_fix_drift():
# xle = "test/ag13c 2016-08-02.xle"
# xle_df = wa.new_xle_imp(xle)
# manualwls = "test/All tape measurements.csv"
# manual = pd.read_csv(manualwls, index_col="DateTime", engine="python")
# manual35 = manual[manual['WellID']==35]
# manual35['dt'] = pd.to_datetime(manual35.index)
# manual_35 = manual35.reset_index()
# manual_35.set_index('dt',inplace=True)
# fd = wa.fix_drift(xle_df, manual_35, meas='Level', corrwl='Level',
# manmeas='MeasuredDTW', outcolname='DriftCorrection')
# assert 'DriftCorrection' in list(fd[0].columns)
def test_getwellid():
inputfile = "test/ag13c 2016-08-02.xle"
wellinfo = pd.read_csv("test/wellinfo4.csv")
wid = wa.getwellid(inputfile, wellinfo)
assert wid[1] == 35
def test_barodistance():
wellinfo = pd.read_csv("test/wellinfo4.csv")
bd = wa.barodistance(wellinfo)
assert 'closest_baro' in list(bd.columns)
#def test_imp_new_well_csv():
# inputfile = "test/ag14a 2016-08-02.csv"
# manualwls = "test/All tape measurements.csv"
# manual = pd.read_csv(manualwls, index_col="DateTime", engine="python")
# barofile = "test/baro.csv"
# baro = pd.read_csv(barofile,index_col=0, parse_dates=True)
# wellinfo = pd.read_csv("test/wellinfo4.csv")
# g, drift, wellname = wa.imp_new_well(inputfile, wellinfo, manual, baro)
# assert wellname == 'ag14a'
def test_jumpfix():
xle = "test/ag13c 2016-08-02.xle"
df = wa.new_xle_imp(xle)
jf = wa.jumpfix(df, 'Level', threashold=0.005)
assert jf['newVal'][-1] > 10
def test_gantt():
ashley = wa.nwis('dv', '09265500', 'sites')
gn = wa.gantt(ashley.data, stations=['value'])
assert type(gn.gantt()[2]) == matplotlib.figure.Figure
#def test_scatterColor():
# x = np.arange(1, 100, 1)
# y = np.arange(0.1, 10.0, 0.1)
# w = np.arange(5, 500, 5)
# out = wa.scatterColor(x, y, w)
# assert round(out[0], 1) == 0.1
def test_get_info():
nw = wa.nwis('gwlevels', '16010204', 'huc', siteStatus='all')
df = nw.get_info(siteStatus='all')
assert 'site_no' in list(df.columns)
#def test_recess():
# ashley = wa.nwis('dv', '09265500', 'sites', startDT='2015-06-02', endDT='2015-06-14')
# rec = wa.graphs.recess(ashley.data, 'value', st=[2015, 6, 2])
# assert round(rec.rec_results[0], 2) == 0.04
#def test_get_recess_int():
# ashley = wa.nwis('dv', '09265500','sites', startDT='2015-01-02' ,endDT='2015-10-14')
# assert type(wa.get_recess_int(ashley.data, 'value')[0]) == pd.DataFrame
def test_mk_ts():
usgsP = pd.read_csv('test/usgsP.csv')
var = wa.MannKendall.mk_ts(usgsP, 'PO4', 'month', 'year',0.05)
assert var[0] == -87.0