def test_from_numpy_array_raises_error_when_incorrect_dims_passed(): array = np.ones((2, 2)) # verify this method works with the correct shape image = ImageStack.from_numpy_array(array.reshape((1, 1, 1, 2, 2))) assert isinstance(image, ImageStack) with pytest.raises(ValueError): ImageStack.from_numpy_array(array.reshape((1, 1, 2, 2))) ImageStack.from_numpy_array(array.reshape((1, 2, 2))) ImageStack.from_numpy_array(array) ImageStack.from_numpy_array(array.reshape((1, 1, 1, 1, 2, 2)))
def test_max_projection_preserves_dtype(): original_dtype = np.uint16 array = np.ones((2, 2, 2), dtype=original_dtype) image = ImageStack.from_numpy_array(array.reshape((1, 1, 2, 2, 2))) max_projection = image.max_proj(Indices.CH, Indices.HYB, Indices.Z) assert max_projection.dtype == original_dtype
def test_iss_pipeline(): np.random.seed(2) synthesizer = SyntheticData(n_spots=5) codebook = synthesizer.codebook() true_intensities = synthesizer.intensities(codebook=codebook) image = synthesizer.spots(intensities=true_intensities) dots_data = image.max_proj(Indices.HYB, Indices.CH, Indices.Z) dots = ImageStack.from_numpy_array( dots_data.reshape((1, 1, 1, *dots_data.shape))) wth = WhiteTophat(disk_size=15) wth.filter(image) wth.filter(dots) fsr = FourierShiftRegistration(upsampling=1000, reference_stack=dots) fsr.register(image) min_sigma = 1.5 max_sigma = 5 num_sigma = 10 threshold = 1e-4 gsd = GaussianSpotDetector( min_sigma=min_sigma, max_sigma=max_sigma, num_sigma=num_sigma, threshold=threshold, blobs_stack=dots, measurement_type='max', ) intensities = gsd.find(hybridization_image=image) assert intensities.shape[0] == 5 codebook.decode_euclidean(intensities)
def labeled_synthetic_dataset(): stp = synthesize.SyntheticSpotTileProvider() image = ImageStack.synthetic_stack(tile_data_provider=stp.tile) max_proj = image.max_proj(Indices.HYB, Indices.CH, Indices.Z) view = max_proj.reshape((1, 1, 1) + max_proj.shape) dots = ImageStack.from_numpy_array(view) def labeled_synthetic_dataset_factory(): return deepcopy(image), deepcopy(dots), deepcopy(stp.codebook) return labeled_synthetic_dataset_factory
def test_from_numpy_array_preserves_dtype(): original_dtype = np.uint16 array = np.ones((2, 2, 2), dtype=original_dtype) image = ImageStack.from_numpy_array(array.reshape((1, 1, 2, 2, 2))) assert image.numpy_array.dtype == original_dtype
def test_from_numpy_array_preserves_data(): array = np.random.random((1, 1, 1, 2, 2)) image_stack = ImageStack.from_numpy_array(array) assert np.array_equal(array, image_stack.numpy_array)
def synthetic_two_spot_imagestack_3d(synthetic_two_spot_3d): data = synthetic_two_spot_3d return ImageStack.from_numpy_array(data.reshape(1, 1, *data.shape))
def synthetic_single_spot_imagestack_2d(synthetic_single_spot_2d): data = synthetic_single_spot_2d return ImageStack.from_numpy_array(data.reshape(1, 1, 1, *data.shape))