From a537ab81d29b9a16c50b8b06221465e4ccdfec70 Mon Sep 17 00:00:00 2001 From: Pedro Lima Date: Sat, 16 Aug 2025 07:45:18 -0400 Subject: [PATCH] A effient way for profile_formatting function --- ramp/post_process/post_process.py | 42 ++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/ramp/post_process/post_process.py b/ramp/post_process/post_process.py index c0bf98d0..f0060b9f 100644 --- a/ramp/post_process/post_process.py +++ b/ramp/post_process/post_process.py @@ -14,21 +14,39 @@ """ -def Profile_formatting(stoch_profiles): - Profile_avg = np.zeros(1440) - for pr in stoch_profiles: - Profile_avg = Profile_avg + pr - Profile_avg = Profile_avg / len(stoch_profiles) +def Profile_formatting(stoch_profiles, return_kw_list=True): + """ + Some post processing data manipulation. + + Parameters + ----------- + stoch_profiles: numpy 2D array + An array of days with 1440 values for each day + return_kw_list: boolean, optional + if True return a list of np.arrays for Profile_kw else a 2d np.array + + Returns + ------- + profile_avg: numpy array + The average of each minute (1440 values) between days + profile_kw: list if return_kw_list is True, else numpy array + The power expressed in Kilowatts. + Use of return_kw_list in True is DEPRECATED because is inefficient, kept for backward compatibility. + profile_series: numpy array + The flatten version of stoch_profiles - Profile_kW = [] - for kW in stoch_profiles: - Profile_kW.append(kW / 1000) + """ + profile_avg = np.mean(stoch_profiles, axis=0) + + if return_kw_list: + profile_kw = [profile / 1000 for profile in stoch_profiles] + else: + # more efficient + profile_kw = stoch_profiles / 1000 - Profile_series = np.array([]) - for iii in stoch_profiles: - Profile_series = np.append(Profile_series, iii) + profile_series = stoch_profiles.flatten() - return (Profile_avg, Profile_kW, Profile_series) + return profile_avg, profile_kw, profile_series def Profile_cloud_plot(stoch_profiles, stoch_profiles_avg):