Unwrap to sphere#

from skimage import io, data
import numpy as np
import os
import vedo
import pandas as pd

import napari_segment_blobs_and_things_with_membranes as nsbatwm
import napari_process_points_and_surfaces as nppas
from napari_shape_odyssey import unwrapping
from skimage.data import download_all
import napari

from scipy.spatial import Delaunay

from napari_stress import measurements
from scipy.interpolate import RegularGridInterpolator as rgi
import pyclesperanto_prototype as cle
viewer = napari.Viewer()
Invalid schema for package 'napari-stl-exporter', please run 'npe2 validate napari-stl-exporter' to check for manifest errors.
WARNING: QWindowsWindow::setGeometry: Unable to set geometry 6880x2754+1280+560 (frame: 6906x2825+1267+502) on QWidgetWindow/"_QtMainWindowClassWindow" on "\\.\DISPLAY1". Resulting geometry: 3844x2119+1280+560 (frame: 3870x2190+1267+502) margins: 13, 58, 13, 13 minimum size: 385x499 MINMAXINFO maxSize=0,0 maxpos=0,0 mintrack=796,1069 maxtrack=0,0)
image = data.cells3d()
nuclei = image[:, 1]
membrane = image[:, 0]

viewer.add_image(membrane, name="membrane")
viewer.add_image(nuclei, name="nuclei")
<Image layer 'nuclei' at 0x1a8a20285e0>
segmentation = nsbatwm.voronoi_otsu_labeling(nuclei, 10, 2)
surface = nppas.label_to_surface(segmentation, 23)
surface_filled = nppas.fill_holes_in_surface(surface)
surface_smoothed = nppas.smooth_surface(surface_filled)
surface_intensity = measurements.measure_intensity_on_surface(surface_smoothed, nuclei, measurement_range=2)
surface_intensity_mean = surface_intensity.mean(axis=1)

surface_intensity = (surface_smoothed[0], surface_smoothed[1], surface_intensity_mean.values)
sphere_intensity = unwrapping.map_surface_to_sphere(surface_intensity)
unwrapping.mercator_projection(sphere_intensity)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[5], line 2
      1 sphere_intensity = unwrapping.map_surface_to_sphere(surface_intensity)
----> 2 unwrapping.mercator_projection(sphere_intensity)

File ~\Documents\BiAPoL\Projects\napari-shape-odyssey\src\napari_shape_odyssey\_unwrapping\projections.py:37, in mercator_projection(surface, width, height)
     35 for i in range(len(x_projected)):
     36     x = int((x_projected[i] / (2 * np.pi)) * width)
---> 37     y = int((y_projected[i] / np.pi) * height)
     38     if x >= 0 and x < width and y >= 0 and y < height:
     39         image_map[y, x] = values[i]

ValueError: cannot convert float NaN to integer
layer_surf = viewer.add_surface(
    sphere_intensity,
    colormap='inferno', opacity=0.5, name='surface')
layer_surf.wireframe.visible = True