changed example punit
This commit is contained in:
@@ -10,41 +10,30 @@ from plotstyle import plot_style, lighter, significance_str
|
||||
data_path = Path('data')
|
||||
|
||||
|
||||
punit_example = [['2020-10-27-ag-invivo-1', 0],
|
||||
['2020-10-27-ag-invivo-1', 1]]
|
||||
ampul_example = [['2012-05-15-ac', 3],
|
||||
['2012-05-15-ac', 1]]
|
||||
from punitexamplecell import example_cell as punit_example
|
||||
from punitexamplecell import example_cells as punit_examples
|
||||
from ampullaryexamplecell import example_cell as ampul_example
|
||||
from ampullaryexamplecell import example_cells as ampul_examples
|
||||
|
||||
|
||||
def plot_corr(ax, data, xcol, ycol, zcol, zmin, zmax, xpdfmax, cmap, color,
|
||||
nli_thresh, example=[], examples=[]):
|
||||
ax.axhline(nli_thresh, color='k', ls=':', lw=0.5)
|
||||
"""
|
||||
for c in np.unique(data('cell')):
|
||||
xdata = data[data('cell') == c, xcol]
|
||||
ydata = data[data('cell') == c, ycol]
|
||||
contrasts = data[data('cell') == c, 'contrast']
|
||||
idx = np.argsort(contrasts)
|
||||
if len(idx) > 1:
|
||||
ax.plot(xdata[idx], ydata[idx], '-k', alpha=0.2, zorder=10)
|
||||
"""
|
||||
xmax = ax.get_xlim()[1]
|
||||
ymax = ax.get_ylim()[1]
|
||||
mask = (data(xcol) < xmax) & (data(ycol) < ymax)
|
||||
mask = (data[xcol] < xmax) & (data[ycol] < ymax)
|
||||
sc = ax.scatter(data[mask, xcol], data[mask, ycol], c=data[mask, zcol],
|
||||
s=4, marker='o', linewidth=0, edgecolors='none',
|
||||
clip_on=False, cmap=cmap, vmin=zmin, vmax=zmax, zorder=20)
|
||||
if 'stimindex' in data:
|
||||
for cell, run in example:
|
||||
mask = (data('cell') == cell) & (data('stimindex') == run)
|
||||
mask = (data['cell'] == cell) & (data['stimindex'] == run)
|
||||
ax.scatter(data[mask, xcol], data[mask, ycol], c=data[mask, zcol],
|
||||
s=6, marker='^', linewidth=0.5, edgecolors='black',
|
||||
clip_on=False, cmap=cmap, vmin=zmin, vmax=zmax,
|
||||
zorder=20)
|
||||
for cell, run in examples:
|
||||
mask = (data('cell') == cell) & (data('stimindex') == run)
|
||||
mask = (data['cell'] == cell) & (data['stimindex'] == run)
|
||||
ax.scatter(data[mask, xcol], data[mask, ycol], c=data[mask, zcol],
|
||||
s=5, marker='o', linewidth=0.5, edgecolors='black',
|
||||
clip_on=False, cmap=cmap, vmin=zmin, vmax=zmax,
|
||||
@@ -57,7 +46,7 @@ def plot_corr(ax, data, xcol, ycol, zcol, zmin, zmax, xpdfmax, cmap, color,
|
||||
cb.outline.set_color('none')
|
||||
cb.outline.set_linewidth(0)
|
||||
# pdf x-axis:
|
||||
kde = gaussian_kde(data(xcol), 0.02*xmax/np.std(data(xcol), ddof=1))
|
||||
kde = gaussian_kde(data[xcol], 0.02*xmax/np.std(data[xcol], ddof=1))
|
||||
xx = np.linspace(0, ax.get_xlim()[1], 400)
|
||||
pdf = kde(xx)
|
||||
xax = ax.inset_axes([0, 1.05, 1, 0.2])
|
||||
@@ -67,7 +56,7 @@ def plot_corr(ax, data, xcol, ycol, zcol, zmin, zmax, xpdfmax, cmap, color,
|
||||
xax.set_ylim(bottom=0)
|
||||
xax.set_ylim(0, xpdfmax)
|
||||
# pdf y-axis:
|
||||
kde = gaussian_kde(data(ycol), 0.02*ymax/np.std(data(ycol), ddof=1))
|
||||
kde = gaussian_kde(data[ycol], 0.02*ymax/np.std(data[ycol], ddof=1))
|
||||
xx = np.linspace(0, ax.get_ylim()[1], 400)
|
||||
pdf = kde(xx)
|
||||
yax = ax.inset_axes([1.05, 0, 0.2, 1])
|
||||
@@ -77,12 +66,12 @@ def plot_corr(ax, data, xcol, ycol, zcol, zmin, zmax, xpdfmax, cmap, color,
|
||||
yax.set_xlim(left=0)
|
||||
# threshold:
|
||||
if 'cvbase' in xcol:
|
||||
ax.text(xmax, 0.4*ymax, f'{100*np.sum(data(ycol) > nli_thresh)/data.rows():.0f}\\%',
|
||||
ax.text(xmax, 0.4*ymax, f'{100*np.sum(data[ycol] > nli_thresh)/len(data):.0f}\\%',
|
||||
ha='right', va='bottom', fontsize='small')
|
||||
ax.text(xmax, 0.3, f'{100*np.sum(data(ycol) < nli_thresh)/data.rows():.0f}\\%',
|
||||
ax.text(xmax, 0.3, f'{100*np.sum(data[ycol] < nli_thresh)/len(data):.0f}\\%',
|
||||
ha='right', va='center', fontsize='small')
|
||||
# statistics:
|
||||
r, p = pearsonr(data(xcol), data(ycol))
|
||||
r, p = pearsonr(data[xcol], data[ycol])
|
||||
ax.text(1, 0.9, f'$R={r:.2f}$ **', ha='right',
|
||||
transform=ax.transAxes, fontsize='small')
|
||||
#ax.text(1, 0.77, f'{significance_str(p)}', ha='right',
|
||||
@@ -98,14 +87,14 @@ def nli_stats(title, data, column, nli_thresh):
|
||||
print(title)
|
||||
print(f' nli threshold: {nli_thresh:.1f}')
|
||||
nrecs = data.rows()
|
||||
ncells = len(np.unique(data('cell')))
|
||||
ncells = len(np.unique(data['cell']))
|
||||
print(f' cells: {ncells}')
|
||||
print(f' recordings: {nrecs}')
|
||||
hcells = np.unique(data[data(column) > nli_thresh, 'cell'])
|
||||
print(f' high nli cells: n={len(hcells):3d}, {100*len(hcells)/ncells:4.1f}%')
|
||||
print(f' high nli recordings: n={np.sum(data(column) > nli_thresh):3d}, '
|
||||
f'{100*np.sum(data(column) > nli_thresh)/nrecs:4.1f}%')
|
||||
nsegs = data('nsegs')
|
||||
nsegs = data['nsegs']
|
||||
print(f' number of segments: {np.min(nsegs):4.0f} - {np.max(nsegs):4.0f}, median={np.median(nsegs):4.0f}, mean={np.mean(nsegs):4.0f}, std={np.std(nsegs):4.0f}')
|
||||
|
||||
|
||||
@@ -132,14 +121,18 @@ def plot_cvstim_nli_punit(ax, data, ycol, nli_thresh, color):
|
||||
# 'coolwarm', color, nli_thresh,
|
||||
# punit_example, punit_examples)
|
||||
#cax.set_ylabel('Response mod.', 'Hz')
|
||||
#cax = plot_corr(ax, data, 'cvstim', ycol, 'cvbase', 0, 1.5, 2,
|
||||
# 'coolwarm', color, nli_thresh,
|
||||
# punit_example, punit_examples)
|
||||
#cax.set_ylabel('CV$_{\\rm base}$')
|
||||
cax = plot_corr(ax, data, 'cvstim', ycol, 'ratebase', 50, 450, 2,
|
||||
cax = plot_corr(ax, data, 'cvstim', ycol, 'cvbase', 0, 1.5, 2,
|
||||
'coolwarm', color, nli_thresh,
|
||||
punit_example, punit_examples)
|
||||
cax.set_ylabel('$r$', 'Hz')
|
||||
cax.set_ylabel('CV$_{\\rm base}$')
|
||||
#cax = plot_corr(ax, data, 'cvstim', ycol, 'ratebase', 50, 450, 2,
|
||||
# 'coolwarm', color, nli_thresh,
|
||||
# punit_example, punit_examples)
|
||||
#cax.set_ylabel('$r$', 'Hz')
|
||||
#cax = plot_corr(ax, data, 'cvstim', ycol, 'serialcorr1', -0.6, 0, 2,
|
||||
# 'coolwarm', color, nli_thresh,
|
||||
# punit_example, punit_examples)
|
||||
#cax.set_ylabel('$\\rho_1$')
|
||||
|
||||
|
||||
def plot_mod_nli_punit(ax, data, ycol, nli_thresh, color):
|
||||
@@ -178,16 +171,16 @@ def plot_cvstim_nli_ampul(ax, data, ycol, nli_thresh, color):
|
||||
# 'coolwarm', color, nli_thresh,
|
||||
# ampul_example, ampul_examples)
|
||||
#cax.set_ylabel('Response mod.', 'Hz')
|
||||
#cax = plot_corr(ax, data, 'cvstim', ycol, 'cvbase', 0, 0.2, 6,
|
||||
# 'coolwarm', color, nli_thresh,
|
||||
# ampul_example, ampul_examples)
|
||||
#cax.set_ylabel('CV$_{\\rm base}$')
|
||||
#cax.set_yticks_delta(0.1)
|
||||
cax = plot_corr(ax, data, 'cvstim', ycol, 'ratebase', 90, 180, 6,
|
||||
cax = plot_corr(ax, data, 'cvstim', ycol, 'cvbase', 0, 0.2, 6,
|
||||
'coolwarm', color, nli_thresh,
|
||||
ampul_example, ampul_examples)
|
||||
cax.set_ylabel('$r$', 'Hz')
|
||||
cax.set_yticks_delta(30)
|
||||
cax.set_ylabel('CV$_{\\rm base}$')
|
||||
cax.set_yticks_delta(0.1)
|
||||
#cax = plot_corr(ax, data, 'cvstim', ycol, 'ratebase', 90, 180, 6,
|
||||
# 'coolwarm', color, nli_thresh,
|
||||
# ampul_example, ampul_examples)
|
||||
#cax.set_ylabel('$r$', 'Hz')
|
||||
#cax.set_yticks_delta(30)
|
||||
|
||||
|
||||
def plot_mod_nli_ampul(ax, data, ycol, nli_thresh, color):
|
||||
@@ -208,7 +201,7 @@ if __name__ == '__main__':
|
||||
punit_model = TableData(data_path /
|
||||
'Apteronotus_leptorhynchus-Punit-models.csv',
|
||||
sep=';')
|
||||
punit_model = punit_model[punit_model('contrast') > 1e-6, :]
|
||||
punit_model = punit_model[punit_model['contrast'] > 1e-6, :]
|
||||
punit_data = TableData(data_path /
|
||||
'Apteronotus_leptorhynchus-Punit-data.csv',
|
||||
sep=';')
|
||||
@@ -217,23 +210,23 @@ if __name__ == '__main__':
|
||||
sep=';')
|
||||
nli_thresh = 1.8
|
||||
|
||||
u, p = mannwhitneyu(punit_model('cvbase'), punit_data('cvbase'))
|
||||
u, p = mannwhitneyu(punit_model['cvbase'], punit_data['cvbase'])
|
||||
print('CV differs between P-unit models and data:')
|
||||
print(f' U={u:g}, p={p:g}')
|
||||
print(f' median model: {np.median(punit_model("cvbase")):.2f}')
|
||||
print(f' median data: {np.median(punit_data("cvbase")):.2f}')
|
||||
print(f' U={u:g}, p={p:.2g}')
|
||||
print(f' median model: {np.median(punit_model["cvbase"]):.2f}')
|
||||
print(f' median data: {np.median(punit_data["cvbase"]):.2f}')
|
||||
print()
|
||||
u, p = mannwhitneyu(punit_model('respmod2'), punit_data('respmod2'))
|
||||
u, p = mannwhitneyu(punit_model['respmod2'], punit_data['respmod2'])
|
||||
print('Response modulation differs between P-unit models and data:')
|
||||
print(f' U={u:g}, p={p:g}')
|
||||
print(f' median model: {np.median(punit_model("respmod2")):.2f}')
|
||||
print(f' median data: {np.median(punit_data("respmod2")):.2f}')
|
||||
print(f' U={u:g}, p={p:.2g}')
|
||||
print(f' median model: {np.median(punit_model["respmod2"]):.2f}')
|
||||
print(f' median data: {np.median(punit_data["respmod2"]):.2f}')
|
||||
print()
|
||||
u, p = mannwhitneyu(punit_model('dnli100'), punit_data('nli'))
|
||||
u, p = mannwhitneyu(punit_model['dnli100'], punit_data['nli'])
|
||||
print('NLI does not differ between P-unit models and data:')
|
||||
print(f' U={u:g}, p={p:g}')
|
||||
print(f' median model: {np.median(punit_model("dnli100")):.1f}')
|
||||
print(f' median data: {np.median(punit_data("nli")):.1f}')
|
||||
print(f' U={u:g}, p={p:.2g}')
|
||||
print(f' median model: {np.median(punit_model["dnli100"]):.1f}')
|
||||
print(f' median data: {np.median(punit_data["nli"]):.1f}')
|
||||
print()
|
||||
|
||||
s = plot_style()
|
||||
|
||||
Reference in New Issue
Block a user