In [1]:
%load_ext autoreload
%autoreload 2

In [2]:
from pandas import DataFrame as DF
from matplotlib.path import Path
from matplotlib import patches
from FlowCytometryTools.core import gates

Generate Data


In [3]:
coords = randn(50, 2)
data = DF(coords)

gate1 = gates.ThresholdGate(1, channel=[0], region='above')
gate2 = gates.ThresholdGate(0.3, channel=[1], region='above')

#~gate1
#gate1 & gate2
#gate1 ^ gate2
#gate1 | gate2
~gate1


Out[3]:
<FlowCytometryTools.core.gates.CompositeGate at 0x4b7ffd0>

In [7]:
gate1.plot(ax_channels=[0, 1])
gate2.plot(ax_channels=[0, 1])

#gate_c = (gate1 ^ gate1 ^ gate1)
gate_c = gate2

#~gate1#CompositeGate(gate1, how='or', gate2=gate1)
#gate1.plot()
gate_c.plot(ax_channels=[0, 1])
data2 = gate_c(data)
#data2 = gate1(data)

plot(data[0], data[1], 'o')
plot(data2[0], data2[1], 'or')


Out[7]:
[<matplotlib.lines.Line2D at 0x50ebd90>]

Interval Gate


In [8]:
gate = gates.IntervalGate([-0.3, 0.7], channel=[1], region='in')
data2 = gate(data)

plot(data[0], data[1], 'o')
plot(data2[0], data2[1], 'or')
gate.plot(flip=True, linestyle='--', linewidth=3)


Out[8]:
(<matplotlib.lines.Line2D at 0x5352ed0>,
 <matplotlib.lines.Line2D at 0x53556d0>)

Quad Gate


In [9]:
verts = (0.0, 0.1)
    
fig = plt.figure()
ax = fig.add_subplot(111)
gate = gates.QuadGate(vert=verts, channels=[0, 1], region='top left')
data2 = gate(data)

gate.plot(linewidth=1, linestyle='-')

plot(data[0], data[1], 'o')
plot(data2[0], data2[1], 'or')


Out[9]:
[<matplotlib.lines.Line2D at 0x54a3450>]

PolyGate


In [10]:
verts = [
    (-2, -1.), # left, bottom
    (0., 1.), # left, top
    (1., 1.), # right, top
    (0.4, 0.3), # right, bottom
    (0., 0.), # final point
    (-2, -1.), # left, bottom
        ]

fig = plt.figure()
ax = fig.add_subplot(111)
gate = gates.PolyGate(vert=verts, channels=[0, 1])
data2 = gate(data)

plot(data[0], data[1], 'o')
plot(data2[0], data2[1], 'or')
gate.plot()


Out[10]:
<matplotlib.patches.Polygon at 0x57f2110>