예제 #1
0
파일: _parser.py 프로젝트: nklick/starfish
    def coordinates(self) -> Mapping[Coordinates, ArrayLike[Number]]:
        xrange = self._wrapped_tile.coordinates[Coordinates.X]
        yrange = self._wrapped_tile.coordinates[Coordinates.Y]
        return_coords = {
            Coordinates.X: np.linspace(xrange[0], xrange[1], self.tile_shape[Axes.X]),
            Coordinates.Y: np.linspace(yrange[0], yrange[1], self.tile_shape[Axes.Y]),
        }

        if Coordinates.Z in self._wrapped_tile.coordinates:
            zrange = self._wrapped_tile.coordinates[Coordinates.Z]
            zplane_coord = _get_physical_coordinates_of_z_plane(zrange)
            return_coords[Coordinates.Z] = [zplane_coord]

        return return_coords
예제 #2
0
def imagestack_with_coords_factory(stack_shape: OrderedDict,
                                   coords: OrderedDict) -> ImageStack:
    """
    Create an ImageStack of given shape and assigns the given x,y,z
    min/max physical coordinates to each tile.

    Parameters
    ----------
    stack_shape: OrderedDict
        Dict[Axes, int] defining the size of each dimension for an ImageStack

    coords: OrderedDict
        Dict[PhysicalCoordinateTypes, float] defining the min/max values of physical
        coordinates to assign to the Imagestack
    """

    stack = synthetic_stack(
        num_round=stack_shape[Axes.ROUND],
        num_ch=stack_shape[Axes.CH],
        num_z=stack_shape[Axes.ZPLANE],
        tile_height=stack_shape[Axes.Y],
        tile_width=stack_shape[Axes.X],
    )

    stack.xarray[Coordinates.X.value] = xr.DataArray(np.linspace(
        coords[PhysicalCoordinateTypes.X_MIN],
        coords[PhysicalCoordinateTypes.X_MAX],
        stack.xarray.sizes[Axes.X.value]),
                                                     dims=Axes.X.value)

    stack.xarray[Coordinates.Y.value] = xr.DataArray(np.linspace(
        coords[PhysicalCoordinateTypes.Y_MIN],
        coords[PhysicalCoordinateTypes.Y_MAX],
        stack.xarray.sizes[Axes.Y.value]),
                                                     dims=Axes.Y.value)

    z_coord = _get_physical_coordinates_of_z_plane(
        (coords[PhysicalCoordinateTypes.Z_MIN],
         coords[PhysicalCoordinateTypes.Z_MAX]))

    stack.xarray[Coordinates.Z.value] = xr.DataArray(np.zeros(
        stack.xarray.sizes[Axes.ZPLANE.value]),
                                                     dims=Axes.ZPLANE.value)

    for z in stack.axis_labels(Axes.ZPLANE):
        stack.xarray[Coordinates.Z.value].loc[z] = z_coord

    return stack
예제 #3
0
    def coordinates(self) -> Mapping[Coordinates, ArrayLike[Number]]:
        return_coords: MutableMapping[Coordinates, ArrayLike[Number]] = dict()
        for axis, coord in ((Axes.X, Coordinates.X), (Axes.Y, Coordinates.Y)):
            coordinate_range = self._tile.coordinates[coord]
            if not isinstance(coordinate_range, tuple):
                raise ValueError("x-y coordinates for a tile must be a range expressed as a tuple.")
            return_coords[coord] = np.linspace(
                coordinate_range[0], coordinate_range[1], self.tile_shape[axis])

        if Coordinates.Z in self._tile.coordinates:
            zrange = self._tile.coordinates[Coordinates.Z]
            if isinstance(zrange, tuple):
                zplane_coord = _get_physical_coordinates_of_z_plane(zrange)
                return_coords[Coordinates.Z] = [zplane_coord]
            else:
                return_coords[Coordinates.Z] = zrange

        return return_coords