Skip to content

Commit

Permalink
Merge branch 'release-1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
castillohair committed Jul 23, 2018
2 parents 2f8827a + 7ceb1d9 commit 356325b
Show file tree
Hide file tree
Showing 18 changed files with 2,530 additions and 432 deletions.
16 changes: 8 additions & 8 deletions FlowCal/__init__.py
Expand Up @@ -6,12 +6,12 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
__version__ = '1.1.4'
__version__ = '1.2.0'

import io
import excel_ui
import gate
import transform
import mef
import plot
import stats
from . import io
from . import excel_ui
from . import gate
from . import transform
from . import mef
from . import plot
from . import stats
328 changes: 246 additions & 82 deletions FlowCal/excel_ui.py

Large diffs are not rendered by default.

48 changes: 24 additions & 24 deletions FlowCal/gate.py
Expand Up @@ -21,7 +21,7 @@

import numpy as np
import scipy.ndimage.filters
import matplotlib._cntr # matplotlib contour, implemented in C
import skimage.measure
import collections

###
Expand Down Expand Up @@ -506,32 +506,32 @@ def density2d(data,
gated_data = data[mask]

if full_output:
# Use matplotlib contour plotter (implemented in C) to generate contour(s)
# at the probability associated with the last accepted bin.
# Use scikit-image to find the contour of the gated region
#
# To find the contour of the gated region, values in the 2D probability
# mass function ``D`` are used to trace contours at the level of the
# probability associated with the last accepted bin, ``vD[sidx[Nidx]]``.

# find_contours() specifies contours as collections of row and column
# indices into the density matrix. The row or column index may be
# interpolated (i.e. non-integer) for greater precision.
contours_ij = skimage.measure.find_contours(D, vD[sidx[Nidx]])

# Map contours from indices into density matrix to histogram x and y
# coordinate spaces (assume values in the density matrix are associated
# with histogram bin centers).
xc = (xe[:-1] + xe[1:]) / 2.0 # x-axis bin centers
yc = (ye[:-1] + ye[1:]) / 2.0 # y-axis bin centers
x,y = np.meshgrid(xc, yc, indexing='ij')
mpl_cntr = matplotlib._cntr.Cntr(x,y,D)
tr = mpl_cntr.trace(vD[sidx[Nidx]])

# trace returns a list of arrays which contain vertices and path codes
# used in matplotlib Path objects (see http://stackoverflow.com/a/18309914
# and the documentation for matplotlib.path.Path for more details). I'm
# just going to make sure the path codes aren't unfamiliar and then extract
# all of the vertices and pack them into a list of 2D contours.
cntr = []
num_cntrs = len(tr)/2
for idx in xrange(num_cntrs):
vertices = tr[idx]
codes = tr[num_cntrs+idx]

# I am only expecting codes 1 and 2 ('MOVETO' and 'LINETO' codes)
if not np.all((codes==1)|(codes==2)):
raise Exception('Contour error: unrecognized path code')

cntr.append(vertices)

contours = [np.array([np.interp(contour_ij[:,0],
np.arange(len(xc)),
xc),
np.interp(contour_ij[:,1],
np.arange(len(yc)),
yc)]).T
for contour_ij in contours_ij]

return Density2dGateOutput(
gated_data=gated_data, mask=mask, contour=cntr)
gated_data=gated_data, mask=mask, contour=contours)
else:
return gated_data

0 comments on commit 356325b

Please sign in to comment.