Skip to content

Change some matplotlib.tri calls to use scipy.spatial.Delaunay#649

Open
David-Baddeley wants to merge 2 commits into
python-microscopy:masterfrom
David-Baddeley:tri-swap
Open

Change some matplotlib.tri calls to use scipy.spatial.Delaunay#649
David-Baddeley wants to merge 2 commits into
python-microscopy:masterfrom
David-Baddeley:tri-swap

Conversation

@David-Baddeley
Copy link
Copy Markdown
Contributor

switch from matplotlib.tri to scipy.spatial.Delaunay for some of the jittered triangulation calls to avoid matplotlib imports and framework issues

Note: calcNeighbourDists still uses matplotlib.tri as we need the .edges property, but this should hopefully be OK as it should get called in the main process, not subprocesses.

Addresses issue #614.

This is pretty much a punt at this point as I can't reproduce #614 on my version of OSX (i.e. I don't know if this will work)

@zacsimile or @barentine - could you try this out.

…jittered triangulation calls. Note: calcNeighbourDists still uses matplotlib.tri as we need the .edges property.
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lintly has detected code quality issues in this pull request.

Comment thread PYME/LMVis/visHelpers.py
from PYME.Analysis.points.SoftRend import drawTriang, drawTriangles
xs = T.x[T.triangles]
ys = T.y[T.triangles]
#xs = T.x[T.triangles]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E265: block comment should start with '# '

Comment thread PYME/LMVis/visHelpers.py
#ys = T.y[T.triangles] # y posititions of vertices [nm], dimensions (# triangles, 3)

verts = T.points[T.simplices]
xs = verts[:,:,0]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E231: missing whitespace after ','

Comment thread PYME/LMVis/visHelpers.py
#ys = T.y[T.triangles] # y posititions of vertices [nm], dimensions (# triangles, 3)

verts = T.points[T.simplices]
xs = verts[:,:,0]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E231: missing whitespace after ','

Comment thread PYME/LMVis/visHelpers.py
ys = T.y[T.triangles] # y posititions of vertices [nm], dimensions (# triangles, 3)
#xs = T.x[T.triangles] # x posititions of vertices [nm], dimensions (# triangles, 3)
#ys = T.y[T.triangles] # y posititions of vertices [nm], dimensions (# triangles, 3)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

W293: blank line contains whitespace

Comment thread PYME/LMVis/visHelpers.py
xs = T.x[T.triangles] # x posititions of vertices [nm], dimensions (# triangles, 3)
ys = T.y[T.triangles] # y posititions of vertices [nm], dimensions (# triangles, 3)
#xs = T.x[T.triangles] # x posititions of vertices [nm], dimensions (# triangles, 3)
#ys = T.y[T.triangles] # y posititions of vertices [nm], dimensions (# triangles, 3)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E265: block comment should start with '# '

Comment thread PYME/LMVis/visHelpers.py
from PYME.Analysis.points.SoftRend import drawTriang, drawTriangles
xs = T.x[T.triangles] # x posititions of vertices [nm], dimensions (# triangles, 3)
ys = T.y[T.triangles] # y posititions of vertices [nm], dimensions (# triangles, 3)
#xs = T.x[T.triangles] # x posititions of vertices [nm], dimensions (# triangles, 3)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E265: block comment should start with '# '

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 27, 2020

Codecov Report

Merging #649 (9d8d9db) into master (2e790c1) will decrease coverage by 0.00%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #649      +/-   ##
==========================================
- Coverage   11.37%   11.37%   -0.01%     
==========================================
  Files         631      631              
  Lines       72396    72398       +2     
==========================================
  Hits         8234     8234              
