def test_save_sprite(): """This test covers _save_sprite as well as _bytesIO_to_base64 """ # Generate a simulated volume with a square inside data = np.random.RandomState(0).uniform(size=140).reshape(7, 5, 4) mask = np.zeros((7, 5, 4), dtype=int) mask[1:-1, 1:-1, 1:-1] = 1 # Save the sprite using BytesIO sprite_io = BytesIO() html_stat_map._save_sprite(data, sprite_io, vmin=0, vmax=1, mask=mask, format='png') # Load the sprite back in base64 sprite_base64 = html_stat_map._bytesIO_to_base64(sprite_io) decoded_io = BytesIO() decoded_io.write(base64.b64decode(sprite_base64)) decoded_io.seek(0) img = plt.imread(decoded_io, format="png") correct_img = np.ma.array(html_stat_map._data_to_sprite(data), mask=html_stat_map._data_to_sprite(mask)) correct_img = plt.Normalize(0, 1)(correct_img) cmapped = plt.get_cmap("Greys")(correct_img) assert np.allclose(img, cmapped, atol=.1)
def test_save_sprite(): """This test covers _save_sprite as well as _bytesIO_to_base64 """ # Generate a simulated volume with a square inside data = np.zeros([2, 1, 1]) data[0, 0, 0] = 1 mask = data > 0 # Save the sprite using BytesIO sprite_io = BytesIO() html_stat_map._save_sprite(data, sprite_io, vmin=0, vmax=1, mask=mask, format='raw') # Load the sprite back in base64 sprite_base64 = html_stat_map._bytesIO_to_base64(sprite_io) # Check the sprite is correct assert sprite_base64 == '////AP////8=\n'