updated figure captions
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from pathlib import Path
|
||||
from spectral import whitenoise
|
||||
from spectral import whitenoise, diag_projection, peakedness
|
||||
from plotstyle import plot_style
|
||||
|
||||
|
||||
@@ -25,10 +25,11 @@ def sort_files(cell_name, all_files, n):
|
||||
return files, nums
|
||||
|
||||
|
||||
def plot_chi2(ax, s, freqs, chi2, nsegs):
|
||||
def plot_chi2(ax, s, freqs, chi2, nsegs, rate):
|
||||
fcutoff = 300
|
||||
ax.set_aspect('equal')
|
||||
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]
|
||||
@@ -45,15 +46,22 @@ def plot_chi2(ax, s, freqs, chi2, nsegs):
|
||||
prev_delta = delta
|
||||
pc = ax.pcolormesh(freqs, freqs, chi2, vmin=0, vmax=vmax,
|
||||
rasterized=True)
|
||||
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')
|
||||
ax.text(1, 1.1, f'$N=10^{{{np.log10(nsegs):.0f}}}$',
|
||||
ha='right', transform=ax.transAxes)
|
||||
|
||||
if nsegs < 10000:
|
||||
ax.text(1, 1.1, f'$N={nsegs}$',
|
||||
ha='right', transform=ax.transAxes)
|
||||
else:
|
||||
ax.text(1, 1.1, f'$N=10^{{{np.log10(nsegs):.0f}}}$',
|
||||
ha='right', transform=ax.transAxes)
|
||||
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)
|
||||
cb = fig.colorbar(pc, cax=cax)
|
||||
@@ -65,6 +73,7 @@ def plot_chi2(ax, s, freqs, chi2, nsegs):
|
||||
|
||||
|
||||
def plot_overn(ax, s, files, nmax=1e6):
|
||||
fcutoff = 300
|
||||
ns = []
|
||||
stats = []
|
||||
for fname in files:
|
||||
@@ -79,7 +88,7 @@ def plot_overn(ax, s, files, nmax=1e6):
|
||||
chi2 = np.abs(data['prss'])/dt_fix*0.5/np.sqrt(pss.reshape(1, -1)*pss.reshape(-1, 1))
|
||||
ns.append(n)
|
||||
i0 = np.argmin(freqs < 0)
|
||||
i1 = np.argmax(freqs > 300)
|
||||
i1 = np.argmax(freqs > fcutoff)
|
||||
if i1 == 0:
|
||||
i1 = len(freqs)
|
||||
chi2 = chi2[i0:i1, i0:i1]
|
||||
@@ -115,7 +124,7 @@ def plot_overn(ax, s, files, nmax=1e6):
|
||||
ax.set_ylabel('$|\\chi_2|$ [Hz]')
|
||||
|
||||
|
||||
def plot_chi2_contrast(ax1, ax2, s, files, nums, nsmall, nlarge):
|
||||
def plot_chi2_contrast(ax1, ax2, s, files, nums, nsmall, nlarge, rate):
|
||||
for ax, n in zip([ax1, ax2], [nsmall, nlarge]):
|
||||
i = nums.index(n)
|
||||
data = np.load(files[i])
|
||||
@@ -124,11 +133,13 @@ def plot_chi2_contrast(ax1, ax2, s, files, nums, nsmall, nlarge):
|
||||
freqs = data['freqs']
|
||||
pss = data['pss']
|
||||
chi2 = np.abs(data['prss'])*0.5/np.sqrt(pss.reshape(1, -1)*pss.reshape(-1, 1))
|
||||
cax = plot_chi2(ax, s, freqs, chi2, n)
|
||||
cax = plot_chi2(ax, s, freqs, chi2, n, rate)
|
||||
cax.set_ylabel('')
|
||||
print(f'Modeled cell {"-".join(files[i].name.split("-")[2:-2])} at {100*alpha:4.1f}% contrast: noise_frac={1:3.1f}, nsegs={n}')
|
||||
print()
|
||||
|
||||
|
||||
def plot_chi2_split(ax1, ax2, s, files, nums, nsmall, nlarge):
|
||||
def plot_chi2_split(ax1, ax2, s, files, nums, nsmall, nlarge, rate):
|
||||
for ax, n in zip([ax1, ax2], [nsmall, nlarge]):
|
||||
i = nums.index(n)
|
||||
data = np.load(files[i])
|
||||
@@ -138,8 +149,10 @@ def plot_chi2_split(ax1, ax2, s, files, nums, nsmall, nlarge):
|
||||
freqs = data['freqs']
|
||||
pss = data['pss']
|
||||
chi2 = np.abs(data['prss'])*0.5/np.sqrt(pss.reshape(1, -1)*pss.reshape(-1, 1))
|
||||
cax = plot_chi2(ax, s, freqs, chi2, n)
|
||||
cax = plot_chi2(ax, s, freqs, chi2, n, rate)
|
||||
cax.set_ylabel('')
|
||||
print(f'Modeled cell {"-".join(files[i].name.split("-")[2:-1])} at {100*alpha:4.1f}% contrast: noise_frac={noise_frac:3.1f}, nsegs={n}')
|
||||
print()
|
||||
return alpha, noise_frac
|
||||
|
||||
|
||||
@@ -152,12 +165,15 @@ def plot_chi2_data(ax, s, cell_name, run):
|
||||
data_file = data_path / f'{cell_name}-spectral-s{run:02d}.npz'
|
||||
data = np.load(data_file)
|
||||
n = data['n']
|
||||
nfft = data['nfft']
|
||||
deltat = data['deltat']
|
||||
alpha = data['alpha']
|
||||
freqs = data['freqs']
|
||||
pss = data['pss']
|
||||
chi2 = np.abs(data['prss'])*0.5/np.sqrt(pss.reshape(1, -1)*pss.reshape(-1, 1))
|
||||
print(f'Measured cell {data_file.name} at {100*alpha:.1f}% contrast: r={ratebase:3.0f}Hz, CV={cvbase:4.2f}')
|
||||
plot_chi2(ax, s, freqs, chi2, n)
|
||||
print(f'Measured cell {"-".join(data_file.name.split("-")[:-2])} at {100*alpha:4.1f}% contrast: r={ratebase:3.0f}Hz, CV={cvbase:4.2f}, dt={1000*deltat:4.2f}ms, nfft={nfft}, win={1000*deltat*nfft:6.1f}ms, nsegs={n}')
|
||||
print()
|
||||
plot_chi2(ax, s, freqs, chi2, n, ratebase)
|
||||
return alpha, ratebase, eodf
|
||||
|
||||
|
||||
@@ -263,7 +279,7 @@ if __name__ == '__main__':
|
||||
files, nums = sort_files(example_cell[0], data_files, 2)
|
||||
axss[1].text(xt, yt, 'P-unit model', fontsize='large',
|
||||
transform=axs[1, 1].transAxes, color=s.model_color1)
|
||||
plot_chi2_contrast(axss[1], axss[2], s, files, nums, nsmall, nlarge)
|
||||
plot_chi2_contrast(axss[1], axss[2], s, files, nums, nsmall, nlarge, ratebase)
|
||||
axr1 = plot_noise_split(axss[0], data_contrast, 0, 1, wtime, wnoise)
|
||||
plot_overn(axss[3], s, files, nmax=1e6)
|
||||
axss[3].legend(loc='lower center', bbox_to_anchor=(0.5, 1.2),
|
||||
@@ -273,7 +289,7 @@ if __name__ == '__main__':
|
||||
axss = axs[2]
|
||||
data_files = sims_path.glob(f'chi2-noisen-{example_cell[0]}-{1000*contrast:03.0f}-*.npz')
|
||||
files, nums = sort_files(example_cell[0], data_files, 2)
|
||||
plot_chi2_contrast(axss[1], axss[2], s, files, nums, nsmall, nlarge)
|
||||
plot_chi2_contrast(axss[1], axss[2], s, files, nums, nsmall, nlarge, ratebase)
|
||||
axr2 = plot_noise_split(axss[0], contrast, 0, 1, wtime, wnoise)
|
||||
plot_overn(axss[3], s, files, nmax=1e6)
|
||||
|
||||
@@ -286,7 +302,7 @@ if __name__ == '__main__':
|
||||
axss[1].text(xt + 0.9, yt, f'(noise split)', fontsize='large',
|
||||
transform=axss[1].transAxes)
|
||||
noise_contrast, noise_frac = plot_chi2_split(axss[1], axss[2], s,
|
||||
files, nums, nsmall, nlarge)
|
||||
files, nums, nsmall, nlarge, ratebase)
|
||||
axr3 = plot_noise_split(axss[0], 0, noise_contrast, noise_frac,
|
||||
wtime, wnoise)
|
||||
plot_overn(axss[3], s, files, nmax=1e6)
|
||||
@@ -303,4 +319,3 @@ if __name__ == '__main__':
|
||||
[axr3] + axs[3, 1:].tolist()],
|
||||
xoffs=[-4.5, 1, 1, -4.5], yoffs=2)
|
||||
fig.savefig()
|
||||
print()
|
||||
|
||||
Reference in New Issue
Block a user