MHKiT-MATLAB
MHKiT-MATLAB copied to clipboard
Bug in `environmental_contours_example.mlx` due to `spectra_to_pandas` return variable
Description:
The environmental_contours_example.mlx script relies on the energy_period.m and significant_wave_height.m functions, both of which call the py.mhkit_python_utils.pandas_dataframe.spectra_to_pandas function. There seems to be a bug in this example that causes it to take hours to run.
Steps to Reproduce: 1- Run the environmental_contours_example.mlx script. 2- Observe the execution time. 3- Check the return variable from py.mhkit_python_utils.pandas_dataframe.spectra_to_pandas.
Expected Behavior: The script should execute within a reasonable timeframe.
Actual Behavior: The script takes hours to complete execution due to an issue related to the spectra_to_pandas return variable.
@MShabara, thanks for reporting this. I think I have a fix in PR #149 here
The underlying issue is how the NDBC spectra gets converted and passed to python. The linked typecast_spectra_to_mhkit_python is meant to explicitly handle this task and formats the input spectrum, either 2d or 1d into the correct format to create a pd.DataFrame that MHKiT-Python understands.
With the changes in #149 and this snippet below for section 2 I was able computer Hm0 and Te from the NDBC data:
% Get list of year fields
year_fields = fieldnames(ndbc_requested_data);
% Initialize as empty arrays - will grow dynamically
Hm0 = [];
Te = [];
% Process and concatenate each year
for i = 1:length(year_fields)
fprintf('Processing %s\n', year_fields{i});
S = struct();
S.frequency = ndbc_requested_data.(year_fields{i}).frequency;
S.spectrum = ndbc_requested_data.(year_fields{i}).spectrum;
S.type = 'time series';
% Concatenate results horizontally
Hm0 = [Hm0, significant_wave_height(S)];
Te = [Te, energy_period(S)];
end
I plan to revisit #113 and incorporate this change.
LMK if you see any issues with this potential solution.
This code section section is used in a few of the WDRT example notebooks. The specific fixes are linked below:
environmental_contours_exampleextreme_response_contour_exampleextreme_response_full_sea_state_example
These fixes will be included in the upcoming v0.6.0 release. @MShabara LMK if this fix is sufficient.
Closing as complete.