Skip to content

Commit

Permalink
Merge pull request #38 from zoccoler/add_example_stack
Browse files Browse the repository at this point in the history
Add example stack
  • Loading branch information
zoccoler authored Aug 18, 2023
2 parents 3cd7f88 + c07b735 commit 07818c9
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 64 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ include README.md
recursive-exclude * __pycache__
recursive-exclude * *.py[co]
include src/napari_flim_phasor_plotter/data/*
include src/napari_flim_phasor_plotter/data/hazelnut_FLIM_z_stack/*
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = napari-flim-phasor-plotter
version = 0.0.4
version = 0.0.5
description = A plugin that performs phasor plot from TCSPC FLIM data.
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down
2 changes: 1 addition & 1 deletion src/napari_flim_phasor_plotter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.0.4"
__version__ = "0.0.5"

from ._reader import napari_get_reader
from ._sample_data import load_seminal_receptacle_image, load_hazelnut_image, load_hazelnut_z_stack, load_lifetime_cat_synthtetic_single_image
Expand Down
105 changes: 55 additions & 50 deletions src/napari_flim_phasor_plotter/_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,6 @@
import numpy as np


def add_phasor_circle(ax):
'''
Generate FLIM universal semi-circle plot
'''
import numpy as np
angles = np.linspace(0, np.pi, 180)
x = (np.cos(angles) + 1) / 2
y = np.sin(angles) / 2
ax.plot(x, y, 'yellow', alpha=0.3)
return ax


def add_tau_lines(ax, tau_list, frequency):
import numpy as np
if not isinstance(tau_list, list):
tau_list = [tau_list]
frequency = frequency * 1E6 # MHz to Hz
w = 2 * np.pi * frequency # Hz to radians/s
for tau in tau_list:
tau = tau * 1E-9 # nanoseconds to seconds
g = 1 / (1 + ((w * tau)**2))
s = (w * tau) / (1 + ((w * tau)**2))
dot, = ax.plot(g, s, marker='o', mfc='none')
array = np.linspace(0, g, 50)
y = (array * s / g)
ax.plot(array, y, color=dot.get_color())


def add_2d_histogram(ax, x, y):
import matplotlib.pyplot as plt
output = ax.hist2d(
x=x,
y=y,
bins=10,
cmap='jet',
norm='log',
alpha=0.5
)
return ax


class PhasorPlotterWidget(PlotterWidget):
def __init__(self, napari_viewer):
super().__init__(napari_viewer)
Expand All @@ -54,21 +13,67 @@ def run(self,
plot_x_axis_name,
plot_y_axis_name,
plot_cluster_name=None,
redraw_cluster_image=True,):
redraw_cluster_image=True,
):
super().run(features=features,
plot_x_axis_name=plot_x_axis_name,
plot_y_axis_name=plot_y_axis_name,
plot_cluster_name=plot_cluster_name,
redraw_cluster_image=redraw_cluster_image,)
add_phasor_circle(self.graphics_widget.axes)

self.redefine_axes_limits(ensure_full_semi_circle_displayed=False)


def redefine_axes_limits(self, ensure_full_semi_circle_displayed=True):
# Redefine axes limits
self.graphics_widget.axes.autoscale()
current_ylim = self.graphics_widget.axes.get_ylim()
current_xlim = self.graphics_widget.axes.get_xlim()
ylim_0 = np.amin([current_ylim[0] - 0.1 * current_ylim[0], -0.1])
ylim_1 = np.amax([current_ylim[1] + 0.1 * current_ylim[1], 0.7])
xlim_0 = np.amin([current_xlim[0] - 0.1 * current_xlim[0], -0.1])
xlim_1 = np.amax([current_xlim[1] + 0.1 * current_xlim[1], 1.1])
if ensure_full_semi_circle_displayed:
self.add_phasor_circle(self.graphics_widget.axes)
self.graphics_widget.axes.autoscale()
self.graphics_widget.draw()
current_ylim = self.graphics_widget.axes.get_ylim()
current_xlim = self.graphics_widget.axes.get_xlim()
ylim_0 = np.amin([current_ylim[0] - 0.1 * current_ylim[0], -0.1])
ylim_1 = np.amax([current_ylim[1] + 0.1 * current_ylim[1], 0.7])
xlim_0 = np.amin([current_xlim[0] - 0.1 * current_xlim[0], -0.1])
xlim_1 = np.amax([current_xlim[1] + 0.1 * current_xlim[1], 1.1])
else:
self.graphics_widget.axes.autoscale()
self.graphics_widget.draw()
current_ylim = self.graphics_widget.axes.get_ylim()
current_xlim = self.graphics_widget.axes.get_xlim()
self.add_phasor_circle(self.graphics_widget.axes)
ylim_0 = current_ylim[0] - 0.1 * current_ylim[0]
ylim_1 = current_ylim[1] + 0.1 * current_ylim[1]
xlim_0 = current_xlim[0] - 0.1 * current_xlim[0]
xlim_1 = current_xlim[1] + 0.1 * current_xlim[1]
self.graphics_widget.axes.set_ylim([ylim_0, ylim_1])
self.graphics_widget.axes.set_xlim([xlim_0, xlim_1])
self.graphics_widget.draw_idle()


def add_phasor_circle(self, ax):
'''
Generate FLIM universal semi-circle plot
'''
import numpy as np
angles = np.linspace(0, np.pi, 180)
x = (np.cos(angles) + 1) / 2
y = np.sin(angles) / 2
ax.plot(x, y, 'white', alpha=0.3)
return ax


def add_tau_lines(self, ax, tau_list, frequency):
import numpy as np
if not isinstance(tau_list, list):
tau_list = [tau_list]
frequency = frequency * 1E6 # MHz to Hz
w = 2 * np.pi * frequency # Hz to radians/s
for tau in tau_list:
tau = tau * 1E-9 # nanoseconds to seconds
g = 1 / (1 + ((w * tau)**2))
s = (w * tau) / (1 + ((w * tau)**2))
dot, = ax.plot(g, s, marker='o', mfc='none')
array = np.linspace(0, g, 50)
y = (array * s / g)
ax.plot(array, y, color=dot.get_color())
13 changes: 1 addition & 12 deletions src/napari_flim_phasor_plotter/_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ def make_flim_phasor_plot(image_layer: "napari.layers.Image",
# TO DO: avoid using private method access to napari_viewer.window._dock_widgets (will be deprecated)
dock_widgets_names = [key for key,
value in napari_viewer.window._dock_widgets.items()]
print(dock_widgets_names)
if 'Phasor Plotter Widget (napari-flim-phasor-plotter)' not in dock_widgets_names:
plotter_widget = PhasorPlotterWidget(napari_viewer)
napari_viewer.window.add_dock_widget(
Expand All @@ -145,17 +144,7 @@ def make_flim_phasor_plot(image_layer: "napari.layers.Image",
plotter_widget.run(labels_layer.features,
plotter_widget.plot_x_axis.currentText(),
plotter_widget.plot_y_axis.currentText())

# Redefine axes limits
plotter_widget.graphics_widget.axes.autoscale()
current_ylim = plotter_widget.graphics_widget.axes.get_ylim()
current_xlim = plotter_widget.graphics_widget.axes.get_xlim()
ylim_0 = np.amin([current_ylim[0] - 0.1 * current_ylim[0], -0.1])
ylim_1 = np.amax([current_ylim[1] + 0.1 * current_ylim[1], 0.7])
xlim_0 = np.amin([current_xlim[0] - 0.1 * current_xlim[0], -0.1])
xlim_1 = np.amax([current_xlim[1] + 0.1 * current_xlim[1], 1.1])
plotter_widget.graphics_widget.axes.set_ylim([ylim_0, ylim_1])
plotter_widget.graphics_widget.axes.set_xlim([xlim_0, xlim_1])
plotter_widget.redefine_axes_limits(ensure_full_semi_circle_displayed=True)

# Update laser frequency spinbox
# TO DO: access and update widget in a better way
Expand Down

0 comments on commit 07818c9

Please sign in to comment.