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

Fix imagehash hex_to_hash #2989

Merged
merged 7 commits into from
Apr 30, 2018
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
16 changes: 8 additions & 8 deletions lib/iris/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) British Crown Copyright 2010 - 2017, Met Office
# (C) British Crown Copyright 2010 - 2018, Met Office
#
# This file is part of Iris.
#
Expand Down Expand Up @@ -552,7 +552,6 @@ def assertWarnsRegexp(self, expected_regexp=''):
msg = msg.format(expected_regexp)
self.assertTrue(matches, msg)


@contextlib.contextmanager
def assertNoWarningsRegexp(self, expected_regexp=''):
# Check that no warning matching the given expression is raised.
Expand Down Expand Up @@ -782,7 +781,7 @@ def check_graphic(self):
def _create_missing():
fname = '{}.png'.format(phash)
base_uri = ('https://scitools.github.io/test-iris-imagehash/'
'images/{}')
'images/v4/{}')
uri = base_uri.format(fname)
hash_fname = os.path.join(image_output_directory, fname)
uris = repo.setdefault(unique_id, [])
Expand Down Expand Up @@ -817,13 +816,14 @@ def _create_missing():
raise AssertionError(emsg.format(unique_id))
else:
uris = repo[unique_id]
# Extract the hex basename strings from the uris.
hexes = [os.path.splitext(os.path.basename(uri))[0]
for uri in uris]
# Create the expected perceptual image hashes from the uris.
to_hash = imagehash.hex_to_hash
expected = [to_hash(os.path.splitext(os.path.basename(uri))[0],
hash_size=_HASH_SIZE)
for uri in uris]
expected = [to_hash(uri_hex) for uri_hex in hexes]

# Calculate the hamming distance vector for the result hash.
# Calculate hamming distance vector for the result hash.
distances = [e - phash for e in expected]

if np.all([hd > _HAMMING_DISTANCE for hd in distances]):
Expand Down Expand Up @@ -1104,7 +1104,7 @@ def assertGribMessageDifference(self, filename1, filename2, diffs,
# for each message.
self.assertEqual(m1_value, diffs[key][0],
msg=msg.format(key, m1_value,
diffs[key][0]))
diffs[key][0]))

self.assertEqual(m2_value, diffs[key][1],
msg=msg.format(key, m2_value,
Expand Down
16 changes: 9 additions & 7 deletions lib/iris/tests/idiff.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# (C) British Crown Copyright 2010 - 2017, Met Office
# (C) British Crown Copyright 2010 - 2018, Met Office
#
# This file is part of Iris.
#
Expand Down Expand Up @@ -83,7 +83,7 @@ def diff_viewer(repo, key, repo_fname, phash, status,

result_dir = os.path.dirname(result_fname)
fname = '{}.png'.format(phash)
base_uri = 'https://scitools.github.io/test-iris-imagehash/images/{}'
base_uri = 'https://scitools.github.io/test-iris-imagehash/images/v4/{}'
uri = base_uri.format(fname)
phash_fname = os.path.join(result_dir, fname)

Expand Down Expand Up @@ -139,24 +139,26 @@ def skip(event):


def _calculate_hit(uris, phash, action):
# Extract the hex basename strings from the uris.
hexes = [os.path.splitext(os.path.basename(uri))[0] for uri in uris]
# Create the expected perceptual image hashes from the uris.
to_hash = imagehash.hex_to_hash
expected = [to_hash(os.path.splitext(os.path.basename(uri))[0],
hash_size=iris.tests._HASH_SIZE)
for uri in uris]
expected = [to_hash(uri_hex) for uri_hex in hexes]
# Calculate the hamming distance vector for the result hash.
distances = [e - phash for e in expected]

if action == 'first':
index = 0
elif action == 'last':
index = -1
elif action == 'similar':
index = np.argmin(distances)
elif action == 'difference':
elif action == 'different':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😕. What's happening here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index = np.argmax(distances)
else:
emsg = 'Unknown action: {!r}'
raise ValueError(emsg.format(action))

return index, distances[index]


Expand Down Expand Up @@ -230,7 +232,7 @@ def step_over_diffs(result_dir, action, display=True):
os.path.basename(uri))
if not os.path.isfile(local_fname):
emsg = 'Bad URI {!r} for test {!r}.'
raise ValueError(uri, key)
raise ValueError(emsg.format(uri, key))
else:
# The temporary expected filename has the test name
# baked into it, and is used in the diff plot title.
Expand Down
Loading