def test_sum(self): """ Test sum """ b = io.StringIO(EXAMPLE_FILE) buf = io.BytesIO() im = PILIm.fromarray(np.loadtxt(b).astype(np.uint32)) im.save(buf, format="png") buf.seek(0) test_image = Image(buf) assert_equal(isinstance(test_image.sum().n, float), True) assert_equal(isinstance(test_image.sum().s, float), True)
def test_background_subtraction(self): """ Test background_subtraction """ b = io.StringIO(EXAMPLE_FILE) buf = io.BytesIO() im = PILIm.fromarray(np.loadtxt(b).astype(np.uint32)) im.save(buf, format="png") buf.seek(0) test_image = Image(buf) test_image.background_subtraction(background.fit_gaussian_2d) assert_equal((10, 10), test_image.shape)
def test_crop(self): """ Test crop """ b = io.StringIO(EXAMPLE_FILE) buf = io.BytesIO() im = PILIm.fromarray(np.loadtxt(b).astype(np.uint32)) im.save(buf, format="png") buf.seek(0) test_image = Image(buf) test_image.crop(cropping.crop_around_peak_2d, x_size=2, y_size=2) assert_equal((2, 2), test_image.shape)
def test_str(self): """ Test str """ b = io.StringIO(EXAMPLE_FILE) buf = io.BytesIO() im = PILIm.fromarray(np.loadtxt(b).astype(np.uint32)) im.save(buf, format="png") buf.seek(0) test_image = Image(buf) data = io.StringIO(EXAMPLE_FILE) load = np.loadtxt(data) expected_image_e = np.sqrt(load) expected_image_e[np.where(load == 0)] = 1 assert_almost_equal(load, unp.nominal_values(test_image.__str__())) assert_almost_equal(expected_image_e, unp.std_devs(test_image.__str__()))
def test_hot_pixel(self): """ Test file reading """ b = io.StringIO(EXAMPLE_HOT_PIXEL) buf = io.BytesIO() im = PILIm.fromarray(np.loadtxt(b).astype(np.uint32)) im.save(buf, format="png") buf.seek(0) test_image = Image(buf, hot_pixel_max=4e4) assert_equal((10, 10), test_image.shape) assert_almost_equal(2, test_image.n[2, 2])
def test_init(self): """ Test file reading """ b = io.StringIO(EXAMPLE_FILE) buf = io.BytesIO() im = PILIm.fromarray(np.loadtxt(b).astype(np.uint32)) im.save(buf, format="png") buf.seek(0) test_image = Image(buf) data = io.StringIO(EXAMPLE_FILE) expected_image = np.loadtxt(data) assert_equal((10, 10), test_image.shape) assert_almost_equal(expected_image, test_image.n)
def test_init_with_transpose(self): """ Test for transposing with reading """ b = io.StringIO(EXAMPLE_FILE) buf = io.BytesIO() im = PILIm.fromarray(np.loadtxt(b).astype(np.uint32)) im.save(buf, format="png") buf.seek(0) test_image = Image(buf, transpose=True) data = io.StringIO(EXAMPLE_FILE) expected_image = np.loadtxt(data, unpack=True) assert_equal((10, 10), test_image.shape) assert_almost_equal(expected_image, test_image.n)
def test_std_devs(self): """ Test standard devs """ b = io.StringIO(EXAMPLE_FILE) buf = io.BytesIO() im = PILIm.fromarray(np.loadtxt(b).astype(np.uint32)) im.save(buf, format="png") buf.seek(0) test_image = Image(buf) data = io.StringIO(EXAMPLE_FILE) load = np.loadtxt(data) expected_image = np.sqrt(load) expected_image[np.where(load == 0)] = 1 assert_equal((10, 10), test_image.shape) assert_almost_equal(expected_image, test_image.std_devs) assert_almost_equal(expected_image, test_image.s)