started to updated example cells to new analysis with the right units
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
import sys
|
||||
sys.path.insert(0, 'ephys') # for analysing data
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from pathlib import Path
|
||||
@@ -13,7 +11,7 @@ example_cell = [['2020-10-27-ag-invivo-1', 0],
|
||||
example_cells = [
|
||||
#['2021-06-18-ae-invivo-1', 3], # 98Hz, 1%, ok
|
||||
['2021-06-18-ae-invivo-1', 2], # 98Hz, 10%, ok
|
||||
['2012-03-30-ah', 2], # 177Hz, 2.5%, 2.0, nice
|
||||
['2012-03-30-ah', 5], # 177Hz, 5%, 2.0, nice
|
||||
##['2012-07-03-ak', 0], # 120Hz, 2.5%, 1.8, broader, the one model cell, nice triangle up to 1%!
|
||||
##['2012-12-20-ac', 0], # 213Hz, 2.5%, 2.1, ok, model cell, weak triangle up to 1%!
|
||||
#['2017-07-18-ai-invivo-1', 1], # 78Hz, 5%, 2.3, weak, nice model cell with clear triangle up to 10%!
|
||||
@@ -51,8 +49,6 @@ def load_noise(path, cell_name, run):
|
||||
contrast = data['contrast']
|
||||
time = data['time']
|
||||
stimulus = data['stimulus']
|
||||
name = str(data['stimulus_name'])
|
||||
fcutoff = float(name.lower().replace('blwn', '').replace('inputarr_', '').replace('gwn', '').split('h')[0])
|
||||
spikes = []
|
||||
for k in range(1000):
|
||||
key = f'spikes_{k:03d}'
|
||||
@@ -62,12 +58,8 @@ def load_noise(path, cell_name, run):
|
||||
return contrast, time, stimulus, spikes
|
||||
|
||||
|
||||
def load_spectra(path, cell_name, run=None):
|
||||
if run is None:
|
||||
data = np.load(cell_name)
|
||||
else:
|
||||
d = list(path.glob(f'{cell_name}-spectral*-s{run:02d}.npz'))
|
||||
data = np.load(d[0])
|
||||
def load_spectra(path, mode, cell_name, run=None):
|
||||
data = np.load(path / f'{cell_name}-spectral-{mode}-s{run:02d}.npz')
|
||||
contrast = float(data['alpha'])
|
||||
fcutoff = float(data['fcutoff'])
|
||||
freqs = data['freqs']
|
||||
@@ -111,18 +103,27 @@ def plot_response_spectrum(ax, s, eodf, rate, freqs, prr):
|
||||
power_db = 10*np.log10(prr/np.max(prr))
|
||||
ax.show_spines('b')
|
||||
mask = freqs < 890
|
||||
ax.plot(freqs[mask], power_db[mask], **s.lsC1)
|
||||
ax.plot(freqs[eod_i], power_db[eod_i] + 2, **s.psFEOD)
|
||||
ax.plot(freqs[rate_i], power_db[rate_i] + 2, **s.psF0)
|
||||
#ax.plot(freqs[mask], power_db[mask], **s.lsC1)
|
||||
#ax.plot(freqs[eod_i], power_db[eod_i] + 2, **s.psFEOD)
|
||||
#ax.plot(freqs[rate_i], power_db[rate_i] + 2, **s.psF0)
|
||||
#ax.set_ylim(-25, 5)
|
||||
ax.plot(freqs[mask], 1e-3*prr[mask], **s.lsC1)
|
||||
ax.plot(freqs[eod_i], 1e-3*prr[eod_i] + 2, **s.psFEOD)
|
||||
ax.plot(freqs[rate_i], 1e-3*prr[rate_i] + 2, **s.psF0)
|
||||
ax.set_ylim(0, 30)
|
||||
ax.set_xlim(0, 900)
|
||||
ax.set_ylim(-25, 5)
|
||||
ax.set_xticks_delta(300)
|
||||
ax.set_xlabel('$f$', 'Hz')
|
||||
ax.text(freqs[eod_i], power_db[eod_i] + 4, '$f_{\\rm EOD}$',
|
||||
#ax.text(freqs[eod_i], power_db[eod_i] + 4, '$f_{\\rm EOD}$',
|
||||
# ha='center')
|
||||
#ax.text(freqs[rate_i], power_db[rate_i] + 4, '$r$',
|
||||
# ha='center')
|
||||
#ax.yscalebar(1.05, 0, 10, 'dB', ha='right')
|
||||
ax.text(freqs[eod_i], 1e-3*prr[eod_i] + 4, '$f_{\\rm EOD}$',
|
||||
ha='center')
|
||||
ax.text(freqs[rate_i], power_db[rate_i] + 4, '$r$',
|
||||
ax.text(freqs[rate_i], 1e-3*prr[rate_i] + 4, '$r$',
|
||||
ha='center')
|
||||
ax.yscalebar(1.05, 0, 10, 'dB', ha='right')
|
||||
ax.yscalebar(1.05, 0, 5, 'kHz', ha='right')
|
||||
|
||||
|
||||
def plot_response(ax, s, eodf, time1, stimulus1, contrast1, spikes1, contrast2, spikes2):
|
||||
@@ -150,30 +151,30 @@ def plot_response(ax, s, eodf, time1, stimulus1, contrast1, spikes1, contrast2,
|
||||
|
||||
|
||||
def plot_gain(ax, s, contrast1, freqs1, gain1, contrast2, freqs2, gain2, fcutoff):
|
||||
ax.plot(freqs2, gain2, label=f'{100*contrast2:.0f}', **s.lsC2)
|
||||
ax.plot(freqs1, gain1, label=f'{100*contrast1:.0f}', **s.lsC1)
|
||||
ax.plot(freqs2, 1e-2*gain2, label=f'{100*contrast2:.0f}', **s.lsC2)
|
||||
ax.plot(freqs1, 1e-2*gain1, label=f'{100*contrast1:.0f}', **s.lsC1)
|
||||
ax.set_xlim(0, fcutoff)
|
||||
ax.set_ylim(0, 800)
|
||||
ax.set_ylim(0, 10)
|
||||
ax.set_xticks_delta(100)
|
||||
ax.set_xlabel('$f$', 'Hz')
|
||||
ax.set_ylabel(r'$|\chi_1|$', 'Hz')
|
||||
ax.set_ylabel(r'$|\chi_1|$', r'Hz/\%')
|
||||
|
||||
|
||||
def plot_colorbar(ax, pc, dc=None):
|
||||
cax = ax.inset_axes([1.04, 0, 0.05, 1])
|
||||
cax.set_spines_outward('lrbt', 0)
|
||||
cb = cax.get_figure().colorbar(pc, cax=cax, label=r'$|\chi_2|$ [kHz]')
|
||||
cb = cax.get_figure().colorbar(pc, cax=cax, label=r'$|\chi_2|$ [Hz/\%$^2$]')
|
||||
cb.outline.set_color('none')
|
||||
cb.outline.set_linewidth(0)
|
||||
if dc is not None:
|
||||
cax.set_yticks_delta(dc)
|
||||
|
||||
|
||||
def plot_chi2(ax, s, contrast, freqs, chi2, fcutoff, vmax):
|
||||
def plot_chi2(ax, s, contrast, freqs, chi2, fcutoff, vmax=None):
|
||||
ax.set_aspect('equal')
|
||||
if vmax is None:
|
||||
vmax = np.quantile(1e-3*chi2, 0.99)
|
||||
pc = ax.pcolormesh(freqs, freqs, 1e-3*chi2, vmin=0, vmax=vmax,
|
||||
vmax = np.quantile(1e-4*chi2, 0.998)
|
||||
pc = ax.pcolormesh(freqs, freqs, 1e-4*chi2, vmin=0, vmax=vmax,
|
||||
rasterized=True, zorder=10)
|
||||
ax.set_xlim(0, fcutoff)
|
||||
ax.set_ylim(0, fcutoff)
|
||||
@@ -200,22 +201,22 @@ def plot_diagonals(ax, s, fbase, contrast1, freqs1, chi21, contrast2, freqs2, ch
|
||||
sifs.append(sif)
|
||||
print(f' SI at {100*contrast:.1f}% contrast: {sinorm:.2f}')
|
||||
#ax.axvline(fbase, **s.lsGrid)
|
||||
ax.plot(diags[1][0], 1e-3*diags[1][1], **s.lsC2)
|
||||
ax.plot(diags[0][0], 1e-3*diags[0][1], **s.lsC1)
|
||||
ax.plot(sifs[1], 1e-3*sips[1], **s.psC2)
|
||||
ax.plot(sifs[0], 1e-3*sips[0], **s.psC1)
|
||||
ax.plot(diags[1][0], 1e-4*diags[1][1], **s.lsC2)
|
||||
ax.plot(diags[0][0], 1e-4*diags[0][1], **s.lsC1)
|
||||
ax.plot(sifs[1], 1e-4*sips[1] + 0.5, clip_on=False, **s.psC2)
|
||||
ax.plot(sifs[0], 1e-4*sips[0] + 0.5, clip_on=False, **s.psC1)
|
||||
ax.set_xlim(0, 2*fcutoff)
|
||||
ax.set_ylim(0, 4.2)
|
||||
ax.set_ylim(0, 14)
|
||||
ax.set_xticks_delta(300)
|
||||
ax.set_yticks_delta(1)
|
||||
ax.set_yticks_delta(4)
|
||||
ax.set_xlabel('$f_1 + f_2$', 'Hz')
|
||||
#ax.set_ylabel(r'$|\chi_2|$', 'kHz')
|
||||
ax.text(sifs[1] - 50, 1e-3*sips[1], f'{100*contrast2:.0f}\\%',
|
||||
#ax.set_ylabel(r'$|\chi_2|$', r'Hz/\%$^2$')
|
||||
ax.text(sifs[1] - 50, 1e-4*sips[1], f'{100*contrast2:.0f}\\%',
|
||||
ha='right')
|
||||
ax.text(sifs[1] + 70, 1e-3*sips[1], f'SI={sis[1]:.1f}')
|
||||
ax.text(sifs[0] - 50, 1e-3*sips[0], f'{100*contrast1:.0f}\\%',
|
||||
ax.text(sifs[1] + 70, 1e-4*sips[1], f'SI={sis[1]:.1f}')
|
||||
ax.text(sifs[0] - 50, 1e-4*sips[0] + 2, f'{100*contrast1:.0f}\\%',
|
||||
ha='right')
|
||||
ax.text(sifs[0] + 70, 1e-3*sips[0], f'SI={sis[0]:.1f}')
|
||||
ax.text(sifs[0] + 70, 1e-4*sips[0] + 2, f'SI={sis[0]:.1f}')
|
||||
#ax.text(fbase, 4.3, '$r$', ha='center')
|
||||
|
||||
|
||||
@@ -237,6 +238,9 @@ if __name__ == '__main__':
|
||||
#exit()
|
||||
"""
|
||||
|
||||
#mode = 'all'
|
||||
mode = '100'
|
||||
|
||||
cell_name = example_cell[0][0]
|
||||
print('Example P-unit:', cell_name)
|
||||
eodf, rate, cv, isis, pdf, freqs, prr = load_baseline(data_path, cell_name)
|
||||
@@ -246,9 +250,9 @@ if __name__ == '__main__':
|
||||
*example_cell[0])
|
||||
contrast2, time2, stimulus2, spikes2 = load_noise(data_path,
|
||||
*example_cell[1])
|
||||
fcutoff1, contrast1, freqs1, gain1, chi21 = load_spectra(data_path,
|
||||
fcutoff1, contrast1, freqs1, gain1, chi21 = load_spectra(data_path, mode,
|
||||
*example_cell[0])
|
||||
fcutoff2, contrast2, freqs2, gain2, chi22 = load_spectra(data_path,
|
||||
fcutoff2, contrast2, freqs2, gain2, chi22 = load_spectra(data_path, mode,
|
||||
*example_cell[1])
|
||||
print(f' contrast1: {100*contrast1:4.1f}% contrast2: {100*contrast2:4.1f}%')
|
||||
print(f' fcutoff1 : {fcutoff1:3.0f}Hz fcutoff2 : {fcutoff2:3.0f}Hz')
|
||||
@@ -279,11 +283,11 @@ if __name__ == '__main__':
|
||||
|
||||
plot_gain(axg, s, contrast1, freqs1, gain1,
|
||||
contrast2, freqs2, gain2, fcutoff1)
|
||||
pc = plot_chi2(axc1, s, contrast2, freqs2, chi22, fcutoff2, 4)
|
||||
pc = plot_chi2(axc1, s, contrast2, freqs2, chi22, fcutoff2, 6)
|
||||
axc1.plot([0, fcutoff2], [0, fcutoff2], zorder=20, **s.lsDiag)
|
||||
axc1.set_title(f'$c$={100*contrast2:g}\\,\\%',
|
||||
fontsize='medium', color=s.cell_color2)
|
||||
pc = plot_chi2(axc2, s, contrast1, freqs1, chi21, fcutoff1, 4)
|
||||
pc = plot_chi2(axc2, s, contrast1, freqs1, chi21, fcutoff1, 6)
|
||||
axc2.set_title(f'$c$={100*contrast1:g}\\,\\%',
|
||||
fontsize='medium', color=s.cell_color1)
|
||||
axc2.plot([0, fcutoff1], [0, fcutoff1], zorder=20, **s.lsDiag)
|
||||
@@ -298,20 +302,19 @@ if __name__ == '__main__':
|
||||
print('Additional example cells:')
|
||||
for k, (cell, run) in enumerate(example_cells):
|
||||
eodf, rate, cv, isis, pdf, _, _ = load_baseline(data_path, cell)
|
||||
fcutoff, contrast, freqs, gain, chi2 = load_spectra(data_path, cell, run)
|
||||
fcutoff, contrast, freqs, gain, chi2 = load_spectra(data_path,
|
||||
mode, cell, run)
|
||||
dfreqs, diag = diag_projection(freqs, chi2, 2*fcutoff)
|
||||
sinorm, sirel, sif = peak_size(dfreqs, diag, rate, median=False)
|
||||
print(f' {cell:<22s}: run={run:2d}, fbase={rate:3.0f}Hz, CV={cv:.2f}, SI={sinorm:3.1f}')
|
||||
plot_isih2(axs[0, k], s, rate, cv, isis, pdf)
|
||||
pc = plot_chi2(axs[1, k], s, contrast, freqs, chi2, fcutoff, 1.0)
|
||||
pc = plot_chi2(axs[1, k], s, contrast, freqs, chi2, fcutoff, 10)
|
||||
axs[1, k].text(0.95, 0.9, f'SI($r$)={sinorm:.1f}', ha='right', zorder=50,
|
||||
color='white', fontsize='medium',
|
||||
transform=axs[1, k].transAxes)
|
||||
axs[0, 0].text(0, 1.6, 'P-units:', transform=axs[0, 0].transAxes,
|
||||
color=s.cell_color1,
|
||||
fontsize='large')
|
||||
#axs[0, -1].text(0.97, -0.45, '5\\,ms', ha='right',
|
||||
# transform=axs[0, -1].transAxes)
|
||||
plot_colorbar(axs[1, -1], pc)
|
||||
fig.common_yticks(axs[1, :])
|
||||
fig.tag([axs[0, :]], xoffs=-3, yoffs=1)
|
||||
|
||||
Reference in New Issue
Block a user