melonora / napari-cell-gater

A napari plugin for cell marker gating.
BSD 3-Clause "New" or "Revised" License
4 stars 1 forks source link

ScatterWidget not showing up #18

Closed sfritzs closed 7 months ago

sfritzs commented 7 months ago

Getting this error upon clicking Validate Not sure, @josenimo will fix it he says

(napari-env) C:\Users\coscia-lab\Desktop\napari-cell-gater>napari
INFO: Loaded 35 regionprops csvs.
INFO: 35 paths of images loaded.
INFO: 35 paths of masks loaded.
INFO: Removed 5 out of list of 25.
07:26:56.44 | DEBUG | ScatterInputWidget initialized
07:26:56.44 | DEBUG | Model regionprops_df shape: (1045563, 41)
07:26:56.44 | DEBUG | Model regionprops_df columns: Index(['CellID', '750_bg', '647_bg', '555_bg', '488_bg', 'DAPI_bg',
       'Ecadherin', 'IDO', 'panCK', 'CD8', 'DAPI_1', 'CTLA4', 'CD4', 'CD3',
       'CD20', 'DAPI_2', 'TIM3', 'PDL1', 'CD68', 'KI67', 'DAPI_3', 'COL1A1',
       'PD1', 'FOXP3', 'CD163', 'DAPI_4', 'Vimentin', 'VISTA', 'LAG3', 'CD138',
       'DAPI_5', 'X_centroid', 'Y_centroid', 'Area', 'MajorAxisLength',
       'MinorAxisLength', 'Eccentricity', 'Solidity', 'Extent', 'Orientation',
       'sample_id'],
      dtype='object')
07:26:56.44 | INFO | Reading data for sample 1.
07:26:56.44 | DEBUG | Reading image from C:\Users\coscia-lab\Desktop\cylinter\tif\1.ome.tif.
07:26:56.44 | DEBUG | Reading mask from C:\Users\coscia-lab\Desktop\cylinter\mask\1.ome.tif.
07:26:57.12 | DEBUG | Plotting scatter plot for 1 and Ecadherin.
07:26:57.13 | DEBUG | The current gate is 0.0.
C:\Users\coscia-lab\AppData\Local\miniforge3\envs\napari-env\lib\site-packages\matplotlib\widgets.py:317: RuntimeWarning: divide by zero encountered in scalar divide!
---------------------------------------------------------------------------
OverflowError                             Traceback (most recent call last)
File ~\Desktop\napari-cell-gater\src\cell_gater\widgets\sample_widget.py:266, in SampleWidget._validate(self=<cell_gater.widgets.sample_widget.SampleWidget object>)
    262             del self.model.markers[marker]
    264 napari_notification(f"Removed {n_markers - len(self.model.markers)} out of list of {n_markers}.")
--> 266 self._scatter_widget = ScatterInputWidget(self.model, self.viewer)
        self._scatter_widget = None
        self = <cell_gater.widgets.sample_widget.SampleWidget object at 0x00000271559E60E0>
        ScatterInputWidget = <class 'cell_gater.widgets.scatter_widget.ScatterInputWidget'>
    267 self.viewer.window.add_dock_widget(
    268     self._scatter_widget, name="cell_gater", area="right", menu=self._viewer.window.window_menu
    269 )
    271 self.model.validated = True