- Misses      64162    64164       +2     
Impacted Files Coverage Δ
PYME/LMVis/visHelpers.py 9.72% <0.00%> (-0.06%) ⬇️
PYME/localization/FitFactories/InterpFitR.py 78.18% <0.00%> (-2.73%) ⬇️
PYME/localization/FitFactories/Dumbell3DFitR.py 98.66% <0.00%> (+4.00%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2e790c1...9d8d9db. Read the comment docs.

@zacsimile
Copy link
Copy Markdown
Member

zacsimile commented Nov 28, 2020

Still need to use @barentine's execute_on_invalidation hack to get the recipe to run. I still get the long run of

Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.

and then the following

Traceback
Created colour filter with chans: ['chan1', 'chan0']
/Users/zachcm/Code/python-microscopy/PYME/IO/DataSources/ArrayDataSource.py:45: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
  r = self.data.__getitem__(keys)
RecipeView._layout
Traceback (most recent call last):
  File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 665, in execute
    m.execute(self.namespace)
  File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 1219, in execute
    namespace[self.outputName] = self.filter(namespace[self.inputName])
  File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 1208, in filter
    filt_ims = [np.atleast_3d(self.applyFilter(image.data[:,:,:,chanNum].squeeze().astype('f'), chanNum, 0, image)) for chanNum in range(image.data.shape[3])]
  File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 1208, in 
    filt_ims = [np.atleast_3d(self.applyFilter(image.data[:,:,:,chanNum].squeeze().astype('f'), chanNum, 0, image)) for chanNum in range(image.data.shape[3])]
  File "/Users/zachcm/Code/python-microscopy/PYME/recipes/processing.py", line 74, in applyFilter
    threshold = thresholding.otsu(data, nbins=self.n_histogram_bins, bin_spacing=self.bin_spacing)
  File "/Users/zachcm/Code/python-microscopy/PYME/Analysis/thresholding.py", line 151, in otsu
    "to have just one color {0}.".format(image.min()))
ValueError: threshold_otsu is expected to work with images having more than one color. The input image seems to have just one color 0.0.

During handling of the above exception, another exception occurred:

wx._core.wxAssertionError: C++ assertion "GetEventHandler() == this" failed at /Users/robind/projects/buildbots/macosx-vm6/dist-osx-py36/Phoenix/ext/wxWidgets/src/common/wincmn.cpp(478) in ~wxWindowBase(): any pushed event handlers must have been removed

The above exception was the direct cause of the following exception:

SystemError: <class 'wx._core.WindowDestroyEvent'> returned a result with an error set
Traceback (most recent call last):
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 665, in execute
m.execute(self.namespace)
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 1219, in execute
namespace[self.outputName] = self.filter(namespace[self.inputName])
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 1208, in filter
filt_ims = [np.atleast_3d(self.applyFilter(image.data[:,:,:,chanNum].squeeze().astype('f'), chanNum, 0, image)) for chanNum in range(image.data.shape[3])]
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 1208, in
filt_ims = [np.atleast_3d(self.applyFilter(image.data[:,:,:,chanNum].squeeze().astype('f'), chanNum, 0, image)) for chanNum in range(image.data.shape[3])]
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/processing.py", line 74, in applyFilter
threshold = thresholding.otsu(data, nbins=self.n_histogram_bins, bin_spacing=self.bin_spacing)
File "/Users/zachcm/Code/python-microscopy/PYME/Analysis/thresholding.py", line 151, in otsu
"to have just one color {0}.".format(image.min()))
ValueError: threshold_otsu is expected to work with images having more than one color. The input image seems to have just one color 0.0.

During handling of the above exception, another exception occurred:

wx._core.wxAssertionError: C++ assertion "GetEventHandler() == this" failed at /Users/robind/projects/buildbots/macosx-vm6/dist-osx-py36/Phoenix/ext/wxWidgets/src/common/wincmn.cpp(478) in ~wxWindowBase(): any pushed event handlers must have been removed

The above exception was the direct cause of the following exception:

SystemError: <class 'wx._core.WindowDestroyEvent'> returned a result with an error set
Traceback (most recent call last):
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 665, in execute
m.execute(self.namespace)
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 1219, in execute
namespace[self.outputName] = self.filter(namespace[self.inputName])
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 1208, in filter
filt_ims = [np.atleast_3d(self.applyFilter(image.data[:,:,:,chanNum].squeeze().astype('f'), chanNum, 0, image)) for chanNum in range(image.data.shape[3])]
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 1208, in
filt_ims = [np.atleast_3d(self.applyFilter(image.data[:,:,:,chanNum].squeeze().astype('f'), chanNum, 0, image)) for chanNum in range(image.data.shape[3])]
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/processing.py", line 74, in applyFilter
threshold = thresholding.otsu(data, nbins=self.n_histogram_bins, bin_spacing=self.bin_spacing)
File "/Users/zachcm/Code/python-microscopy/PYME/Analysis/thresholding.py", line 151, in otsu
"to have just one color {0}.".format(image.min()))
ValueError: threshold_otsu is expected to work with images having more than one color. The input image seems to have just one color 0.0.

