Skip to content

Commit

Permalink
replace deprecated time.clock() in tests
Browse files Browse the repository at this point in the history
Fix warnings and prepare for Python 3.8.
  • Loading branch information
cjmayo committed Apr 6, 2019
1 parent 02fe960 commit f5d108c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions test/test_awips221.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ def test_awips221():
dy = (urcrnry - llcrnry) / (ny - 1)
x = llcrnrx + dx * numpy.indices((ny, nx), "f")[1, :, :]
y = llcrnry + dy * numpy.indices((ny, nx), "f")[0, :, :]
t1 = time.clock()
t1 = time.perf_counter()
lons, lats = awips221(
numpy.ravel(x).tolist(), numpy.ravel(y).tolist(), inverse=True
)
t2 = time.clock()
t2 = time.perf_counter()
print("data in lists:")
print("compute lats/lons for all points on AWIPS 221 grid (%sx%s)" % (nx, ny))
print("max/min lons")
Expand All @@ -73,19 +73,19 @@ def test_awips221():
print("took", t2 - t1, "secs")
xa = array.array("f", numpy.ravel(x).tolist())
ya = array.array("f", numpy.ravel(y).tolist())
t1 = time.clock()
t1 = time.perf_counter()
lons, lats = awips221(xa, ya, inverse=True)
t2 = time.clock()
t2 = time.perf_counter()
print("data in python arrays:")
print("compute lats/lons for all points on AWIPS 221 grid (%sx%s)" % (nx, ny))
print("max/min lons")
print(min(lons), max(lons))
print("max/min lats")
print(min(lats), max(lats))
print("took", t2 - t1, "secs")
t1 = time.clock()
t1 = time.perf_counter()
lons, lats = awips221(x, y, inverse=True)
t2 = time.clock()
t2 = time.perf_counter()
print("data in a numpy array:")
print("compute lats/lons for all points on AWIPS 221 grid (%sx%s)" % (nx, ny))
print("max/min lons")
Expand All @@ -98,9 +98,9 @@ def test_awips221():
)
print("took", t2 - t1, "secs")
# reverse transformation.
t1 = time.clock()
t1 = time.perf_counter()
xx, yy = awips221(lons, lats)
t2 = time.clock()
t2 = time.perf_counter()
print("max abs error for x")
max_abs_err_x = numpy.maximum.reduce(numpy.fabs(numpy.ravel(x - xx)))
print(max_abs_err_x)
Expand Down
8 changes: 4 additions & 4 deletions test/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def test_pickle():
pickle.dump(awips221_pre_pickle, pfh, -1)
with open(os.path.join(tmpdir, "test.pickle"), "rb") as prh:
awips221 = pickle.load(prh)
t1 = time.clock()
t1 = time.perf_counter()
lons, lats = awips221(x, y, inverse=True)
t2 = time.clock()
t2 = time.perf_counter()
print("compute lats/lons for all points on AWIPS 221 grid (%sx%s)" % (nx, ny))
print("max/min lons in radians")
print(
Expand All @@ -59,9 +59,9 @@ def test_pickle():
)
print("took", t2 - t1, "secs")
# reverse transformation.
t1 = time.clock()
t1 = time.perf_counter()
xx, yy = awips221(lons, lats)
t2 = time.clock()
t2 = time.perf_counter()
print("max abs error for x")
max_abs_err_x = numpy.maximum.reduce(numpy.fabs(numpy.ravel(x - xx)))
print(max_abs_err_x)
Expand Down

0 comments on commit f5d108c

Please sign in to comment.