From 2401bcbc16132c252e923fee00a6d696afa7d12a Mon Sep 17 00:00:00 2001 From: mbergmann Date: Tue, 22 Oct 2024 10:15:32 +0200 Subject: [PATCH] updated test.py with new functions --- code/test.py | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/code/test.py b/code/test.py index 32b704e..b407995 100644 --- a/code/test.py +++ b/code/test.py @@ -60,18 +60,52 @@ def extract_stim_data(stimulus): Current EODf. stim_freq : float The total stimulus frequency (EODF+df). + amp_mod : float + The current amplitude modulation. + ny_freq : float + The current nyquist frequency. ''' # extract metadata # the stim.name adjusts the first key as it changes with every stimulus amplitude = stim.metadata[stim.name]['Contrast'][0][0] df = stim.metadata[stim.name]['DeltaF'][0][0] - eodf = stim.metadata[stim.name]['EODf'][0][0] - stim_freq = stim.metadata[stim.name]['Frequency'][0][0] - return amplitude, df, eodf, stim_freq + eodf = round(stim.metadata[stim.name]['EODf'][0][0]) + stim_freq = round(stim.metadata[stim.name]['Frequency'][0][0]) + # 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 -datafolder = "../data" +datafolder = "../../data" example_file = datafolder + "/" + "2024-10-16-ad-invivo-1.nix" @@ -120,6 +154,10 @@ for stim in stims: freq, power = power_spectrum(rate, dt) ax2.plot(freq,power) 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 fig = plt.figure(figsize = (5, 3), layout = 'constrained')