From 887df50f38b4dbd7f513cc295f42c541dceb97f6 Mon Sep 17 00:00:00 2001 From: Diana Date: Wed, 23 Oct 2024 15:24:16 +0200 Subject: [PATCH 1/4] changed all_coming_together --- code/useful_functions.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/code/useful_functions.py b/code/useful_functions.py index 7153e09..c259f2c 100644 --- a/code/useful_functions.py +++ b/code/useful_functions.py @@ -32,7 +32,7 @@ def all_coming_together(freq_array, power_array, points_list, categories, num_ha Returns ------- valid_points : list - A list of valid points with their harmonics. + A continuous list of harmonics for all valid points. color_mapping : dict A dictionary mapping categories to corresponding colors. category_harmonics : dict @@ -40,7 +40,7 @@ def all_coming_together(freq_array, power_array, points_list, categories, num_ha messages : list A list of messages for each point, stating whether it was valid or not. """ - valid_points = [] + valid_points = [] # A continuous list of harmonics for valid points color_mapping = {} category_harmonics = {} messages = [] @@ -58,7 +58,7 @@ def all_coming_together(freq_array, power_array, points_list, categories, num_ha if valid: # Step 3: Prepare harmonics if the point is valid harmonics, color_map, category_harm = prepare_harmonic(point, category, num_harmonics, color) - valid_points.append((point, harmonics)) + valid_points.extend(harmonics) # Use extend() to append harmonics in a continuous manner color_mapping.update(color_map) category_harmonics.update(category_harm) messages.append(f"The point {point} is valid.") @@ -67,6 +67,8 @@ def all_coming_together(freq_array, power_array, points_list, categories, num_ha return valid_points, color_mapping, category_harmonics, messages + + def AM(EODf, stimulus): """ Calculates the Amplitude Modulation and Nyquist frequency @@ -426,7 +428,7 @@ def spike_times(stim): return spikes, stim_dur, dt # se changed spike_times to spikes so its not the same as name of function -def valid_integrals(integral, local_mean, point, threshold = 0.5): +def valid_integrals(integral, local_mean, point, threshold = 0.1): """ Check if the integral exceeds the threshold compared to the local mean and provide feedback on whether the given point is valid or not. From 7ce9c39ae87e7b3958007a1dc2cdb2f1b1533099 Mon Sep 17 00:00:00 2001 From: Diana Date: Wed, 23 Oct 2024 15:29:38 +0200 Subject: [PATCH 2/4] changed all_coming_together --- code/useful_functions.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/code/useful_functions.py b/code/useful_functions.py index 6988861..39ba01e 100644 --- a/code/useful_functions.py +++ b/code/useful_functions.py @@ -427,12 +427,7 @@ def spike_times(stim): dt = ti.sampling_interval return spikes, stim_dur, dt # se changed spike_times to spikes so its not the same as name of function - -<<<<<<< HEAD def valid_integrals(integral, local_mean, point, threshold = 0.1): -======= -def valid_integrals(integral, local_mean, point, threshold = 0.3): ->>>>>>> 3575361af10b14a99959f8aeb1b57a1e08d0446a """ Check if the integral exceeds the threshold compared to the local mean and provide feedback on whether the given point is valid or not. From 0a3a8c59af463359a8b89d926f7aabff3568ec37 Mon Sep 17 00:00:00 2001 From: Diana Date: Wed, 23 Oct 2024 15:31:57 +0200 Subject: [PATCH 3/4] changed all_coming_together --- code/useful_functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/useful_functions.py b/code/useful_functions.py index 39ba01e..edea81b 100644 --- a/code/useful_functions.py +++ b/code/useful_functions.py @@ -275,7 +275,7 @@ def power_spectrum(stimulus): # computes firing rates rate = firing_rate(binary, dt = dt) # creates power spectrum - freq, power = welch(rate, fs = 1/dt, nperseg = 2**16, noverlap = 2**15) + freq, power = welch(binary, fs = 1/dt, nperseg = 2**16, noverlap = 2**15) return freq, power def prepare_harmonic(frequency, category, num_harmonics, color): From 9ea4e23bae3e9b6c0d5cb2defdd7d010644aad61 Mon Sep 17 00:00:00 2001 From: Diana Date: Wed, 23 Oct 2024 15:35:47 +0200 Subject: [PATCH 4/4] changed plotting for integrals --- code/plot_functions.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/code/plot_functions.py b/code/plot_functions.py index 63be604..1f84e19 100644 --- a/code/plot_functions.py +++ b/code/plot_functions.py @@ -72,7 +72,7 @@ functions_path = r"C:\Users\diana\OneDrive - UT Cloud\Master\GPs\GP1_Grewe\Proje sys.path.append(functions_path) import useful_functions as u -def plot_highlighted_integrals(frequency, power, points, color_mapping, points_categories, delta = 2.5): +def plot_highlighted_integrals(frequency, power, points, color_mapping, points_categories, delta=2.5): """ Plot the power spectrum and highlight integrals that exceed the threshold. @@ -82,12 +82,10 @@ def plot_highlighted_integrals(frequency, power, points, color_mapping, points_c An array of frequencies corresponding to the power values. power : np.array An array of power spectral density values. - exceeding_points : list - A list of harmonic frequencies that exceed the threshold. + points : list + A list of harmonic frequencies to check and highlight. delta : float Half-width of the range for integration around each point. - threshold : float - Threshold value to compare integrals with local mean. color_mapping : dict A dictionary mapping each category to its color. points_categories : dict @@ -111,10 +109,16 @@ def plot_highlighted_integrals(frequency, power, points, color_mapping, points_c if valid: # Define color based on the category of the point color = next((c for cat, c in color_mapping.items() if point in points_categories[cat]), 'gray') + # Shade the region around the point where the integral was calculated ax.axvspan(point - delta, point + delta, color=color, alpha=0.3, label=f'{point:.2f} Hz') - print(f"Integral around {point:.2f} Hz: {integral:.5e}") - + + # Print out point and color + print(f"Integral around {point:.2f} Hz: {integral:.5e}, Color: {color}") + + # Annotate the plot with the point and its color + ax.text(point, max(power) * 0.9, f'{point:.2f}', color=color, fontsize=10, ha='center') + # Define left and right boundaries of adjacent regions left_boundary = frequency[np.where((frequency >= point - 5 * delta) & (frequency < point - delta))[0][0]] right_boundary = frequency[np.where((frequency > point + delta) & (frequency <= point + 5 * delta))[0][-1]] @@ -132,3 +136,4 @@ def plot_highlighted_integrals(frequency, power, points, color_mapping, points_c return fig +