How to use the merlin.util.spatialfeature.HDF5SpatialFeatureDB function in merlin

To help you get started, we’ve selected a few merlin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github emanuega / MERlin / test / test_spatialfeature.py View on Github external
def test_feature_hdf5_db_read_write_delete_one_fov(
        single_task, simple_merfish_data):
    featureDB = spatialfeature.HDF5SpatialFeatureDB(
        simple_merfish_data, single_task)
    featureDB.write_features([feature1, feature2], fov=0)
    readFeatures = featureDB.read_features(fov=0)
    featureDB.empty_database(0)
    readFeatures2 = featureDB.read_features(fov=0)

    assert len(readFeatures) == 2
    if readFeatures[0].get_feature_id() == feature1.get_feature_id():
        f1Index = 0
        f2Index = 1
    else:
        f1Index = 1
        f2Index = 0
    assert readFeatures[f1Index].equals(feature1)
    assert readFeatures[f2Index].equals(feature2)
github emanuega / MERlin / test / test_spatialfeature.py View on Github external
def test_feature_hdf5_db_read_write_delete_multiple_fov(
        single_task, simple_merfish_data):
    tempFeature2 = spatialfeature.SpatialFeature(
        [[geometry.Polygon(testCoords2)]], 1)
    featureDB = spatialfeature.HDF5SpatialFeatureDB(
        simple_merfish_data, single_task)
    featureDB.write_features([feature1, tempFeature2])
    readFeatures = featureDB.read_features()
    readFeatures0 = featureDB.read_features(0)
    readFeatures1 = featureDB.read_features(1)
    featureMetadata = featureDB.read_feature_metadata()
    featureMetadata0 = featureDB.read_feature_metadata(0)
    featureMetadata1 = featureDB.read_feature_metadata(1)
    featureDB.empty_database()
    readFeaturesEmpty = featureDB.read_features()
    metaDataEmpty = featureDB.read_feature_metadata()

    assert len(readFeatures0) == 1
    assert len(featureMetadata0) == 1
    assert readFeatures0[0].equals(feature1)
    assert int(featureMetadata0.index[0]) == feature1.get_feature_id()
github emanuega / MERlin / merlin / analysis / segment.py View on Github external
def get_feature_database(self) -> spatialfeature.SpatialFeatureDB:
        """ Get the spatial feature database this analysis task saves
        features into.

        Returns: The spatial feature database reference.
        """
        return spatialfeature.HDF5SpatialFeatureDB(self.dataSet, self)
github emanuega / MERlin / merlin / analysis / segment.py View on Github external
def get_feature_database(self) -> spatialfeature.SpatialFeatureDB:
        """ Get the spatial feature database this analysis task saves
        features into.

        Returns: The spatial feature database reference.
        """
        return spatialfeature.HDF5SpatialFeatureDB(self.dataSet, self)
github emanuega / MERlin / merlin / util / spatialfeature.py View on Github external
def _load_feature_from_hdf5_group(h5Group):
        zCount = len([x for x in h5Group.keys() if x.startswith('zIndex_')])
        boundaryList = []
        for z in range(zCount):
            zBoundaryList = []
            zGroup = h5Group['zIndex_' + str(z)]
            pCount = len([x for x in zGroup.keys() if x[:2] == 'p_'])
            for p in range(pCount):
                zBoundaryList.append(
                    HDF5SpatialFeatureDB._load_geometry_from_hdf5_group(
                        zGroup['p_' + str(p)]))
            boundaryList.append(zBoundaryList)

        loadedFeature = SpatialFeature(
            boundaryList,
            h5Group.attrs['fov'],
            np.array(h5Group['z_coordinates']),
            int(h5Group.attrs['id']))

        return loadedFeature
github emanuega / MERlin / merlin / util / spatialfeature.py View on Github external
feature: SpatialFeature,
                                    fov: int) -> None:
        featureKey = str(feature.get_feature_id())
        featureGroup = h5Group.create_group(featureKey)
        featureGroup.attrs['id'] = np.string_(feature.get_feature_id())
        featureGroup.attrs['fov'] = fov
        featureGroup.attrs['bounding_box'] = \
            np.array(feature.get_bounding_box())
        featureGroup.attrs['volume'] = feature.get_volume()
        featureGroup['z_coordinates'] = feature.get_z_coordinates()

        for i, bSet in enumerate(feature.get_boundaries()):
            zBoundaryGroup = featureGroup.create_group('zIndex_' + str(i))
            for j, b in enumerate(bSet):
                geometryGroup = zBoundaryGroup.create_group('p_' + str(j))
                HDF5SpatialFeatureDB._save_geometry_to_hdf5_group(
                    geometryGroup, b)