During handling of the above exception, another exception occurred:

wx._core.wxAssertionError: C++ assertion "GetEventHandler() == this" failed at /Users/robind/projects/buildbots/macosx-vm6/dist-osx-py36/Phoenix/ext/wxWidgets/src/common/wincmn.cpp(478) in ~wxWindowBase(): any pushed event handlers must have been removed

The above exception was the direct cause of the following exception:

SystemError: <class 'wx._core.WindowDestroyEvent'> returned a result with an error set
Traceback (most recent call last):
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 665, in execute
m.execute(self.namespace)
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 1219, in execute
namespace[self.outputName] = self.filter(namespace[self.inputName])
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 1208, in filter
filt_ims = [np.atleast_3d(self.applyFilter(image.data[:,:,:,chanNum].squeeze().astype('f'), chanNum, 0, image)) for chanNum in range(image.data.shape[3])]
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 1208, in
filt_ims = [np.atleast_3d(self.applyFilter(image.data[:,:,:,chanNum].squeeze().astype('f'), chanNum, 0, image)) for chanNum in range(image.data.shape[3])]
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/processing.py", line 74, in applyFilter
threshold = thresholding.otsu(data, nbins=self.n_histogram_bins, bin_spacing=self.bin_spacing)
File "/Users/zachcm/Code/python-microscopy/PYME/Analysis/thresholding.py", line 151, in otsu
"to have just one color {0}.".format(image.min()))
ValueError: threshold_otsu is expected to work with images having more than one color. The input image seems to have just one color 0.0.

During handling of the above exception, another exception occurred:

wx._core.wxAssertionError: C++ assertion "GetEventHandler() == this" failed at /Users/robind/projects/buildbots/macosx-vm6/dist-osx-py36/Phoenix/ext/wxWidgets/src/common/wincmn.cpp(478) in ~wxWindowBase(): any pushed event handlers must have been removed

The above exception was the direct cause of the following exception:

SystemError: <class 'wx._core.WindowDestroyEvent'> returned a result with an error set
Traceback (most recent call last):
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 665, in execute
m.execute(self.namespace)
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 1219, in execute
namespace[self.outputName] = self.filter(namespace[self.inputName])
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 1208, in filter
filt_ims = [np.atleast_3d(self.applyFilter(image.data[:,:,:,chanNum].squeeze().astype('f'), chanNum, 0, image)) for chanNum in range(image.data.shape[3])]
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 1208, in
filt_ims = [np.atleast_3d(self.applyFilter(image.data[:,:,:,chanNum].squeeze().astype('f'), chanNum, 0, image)) for chanNum in range(image.data.shape[3])]
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/processing.py", line 74, in applyFilter
threshold = thresholding.otsu(data, nbins=self.n_histogram_bins, bin_spacing=self.bin_spacing)
File "/Users/zachcm/Code/python-microscopy/PYME/Analysis/thresholding.py", line 151, in otsu
"to have just one color {0}.".format(image.min()))
ValueError: threshold_otsu is expected to work with images having more than one color. The input image seems to have just one color 0.0.

During handling of the above exception, another exception occurred:

wx._core.wxAssertionError: C++ assertion "GetEventHandler() == this" failed at /Users/robind/projects/buildbots/macosx-vm6/dist-osx-py36/Phoenix/ext/wxWidgets/src/common/wincmn.cpp(478) in ~wxWindowBase(): any pushed event handlers must have been removed

The above exception was the direct cause of the following exception:

SystemError: <class 'wx._core.WindowDestroyEvent'> returned a result with an error set
Traceback (most recent call last):
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 665, in execute
m.execute(self.namespace)
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 1219, in execute
namespace[self.outputName] = self.filter(namespace[self.inputName])
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 1208, in filter
filt_ims = [np.atleast_3d(self.applyFilter(image.data[:,:,:,chanNum].squeeze().astype('f'), chanNum, 0, image)) for chanNum in range(image.data.shape[3])]
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 1208, in
filt_ims = [np.atleast_3d(self.applyFilter(image.data[:,:,:,chanNum].squeeze().astype('f'), chanNum, 0, image)) for chanNum in range(image.data.shape[3])]
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/processing.py", line 74, in applyFilter
threshold = thresholding.otsu(data, nbins=self.n_histogram_bins, bin_spacing=self.bin_spacing)
File "/Users/zachcm/Code/python-microscopy/PYME/Analysis/thresholding.py", line 151, in otsu
"to have just one color {0}.".format(image.min()))
ValueError: threshold_otsu is expected to work with images having more than one color. The input image seems to have just one color 0.0.

