neuron_morphology.snap_polygons.geometries module¶
-
class
neuron_morphology.snap_polygons.geometries.Geometries[source]¶ Bases:
objectAttributes: - close_bounds
Methods
rasterize(self, box, NoneType] = None, …)Rasterize one or more owned geometries. register_polygon(self, name, path, …)Adds a named polygon path to this object. register_polygons(self, polygons, Union[str, …)utility for registering multiple polygons. register_surface(self, name, path, …)Adds a line (e.g. register_surfaces(self, surfaces, Union[str, …)utility for registering multiple surfaces. to_json(self)Write contained polygons to a json-serializable format transform(self, transform, float], …)Apply a transform to each owned geometry. -
close_bounds¶
-
rasterize(self, box: Union[neuron_morphology.snap_polygons.bounding_box.BoundingBox, NoneType] = None, polygons: Union[Sequence[str], bool] = True, surfaces: Union[Sequence[str], bool] = False) → Dict[str, numpy.ndarray][source]¶ Rasterize one or more owned geometries. Produce a mapping from object names to masks.
Parameters: - shape : if provided, the output image shape. Otherwise, use the rounded close bounding box shape
- polygons : a list of names. Alternatively all (True) or none (False)
- lines : a list of names. Alternatively all (True) or none (False)
Notes
uses rasterio.features.rasterize
-
register_polygon(self, name: str, path: Union[str, Sequence[Sequence[float]], shapely.geometry.polygon.Polygon, shapely.geometry.polygon.LinearRing])[source]¶ Adds a named polygon path to this object. Updates the close bounding box.
Parameters: - name : identifier for this polygon
- path : defines the exterior of this (simple) polygon
-
register_polygons(self, polygons: Union[Dict[str, Union[str, Sequence[Sequence[float]], shapely.geometry.polygon.Polygon, shapely.geometry.polygon.LinearRing]], Sequence[Dict[str, Union[str, Sequence[Sequence[float]], shapely.geometry.polygon.Polygon, shapely.geometry.polygon.LinearRing]]]])[source]¶ utility for registering multiple polygons. See register_polygon
-
register_surface(self, name: str, path: Union[str, Sequence[Sequence[float]], shapely.geometry.linestring.LineString])[source]¶ Adds a line (e.g. the pia/wm surfaces) to this object. Updates the bounding box.
Parameters: - name : identifier for this surface
- path : defines the surface
-
neuron_morphology.snap_polygons.geometries.clear_overlaps(stack: Dict[str, numpy.ndarray])[source]¶ Given a stack of masks, remove all inter-mask overlaps inplace
Parameters: - stack : Keys are names, values are masks (of the same shape). 0 indicates
absence
-
neuron_morphology.snap_polygons.geometries.closest_from_stack(stack: Dict[str, numpy.ndarray])[source]¶ Given a stack of images describing distance from several objects, find the closest object to each pixel.
Parameters: - stack : Keys are names, values are ndarrays (of the same shape). Each pixel
in the values describes the distance from that pixel to the named object
Returns: - closest : An integer array whose values are the closest object to each
pixel
- names : A mapping from the integer codes in the “closest” array to names
-
neuron_morphology.snap_polygons.geometries.find_vertical_surfaces(polygons: Dict[str, shapely.geometry.polygon.Polygon], order: Sequence[str], pia: Union[shapely.geometry.linestring.LineString, NoneType] = None, wm: Union[shapely.geometry.linestring.LineString, NoneType] = None)[source]¶ Given a set of polygons describing cortical layer boundaries, find the boundaries between each layer.
Parameters: - polygons : named layer polygons
- order : A sequence of names defining the order of the layer polygons from
pia to white matter
- pia : The upper pia surface.
- wm : The lower white matter surface.
Returns: - dictionary whose keys are as “{name}_{side}” and whose values are
linestrings describing these boundaries.
-
neuron_morphology.snap_polygons.geometries.get_snapped_polys(closest: numpy.ndarray, name_lut: Dict[int, str]) → Dict[str, shapely.geometry.polygon.Polygon][source]¶ Obtains named shapes from a label image.
Parameters: - closest : label integer with integer codes
- name_lut : look up table from integer codes to string names
Returns: - mapping from names to polygons describing each labelled region
-
neuron_morphology.snap_polygons.geometries.make_scale(scale: float = 1.0) → Callable[[float, float], Tuple[float, float]][source]¶ A utility for making a 2D scale transform, suitable for transforming bounding boxes and Geometries
Parameters: - scale : isometric scale factor
Returns: - A transform function
-
neuron_morphology.snap_polygons.geometries.rasterize(geometry: shapely.geometry.base.BaseGeometry, box: neuron_morphology.snap_polygons.bounding_box.BoundingBox) → <built-in function array>[source]¶ Rasterize a shapely object to a grid defined by a provided bounding box.
Parameters: - geometry : to be rasterized
- box : defines the window (in the same coordinate space as the geometry)
into which the geometry will be rasterized
Returns: - A mask, where 1 indicates presence and 0 absence