File ~\Desktop\napari-cell-gater\src\cell_gater\widgets\scatter_widget.py:122, in ScatterInputWidget.__init__(self=<cell_gater.widgets.scatter_widget.ScatterInputWidget object>, model=DataModel(events=<napari.utils.events.event.Emit...taFrame
Columns: []
Index: [], _current_gate=0.0), viewer=Viewer(camera=Camera(center=(0.0, 3254.0, 4223.0...ouse_drag_gen={}, _mouse_wheel_gen={}, keymap={}))
    120 self.slider_canvas = FigureCanvas(self.slider_figure)
    121 self.slider_ax = self.slider_figure.add_subplot(111)
--> 122 self.update_slider()
        self = <cell_gater.widgets.scatter_widget.ScatterInputWidget object at 0x000002715CC31FC0>
    123 self.layout().addWidget(self.slider_canvas, 4, 0, 1, 4)
    125 # plot points button

File ~\Desktop\napari-cell-gater\src\cell_gater\widgets\scatter_widget.py:250, in ScatterInputWidget.update_slider(self=<cell_gater.widgets.scatter_widget.ScatterInputWidget object>)
    248 min, max, init, step = self.get_min_max_median_step()
    249 self.slider_ax.clear()
--> 250 self.slider = Slider(self.slider_ax, "Gate", min, max, valinit=init, valstep=step, color="black")
        min = 0.0
        max = 777.4529914529915
        init = 42.556179775280896
        step = 0.0
        self = <cell_gater.widgets.scatter_widget.ScatterInputWidget object at 0x000002715CC31FC0>
        self.slider_ax = <Axes: >
    251 self.slider.on_changed(self.slider_changed)
    252 self.slider_canvas.draw()

File ~\AppData\Local\miniforge3\envs\napari-env\lib\site-packages\matplotlib\_api\deprecation.py:454, in make_keyword_only.<locals>.wrapper(*args=(<matplotlib.widgets.Slider object>, <Axes: >, 'Gate', 0.0, 777.4529914529915), **kwargs={'color': 'black', 'valinit': 42.556179775280896, 'valstep': 0.0})
    448 if len(args) > name_idx:
    449     warn_deprecated(
    450         since, message="Passing the %(name)s %(obj_type)s "
    451         "positionally is deprecated since Matplotlib %(since)s; the "
    452         "parameter will become keyword-only %(removal)s.",
    453         name=name, obj_type=f"parameter of {func.__name__}()")
--> 454 return func(*args, **kwargs)
        func = <function Slider.__init__ at 0x00000271504CB910>
        args = (<matplotlib.widgets.Slider object at 0x0000027100850730>, <Axes: >, 'Gate', 0.0, 777.4529914529915)
        kwargs = {'valinit': 42.556179775280896, 'valstep': 0.0, 'color': 'black'}

File ~\AppData\Local\miniforge3\envs\napari-env\lib\site-packages\matplotlib\widgets.py:451, in Slider.__init__(self=<matplotlib.widgets.Slider object>, ax=<Axes: >, label='Gate', valmin=0.0, valmax=777.4529914529915, valinit=42.556179775280896, valfmt=None, closedmin=True, closedmax=True, slidermin=None, slidermax=None, dragging=True, valstep=0.0, orientation='horizontal', initcolor='r', track_color='lightgrey', handle_style=None, **kwargs={'color': 'black'})
    449 self.slidermin = slidermin
    450 self.slidermax = slidermax
--> 451 valinit = self._value_in_bounds(valinit)
        valinit = 42.556179775280896
        self = <matplotlib.widgets.Slider object at 0x0000027100850730>
    452 if valinit is None:
    453     valinit = valmin

File ~\AppData\Local\miniforge3\envs\napari-env\lib\site-packages\matplotlib\widgets.py:517, in Slider._value_in_bounds(self=<matplotlib.widgets.Slider object>, val=42.556179775280896)
    515 def _value_in_bounds(self, val):
    516     """Makes sure *val* is with given bounds."""
--> 517     val = self._stepped_value(val)
        val = 42.556179775280896
        self = <matplotlib.widgets.Slider object at 0x0000027100850730>
    519     if val <= self.valmin:
    520         if not self.closedmin:

File ~\AppData\Local\miniforge3\envs\napari-env\lib\site-packages\matplotlib\widgets.py:317, in SliderBase._stepped_value(self=<matplotlib.widgets.Slider object>, val=42.556179775280896)
    314 """Return *val* coerced to closest number in the ``valstep`` grid."""
    315 if isinstance(self.valstep, Number):
    316     val = (self.valmin
--> 317            + round((val - self.valmin) / self.valstep) * self.valstep)
        val = 42.556179775280896
        self = <matplotlib.widgets.Slider object at 0x0000027100850730>
        self.valmin = 0.0
        self.valstep = 0.0
    318 elif self.valstep is not None:
    319     valstep = np.asanyarray(self.valstep)

OverflowError: cannot convert float infinity to integer
josenimo commented 7 months ago

fixed in https://github.com/melonora/napari-cell-gater/pull/17/commits/e6a988d76cfec9d9600e9bef80f97cf1371e4f96