This commit is contained in:
Diana 2024-10-25 17:10:56 +02:00
parent 136e8a380c
commit 447e88b212

View File

@ -3,40 +3,8 @@ import rlxnix as rlx
from scipy.signal import welch
def all_coming_together(freq_array, power_array, points_list, categories, num_harmonics_list, colors, delta=2.5, threshold=0.5):
"""
Process a list of points, calculating integrals, checking validity, and preparing harmonics for valid points.
Parameters
----------
freq_array : np.array
Array of frequencies corresponding to the power values.
power_array : np.array
Array of power spectral density values.
points_list : list
List of harmonic frequency points to process.
categories : list
List of corresponding categories for each point.
num_harmonics_list : list
List of the number of harmonics for each point.
colors : list
List of colors corresponding to each point's category.
delta : float, optional
Radius of the range for integration around each point (default is 2.5).
threshold : float, optional
Threshold value to compare integrals with local mean (default is 0.5).
Returns
-------
valid_points : list
A continuous list of harmonics for all valid points.
color_mapping : dict
A dictionary mapping categories to corresponding colors.
category_harmonics : dict
A mapping of categories to their harmonic frequencies.
messages : list
A list of messages for each point, stating whether it was valid or not.
"""
valid_points = [] # A continuous list of harmonics for valid points
# Initialize dictionaries and lists
valid_points = []
color_mapping = {}
category_harmonics = {}
messages = []
@ -46,21 +14,25 @@ def all_coming_together(freq_array, power_array, points_list, categories, num_ha
num_harmonics = num_harmonics_list[i]
color = colors[i]
# Step 1: Calculate the integral for the point
# Calculate the integral for the point
integral, local_mean = calculate_integral_2(freq_array, power_array, point, delta)
# Step 2: Check if the point is valid
# Check if the point is valid
valid = valid_integrals(integral, local_mean, point, threshold)
if valid:
# Step 3: Prepare harmonics if the point is valid
# Prepare harmonics if the point is valid
harmonics, color_map, category_harm = prepare_harmonic(point, category, num_harmonics, color)
valid_points.extend(harmonics) # Use extend() to append harmonics in a continuous manner
color_mapping.update(color_map)
category_harmonics.update(category_harm)
valid_points.extend(harmonics)
color_mapping[category] = color # Store color for category
category_harmonics[category] = harmonics
messages.append(f"The point {point} is valid.")
else:
messages.append(f"The point {point} is not valid.")
# Debugging print statements
print("Color Mapping:", color_mapping)
print("Category Harmonics:", category_harmonics)
return valid_points, color_mapping, category_harmonics, messages