Skip to content

Commit 6d7bf50

Browse files
added merging things but will not be used
1 parent 29ef8e1 commit 6d7bf50

File tree

4 files changed

+135
-57
lines changed

4 files changed

+135
-57
lines changed

MANIFEST.in

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
include suite2p/classifiers/classifier.npy
2-
include suite2p/classifiers/classifier_user.npy
32
include suite2p/logo/logo.png
43
include suite2p/logo/logo_unshaded.png
54
include suite2p/ops/ops.npy
5+
include suite2p/ops/ops_soma.npy
6+
include suite2p/ops/ops_dendrite.npy
67
include README.md
78
include LICENSE

suite2p/fig.py

-50
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,6 @@ def init_masks(parent):
198198
iExt[i,1,yext,xext] = iExt[i,0,yext,xext]
199199
iunder = iExt[i,1,yext,xext]
200200
iExt[i,0,yext,xext] = n
201-
#stat[n]['yext_overlap'] = np.append(stat[n]['yext_overlap'], yext[iunder>=0], axis=0)
202-
#stat[n]['xext_overlap'] = np.append(stat[n]['xext_overlap'], xext[iunder>=0], axis=0)
203-
#for k in np.unique(iunder[iunder>=0]):
204-
# stat[k]['yext_overlap'] = np.append(stat[k]['yext_overlap'], yext[iunder==k], axis=0)
205-
# stat[k]['xext_overlap'] = np.append(stat[k]['xext_overlap'], xext[iunder==k], axis=0)
206201
# add weighting to all layers
207202
Lam[i,2,ypix,xpix] = Lam[i,1,ypix,xpix]
208203
Lam[i,1,ypix,xpix] = Lam[i,0,ypix,xpix]
@@ -561,51 +556,6 @@ def draw_masks(parent): #ops, stat, ops_plot, iscell, ichosen):
561556
M[wplot] = make_chosen_circle(M[wplot], ycirc, xcirc, col, sat)
562557
return M[0],M[1]
563558

