updated test.py with new functions

This commit is contained in:
mbergmann 2024-10-22 10:15:32 +02:00
parent 51ce9d1178
commit 2401bcbc16

View File

@ -60,18 +60,52 @@ def extract_stim_data(stimulus):
Current EODf. Current EODf.
stim_freq : float stim_freq : float
The total stimulus frequency (EODF+df). The total stimulus frequency (EODF+df).
amp_mod : float
The current amplitude modulation.
ny_freq : float
The current nyquist frequency.
''' '''
# extract metadata # extract metadata
# the stim.name adjusts the first key as it changes with every stimulus # the stim.name adjusts the first key as it changes with every stimulus
amplitude = stim.metadata[stim.name]['Contrast'][0][0] amplitude = stim.metadata[stim.name]['Contrast'][0][0]
df = stim.metadata[stim.name]['DeltaF'][0][0] df = stim.metadata[stim.name]['DeltaF'][0][0]
eodf = stim.metadata[stim.name]['EODf'][0][0] eodf = round(stim.metadata[stim.name]['EODf'][0][0])
stim_freq = stim.metadata[stim.name]['Frequency'][0][0] stim_freq = round(stim.metadata[stim.name]['Frequency'][0][0])
return amplitude, df, eodf, stim_freq # calculates the amplitude modulation
amp_mod, ny_freq = AM(eodf, stim_freq)
return amplitude, df, eodf, stim_freq, amp_mod, ny_freq
def AM(EODf, stimulus):
"""
Calculates the Amplitude Modulation and Nyquist frequency
Parameters
----------
EODf : float or int
The current EODf.
stimulus : float or int
The absolute frequency of the stimulus.
Returns
-------
AM : float
The amplitude modulation resulting from the stimulus.
nyquist : float
The maximum frequency possible to resolve with the EODf.
"""
nyquist = EODf * 0.5
AM = np.mod(stimulus, nyquist)
return AM, nyquist
def remove_poor(files):
good_files =files
print('x')
return good_files
#find example data #find example data
datafolder = "../data" datafolder = "../../data"
example_file = datafolder + "/" + "2024-10-16-ad-invivo-1.nix" example_file = datafolder + "/" + "2024-10-16-ad-invivo-1.nix"
@ -120,6 +154,10 @@ for stim in stims:
freq, power = power_spectrum(rate, dt) freq, power = power_spectrum(rate, dt)
ax2.plot(freq,power) ax2.plot(freq,power)
ax2.set_xlim(0,1000) ax2.set_xlim(0,1000)
plt.close()
if stim == stims[-1]:
amplitude, df, eodf, stim_freq = extract_stim_data(stim)
print(amplitude, df, eodf, stim_freq)
# make an eventplot # make an eventplot
fig = plt.figure(figsize = (5, 3), layout = 'constrained') fig = plt.figure(figsize = (5, 3), layout = 'constrained')