updated figure captions

This commit is contained in:
2025-05-22 19:03:41 +02:00
parent ee2b8f98b7
commit 3e07684093
12 changed files with 142 additions and 95 deletions

View File

@@ -3,6 +3,7 @@ import matplotlib.pyplot as plt
from scipy.stats import pearsonr, linregress, gaussian_kde
from thunderlab.tabledata import TableData
from pathlib import Path
from spectral import whitenoise, diag_projection, peakedness
from plotstyle import plot_style, labels_params, significance_str
@@ -23,24 +24,24 @@ def sort_files(cell_name, all_files, n):
return files, nums
def plot_chi2(ax, s, data_file):
def plot_chi2(ax, s, data_file, rate):
fcutoff = 300
data = np.load(data_file)
n = data['n']
alpha = data['alpha']
freqs = data['freqs']
pss = data['pss']
dt_fix = 1 # 0.0005
prss = np.abs(data['prss'])/dt_fix*0.5/np.sqrt(pss.reshape(1, -1)*pss.reshape(-1, 1))
chi2 = np.abs(data['prss'])*0.5/np.sqrt(pss.reshape(1, -1)*pss.reshape(-1, 1))
ax.set_visible(True)
ax.set_aspect('equal')
i0 = np.argmin(freqs < -300)
i0 = np.argmin(freqs < -fcutoff)
i0 = np.argmin(freqs < 0)
i1 = np.argmax(freqs > 300)
i1 = np.argmax(freqs > fcutoff)
if i1 == 0:
i1 = len(freqs)
freqs = freqs[i0:i1]
prss = prss[i0:i1, i0:i1]
vmax = np.quantile(prss, 0.996)
chi2 = chi2[i0:i1, i0:i1]
vmax = np.quantile(chi2, 0.996)
ten = 10**np.floor(np.log10(vmax))
for fac, delta in zip([1, 2, 3, 4, 6, 8, 10],
[0.5, 1, 1, 2, 3, 4, 5]):
@@ -48,19 +49,23 @@ def plot_chi2(ax, s, data_file):
vmax = fac*ten
ten *= delta
break
pc = ax.pcolormesh(freqs, freqs, prss, vmin=0, vmax=vmax,
pc = ax.pcolormesh(freqs, freqs, chi2, vmin=0, vmax=vmax,
rasterized=True)
ns = f'$N={n}$' if n <= 100 else f'$N=10^{np.log10(n):.0f}$'
if 'noise_frac' in data:
ax.set_title(f'$c$=0\\,\\%, {ns}', fontsize='medium')
else:
ax.set_title(f'$c$={100*alpha:g}\\,\\%, {ns}', fontsize='medium')
ax.set_xlim(0, 300)
ax.set_ylim(0, 300)
ax.set_xlim(0, fcutoff)
ax.set_ylim(0, fcutoff)
ax.set_xticks_delta(100)
ax.set_yticks_delta(100)
ax.set_xlabel('$f_1$', 'Hz')
ax.set_ylabel('$f_2$', 'Hz')
dfreqs, diag = diag_projection(freqs, chi2, 2*fcutoff)
nli, nlif = peakedness(dfreqs, diag, rate, median=False)
ax.text(0.95, 0.88, f'SI($r$)={nli:.1f}', ha='right', zorder=50,
color='white', fontsize='medium', transform=ax.transAxes)
cax = ax.inset_axes([1.04, 0, 0.05, 1])
cax.set_spines_outward('lrbt', 0)
if alpha == 0.1:
@@ -73,16 +78,20 @@ def plot_chi2(ax, s, data_file):
def plot_chi2_contrasts(axs, s, cell_name, n=None):
print(f' {cell_name}')
d = sims_path / f'baseline-{cell_name}.npz'
data = np.load(d)
rate = float(data['rate'])
cv = float(data['cv'])
print(f' {cell_name}: r={rate:3.0f}Hz, CV={cv:4.2f}')
files, nums = sort_files(cell_name,
sims_path.glob(f'chi2-split-{cell_name}-*.npz'), 1)
idx = -1 if n is None else nums.index(n)
plot_chi2(axs[0], s, files[idx])
plot_chi2(axs[0], s, files[idx], rate)
for k, alphastr in enumerate(['010', '030', '100']):
files, nums = sort_files(cell_name,
sims_path.glob(f'chi2-noisen-{cell_name}-{alphastr}-*.npz'), 2)
idx = -1 if n is None else nums.index(n)
plot_chi2(axs[k + 1], s, files[idx])
plot_chi2(axs[k + 1], s, files[idx], rate)
def plot_nli_diags(ax, s, data, alphax, alphay, xthresh, ythresh, cell_name):
@@ -176,27 +185,28 @@ def plot_summary_diags(axs, s, xthresh, ythresh, cell_name):
if __name__ == '__main__':
nsmall = 100
xthresh = 1.2
ythresh = 1.8
s = plot_style()
fig, axs = plt.subplots(6, 4, cmsize=(s.plot_width, 0.85*s.plot_width),
fig, axs = plt.subplots(4, 4, cmsize=(s.plot_width, 0.85*s.plot_width),
height_ratios=[1, 1, 0, 1, 0, 1])
fig.subplots_adjust(leftm=7, rightm=9, topm=2, bottomm=4,
wspace=1, hspace=1)
wspace=1, hspace=0.8)
for ax in axs.flat:
ax.set_visible(False)
print('Example cells:')
plot_chi2_contrasts(axs[0], s, model_cell)
plot_chi2_contrasts(axs[1], s, model_cell, 10)
plot_chi2_contrasts(axs[1], s, model_cell, nsmall)
for k in range(2):
fig.common_yticks(axs[k, :])
for k in range(4):
fig.common_xticks(axs[:2, k])
print()
plot_summary_contrasts(axs[3], s, xthresh, ythresh, model_cell)
plot_summary_diags(axs[5], s, xthresh, ythresh, model_cell)
plot_summary_contrasts(axs[2], s, xthresh, ythresh, model_cell)
plot_summary_diags(axs[3], s, xthresh, ythresh, model_cell)
fig.common_yticks(axs[2, 1:])
fig.common_yticks(axs[3, 1:])
fig.common_yticks(axs[5, 1:])
fig.tag(axs, xoffs=-4.5, yoffs=1.8)
axs[1, 0].set_visible(False)
fig.savefig()