This commit is contained in:
mbergmann 2024-10-24 09:15:36 +02:00
commit 78af3d05bd
2 changed files with 18 additions and 12 deletions

View File

@ -82,12 +82,10 @@ def plot_highlighted_integrals(frequency, power, points, color_mapping, points_c
An array of frequencies corresponding to the power values. An array of frequencies corresponding to the power values.
power : np.array power : np.array
An array of power spectral density values. An array of power spectral density values.
exceeding_points : list points : list
A list of harmonic frequencies that exceed the threshold. A list of harmonic frequencies to check and highlight.
delta : float delta : float
Half-width of the range for integration around each point. Half-width of the range for integration around each point.
threshold : float
Threshold value to compare integrals with local mean.
color_mapping : dict color_mapping : dict
A dictionary mapping each category to its color. A dictionary mapping each category to its color.
points_categories : dict points_categories : dict
@ -111,9 +109,15 @@ def plot_highlighted_integrals(frequency, power, points, color_mapping, points_c
if valid: if valid:
# Define color based on the category of the point # 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') 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 # 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') 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 # Define left and right boundaries of adjacent regions
left_boundary = frequency[np.where((frequency >= point - 5 * delta) & (frequency < point - delta))[0][0]] left_boundary = frequency[np.where((frequency >= point - 5 * delta) & (frequency < point - delta))[0][0]]
@ -132,3 +136,4 @@ def plot_highlighted_integrals(frequency, power, points, color_mapping, points_c
return fig return fig

View File

@ -32,7 +32,7 @@ def all_coming_together(freq_array, power_array, points_list, categories, num_ha
Returns Returns
------- -------
valid_points : list valid_points : list
A list of valid points with their harmonics. A continuous list of harmonics for all valid points.
color_mapping : dict color_mapping : dict
A dictionary mapping categories to corresponding colors. A dictionary mapping categories to corresponding colors.
category_harmonics : dict category_harmonics : dict
@ -40,7 +40,7 @@ def all_coming_together(freq_array, power_array, points_list, categories, num_ha
messages : list messages : list
A list of messages for each point, stating whether it was valid or not. 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 = {} color_mapping = {}
category_harmonics = {} category_harmonics = {}
messages = [] messages = []
@ -58,7 +58,7 @@ def all_coming_together(freq_array, power_array, points_list, categories, num_ha
if valid: if valid:
# Step 3: Prepare harmonics if the point is valid # Step 3: Prepare harmonics if the point is valid
harmonics, color_map, category_harm = prepare_harmonic(point, category, num_harmonics, color) 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) color_mapping.update(color_map)
category_harmonics.update(category_harm) category_harmonics.update(category_harm)
messages.append(f"The point {point} is valid.") 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 return valid_points, color_mapping, category_harmonics, messages
def AM(EODf, stimulus): def AM(EODf, stimulus):
""" """
Calculates the Amplitude Modulation and Nyquist frequency Calculates the Amplitude Modulation and Nyquist frequency
@ -425,8 +427,7 @@ def spike_times(stim):
dt = ti.sampling_interval dt = ti.sampling_interval
return spikes, stim_dur, dt # se changed spike_times to spikes so its not the same as name of function 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.1):
def valid_integrals(integral, local_mean, point, threshold = 0.3):
""" """
Check if the integral exceeds the threshold compared to the local mean and Check if the integral exceeds the threshold compared to the local mean and
provide feedback on whether the given point is valid or not. provide feedback on whether the given point is valid or not.