def test_from_spot_attributes_must_have_aligned_dimensions_spot_attributes_and_data( ): """ Number of features must match number of SpotAttributes. Pass two attributes and 3 features and verify a ValueError is raised. """ spot_attributes = spot_attribute_factory(2) data = np.zeros(30).reshape(3, 5, 2) with pytest.raises(ValueError): IntensityTable.from_spot_data(data, spot_attributes)
def intensity_table_factory() -> IntensityTable: """IntensityTable with a single feature that was measured over 2 channels and 2 rounds.""" intensities = np.array([[[0, 3], [4, 0]]], dtype=float) spot_attribute_data = pd.DataFrame( data=[0, 0, 0, 1], index=[Axes.ZPLANE, Axes.Y, Axes.X, Features.SPOT_RADIUS]).T spot_attributes = SpotAttributes(spot_attribute_data) intensity_table = IntensityTable.from_spot_data(intensities, spot_attributes) return intensity_table
def test_intensity_table_can_be_constructed_from_a_numpy_array_and_spot_attributes( ): """ Verify that the IntensityTable can be created and that the resulting data matches the array it was constructed from. """ spot_attributes = spot_attribute_factory(3) data = np.zeros(30).reshape(3, 5, 2) intensities = IntensityTable.from_spot_data(data, spot_attributes) assert intensities.shape == data.shape assert np.array_equal(intensities.values, data)
def intensity_table_factory(data: np.ndarray=np.array([[[0, 3], [4, 0]]])) -> IntensityTable: """IntensityTable with a single feature that was measured over 2 channels and 2 rounds.""" # generates spot attributes equal in size to the number of passed features. # each attribute has coordinates (z, y, x) equal to the feature index, and radius 1. spot_attributes_data = pd.DataFrame( data=np.array([[i, i, i, 1] for i in np.arange(data.shape[0])]), columns=[Axes.ZPLANE, Axes.Y, Axes.X, Features.SPOT_RADIUS] ) spot_attributes = SpotAttributes(spot_attributes_data) intensity_table = IntensityTable.from_spot_data(data, spot_attributes) return intensity_table