nguyen1j / py-fcm

Automatically exported from code.google.com/p/py-fcm
0 stars 0 forks source link

'import fcm' with matplotlib 1.3.1rc2 fails as matplotlib.nxutils no longer exists #23

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Install latest 'matplotlib' v 1.3.1rc2, supporting modules, and py-fcm from 
http://www.lfd.uci.edu/~gohlke/pythonlibs onto fresh Python 2.7.5 Win7 64-bit 
install
2. Run IPython, enter 'import fcm'
3. Get traceback:
In [1]: import fcm
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-ec1ac52045f7> in <module>()
----> 1 import fcm

c:\python27\lib\site-packages\fcm\__init__.py in <module>()
      2 """
      3 
----> 4 from core import FCMdata, FCMcollection
      5 from core import Annotation
      6 from core import PolyGate, points_in_poly, QuadGate, IntervalGate, ThresholdGate

c:\python27\lib\site-packages\fcm\core\__init__.py in <module>()
      5 from fcmexceptions import CompensationError
      6 from transforms import logicle, hyperlog, productlog
----> 7 from gate import PolyGate, points_in_poly, QuadGate, IntervalGate, 
ThresholdGate
      8 from gate import generate_f_score_gate
      9 from subsample import Subsample, SubsampleFactory, DropChannel

c:\python27\lib\site-packages\fcm\core\gate.py in <module>()
      1 import numpy
----> 2 from matplotlib.nxutils import points_inside_poly
      3 from tree import GatingNode
      4 
      5 

ImportError: No module named nxutils

What is the expected output? What do you see instead?
The expected output is nothing - a successful import

What version of the product are you using? On what operating system?
py-fcm 0.9.1 amd64-py27 from cgohlke, as described above. This is running in 
IPython 1.1.0 (most likely not relevant) on Win7 Ultimate x64. I haven't had a 
chance to confirm on other OSes, but I suspect the behavior would be the same.

Please provide any additional information below.
I did a little digging, and found a reason and a workaround. The reason: as of 
matplotlib 1.2.0, the pnpoly() and points_inside_poly() functions in 
matplotlib.nxutils were deprecated 
(http://matplotlib.org/1.2.1/api/nxutils_api.html), instead 
matplotlib.path.Path.contains_points() should be used instead. Since you are 
now operating on a Path instead of a collection of points and vertices, the 
computation of the gate in the PolyGate class could be quite different.

The workaround: some enterprising soul wrote his/her own points_in_poly() 
function further down in fcm/core/gate.py, using numpy instead of matplotlib to 
do the heavy lifting. A line using this function was already included (but 
commented out) just above the offending statement on line 56 of gate.py. All 
you need to do to (apparently) fix the problem is comment out line 56, and 
uncomment line 52 like so:

...
        if name is None:
            name = self.name
        idxs = points_in_poly(self.vert, fcm.view()[:, chan])

        # matplotlib has points in poly routine in C
        # no faster than our numpy version
        # idxs = points_inside_poly(fcm.view()[:, chan], self.vert)

        if invert:
            idxs = numpy.invert(idxs)
...

Just doing this simple change allowed for a seamless import.

I need to add that I am very new to py-fcm, so I don't have any ready-set code 
to test the new logic and make sure it works, so I'll leave that up to you. As 
an aside, I was really excited when I came across this project, as I'm having 
trouble affording the exorbitant price of FlowJo, and I'd love to get my data 
and hopefully generate images programmatically, so I'm very excited to dig in 
and learn all about it. 

Original issue reported on code.google.com by MatthewD...@gmail.com on 2 Oct 2013 at 2:55

GoogleCodeExporter commented 8 years ago
Having had a chance to go through the previously provided algorithm more, it 
looks like it works.  Not sure if it's still just as fast as the old C wrapped 
matplotlib version but that's gone way.  Points on vertices are excluded, and 
points that lie on an edge seem to be out or in based on it being on an initial 
edge or a ending edge respectively.  Committing change.

Original comment by Jacob.Frelinger@gmail.com on 2 Oct 2013 at 8:54

GoogleCodeExporter commented 8 years ago
change pushed

Original comment by Jacob.Frelinger@gmail.com on 2 Oct 2013 at 9:07

GoogleCodeExporter commented 8 years ago
I'm having a similar issue, but the uncommenting of line 52 and commenting out 
line 56 in the gate.py file doesn't seem to work.  I'm using Python 2.7.6, the 
Anaconda distribution and the Spyder 2.2 development environment on my MacBook 
Pro (OS X 10.9.2).  I get the following error:

>>> import fcm
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/bhcsemployee/anaconda/lib/python2.7/site-packages/fcm-0.9.1-py2.7-macosx-10.5-x86_64.egg/fcm/__init__.py", line 4, in <module>
    from core import FCMdata, FCMcollection
  File "/Users/bhcsemployee/anaconda/lib/python2.7/site-packages/fcm-0.9.1-py2.7-macosx-10.5-x86_64.egg/fcm/core/__init__.py", line 7, in <module>
    from gate import PolyGate, points_in_poly, QuadGate, IntervalGate, ThresholdGate
  File "/Users/bhcsemployee/anaconda/lib/python2.7/site-packages/fcm-0.9.1-py2.7-macosx-10.5-x86_64.egg/fcm/core/gate.py", line 2, in <module>
    from matplotlib.nxutils import points_inside_poly
ImportError: No module named nautilus

Original comment by dsdoug...@sbcglobal.net on 6 May 2014 at 8:20

GoogleCodeExporter commented 8 years ago
dsdougall, are you running from the development version or the last released 
package?

Original comment by Jacob.Frelinger@gmail.com on 6 May 2014 at 8:51

GoogleCodeExporter commented 8 years ago
I'm running Anaconda (3.4.3) and Spyder 2.24 and Python 2.7.6, which should all 
be stable versions.

Original comment by dsdoug...@sbcglobal.net on 7 May 2014 at 1:46

GoogleCodeExporter commented 8 years ago
 dsdougall can you try the attached fcm/core/gate.py? 

Original comment by Jacob.Frelinger@gmail.com on 10 May 2014 at 1:23

Attachments:

GoogleCodeExporter commented 8 years ago

Original comment by Jacob.Frelinger@gmail.com on 10 May 2014 at 1:24

GoogleCodeExporter commented 8 years ago
Jacob

The new gate.py file seems to work.  I can import the fcm package and load an 
fcs file.  I look forward to playing with the package.  Thanks for all of your 
help.

Dave

Original comment by dsdoug...@sbcglobal.net on 12 May 2014 at 12:03