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
Adding testcases for visualization.image_writer #1842
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
""" | ||
Tests for visualization.image_writer | ||
""" | ||
# ----------------------------------------------------------------------------- | ||
# Copyright (c) 2018, yt Development Team. | ||
# | ||
# Distributed under the terms of the Modified BSD License. | ||
# | ||
# The full license is in the file COPYING.txt, distributed with this software. | ||
# ----------------------------------------------------------------------------- | ||
import os | ||
import shutil | ||
import tempfile | ||
import unittest | ||
|
||
import numpy as np | ||
from nose.tools import assert_raises | ||
|
||
from yt.testing import fake_random_ds, assert_equal | ||
from yt.visualization.image_writer import multi_image_composite, splat_points, \ | ||
write_bitmap, apply_colormap, strip_colormap_data | ||
|
||
|
||
class TestImageWriter(unittest.TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
cls.tmpdir = tempfile.mkdtemp() | ||
cls.curdir = os.getcwd() | ||
os.chdir(cls.tmpdir) | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
os.chdir(cls.curdir) | ||
shutil.rmtree(cls.tmpdir) | ||
|
||
def test_multi_image_composite(self): | ||
ds = fake_random_ds(64, nprocs=4, particles=16**3) | ||
center = [0.5, 0.5, 0.5] | ||
normal = [1, 1, 1] | ||
cut = ds.cutting(normal, center) | ||
frb = cut.to_frb((0.75, 'unitary'), 64) | ||
multi_image_composite("multi_channel1.png", frb["x"], frb["y"]) | ||
|
||
# Test multi_image_composite with user specified scaling values | ||
mi = ds.quan(0.1, 'code_length') | ||
ma = ds.quan(0.9, 'code_length') | ||
multi_image_composite("multi_channel2.png", (frb["x"], mi, ma), | ||
[frb["y"], mi, None], green_channel=frb["z"], | ||
alpha_channel=frb["density"]) | ||
|
||
# Test with numpy integer array | ||
x = np.array(np.random.randint(0, 256, size=(10, 10)), dtype='uint8') | ||
y = np.array(np.random.randint(0, 256, size=(10, 10)), dtype='uint8') | ||
multi_image_composite("multi_channel3.png", x, y) | ||
|
||
def test_write_bitmap(self): | ||
image = np.zeros([16, 16, 4], dtype='uint8') | ||
xs = np.random.rand(100) | ||
ys = np.random.rand(100) | ||
image = splat_points(image, xs, ys) | ||
png_str = write_bitmap(image.copy(), None) | ||
|
||
image_trans = image.swapaxes(0, 1).copy(order="C") | ||
png_str_trans = write_bitmap(image_trans, None, transpose=True) | ||
assert_equal(png_str, png_str_trans) | ||
|
||
with assert_raises(RuntimeError) as ex: | ||
write_bitmap(np.ones([16, 16]), None) | ||
desired = ("Expecting image array of shape (N,M,3) " | ||
"or (N,M,4), received (16, 16)") | ||
assert_equal(str(ex.exception)[:50], desired[:50]) | ||
|
||
def test_strip_colormap_data(self): | ||
strip_colormap_data("_stripped_cmap.py", ("arbre")) | ||
|
||
def test_apply_colormap(self): | ||
x = np.array(np.random.randint(0, 256, size=(10, 10)), dtype='uint8') | ||
apply_colormap(x, color_bounds=None, cmap_name=None, func=lambda x:x**2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you restore the logic that was originally here? We want the warning message about the unknown suffix I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_image_suffix(filename)
returns['.png', '.eps', '.ps', '.pdf', '']
thus, it will never execute the originalelse
block.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, fair enough