564-
def merge_masks(parent):
565-
ncells = len(parent.stat)
566-
nmerged = len(parent.merged)
567-
# cells or notcells
568-
i0 = int(1-parent.iscell[parent.ichosen])
569-
ypix = np.array([])
570-
xpix = np.array([])
571-
for n in np.array(parent.imerge):
572-
#for k in range(parent.iROI.shape[1]):
573-
# ipix = np.array((parent.iROI[i0,k,:,:]==n).nonzero()).astype(np.int32)
574-
# parent.iROI[i0, k, ipix[0,:], ipix[1,:]] = ncells + nmerged
575-
# ipix = np.array((parent.iExt[i0,k,:,:]==n).nonzero()).astype(np.int32)
576-
# parent.iExt[i0, k, ipix[0,:], ipix[1,:]] = ncells + nmerged
577-
ypix = np.append(ypix, parent.stat[n]['ypix'])
578-
xpix = np.append(xpix, parent.stat[n]['xpix'])
579-
ypix = ypix.astype(np.int32)
580-
xpix = xpix.astype(np.int32)
581-
parent.iROI[i0, 0, ypix, xpix] = ncells + nmerged
582-
parent.iExt[i0, 0, ypix, xpix] = ncells + nmerged
583-
584-
cols = parent.ops_plot[3]
585-
cols = np.append(cols, np.ones((1,cols.shape[1])), axis=0)
586-
parent.ops_plot[3] = cols
587-
for c in range(cols.shape[1]):
588-
for k in range(5):
589-
if k<3 or k==4:
590-
H = cols[parent.iROI[i0,0,ypix,xpix],c]
591-
S = parent.Sroi[i0,ypix,xpix]
592-
else:
593-
H = cols[parent.iExt[i0,0,ypix,xpix],c]
594-
S = parent.Sext[i0,ypix,xpix]
595-
if k==0:
596-
V = np.maximum(0, np.minimum(1, 0.75*parent.Lam[i0,0,ypix,xpix]/parent.LamMean))
597-
elif k==1 or k==2 or k==4:
598-
V = parent.Vback[k-1,ypix,xpix]
599-
S = np.maximum(0, np.minimum(1, 1.5*0.75*parent.Lam[i0,0,ypix,xpix]/parent.LamMean))
600-
elif k==3:
601-
V = parent.Vback[k-1,ypix,xpix]
602-
V = np.minimum(1, V + S)
603-
H = np.expand_dims(H.flatten(),axis=1)
604-
S = np.expand_dims(S.flatten(),axis=1)
605-
V = np.expand_dims(V.flatten(),axis=1)
606-
hsv = np.concatenate((H,S,V),axis=1)
607-
parent.RGBall[i0,c,k,ypix,xpix,:] = hsv_to_rgb(hsv)
608-
609559
def flip_cell(parent):
610560
''' flips a cell to other plot
611561
there are 3 levels of overlap so this may be buggy if more than 3 cells are on

suite2p/gui2p.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from PyQt5 import QtGui, QtCore
77
import pyqtgraph as pg
88
from pyqtgraph import GraphicsScene
9-
from suite2p import fig, gui, classifier, visualize, reggui, classgui
9+
from suite2p import fig, gui, classifier, visualize, reggui, classgui, merge
1010
from pkg_resources import iter_entry_points
1111

1212
class MainW(QtGui.QMainWindow):
@@ -501,15 +501,13 @@ def __init__(self):
501501
)
502502
# initialize merges
503503
self.merged = []
504-
self.Fmerge = []
505-
self.stat_merge = []
506504

507505
model = np.load(self.classorig)
508506
model = model.item()
509507
self.default_keys = model["keys"]
510-
# self.fname = '/media/carsen/DATA2/Github/TX4/stat.npy'
508+
self.fname = '/media/carsen/DATA2/Github/TX4/stat.npy'
511509
#self.fname = 'C:/Users/carse/github/TX4/stat.npy'
512-
#self.load_proc()
510+
self.load_proc()
513511
# self.load_behavior('C:/Users/carse/github/TX4/beh.npy')
514512

515513
def export_fig(self):
@@ -616,7 +614,9 @@ def merge_cells(self):
616614
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No,
617615
)
618616
if dm == QtGui.QMessageBox.Yes:
619-
fig.merge_masks(self)
617+
nmerged = len(self.merged)
618+
merge.activity_stats(self)
619+
merge.fig_masks(self)
620620
M = fig.draw_masks(self)
621621
fig.plot_masks(self, M)
622622
fig.plot_trace(self)

suite2p/merge.py

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import numpy as np
2+
import pyqtgraph as pg
3+
from scipy import stats
4+
from suite2p import utils, dcnv, celldetect2, fig
5+
import math
6+
from PyQt5 import QtGui
7+
from matplotlib.colors import hsv_to_rgb
8+
import time
9+
10+
def activity_stats(parent):
11+
i0 = int(1-parent.iscell[parent.ichosen])
12+
ypix = np.array([])
13+
xpix = np.array([])
14+
lam = np.array([])
15+
footprints = np.array([])
16+
F = np.zeros((0,parent.Fcell.shape[1]), np.float32)
17+
Fneu = np.zeros((0,parent.Fcell.shape[1]), np.float32)
18+
for n in np.array(parent.imerge):
19+
ypix = np.append(ypix, parent.stat[n]["ypix"])
20+
xpix = np.append(xpix, parent.stat[n]["xpix"])
21+
lam = np.append(lam, parent.stat[n]["lam"])
22+
footprints = np.append(footprints, parent.stat[n]["footprint"])
23+
F = np.append(F, parent.Fcell[n,:][np.newaxis,:], axis=0)
24+
Fneu = np.append(Fneu, parent.Fneu[n,:][np.newaxis,:], axis=0)
25+
26+
# remove overlaps
27+
ipix = np.concatenate((ypix[:,np.newaxis], xpix[:,np.newaxis]), axis=1)
28+
_, goodi = np.unique(ipix, return_index=True, axis=0)
29+
ypix = ypix[goodi]
30+
xpix = xpix[goodi]
31+
lam = lam[goodi]
32+
stat0 = {}
33+
stat0["ypix"] = ypix.astype(np.int32)
34+
stat0["xpix"] = xpix.astype(np.int32)
35+
stat0["lam"] = lam
36+
stat0['med'] = [np.median(stat0["ypix"]), np.median(stat0["xpix"])]
37+
stat0["npix"] = ypix.size
38+
d0 = parent.ops["diameter"]
39+
radius = utils.fitMVGaus(ypix / d0[0], xpix / d0[1], lam, 2)[2]
40+
stat0["radius"] = radius[0] * d0.mean()
41+
stat0["aspect_ratio"] = 2 * radius[0]/(.01 + radius[0] + radius[1])
42+
npix = np.array([parent.stat[n]['npix'] for n in range(len(parent.stat))]).astype('float32')
43+
stat0["npix_norm"] = stat0["npix"] / npix.mean()
44+
# compactness
45+
rs,dy,dx = celldetect2.circleMask(d0)
46+
rsort = np.sort(rs.flatten())
47+
r2 = ((ypix - stat0["med"][0])/d0[0])**2 + ((xpix - stat0["med"][1])/d0[1])**2
48+
r2 = r2**.5
49+
stat0["mrs"] = np.mean(r2)
50+
stat0["mrs0"] = np.mean(rsort[:r2.size])
51+
stat0["compact"] = stat0["mrs"] / (1e-10 + stat0["mrs0"])
52+
# footprint
53+
stat0["footprint"] = footprints.mean()
54+
F = F.mean(axis=0)
55+
Fneu = Fneu.mean(axis=0)
56+
dF = F - parent.ops["neucoeff"]*Fneu
57+
# activity stats
58+
stat0["skew"] = stats.skew(dF)
59+
stat0["std"] = dF.std()
60+
# compute outline and circle around cell
61+
iext = fig.boundary(ypix, xpix)
62+
stat0["yext"] = ypix[iext]
63+
stat0["xext"] = xpix[iext]
64+
ycirc, xcirc = fig.circle(stat0["med"], stat0["radius"])
65+
goodi = (
66+
(ycirc >= 0)
67+
& (xcirc >= 0)
68+
& (ycirc < parent.ops["Ly"])
69+
& (xcirc < parent.ops["Lx"])
70+
)
71+
stat0["ycirc"] = ycirc[goodi]
72+
stat0["xcirc"] = xcirc[goodi]
73+
# deconvolve activity
74+
spks = dcnv.oasis(dF[np.newaxis, :], parent.ops)
75+
# add cell to structs
76+
parent.stat = np.concatenate((parent.stat, np.array([stat0])), axis=0)
77+
print(parent.stat[-1]["ypix"].shape)
78+
parent.Fcell = np.concatenate((parent.Fcell, F[np.newaxis,:]), axis=0)
79+
parent.Fneu = np.concatenate((parent.Fneu, Fneu[np.newaxis,:]), axis=0)
80+
parent.Spks = np.concatenate((parent.Spks, spks), axis=0)
81+
iscell = np.array([parent.iscell[parent.ichosen]], dtype=bool)
82+
parent.iscell = np.concatenate((parent.iscell, iscell), axis=0)
83+
84+
def fig_masks(parent):
85+
""" merges multiple cells' colors together """
86+
ncells = parent.stat.size
87+
nmerge = int(ncells - 1)
88+
# cells or notcells
89+
i0 = int(1-parent.iscell[-1])
90+
#for n in np.array(parent.imerge):
91+
# for k in range(parent.iROI.shape[1]):
92+
# ipix = np.array((parent.iROI[i0,k,:,:]==n).nonzero()).astype(np.int32)
93+
# parent.iROI[i0, k, ipix[0,:], ipix[1,:]] = nmerge
94+
# ipix = np.array((parent.iExt[i0,k,:,:]==n).nonzero()).astype(np.int32)
95+
# parent.iExt[i0, k, ipix[0,:], ipix[1,:]] = ncells + nmerged
96+
#ypix = np.append(ypix, parent.stat[n]["ypix"])
97+
#xpix = np.append(xpix, parent.stat[n]["xpix"])
98+
ypix = parent.stat[nmerge]["ypix"].astype(np.int32)
99+
xpix = parent.stat[nmerge]["xpix"].astype(np.int32)
100+
parent.iROI[i0, 0, ypix, xpix] = nmerge
101+
parent.iExt[i0, 0, ypix, xpix] = nmerge
102+
103+
cols = parent.ops_plot[3]
104+
cols = np.concatenate((cols, np.ones((1,cols.shape[1]))), axis=0)
105+
parent.ops_plot[3] = cols
106+
print(cols[nmerge,:])
107+
for c in range(cols.shape[1]):
108+
for k in range(5):
109+
if k<3 or k==4:
110+
H = cols[parent.iROI[i0,0,ypix,xpix],c]
111+
S = parent.Sroi[i0,ypix,xpix]
112+
else:
113+
H = cols[parent.iExt[i0,0,ypix,xpix],c]
114+
S = parent.Sext[i0,ypix,xpix]
115+
if k==0:
116+
V = np.maximum(0, np.minimum(1, 0.75*parent.Lam[i0,0,ypix,xpix]/parent.LamMean))
117+
elif k==1 or k==2 or k==4:
118+
V = parent.Vback[k-1,ypix,xpix]
119+
S = np.maximum(0, np.minimum(1, 1.5*0.75*parent.Lam[i0,0,ypix,xpix]/parent.LamMean))
120+
elif k==3:
121+
V = parent.Vback[k-1,ypix,xpix]
122+
V = np.minimum(1, V + S)
123+
H = np.expand_dims(H.flatten(),axis=1)
124+
S = np.expand_dims(S.flatten(),axis=1)
125+
V = np.expand_dims(V.flatten(),axis=1)
126+
hsv = np.concatenate((H,S,V),axis=1)
127+
parent.RGBall[i0,c,k,ypix,xpix,:] = hsv_to_rgb(hsv)

0 commit comments

Comments
 (0)