Beispiel #1
0
    def test_expected_output(self):

        c = [
            [255, 255, 255],
            [255, 0, 0],
            [0, 255, 0],
            [0, 0, 255],
            [0, 255, 255],
            [255, 0, 255],
            [255, 255, 0],
            [0, 0, 0],
        ]
        parameters = [(array([[0, 1],
                              [0, 1]]), array([[c[0], c[1]], [c[0], c[1]]])),
                      (array([[0, 1, 6], [0, 1, 6], [0, 1, 6]]),
                       array([[c[0], c[1], c[6]], [c[0], c[1], c[6]],
                              [c[0], c[1], c[6]]])),
                      (
                          array(list(range(8)) * 8).reshape(8, 8),
                          array([c[x] for x in range(8)] * 8).reshape(8, 8, 3),
                      )]

        for arr_in, expected_arr_out in parameters:
            with self.subTest(arr_in=arr_in):
                arr_out = to_image(arr_in, size=arr_in.shape[0])
                self.assertTrue(array_equal(arr_out, expected_arr_out))
	def save_state(array, result, iteration):
		file_name = str(iteration).zfill(iter_order_of_magnitude + 1) + '.png'
		image_save(to_image(array), 
			os.path.join(save_directory, file_name))
		result.save_JSON(os.path.join(save_directory, 'result.json'))
		if verbose:
			click.echo(iteration)
			click.echo(result)
Beispiel #3
0
    def test_image_save_load(self):
        size = 10
        values = [randrange(0, 8) for _ in range(size**2)]
        name = 'tmp.png'

        arr = array(values).reshape((size, size))
        image_save(to_image(arr), name)
        parsed = image_parse(name, grid_size=10)

        os.remove(name)

        self.assertTrue(array_equal(arr, parsed))
Beispiel #4
0
def gui_callback(array, result, iteration):
	size = 600
	image = im.to_image(array, size=size)
	# name = str(iteration).zfill(8) + ".gif"
	# im.image_save(image, os.path.join(image_path, name))
	# app.setImage("simulation", name)
	# app.setScaleRange("pos", 0, iteration, curr=iteration)

	# # app.setScale("pos", iteration, callFunction=True)
	# print(iteration)
	
	pil_image = Image.fromarray(image)
	image_bytes = BytesIO()
	pil_image.save(image_bytes, format="gif")
	base64_image = base64.b64encode(image_bytes.getvalue())
	
	images.append(base64_image)
	simulation_result.append(str(result))
	
	app.setImageData("simulation", base64_image)
	app.setScaleRange("pos", 0, iteration, curr=iteration)
Beispiel #5
0
 def test_value_over_seven_error(self):
     arr = array([[0, 10], [0, 10]])
     with self.assertRaises(ValueError):
         to_image(arr)
Beispiel #6
0
 def test_eight_colors_supported_error(self):
     arr = array(list(range(10)) * 10).reshape((10, 10))
     with self.assertRaises(ValueError):
         to_image(arr)