Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace deprecated time.clock() in tests #245

Merged
merged 1 commit into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions test/test_awips221.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import array
import time

try:
from time import perf_counter
except ImportError:
from time import clock as perf_counter

import numpy
from numpy.testing import assert_allclose
Expand Down Expand Up @@ -59,11 +63,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 = perf_counter()
lons, lats = awips221(
numpy.ravel(x).tolist(), numpy.ravel(y).tolist(), inverse=True
)
t2 = time.clock()
t2 = 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 +77,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 = perf_counter()
lons, lats = awips221(xa, ya, inverse=True)
t2 = time.clock()
t2 = 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 = perf_counter()
lons, lats = awips221(x, y, inverse=True)
t2 = time.clock()
t2 = 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 +102,9 @@ def test_awips221():
)
print("took", t2 - t1, "secs")
# reverse transformation.
t1 = time.clock()
t1 = perf_counter()
xx, yy = awips221(lons, lats)
t2 = time.clock()
t2 = 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
14 changes: 9 additions & 5 deletions test/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import pickle
import shutil
import tempfile
import time
from contextlib import contextmanager

try:
from time import perf_counter
except ImportError:
from time import clock as perf_counter

import numpy
from numpy.testing import assert_allclose

Expand Down Expand Up @@ -45,9 +49,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 = perf_counter()
lons, lats = awips221(x, y, inverse=True)
t2 = time.clock()
t2 = 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 +63,9 @@ def test_pickle():
)
print("took", t2 - t1, "secs")
# reverse transformation.
t1 = time.clock()
t1 = perf_counter()
xx, yy = awips221(lons, lats)
t2 = time.clock()
t2 = 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