updated regimes figure

This commit is contained in:
2025-05-16 09:22:34 +02:00
parent 9510b8bbe5
commit 273b7a04ae
3 changed files with 257 additions and 18 deletions

View File

@@ -1,12 +1,16 @@
import os
import numpy as np
from scipy.stats import linregress
import matplotlib.pyplot as plt
from pathlib import Path
from scipy.stats import linregress
from numba import jit
from thunderlab.tabledata import TableData
from plotstyle import plot_style, lighter, darker
data_path = Path('data')
cell_path = data_path / 'cells'
def load_models(file):
""" Load model parameter from csv file.
@@ -21,7 +25,7 @@ def load_models(file):
For each cell a dictionary with model parameters.
"""
parameters = []
with open(file, 'r') as file:
with file.open('r') as file:
header_line = file.readline()
header_parts = header_line.strip().split(",")
keys = header_parts
@@ -192,9 +196,12 @@ def peak_ampl(freqs, psd, f):
def compute_peaks(name, cell, alpha_max, beatf1, beatf2, nfft, trials):
file_name = f'{name}-contrastpeaks.csv'
if os.path.exists(file_name):
data = TableData(file_name)
data_file = cell_path / f'{name}-contrastpeaks.csv'
data = TableData(data_file)
return data
"""
if data_file.exists():
data = TableData(data_file)
return data
dt = 0.0001
tmax = nfft*dt
@@ -217,9 +224,9 @@ def compute_peaks(name, cell, alpha_max, beatf1, beatf2, nfft, trials):
data.append('f2', 'Hz', '%g', ampl_f2)
data.append('f1+f2', 'Hz', '%g', ampl_sum)
data.append('f2-f1', 'Hz', '%g', ampl_diff)
data.write(file_name)
data.write(data_file)
return data
"""
def amplitude(power):
power -= power[0]
@@ -281,23 +288,14 @@ def plot_peaks(ax, s, data, alphas):
if __name__ == '__main__':
parameters = load_models('models.csv')
parameters = load_models(data_path / 'punitmodels.csv')
cell_name = '2013-01-08-aa-invivo-1' # 138Hz, CV=0.26: perfect!
beatf1 = 40
beatf2 = 138
# cell_name = '2012-07-03-ak-invivo-1' # 128Hz, CV=0.24
# cell_name = '2018-05-08-ae-invivo-1' # 142Hz, CV=0.48
"""
parameters = load_models('models_big_fit_d_right.csv')
cell_name = '2013-01-08-aa-invivo-1' # 131Hz, CV=0.04: wrong!
beatf1 = 30
beatf2 = 132
"""
cell = cell_parameters(parameters, cell_name)
for k in cell:
print(k, cell[k])
s = plot_style()
s.lwmid = 1.0