Merge branch 'main' of https://whale.am28.uni-tuebingen.de/git/mbergmann/gpgrewe2024
This commit is contained in:
commit
78af3d05bd
@ -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,9 +109,15 @@ 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]]
|
||||
@ -132,3 +136,4 @@ def plot_highlighted_integrals(frequency, power, points, color_mapping, points_c
|
||||
return fig
|
||||
|
||||
|
||||
|
||||
|
@ -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
|
||||
@ -425,8 +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
|
||||
|
||||
|
||||
def valid_integrals(integral, local_mean, point, threshold = 0.3):
|
||||
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.
|
||||
|
Loading…
Reference in New Issue
Block a user