During handling of the above exception, another exception occurred:

wx._core.wxAssertionError: C++ assertion "GetEventHandler() == this" failed at /Users/robind/projects/buildbots/macosx-vm6/dist-osx-py36/Phoenix/ext/wxWidgets/src/common/wincmn.cpp(478) in ~wxWindowBase(): any pushed event handlers must have been removed

The above exception was the direct cause of the following exception:

SystemError: <class 'wx._core.WindowDestroyEvent'> returned a result with an error set
Traceback (most recent call last):
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 665, in execute
m.execute(self.namespace)
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 1219, in execute
namespace[self.outputName] = self.filter(namespace[self.inputName])
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 1208, in filter
filt_ims = [np.atleast_3d(self.applyFilter(image.data[:,:,:,chanNum].squeeze().astype('f'), chanNum, 0, image)) for chanNum in range(image.data.shape[3])]
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 1208, in
filt_ims = [np.atleast_3d(self.applyFilter(image.data[:,:,:,chanNum].squeeze().astype('f'), chanNum, 0, image)) for chanNum in range(image.data.shape[3])]
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/processing.py", line 74, in applyFilter
threshold = thresholding.otsu(data, nbins=self.n_histogram_bins, bin_spacing=self.bin_spacing)
File "/Users/zachcm/Code/python-microscopy/PYME/Analysis/thresholding.py", line 151, in otsu
"to have just one color {0}.".format(image.min()))
ValueError: threshold_otsu is expected to work with images having more than one color. The input image seems to have just one color 0.0.

During handling of the above exception, another exception occurred:

wx._core.wxAssertionError: C++ assertion "GetEventHandler() == this" failed at /Users/robind/projects/buildbots/macosx-vm6/dist-osx-py36/Phoenix/ext/wxWidgets/src/common/wincmn.cpp(478) in ~wxWindowBase(): any pushed event handlers must have been removed

The above exception was the direct cause of the following exception:

SystemError: <class 'wx._core.WindowDestroyEvent'> returned a result with an error set
Input datasources: ['_fitResults', 'FitResults']
Traceback (most recent call last):
File "", line 1, in
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 665, in execute
m.execute(self.namespace)
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 1219, in execute
namespace[self.outputName] = self.filter(namespace[self.inputName])
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 1208, in filter
filt_ims = [np.atleast_3d(self.applyFilter(image.data[:,:,:,chanNum].squeeze().astype('f'), chanNum, 0, image)) for chanNum in range(image.data.shape[3])]
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/base.py", line 1208, in
filt_ims = [np.atleast_3d(self.applyFilter(image.data[:,:,:,chanNum].squeeze().astype('f'), chanNum, 0, image)) for chanNum in range(image.data.shape[3])]
File "/Users/zachcm/Code/python-microscopy/PYME/recipes/processing.py", line 74, in applyFilter
threshold = thresholding.otsu(data, nbins=self.n_histogram_bins, bin_spacing=self.bin_spacing)
File "/Users/zachcm/Code/python-microscopy/PYME/Analysis/thresholding.py", line 151, in otsu
"to have just one color {0}.".format(image.min()))
ValueError: threshold_otsu is expected to work with images having more than one color. The input image seems to have just one color 0.0.

@barentine
Copy link
Copy Markdown
Member

Thanks for testing @zacsimile. That Otsu error just means that the jittered triangulation forks died and we tried to threshold an image of all zeros. Would seem this punt doesn't work, but I appreciate the try @David-Baddeley!

@David-Baddeley
Copy link
Copy Markdown
Contributor Author

I'm going to leave this open for now (even though it doesn't solve #614) as it might make sense to make us less dependant on matplotlib anyway.

@David-Baddeley David-Baddeley changed the title Candidate fix for #614 Change some matplotlib.tri calls to use scipy.spatial.Delaunay Dec 23, 2020
@David-Baddeley David-Baddeley marked this pull request as draft December 23, 2020 00:51
@David-Baddeley David-Baddeley marked this pull request as ready for review April 13, 2021 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants