From 278501b5ab1c5e9d805a50491812715653094860 Mon Sep 17 00:00:00 2001 From: KonstantinChri Date: Sat, 23 Nov 2024 12:29:11 +0100 Subject: [PATCH 1/9] update --- .../{example_NORA.py => example_NORA_full.py} | 0 examples/example_NORA_mini.py | 76 +++++++++++++++++++ 2 files changed, 76 insertions(+) rename examples/{example_NORA.py => example_NORA_full.py} (100%) create mode 100644 examples/example_NORA_mini.py diff --git a/examples/example_NORA.py b/examples/example_NORA_full.py similarity index 100% rename from examples/example_NORA.py rename to examples/example_NORA_full.py diff --git a/examples/example_NORA_mini.py b/examples/example_NORA_mini.py new file mode 100644 index 0000000..fa8d3da --- /dev/null +++ b/examples/example_NORA_mini.py @@ -0,0 +1,76 @@ +from metocean_stats import plots, tables, maps +from metocean_stats.stats.aux_funcs import * +from pathlib import Path +import warnings +warnings.filterwarnings("ignore") + +## For NORA10 data use: +df = readNora10File('../tests/data/NORA_test.txt') +## For NORA3 data use: +#import pandas as pd +#df = pd.read_csv('../tests/data/NORA.csv', comment="#", index_col=0, parse_dates=True) + +folder = Path(__file__).parent / 'output_mini' +if not folder.exists(): + folder.mkdir(parents=True) + +## Map: +#maps.plot_points_on_map(lon=[3.35,3.10], lat=[60.40,60.90],label=['NORA3','NORKYST800'],bathymetry='NORA3',output_file='map.png') +#maps.plot_extreme_wave_map(return_period=100, product='NORA3', title='100-yr return values Hs (NORA3)', set_extent = [0,30,52,73],output_file='wave_100yrs.png') +#maps.plot_extreme_wind_map(return_period=100, product='NORA3',z=10, title='100-yr return values Wind at 100 m (NORA3)', set_extent = [0,30,52,73], output_file='wind_100yrs.png') + +# Wind: +plots.var_rose(df,var_dir='D10',var='W10',method='overall',max_perc=40,decimal_places=1, units='m/s',output_file='output_mini/wind_omni.png') +plots.var_rose(df,var_dir='D10',var='W10',method='monthly',max_perc=40,decimal_places=1, units='m/s',output_file='output_mini/wind_monthly.png') +plots.plot_directional_stats(df,var='W10',step_var=0.1,var_dir='D10',title = '', output_file='output_mini/directional_stats.png') +plots.table_directional_non_exceedance(df,var='W10',step_var=2,var_dir='D10',output_file='output_mini/table_directional_non_exceedance.csv') +plots.plot_monthly_stats(df,var='W10',title = 'Wind Speed at 10 m [m/s]', output_file='output_mini/monthly_stats.png') +tables.table_monthly_non_exceedance(df,var='W10',step_var=2,output_file='output_mini/table_monthly_non_exceedance.csv') +plots.plot_prob_non_exceedance_fitted_3p_weibull(df,var='W10',output_file='output_mini/prob_non_exceedance_fitted_3p_weibull.png') +plots.plot_monthly_return_periods(df,var='W10',periods=[1, 10, 100],distribution='Weibull3P_MOM', units='m/s',output_file='output_mini/W10_monthly_extremes.png') +plots.plot_directional_return_periods(df,var='W10',var_dir='D10',periods=[1, 10, 100],distribution='Weibull3P_MOM', units='m/s',adjustment='NORSOK',output_file='output_mini/W10_dir_extremes_Weibull_norsok.png') +plots.plot_monthly_weather_window(df,var='W10',threshold=10, window_size=12,output_file='output_mini/NORA10_monthly_weather_window4_12_plot.png') +plots.plot_scatter(df,var1='W10',var2='W100',var1_units='m/s',var2_units='m/s', title='Scatter',regression_line=True,qqplot=False,density=True,output_file='output_mini/scatter_plot.png') +plots.plot_multi_diagnostic_return_levels(df, var='HS', periods=[10, 100],threshold=None,output_file='output_mini/plot_diagnostic_return_levels.png') + +# Waves: +plots.plot_prob_non_exceedance_fitted_3p_weibull(df,var='HS',output_file='output_mini/prob_non_exceedance_fitted_3p_weibull.png') +tables.scatter_diagram(df, var1='HS', step_var1=1, var2='TP', step_var2=1, output_file= 'output_mini/Hs_Tp_scatter.csv') +tables.table_var_sorted_by_hs(df, var='TP', var_hs='HS', output_file='output_mini/Tp_sorted_by_Hs.csv') +tables.table_monthly_non_exceedance(df,var='HS',step_var=0.5,output_file='output_mini/Hs_table_monthly_non_exceedance.csv') +plots.plot_monthly_stats(df,var='HS',show=['Maximum','P99','Mean'], title = 'Hs[m]', output_file='output_mini/Hs_monthly_stats.png') +tables.table_directional_non_exceedance(df,var='HS',step_var=0.5,var_dir='DIRM',output_file='output_mini/table_directional_non_exceedance.csv') +plots.plot_directional_stats(df,var='HS',step_var=0.5, var_dir='DIRM', title = '$H_s$[m]', output_file='output_mini/directional_stats.png') +plots.plot_joint_distribution_Hs_Tp(df,var_hs='HS',var_tp='TP',periods=[1,10,100,1000], title='Hs-Tp joint distribution',output_file='output_mini/Hs.Tp.joint.distribution.png',density_plot=True) +tables.table_monthly_joint_distribution_Hs_Tp_param(df,var_hs='HS',var_tp='TP',periods=[1,10,100,10000],output_file='monthly_Hs_Tp_joint_param.csv') +tables.table_directional_joint_distribution_Hs_Tp_param(df,var_hs='HS',var_tp='TP',var_dir='DIRM',periods=[1,10,100],output_file='output_mini/dir_Hs_Tp_joint_param.csv') +plots.plot_monthly_weather_window(df,var='HS',threshold=4, window_size=12,output_file='output_mini/_monthly_weather_window4_12_plot.png') +tables.table_monthly_return_periods(df,var='HS',periods=[1, 10, 100, 10000],distribution='Weibull3P_MOM', units='m',output_file='output_mini/HS_monthly_extremes_Weibull.csv') +tables.table_directional_return_periods(df,var='HS',periods=[1, 10, 100, 10000], units='m',var_dir = 'DIRM',distribution='Weibull3P_MOM', adjustment='NORSOK' ,output_file='output_mini/directional_extremes_weibull.csv') +plots.plot_monthly_return_periods(df,var='HS',periods=[1, 10, 100],distribution='Weibull3P_MOM', units='m',output_file='output_mini/HS_monthly_extremes.png') +plots.plot_directional_return_periods(df,var='HS',var_dir='DIRM',periods=[1, 10, 100, 10000 ],distribution='GUM', units='m',output_file='output_mini/dir_extremes_GUM.png') +plots.plot_directional_return_periods(df,var='HS',var_dir='DIRM',periods=[1, 10, 100, 10000],distribution='Weibull3P_MOM', units='m',adjustment='NORSOK',output_file='output_mini/dir_extremes_Weibull_norsok.png') +tables.table_monthly_joint_distribution_Hs_Tp_return_values(df,var_hs='HS',var_tp='TP',periods=[1,10,100,10000],output_file='output_mini/monthly_Hs_Tp_joint_return_values.csv') +tables.table_directional_joint_distribution_Hs_Tp_return_values(df,var_hs='HS',var_tp='TP',var_dir='DIRM',periods=[1,10,100,1000],adjustment='NORSOK',output_file='output_mini/directional_Hs_Tp_joint_return_values.csv') +tables.table_Hs_Tpl_Tph_return_values(df,var_hs='HS',var_tp='TP',periods=[1,10,100,10000],output_file='output_mini/hs_tpl_tph_return_values.csv') +plots.plot_tp_for_given_hs(df, 'HS', 'TP',output_file='output_mini/tp_for_given_hs.png') +tables.table_tp_for_given_hs(df, 'HS', 'TP',max_hs=20,output_file='output_mini/tp_for_given_hs.csv') +tables.table_tp_for_rv_hs(df, var_hs='HS', var_tp='TP',periods=[1,10,100,10000],output_file='output_mini/tp_for_rv_hs.csv') +tables.table_wave_induced_current(df, var_hs='HS',var_tp='TP',depth=200,ref_depth=200, spectrum = 'JONSWAP',output_file='output_mini/JONSWAP_wave_induced_current_depth200.csv') +tables.table_wave_induced_current(df, var_hs='HS',var_tp='TP',depth=200,ref_depth=200, spectrum = 'TORSEHAUGEN',output_file='output_mini/TORSEHAUGEN_wave_induced_current_depth200.csv') +tables.table_hs_for_given_wind(df, 'HS','W10', bin_width=2, max_wind=42, output_file= 'output_mini/table_perc_hs_for_wind.csv') +plots.plot_hs_for_given_wind(df, 'HS', 'W10',output_file='output_mini/hs_for_given_wind.png') +tables.table_hs_for_rv_wind(df, var_wind='W10', var_hs='HS',periods=[1,10,100,10000],output_file='output_mini/hs_for_rv_wind.csv') +tables.table_Hmax_crest_return_periods(df,var_hs='HS', var_tp='TP', depth=200, periods=[1, 10, 100,10000],sea_state='long-crested',output_file='output_mini/table_Hmax_crest_rp.csv') +tables.table_directional_Hmax_return_periods(df,var_hs='HS', var_tp = 'TP',var_dir='DIRM', periods=[10, 100,10000],adjustment='NORSOK', output_file='output_mini/table_dir_Hmax_return_values.csv') +plots.plot_multi_joint_distribution_Hs_Tp_var3(df,var_hs='HS',var_tp='TP',var3='W10',var3_units='m/s',periods=[100],var3_bin=5,threshold_min=100,output_file='output_mini/Hs.Tp.joint.distribution.multi.binned.var3.png') + + +# Air Temperature: +plots.plot_monthly_return_periods(df,var='T2m',periods=[1, 10, 100],distribution='GUM_L',method='minimum', units='°C',output_file='output_mini/T2m_monthly_extremes_neg.png') +tables.table_monthly_return_periods(df,var='T2m',periods=[1, 10, 100],distribution='GUM_L', method='minimum' ,units='°C',output_file='output_mini/T2m_monthly_extremes_neg.csv') +plots.plot_monthly_return_periods(df,var='T2m',periods=[1, 10, 100],distribution='GUM', method='maximum', units='°C',output_file='output_mini/T2m_monthly_extremes_pos.png') +tables.table_monthly_return_periods(df,var='T2m',periods=[1, 10, 100],distribution='GUM', method='maximum' ,units='°C',output_file='output_mini/T2m_monthly_extremes_pos.csv') +plots.plot_monthly_stats(df,var='T2m',show=['Minimum','Mean','Maximum'], title = 'T2m', output_file='output_mini/T2m_monthly_stats.png') +tables.table_monthly_non_exceedance(df,var='T2m',step_var=0.5,output_file='output_mini/T2m_table_monthly_non_exceedance.csv') + From 9b157d50fc7b69987cff3b1bb10582ff484852a8 Mon Sep 17 00:00:00 2001 From: Konstantinos Christakos <67804784+KonstantinChri@users.noreply.github.com> Date: Sat, 23 Nov 2024 12:36:46 +0100 Subject: [PATCH 2/9] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d6f7f53..fab3a72 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,8 @@ [![Documentation Status](https://readthedocs.org/projects/metocean-stats/badge/?version=latest)](https://metocean-stats.readthedocs.io/en/latest/?badge=latest) ## Purpose 🎯 -Metocean-stats is a tool for comprehensive statistics and visualization of metocean data (wind, waves, ocean currents, tide levels, air and water temperature, sea ice, and more). The tool is also compatible with WEkEO Jupyter Lab, allowing seamless integration and use. +Metocean-stats is a tool for comprehensive statistics and visualization of metocean data (wind, waves, ocean currents, tide levels, air and water temperature, sea ice, and more). The tool is also compatible with WEkEO Jupyter Lab, allowing seamless integration and use. +[metocean-stats in WEkEO](https://docs.google.com/document/d/1uEvG_YZ43eu3vE33Qv9t5Bzd0QAmspKjqjzFLHEkJys/edit?usp=sharing). ![metocean-stats](https://github.com/MET-OM/metocean-stats/blob/main/docs/files/readme_plots.png) From c9437afb08a9ac0b62ac40bbcfb5fb51eb4ac11c Mon Sep 17 00:00:00 2001 From: KonstantinChri Date: Sun, 24 Nov 2024 14:10:23 +0100 Subject: [PATCH 3/9] update --- examples/example_NORA_mini.py | 76 -------------------------- examples/example_NORA_wind_waves.py | 85 +++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 76 deletions(-) delete mode 100644 examples/example_NORA_mini.py create mode 100644 examples/example_NORA_wind_waves.py diff --git a/examples/example_NORA_mini.py b/examples/example_NORA_mini.py deleted file mode 100644 index fa8d3da..0000000 --- a/examples/example_NORA_mini.py +++ /dev/null @@ -1,76 +0,0 @@ -from metocean_stats import plots, tables, maps -from metocean_stats.stats.aux_funcs import * -from pathlib import Path -import warnings -warnings.filterwarnings("ignore") - -## For NORA10 data use: -df = readNora10File('../tests/data/NORA_test.txt') -## For NORA3 data use: -#import pandas as pd -#df = pd.read_csv('../tests/data/NORA.csv', comment="#", index_col=0, parse_dates=True) - -folder = Path(__file__).parent / 'output_mini' -if not folder.exists(): - folder.mkdir(parents=True) - -## Map: -#maps.plot_points_on_map(lon=[3.35,3.10], lat=[60.40,60.90],label=['NORA3','NORKYST800'],bathymetry='NORA3',output_file='map.png') -#maps.plot_extreme_wave_map(return_period=100, product='NORA3', title='100-yr return values Hs (NORA3)', set_extent = [0,30,52,73],output_file='wave_100yrs.png') -#maps.plot_extreme_wind_map(return_period=100, product='NORA3',z=10, title='100-yr return values Wind at 100 m (NORA3)', set_extent = [0,30,52,73], output_file='wind_100yrs.png') - -# Wind: -plots.var_rose(df,var_dir='D10',var='W10',method='overall',max_perc=40,decimal_places=1, units='m/s',output_file='output_mini/wind_omni.png') -plots.var_rose(df,var_dir='D10',var='W10',method='monthly',max_perc=40,decimal_places=1, units='m/s',output_file='output_mini/wind_monthly.png') -plots.plot_directional_stats(df,var='W10',step_var=0.1,var_dir='D10',title = '', output_file='output_mini/directional_stats.png') -plots.table_directional_non_exceedance(df,var='W10',step_var=2,var_dir='D10',output_file='output_mini/table_directional_non_exceedance.csv') -plots.plot_monthly_stats(df,var='W10',title = 'Wind Speed at 10 m [m/s]', output_file='output_mini/monthly_stats.png') -tables.table_monthly_non_exceedance(df,var='W10',step_var=2,output_file='output_mini/table_monthly_non_exceedance.csv') -plots.plot_prob_non_exceedance_fitted_3p_weibull(df,var='W10',output_file='output_mini/prob_non_exceedance_fitted_3p_weibull.png') -plots.plot_monthly_return_periods(df,var='W10',periods=[1, 10, 100],distribution='Weibull3P_MOM', units='m/s',output_file='output_mini/W10_monthly_extremes.png') -plots.plot_directional_return_periods(df,var='W10',var_dir='D10',periods=[1, 10, 100],distribution='Weibull3P_MOM', units='m/s',adjustment='NORSOK',output_file='output_mini/W10_dir_extremes_Weibull_norsok.png') -plots.plot_monthly_weather_window(df,var='W10',threshold=10, window_size=12,output_file='output_mini/NORA10_monthly_weather_window4_12_plot.png') -plots.plot_scatter(df,var1='W10',var2='W100',var1_units='m/s',var2_units='m/s', title='Scatter',regression_line=True,qqplot=False,density=True,output_file='output_mini/scatter_plot.png') -plots.plot_multi_diagnostic_return_levels(df, var='HS', periods=[10, 100],threshold=None,output_file='output_mini/plot_diagnostic_return_levels.png') - -# Waves: -plots.plot_prob_non_exceedance_fitted_3p_weibull(df,var='HS',output_file='output_mini/prob_non_exceedance_fitted_3p_weibull.png') -tables.scatter_diagram(df, var1='HS', step_var1=1, var2='TP', step_var2=1, output_file= 'output_mini/Hs_Tp_scatter.csv') -tables.table_var_sorted_by_hs(df, var='TP', var_hs='HS', output_file='output_mini/Tp_sorted_by_Hs.csv') -tables.table_monthly_non_exceedance(df,var='HS',step_var=0.5,output_file='output_mini/Hs_table_monthly_non_exceedance.csv') -plots.plot_monthly_stats(df,var='HS',show=['Maximum','P99','Mean'], title = 'Hs[m]', output_file='output_mini/Hs_monthly_stats.png') -tables.table_directional_non_exceedance(df,var='HS',step_var=0.5,var_dir='DIRM',output_file='output_mini/table_directional_non_exceedance.csv') -plots.plot_directional_stats(df,var='HS',step_var=0.5, var_dir='DIRM', title = '$H_s$[m]', output_file='output_mini/directional_stats.png') -plots.plot_joint_distribution_Hs_Tp(df,var_hs='HS',var_tp='TP',periods=[1,10,100,1000], title='Hs-Tp joint distribution',output_file='output_mini/Hs.Tp.joint.distribution.png',density_plot=True) -tables.table_monthly_joint_distribution_Hs_Tp_param(df,var_hs='HS',var_tp='TP',periods=[1,10,100,10000],output_file='monthly_Hs_Tp_joint_param.csv') -tables.table_directional_joint_distribution_Hs_Tp_param(df,var_hs='HS',var_tp='TP',var_dir='DIRM',periods=[1,10,100],output_file='output_mini/dir_Hs_Tp_joint_param.csv') -plots.plot_monthly_weather_window(df,var='HS',threshold=4, window_size=12,output_file='output_mini/_monthly_weather_window4_12_plot.png') -tables.table_monthly_return_periods(df,var='HS',periods=[1, 10, 100, 10000],distribution='Weibull3P_MOM', units='m',output_file='output_mini/HS_monthly_extremes_Weibull.csv') -tables.table_directional_return_periods(df,var='HS',periods=[1, 10, 100, 10000], units='m',var_dir = 'DIRM',distribution='Weibull3P_MOM', adjustment='NORSOK' ,output_file='output_mini/directional_extremes_weibull.csv') -plots.plot_monthly_return_periods(df,var='HS',periods=[1, 10, 100],distribution='Weibull3P_MOM', units='m',output_file='output_mini/HS_monthly_extremes.png') -plots.plot_directional_return_periods(df,var='HS',var_dir='DIRM',periods=[1, 10, 100, 10000 ],distribution='GUM', units='m',output_file='output_mini/dir_extremes_GUM.png') -plots.plot_directional_return_periods(df,var='HS',var_dir='DIRM',periods=[1, 10, 100, 10000],distribution='Weibull3P_MOM', units='m',adjustment='NORSOK',output_file='output_mini/dir_extremes_Weibull_norsok.png') -tables.table_monthly_joint_distribution_Hs_Tp_return_values(df,var_hs='HS',var_tp='TP',periods=[1,10,100,10000],output_file='output_mini/monthly_Hs_Tp_joint_return_values.csv') -tables.table_directional_joint_distribution_Hs_Tp_return_values(df,var_hs='HS',var_tp='TP',var_dir='DIRM',periods=[1,10,100,1000],adjustment='NORSOK',output_file='output_mini/directional_Hs_Tp_joint_return_values.csv') -tables.table_Hs_Tpl_Tph_return_values(df,var_hs='HS',var_tp='TP',periods=[1,10,100,10000],output_file='output_mini/hs_tpl_tph_return_values.csv') -plots.plot_tp_for_given_hs(df, 'HS', 'TP',output_file='output_mini/tp_for_given_hs.png') -tables.table_tp_for_given_hs(df, 'HS', 'TP',max_hs=20,output_file='output_mini/tp_for_given_hs.csv') -tables.table_tp_for_rv_hs(df, var_hs='HS', var_tp='TP',periods=[1,10,100,10000],output_file='output_mini/tp_for_rv_hs.csv') -tables.table_wave_induced_current(df, var_hs='HS',var_tp='TP',depth=200,ref_depth=200, spectrum = 'JONSWAP',output_file='output_mini/JONSWAP_wave_induced_current_depth200.csv') -tables.table_wave_induced_current(df, var_hs='HS',var_tp='TP',depth=200,ref_depth=200, spectrum = 'TORSEHAUGEN',output_file='output_mini/TORSEHAUGEN_wave_induced_current_depth200.csv') -tables.table_hs_for_given_wind(df, 'HS','W10', bin_width=2, max_wind=42, output_file= 'output_mini/table_perc_hs_for_wind.csv') -plots.plot_hs_for_given_wind(df, 'HS', 'W10',output_file='output_mini/hs_for_given_wind.png') -tables.table_hs_for_rv_wind(df, var_wind='W10', var_hs='HS',periods=[1,10,100,10000],output_file='output_mini/hs_for_rv_wind.csv') -tables.table_Hmax_crest_return_periods(df,var_hs='HS', var_tp='TP', depth=200, periods=[1, 10, 100,10000],sea_state='long-crested',output_file='output_mini/table_Hmax_crest_rp.csv') -tables.table_directional_Hmax_return_periods(df,var_hs='HS', var_tp = 'TP',var_dir='DIRM', periods=[10, 100,10000],adjustment='NORSOK', output_file='output_mini/table_dir_Hmax_return_values.csv') -plots.plot_multi_joint_distribution_Hs_Tp_var3(df,var_hs='HS',var_tp='TP',var3='W10',var3_units='m/s',periods=[100],var3_bin=5,threshold_min=100,output_file='output_mini/Hs.Tp.joint.distribution.multi.binned.var3.png') - - -# Air Temperature: -plots.plot_monthly_return_periods(df,var='T2m',periods=[1, 10, 100],distribution='GUM_L',method='minimum', units='°C',output_file='output_mini/T2m_monthly_extremes_neg.png') -tables.table_monthly_return_periods(df,var='T2m',periods=[1, 10, 100],distribution='GUM_L', method='minimum' ,units='°C',output_file='output_mini/T2m_monthly_extremes_neg.csv') -plots.plot_monthly_return_periods(df,var='T2m',periods=[1, 10, 100],distribution='GUM', method='maximum', units='°C',output_file='output_mini/T2m_monthly_extremes_pos.png') -tables.table_monthly_return_periods(df,var='T2m',periods=[1, 10, 100],distribution='GUM', method='maximum' ,units='°C',output_file='output_mini/T2m_monthly_extremes_pos.csv') -plots.plot_monthly_stats(df,var='T2m',show=['Minimum','Mean','Maximum'], title = 'T2m', output_file='output_mini/T2m_monthly_stats.png') -tables.table_monthly_non_exceedance(df,var='T2m',step_var=0.5,output_file='output_mini/T2m_table_monthly_non_exceedance.csv') - diff --git a/examples/example_NORA_wind_waves.py b/examples/example_NORA_wind_waves.py new file mode 100644 index 0000000..2c2854c --- /dev/null +++ b/examples/example_NORA_wind_waves.py @@ -0,0 +1,85 @@ +from metocean_stats import plots, tables, maps +from metocean_stats.stats.aux_funcs import * +from pathlib import Path +import warnings +warnings.filterwarnings("ignore") +warnings.simplefilter('ignore', SyntaxWarning) + +# Impot data (e.g., use metocean-api to download metocean data) +## For NORA10 data use: +df = readNora10File('../tests/data/NORA_test.txt') +## For NORA3 data use: +#import pandas as pd +#df = pd.read_csv('../path/to/NORA3.csv', comment="#", index_col=0, parse_dates=True) + +# Define names for each variable in the dataframe (df): +var_wind_dir = 'D10' +var_wind = 'W10' +var_hs = 'HS' +var_wave_dir='DIRM' +var_tp = 'TP' +output_folder = 'output_wind_waves' + + +# Check if the output directory exists, if not, create it +folder = Path(__file__).parent / output_folder +if not folder.exists(): + folder.mkdir(parents=True) + + +# The following code is used to generate various plots and tables for wind and wave data analysis. +# Map: +#maps.plot_points_on_map(lon=[3.35], lat=[60.40],label=['NORA'],bathymetry='NORA3',output_file=output_folder+'/map.png') +#maps.plot_extreme_wave_map(return_period=100, product='NORA3', title='100-yr return values Hs (NORA3)', set_extent = [0,30,52,73],output_file=output_folder+'/wave_100yrs.png') +#maps.plot_extreme_wind_map(return_period=100, product='NORA3',z=10, title='100-yr return values Wind at 100 m (NORA3)', set_extent = [0,30,52,73], output_file=output_folder+'/wind_100yrs.png') + +# Wind: +plots.var_rose(df,var_dir=var_wind_dir,var=var_wind,method='overall',max_perc=40,decimal_places=1, units='m/s',output_file=output_folder+'/wind_omni.png') +plots.var_rose(df,var_dir=var_wind_dir,var=var_wind,method='monthly',max_perc=40,decimal_places=1, units='m/s',output_file=output_folder+'/wind_monthly.png') +plots.plot_directional_stats(df,var=var_wind,step_var=0.1,var_dir='D10',title = '', output_file=output_folder+'/directional_stats.png') +plots.table_directional_non_exceedance(df,var=var_wind,step_var=2,var_dir='D10',output_file=output_folder+'/table_directional_non_exceedance.csv') +plots.plot_monthly_stats(df,var=var_wind,title = 'Wind Speed at 10 m [m/s]', output_file=output_folder+'/monthly_stats.png') +tables.table_monthly_non_exceedance(df,var=var_wind,step_var=2,output_file=output_folder+'/table_monthly_non_exceedance.csv') +plots.plot_prob_non_exceedance_fitted_3p_weibull(df,var=var_wind,output_file=output_folder+'/prob_non_exceedance_fitted_3p_weibull.png') +plots.plot_monthly_return_periods(df,var=var_wind,periods=[1, 10, 100],distribution='Weibull3P_MOM', units='m/s',output_file=output_folder+'/W10_monthly_extremes.png') +plots.plot_directional_return_periods(df,var=var_wind,var_dir='D10',periods=[1, 10, 100],distribution='Weibull3P_MOM', units='m/s',adjustment='NORSOK',output_file=output_folder+'/W10_dir_extremes_Weibull_norsok.png') +plots.plot_monthly_weather_window(df,var=var_wind,threshold=10, window_size=12,output_file=output_folder+'/NORA10_monthly_weather_window4_12_plot.png') +plots.plot_multi_diagnostic_return_levels(df, var=var_wind, dist_list = ['GP', 'Weibull_2P', 'EXP'], periods=np.arange(0.1, 1000, 0.1),threshold=None,output_file=output_folder+'/plot_wind_diagnostic_return_levels.png') + + +# Waves: +plots.plot_multi_diagnostic_return_levels(df, var=var_hs, dist_list = ['GP', 'Weibull_2P', 'EXP'], periods=np.arange(0.1, 1000, 0.1),threshold=None,output_file=output_folder+'/plot_waves_diagnostic_return_levels.png') +plots.plot_prob_non_exceedance_fitted_3p_weibull(df,var=var_hs,output_file=output_folder+'/prob_non_exceedance_fitted_3p_weibull.png') +tables.scatter_diagram(df, var1=var_hs, step_var1=1, var2=var_tp, step_var2=1, output_file= output_folder+'/Hs_Tp_scatter.csv') +tables.table_var_sorted_by_hs(df, var=var_tp, var_hs=var_hs, output_file=output_folder+'/Tp_sorted_by_Hs.csv') +tables.table_monthly_non_exceedance(df,var=var_hs,step_var=0.5,output_file=output_folder+'/Hs_table_monthly_non_exceedance.csv') +plots.plot_monthly_stats(df,var=var_hs,show=['Maximum','P99','Mean'], title = 'Hs[m]', output_file=output_folder+'/Hs_monthly_stats.png') +tables.table_directional_non_exceedance(df,var=var_hs,step_var=0.5,var_dir=var_wave_dir,output_file=output_folder+'/table_directional_non_exceedance.csv') +plots.plot_directional_stats(df,var=var_hs,step_var=0.5, var_dir=var_wave_dir, title = '$H_s$[m]', output_file=output_folder+'/directional_stats.png') +plots.plot_joint_distribution_Hs_Tp(df,var_hs=var_hs,var_tp=var_tp,periods=[1,10,100,1000], title='Hs-Tp joint distribution',output_file=output_folder+'/Hs.Tp.joint.distribution.png',density_plot=True) +tables.table_monthly_joint_distribution_Hs_Tp_param(df,var_hs=var_hs,var_tp=var_tp,periods=[1,10,100,10000],output_file=output_folder+'/monthly_Hs_Tp_joint_param.csv') +tables.table_directional_joint_distribution_Hs_Tp_param(df,var_hs=var_hs,var_tp=var_tp,var_dir=var_wave_dir,periods=[1,10,100],output_file=output_folder+'/dir_Hs_Tp_joint_param.csv') +plots.plot_monthly_weather_window(df,var=var_hs,threshold=4, window_size=12,output_file=output_folder+'/_monthly_weather_window4_12_plot.png') +plots.plot_nb_hours_below_threshold(df,var=var_hs,thr_arr=(np.arange(0.05,20.05,0.05)).tolist(),output_file=output_folder+'/Hs_number_hours_per_year.png') +tables.table_monthly_return_periods(df,var=var_hs,periods=[1, 10, 100, 10000],distribution='Weibull3P_MOM', units='m',output_file=output_folder+'/HS_monthly_extremes_Weibull.csv') +tables.table_directional_return_periods(df,var=var_hs,periods=[1, 10, 100, 10000], units='m',var_dir = var_wave_dir,distribution='Weibull3P_MOM', adjustment='NORSOK' ,output_file=output_folder+'/directional_extremes_weibull.csv') +plots.plot_monthly_return_periods(df,var=var_hs,periods=[1, 10, 100],distribution='Weibull3P_MOM', units='m',output_file=output_folder+'/HS_monthly_extremes.png') +plots.plot_directional_return_periods(df,var=var_hs,var_dir=var_wave_dir,periods=[1, 10, 100, 10000 ],distribution='GUM', units='m',output_file=output_folder+'/dir_extremes_GUM.png') +plots.plot_directional_return_periods(df,var=var_hs,var_dir=var_wave_dir,periods=[1, 10, 100, 10000],distribution='Weibull3P_MOM', units='m',adjustment='NORSOK',output_file=output_folder+'/dir_extremes_Weibull_norsok.png') +tables.table_monthly_joint_distribution_Hs_Tp_return_values(df,var_hs=var_hs,var_tp=var_tp,periods=[1,10,100,10000],output_file=output_folder+'/monthly_Hs_Tp_joint_return_values.csv') +tables.table_directional_joint_distribution_Hs_Tp_return_values(df,var_hs=var_hs,var_tp=var_tp,var_dir=var_wave_dir,periods=[1,10,100,1000],adjustment='NORSOK',output_file=output_folder+'/directional_Hs_Tp_joint_return_values.csv') +tables.table_Hs_Tpl_Tph_return_values(df,var_hs=var_hs,var_tp=var_tp,periods=[1,10,100,10000],output_file=output_folder+'/hs_tpl_tph_return_values.csv') +plots.plot_tp_for_given_hs(df, var_hs, var_tp,output_file=output_folder+'/tp_for_given_hs.png') +tables.table_tp_for_given_hs(df, var_hs, var_tp,max_hs=20,output_file=output_folder+'/tp_for_given_hs.csv') +tables.table_tp_for_rv_hs(df, var_hs=var_hs, var_tp=var_tp,periods=[1,10,100,10000],output_file=output_folder+'/tp_for_rv_hs.csv') +tables.table_wave_induced_current(df, var_hs=var_hs,var_tp=var_tp,depth=200,ref_depth=200, spectrum = 'JONSWAP',output_file=output_folder+'/JONSWAP_wave_induced_current_depth200.csv') +tables.table_wave_induced_current(df, var_hs=var_hs,var_tp=var_tp,depth=200,ref_depth=200, spectrum = 'TORSEHAUGEN',output_file=output_folder+'/TORSEHAUGEN_wave_induced_current_depth200.csv') +tables.table_hs_for_given_wind(df, var_hs,var_wind, bin_width=2, max_wind=42, output_file= output_folder+'/table_perc_hs_for_wind.csv') +plots.plot_hs_for_given_wind(df, var_hs, var_wind,output_file=output_folder+'/hs_for_given_wind.png') +tables.table_hs_for_rv_wind(df, var_wind=var_wind, var_hs=var_hs,periods=[1,10,100,10000],output_file=output_folder+'/hs_for_rv_wind.csv') +tables.table_Hmax_crest_return_periods(df,var_hs=var_hs, var_tp=var_tp, depth=200, periods=[1, 10, 100,10000],sea_state='long-crested',output_file=output_folder+'/table_Hmax_crest_rp.csv') +tables.table_directional_Hmax_return_periods(df,var_hs=var_hs, var_tp = var_tp,var_dir=var_wave_dir, periods=[10, 100,10000],adjustment='NORSOK', output_file=output_folder+'/table_dir_Hmax_return_values.csv') +plots.plot_multi_joint_distribution_Hs_Tp_var3(df,var_hs=var_hs,var_tp=var_tp,var3=var_wind,var3_units='m/s',periods=[100],var3_bin=5,threshold_min=100,output_file=output_folder+'/Hs.Tp.joint.distribution.multi.binned.var3.png') + + + From 78238801b757790b7f73aabc3155d67867a71c34 Mon Sep 17 00:00:00 2001 From: KonstantinChri Date: Sun, 24 Nov 2024 16:58:34 +0100 Subject: [PATCH 4/9] update --- examples/example_NORA_wind_waves.py | 94 ++++++++++++++-------------- examples/example_automatic_report.py | 2 - metocean_stats/stats/general.py | 32 +++++----- metocean_stats/tables/extreme.py | 4 +- metocean_stats/tables/general.py | 22 +++---- 5 files changed, 76 insertions(+), 78 deletions(-) diff --git a/examples/example_NORA_wind_waves.py b/examples/example_NORA_wind_waves.py index 2c2854c..f63e582 100644 --- a/examples/example_NORA_wind_waves.py +++ b/examples/example_NORA_wind_waves.py @@ -3,7 +3,6 @@ from pathlib import Path import warnings warnings.filterwarnings("ignore") -warnings.simplefilter('ignore', SyntaxWarning) # Impot data (e.g., use metocean-api to download metocean data) ## For NORA10 data use: @@ -26,60 +25,59 @@ if not folder.exists(): folder.mkdir(parents=True) - # The following code is used to generate various plots and tables for wind and wave data analysis. # Map: -#maps.plot_points_on_map(lon=[3.35], lat=[60.40],label=['NORA'],bathymetry='NORA3',output_file=output_folder+'/map.png') -#maps.plot_extreme_wave_map(return_period=100, product='NORA3', title='100-yr return values Hs (NORA3)', set_extent = [0,30,52,73],output_file=output_folder+'/wave_100yrs.png') -#maps.plot_extreme_wind_map(return_period=100, product='NORA3',z=10, title='100-yr return values Wind at 100 m (NORA3)', set_extent = [0,30,52,73], output_file=output_folder+'/wind_100yrs.png') +#maps.plot_points_on_map(lon=[3.35], lat=[60.40],label=['NORA'],bathymetry='NORA3',output_file=folder / 'map.png') +#maps.plot_extreme_wave_map(return_period=100, product='NORA3', title='100-yr return values Hs (NORA3)', set_extent = [0,30,52,73],output_file=folder / 'wave_100yrs.png') +#maps.plot_extreme_wind_map(return_period=100, product='NORA3',z=10, title='100-yr return values Wind at 100 m (NORA3)', set_extent = [0,30,52,73], output_file=folder / 'wind_100yrs.png') # Wind: -plots.var_rose(df,var_dir=var_wind_dir,var=var_wind,method='overall',max_perc=40,decimal_places=1, units='m/s',output_file=output_folder+'/wind_omni.png') -plots.var_rose(df,var_dir=var_wind_dir,var=var_wind,method='monthly',max_perc=40,decimal_places=1, units='m/s',output_file=output_folder+'/wind_monthly.png') -plots.plot_directional_stats(df,var=var_wind,step_var=0.1,var_dir='D10',title = '', output_file=output_folder+'/directional_stats.png') -plots.table_directional_non_exceedance(df,var=var_wind,step_var=2,var_dir='D10',output_file=output_folder+'/table_directional_non_exceedance.csv') -plots.plot_monthly_stats(df,var=var_wind,title = 'Wind Speed at 10 m [m/s]', output_file=output_folder+'/monthly_stats.png') -tables.table_monthly_non_exceedance(df,var=var_wind,step_var=2,output_file=output_folder+'/table_monthly_non_exceedance.csv') -plots.plot_prob_non_exceedance_fitted_3p_weibull(df,var=var_wind,output_file=output_folder+'/prob_non_exceedance_fitted_3p_weibull.png') -plots.plot_monthly_return_periods(df,var=var_wind,periods=[1, 10, 100],distribution='Weibull3P_MOM', units='m/s',output_file=output_folder+'/W10_monthly_extremes.png') -plots.plot_directional_return_periods(df,var=var_wind,var_dir='D10',periods=[1, 10, 100],distribution='Weibull3P_MOM', units='m/s',adjustment='NORSOK',output_file=output_folder+'/W10_dir_extremes_Weibull_norsok.png') -plots.plot_monthly_weather_window(df,var=var_wind,threshold=10, window_size=12,output_file=output_folder+'/NORA10_monthly_weather_window4_12_plot.png') -plots.plot_multi_diagnostic_return_levels(df, var=var_wind, dist_list = ['GP', 'Weibull_2P', 'EXP'], periods=np.arange(0.1, 1000, 0.1),threshold=None,output_file=output_folder+'/plot_wind_diagnostic_return_levels.png') +plots.var_rose(df,var_dir=var_wind_dir,var=var_wind,method='overall',max_perc=40,decimal_places=1, units='m/s',output_file=folder / 'wind_omni.png') +plots.var_rose(df,var_dir=var_wind_dir,var=var_wind,method='monthly',max_perc=40,decimal_places=1, units='m/s',output_file=folder / 'wind_monthly.png') +plots.plot_directional_stats(df,var=var_wind,step_var=0.1,var_dir='D10',title = '', output_file=folder / 'directional_wind_stats.png') +plots.table_directional_non_exceedance(df,var=var_wind,step_var=2,var_dir='D10',output_file=folder / 'table_wind_directional_non_exceedance.csv') +plots.plot_monthly_stats(df,var=var_wind,title = 'Wind Speed at 10 m [m/s]', output_file=folder / 'monthly_wind_stats.png') +tables.table_monthly_non_exceedance(df,var=var_wind,step_var=2,output_file=folder / 'table_monthly_non_exceedance.csv') +plots.plot_prob_non_exceedance_fitted_3p_weibull(df,var=var_wind,output_file=folder / 'prob_non_exceedance_fitted_3p_weibull_wind.png') +plots.plot_monthly_return_periods(df,var=var_wind,periods=[1, 10, 100],distribution='Weibull3P_MOM', units='m/s',output_file=folder / 'W10_monthly_extremes.png') +plots.plot_directional_return_periods(df,var=var_wind,var_dir='D10',periods=[1, 10, 100],distribution='Weibull3P_MOM', units='m/s',adjustment='NORSOK',output_file=folder / 'W10_dir_extremes_Weibull_norsok.png') +plots.plot_monthly_weather_window(df,var=var_wind,threshold=10, window_size=12,output_file=folder / 'NORA10_monthly_weather_window_wind_10_12_plot.png') +plots.plot_multi_diagnostic_return_levels(df, var=var_wind, dist_list = ['GP', 'Weibull_2P', 'EXP'], periods=np.arange(0.1, 1000, 0.1),threshold=None,output_file=folder / 'plot_wind_diagnostic_return_levels.png') # Waves: -plots.plot_multi_diagnostic_return_levels(df, var=var_hs, dist_list = ['GP', 'Weibull_2P', 'EXP'], periods=np.arange(0.1, 1000, 0.1),threshold=None,output_file=output_folder+'/plot_waves_diagnostic_return_levels.png') -plots.plot_prob_non_exceedance_fitted_3p_weibull(df,var=var_hs,output_file=output_folder+'/prob_non_exceedance_fitted_3p_weibull.png') -tables.scatter_diagram(df, var1=var_hs, step_var1=1, var2=var_tp, step_var2=1, output_file= output_folder+'/Hs_Tp_scatter.csv') -tables.table_var_sorted_by_hs(df, var=var_tp, var_hs=var_hs, output_file=output_folder+'/Tp_sorted_by_Hs.csv') -tables.table_monthly_non_exceedance(df,var=var_hs,step_var=0.5,output_file=output_folder+'/Hs_table_monthly_non_exceedance.csv') -plots.plot_monthly_stats(df,var=var_hs,show=['Maximum','P99','Mean'], title = 'Hs[m]', output_file=output_folder+'/Hs_monthly_stats.png') -tables.table_directional_non_exceedance(df,var=var_hs,step_var=0.5,var_dir=var_wave_dir,output_file=output_folder+'/table_directional_non_exceedance.csv') -plots.plot_directional_stats(df,var=var_hs,step_var=0.5, var_dir=var_wave_dir, title = '$H_s$[m]', output_file=output_folder+'/directional_stats.png') -plots.plot_joint_distribution_Hs_Tp(df,var_hs=var_hs,var_tp=var_tp,periods=[1,10,100,1000], title='Hs-Tp joint distribution',output_file=output_folder+'/Hs.Tp.joint.distribution.png',density_plot=True) -tables.table_monthly_joint_distribution_Hs_Tp_param(df,var_hs=var_hs,var_tp=var_tp,periods=[1,10,100,10000],output_file=output_folder+'/monthly_Hs_Tp_joint_param.csv') -tables.table_directional_joint_distribution_Hs_Tp_param(df,var_hs=var_hs,var_tp=var_tp,var_dir=var_wave_dir,periods=[1,10,100],output_file=output_folder+'/dir_Hs_Tp_joint_param.csv') -plots.plot_monthly_weather_window(df,var=var_hs,threshold=4, window_size=12,output_file=output_folder+'/_monthly_weather_window4_12_plot.png') -plots.plot_nb_hours_below_threshold(df,var=var_hs,thr_arr=(np.arange(0.05,20.05,0.05)).tolist(),output_file=output_folder+'/Hs_number_hours_per_year.png') -tables.table_monthly_return_periods(df,var=var_hs,periods=[1, 10, 100, 10000],distribution='Weibull3P_MOM', units='m',output_file=output_folder+'/HS_monthly_extremes_Weibull.csv') -tables.table_directional_return_periods(df,var=var_hs,periods=[1, 10, 100, 10000], units='m',var_dir = var_wave_dir,distribution='Weibull3P_MOM', adjustment='NORSOK' ,output_file=output_folder+'/directional_extremes_weibull.csv') -plots.plot_monthly_return_periods(df,var=var_hs,periods=[1, 10, 100],distribution='Weibull3P_MOM', units='m',output_file=output_folder+'/HS_monthly_extremes.png') -plots.plot_directional_return_periods(df,var=var_hs,var_dir=var_wave_dir,periods=[1, 10, 100, 10000 ],distribution='GUM', units='m',output_file=output_folder+'/dir_extremes_GUM.png') -plots.plot_directional_return_periods(df,var=var_hs,var_dir=var_wave_dir,periods=[1, 10, 100, 10000],distribution='Weibull3P_MOM', units='m',adjustment='NORSOK',output_file=output_folder+'/dir_extremes_Weibull_norsok.png') -tables.table_monthly_joint_distribution_Hs_Tp_return_values(df,var_hs=var_hs,var_tp=var_tp,periods=[1,10,100,10000],output_file=output_folder+'/monthly_Hs_Tp_joint_return_values.csv') -tables.table_directional_joint_distribution_Hs_Tp_return_values(df,var_hs=var_hs,var_tp=var_tp,var_dir=var_wave_dir,periods=[1,10,100,1000],adjustment='NORSOK',output_file=output_folder+'/directional_Hs_Tp_joint_return_values.csv') -tables.table_Hs_Tpl_Tph_return_values(df,var_hs=var_hs,var_tp=var_tp,periods=[1,10,100,10000],output_file=output_folder+'/hs_tpl_tph_return_values.csv') -plots.plot_tp_for_given_hs(df, var_hs, var_tp,output_file=output_folder+'/tp_for_given_hs.png') -tables.table_tp_for_given_hs(df, var_hs, var_tp,max_hs=20,output_file=output_folder+'/tp_for_given_hs.csv') -tables.table_tp_for_rv_hs(df, var_hs=var_hs, var_tp=var_tp,periods=[1,10,100,10000],output_file=output_folder+'/tp_for_rv_hs.csv') -tables.table_wave_induced_current(df, var_hs=var_hs,var_tp=var_tp,depth=200,ref_depth=200, spectrum = 'JONSWAP',output_file=output_folder+'/JONSWAP_wave_induced_current_depth200.csv') -tables.table_wave_induced_current(df, var_hs=var_hs,var_tp=var_tp,depth=200,ref_depth=200, spectrum = 'TORSEHAUGEN',output_file=output_folder+'/TORSEHAUGEN_wave_induced_current_depth200.csv') -tables.table_hs_for_given_wind(df, var_hs,var_wind, bin_width=2, max_wind=42, output_file= output_folder+'/table_perc_hs_for_wind.csv') -plots.plot_hs_for_given_wind(df, var_hs, var_wind,output_file=output_folder+'/hs_for_given_wind.png') -tables.table_hs_for_rv_wind(df, var_wind=var_wind, var_hs=var_hs,periods=[1,10,100,10000],output_file=output_folder+'/hs_for_rv_wind.csv') -tables.table_Hmax_crest_return_periods(df,var_hs=var_hs, var_tp=var_tp, depth=200, periods=[1, 10, 100,10000],sea_state='long-crested',output_file=output_folder+'/table_Hmax_crest_rp.csv') -tables.table_directional_Hmax_return_periods(df,var_hs=var_hs, var_tp = var_tp,var_dir=var_wave_dir, periods=[10, 100,10000],adjustment='NORSOK', output_file=output_folder+'/table_dir_Hmax_return_values.csv') -plots.plot_multi_joint_distribution_Hs_Tp_var3(df,var_hs=var_hs,var_tp=var_tp,var3=var_wind,var3_units='m/s',periods=[100],var3_bin=5,threshold_min=100,output_file=output_folder+'/Hs.Tp.joint.distribution.multi.binned.var3.png') +plots.plot_multi_diagnostic_return_levels(df, var=var_hs, dist_list = ['GP', 'Weibull_2P', 'EXP'], periods=np.arange(0.1, 1000, 0.1),threshold=None,output_file=folder / 'plot_waves_diagnostic_return_levels.png') +plots.plot_prob_non_exceedance_fitted_3p_weibull(df,var=var_hs,output_file=folder / 'prob_non_exceedance_fitted_3p_weibull_hs.png') +tables.scatter_diagram(df, var1=var_hs, step_var1=1, var2=var_tp, step_var2=1, output_file= folder / 'Hs_Tp_scatter.csv') +tables.table_var_sorted_by_hs(df, var=var_tp, var_hs=var_hs, output_file=folder / 'Tp_sorted_by_Hs.csv') +tables.table_monthly_non_exceedance(df,var=var_hs,step_var=0.5,output_file=folder / 'Hs_table_monthly_non_exceedance.csv') +plots.plot_monthly_stats(df,var=var_hs,show=['Maximum','P99','Mean'], title = 'Hs[m]', output_file=folder / 'Hs_monthly_stats.png') +tables.table_directional_non_exceedance(df,var=var_hs,step_var=0.5,var_dir=var_wave_dir,output_file=folder / 'Hs_table_directional_non_exceedance.csv') +plots.plot_directional_stats(df,var=var_hs,step_var=0.5, var_dir=var_wave_dir, title = '$H_s$[m]', output_file=folder / 'directional_waves_stats.png') +plots.plot_joint_distribution_Hs_Tp(df,var_hs=var_hs,var_tp=var_tp,periods=[1,10,100,1000], title='Hs-Tp joint distribution',output_file=folder / 'Hs.Tp.joint.distribution.png',density_plot=True) +tables.table_monthly_joint_distribution_Hs_Tp_param(df,var_hs=var_hs,var_tp=var_tp,periods=[1,10,100,10000],output_file=folder / 'monthly_Hs_Tp_joint_param.csv') +tables.table_directional_joint_distribution_Hs_Tp_param(df,var_hs=var_hs,var_tp=var_tp,var_dir=var_wave_dir,periods=[1,10,100],output_file=folder / 'dir_Hs_Tp_joint_param.csv') +plots.plot_monthly_weather_window(df,var=var_hs,threshold=4, window_size=12,output_file=folder / '_monthly_weather_window_Hs_4_12_plot.png') +plots.plot_nb_hours_below_threshold(df,var=var_hs,thr_arr=(np.arange(0.05,20.05,0.05)).tolist(),output_file=folder / 'Hs_number_hours_per_year.png') +tables.table_monthly_return_periods(df,var=var_hs,periods=[1, 10, 100, 10000],distribution='Weibull3P_MOM', units='m',output_file=folder / 'HS_monthly_extremes_Weibull.csv') +tables.table_directional_return_periods(df,var=var_hs,periods=[1, 10, 100, 10000], units='m',var_dir = var_wave_dir,distribution='Weibull3P_MOM', adjustment='NORSOK' ,output_file=folder / 'directional_wave_extremes_weibull.csv') +plots.plot_monthly_return_periods(df,var=var_hs,periods=[1, 10, 100],distribution='Weibull3P_MOM', units='m',output_file=folder / 'HS_monthly_extremes.png') +plots.plot_directional_return_periods(df,var=var_hs,var_dir=var_wave_dir,periods=[1, 10, 100, 10000 ],distribution='GUM', units='m',output_file=folder / 'dir_extremes_GUM.png') +plots.plot_directional_return_periods(df,var=var_hs,var_dir=var_wave_dir,periods=[1, 10, 100, 10000],distribution='Weibull3P_MOM', units='m',adjustment='NORSOK',output_file=folder / 'dir_extremes_wave_Weibull_norsok.png') +tables.table_monthly_joint_distribution_Hs_Tp_return_values(df,var_hs=var_hs,var_tp=var_tp,periods=[1,10,100,10000],output_file=folder / 'monthly_Hs_Tp_joint_return_values.csv') +tables.table_directional_joint_distribution_Hs_Tp_return_values(df,var_hs=var_hs,var_tp=var_tp,var_dir=var_wave_dir,periods=[1,10,100,1000],adjustment='NORSOK',output_file=folder / 'directional_Hs_Tp_joint_return_values.csv') +tables.table_Hs_Tpl_Tph_return_values(df,var_hs=var_hs,var_tp=var_tp,periods=[1,10,100,10000],output_file=folder / 'hs_tpl_tph_return_values.csv') +plots.plot_tp_for_given_hs(df, var_hs, var_tp,output_file=folder / 'tp_for_given_hs.png') +tables.table_tp_for_given_hs(df, var_hs, var_tp,max_hs=20,output_file=folder / 'tp_for_given_hs.csv') +tables.table_tp_for_rv_hs(df, var_hs=var_hs, var_tp=var_tp,periods=[1,10,100,10000],output_file=folder / 'tp_for_rv_hs.csv') +tables.table_wave_induced_current(df, var_hs=var_hs,var_tp=var_tp,depth=200,ref_depth=200, spectrum = 'JONSWAP',output_file=folder / 'JONSWAP_wave_induced_current_depth200.csv') +tables.table_wave_induced_current(df, var_hs=var_hs,var_tp=var_tp,depth=200,ref_depth=200, spectrum = 'TORSEHAUGEN',output_file=folder / 'TORSEHAUGEN_wave_induced_current_depth200.csv') +tables.table_hs_for_given_wind(df, var_hs,var_wind, bin_width=2, max_wind=42, output_file= folder / 'table_perc_hs_for_wind.csv') +plots.plot_hs_for_given_wind(df, var_hs, var_wind,output_file=folder / 'hs_for_given_wind.png') +tables.table_hs_for_rv_wind(df, var_wind=var_wind, var_hs=var_hs,periods=[1,10,100,10000],output_file=folder / 'hs_for_rv_wind.csv') +tables.table_Hmax_crest_return_periods(df,var_hs=var_hs, var_tp=var_tp, depth=200, periods=[1, 10, 100,10000],sea_state='long-crested',output_file=folder / 'table_Hmax_crest_rp.csv') +tables.table_directional_Hmax_return_periods(df,var_hs=var_hs, var_tp = var_tp,var_dir=var_wave_dir, periods=[10, 100,10000],adjustment='NORSOK', output_file=folder / 'table_dir_Hmax_return_values.csv') +plots.plot_multi_joint_distribution_Hs_Tp_var3(df,var_hs=var_hs,var_tp=var_tp,var3=var_wind,var3_units='m/s',periods=[100],var3_bin=5,threshold_min=100,output_file=folder / 'Hs.Tp.joint.distribution.multi.binned.var3.png') diff --git a/examples/example_automatic_report.py b/examples/example_automatic_report.py index f6f7729..59c56b4 100644 --- a/examples/example_automatic_report.py +++ b/examples/example_automatic_report.py @@ -12,9 +12,7 @@ import lxml.etree as ET from docx.enum.section import WD_ORIENTATION, WD_SECTION, WD_ORIENT import warnings - warnings.filterwarnings("ignore") -warnings.simplefilter('ignore', SyntaxWarning) # relative path from file to example data relative_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..","tests","data","NORA_test.txt") diff --git a/metocean_stats/stats/general.py b/metocean_stats/stats/general.py index 757c576..94ef0a3 100644 --- a/metocean_stats/stats/general.py +++ b/metocean_stats/stats/general.py @@ -127,9 +127,9 @@ def table_var_sorted_by_hs(data, var, var_hs='hs', output_file='var_sorted_by_Hs with open(temp_file, 'w') as f: f.write('\\begin{tabular}{l p{1.5cm}|p{1.5cm} p{1.5cm} p{1.5cm} p{1.5cm} p{1.5cm}}' + '\n') - f.write('& & \multicolumn{5}{c}{'+var+'} \\\\' + '\n') - f.write('Hs & Entries & Min & 5\% & Mean & 95\% & Max \\\\' + '\n') - f.write('\hline' + '\n') + f.write(r'& & \multicolumn{5}{c}{'+var+'} \\\\' + '\n') + f.write(r'Hs & Entries & Min & 5\% & Mean & 95\% & Max \\\\' + '\n') + f.write(r'\hline' + '\n') for j in range(len(binsHs)-1) : Var_binsHs_temp = Var_binsHs[str(int(binsHs[j]))+'-'+str(int(binsHs[j+1]))] @@ -154,8 +154,8 @@ def table_var_sorted_by_hs(data, var, var_hs='hs', output_file='var_sorted_by_Hs hs_bin_temp = str(int(binsHs[0]))+'-'+str(int(binsHs[-1]+1)) # +1 for one empty row f.write(hs_bin_temp + ' & '+str(len(Var))+' & '+str(Var_min)+' & '+str(Var_P5)+' & '+str(Var_mean)+' & '+str(Var_P95)+' & '+str(Var_max)+' \\\\' + '\n') - f.write('\hline' + '\n') - f.write('\end{tabular}' + '\n') + f.write(r'\hline' + '\n') + f.write(r'\end{tabular}' + '\n') if output_file.split('.')[1] == 'csv': convert_latexTab_to_csv(temp_file, output_file) @@ -196,10 +196,10 @@ def table_monthly_percentile(data,var,output_file='var_monthly_percentile.txt'): with open(temp_file, 'w') as f: - f.write('\\begin{tabular}{l | p{1.5cm} p{1.5cm} p{1.5cm} p{1.5cm} p{1.5cm}}' + '\n') - f.write('& \multicolumn{5}{c}{' + varName + '} \\\\' + '\n') - f.write('Month & 5\% & 50\% & Mean & 95\% & 99\% \\\\' + '\n') - f.write('\hline' + '\n') + f.write(r'\\begin{tabular}{l | p{1.5cm} p{1.5cm} p{1.5cm} p{1.5cm} p{1.5cm}}' + '\n') + f.write(r'& \multicolumn{5}{c}{' + varName + '} \\\\' + '\n') + f.write(r'Month & 5\% & 50\% & Mean & 95\% & 99\% \\\\' + '\n') + f.write(r'\hline' + '\n') for j in range(len(months)) : Var_P5 = round(np.percentile(monthlyVar[months[j]],5),1) @@ -212,8 +212,8 @@ def table_monthly_percentile(data,var,output_file='var_monthly_percentile.txt'): # annual row f.write('Annual & '+str(Var_P5)+' & '+str(Var_P50)+' & '+str(Var_mean)+' & '+str(Var_P95)+' & '+str(Var_P99)+' \\\\' + '\n') - f.write('\hline' + '\n') - f.write('\end{tabular}' + '\n') + f.write(r'\hline' + '\n') + f.write(r'\end{tabular}' + '\n') if output_file.split('.')[1] == 'csv': convert_latexTab_to_csv(temp_file, output_file) @@ -245,9 +245,9 @@ def table_monthly_min_mean_max(data, var,output_file='montly_min_mean_max.txt') maximum = monthly_max.groupby(monthly_max.index.month).max() # max, sort by month with open(temp_file, 'w') as f : - f.write('\\begin{tabular}{l | c c c }' + '\n') - f.write('Month & Minimum & Mean & Maximum \\\\' + '\n') - f.write('\hline' + '\n') + f.write(r'\\begin{tabular}{l | c c c }' + '\n') + f.write(r'Month & Minimum & Mean & Maximum \\\\' + '\n') + f.write(r'\hline' + '\n') for i in range(len(months)): f.write(months[i] + ' & ' + str(minimum.values[i]) + ' & ' + str(round(mean.values[i],1)) + ' & ' + str(maximum.values[i]) + ' \\\\' + '\n') @@ -258,8 +258,8 @@ def table_monthly_min_mean_max(data, var,output_file='montly_min_mean_max.txt') max_year = annual_max.max() f.write('Annual Max. & ' + str(min_year) + ' & ' + str(round(mean_year,1)) + ' & ' + str(max_year) + ' \\\\' + '\n') - f.write('\hline' + '\n') - f.write('\end{tabular}' + '\n') + f.write(r'\hline' + '\n') + f.write(r'\end{tabular}' + '\n') if output_file.split('.')[1] == 'csv': diff --git a/metocean_stats/tables/extreme.py b/metocean_stats/tables/extreme.py index d4331b9..04f6cac 100644 --- a/metocean_stats/tables/extreme.py +++ b/metocean_stats/tables/extreme.py @@ -346,7 +346,9 @@ def table_hs_for_given_wind(data: pd.DataFrame, var_hs: str,var_wind: str, bin_w } df_coeff = pd.DataFrame(table_data) if output_file: - df_coeff.round(3).to_csv(output_file.split('.')[0]+'_coeff.csv',index=False) + output_file_str = str(output_file) + output_file_no_ext = output_file_str.split('.')[0] + df_coeff.round(3).to_csv(output_file_no_ext + '_coeff.csv', index=False) # Create a new dataframe with the results if output_file: diff --git a/metocean_stats/tables/general.py b/metocean_stats/tables/general.py index 5aa1f0e..ea4dacb 100644 --- a/metocean_stats/tables/general.py +++ b/metocean_stats/tables/general.py @@ -66,9 +66,9 @@ def scatter_diagram(data: pd.DataFrame, var1: str, step_var1: float, var2: str, pass dfout = pd.DataFrame(data=np.round(tbl,2), index=rows, columns=cols) - if output_file.split('.')[-1]=='csv': + if output_file.suffix=='csv': dfout.to_csv(output_file,index_label=var1+'/'+var2) - elif output_file.split('.')[-1]=='png': + elif output_file.suffix=='png': hi = sns.heatmap(data=dfout.where(dfout>0), cbar=True, cmap='Blues', fmt=".1f") plt.ylabel(var1) plt.xlabel(var2) @@ -193,10 +193,10 @@ def table_monthly_percentile(data,var,output_file='var_monthly_percentile.txt'): with open(temp_file, 'w') as f: - f.write('\\begin{tabular}{l | p{1.5cm} p{1.5cm} p{1.5cm} p{1.5cm} p{1.5cm}}' + '\n') - f.write('& \multicolumn{5}{c}{' + varName + '} \\\\' + '\n') - f.write('Month & 5\% & 50\% & Mean & 95\% & 99\% \\\\' + '\n') - f.write('\hline' + '\n') + f.write(r'\\begin{tabular}{l | p{1.5cm} p{1.5cm} p{1.5cm} p{1.5cm} p{1.5cm}}' + '\n') + f.write(r'& \multicolumn{5}{c}{' + varName + '} \\\\' + '\n') + f.write(r'Month & 5\% & 50\% & Mean & 95\% & 99\% \\\\' + '\n') + f.write(r'\hline' + '\n') for j in range(len(months)) : Var_P5 = round(np.percentile(monthlyVar[months[j]],5),1) @@ -209,8 +209,8 @@ def table_monthly_percentile(data,var,output_file='var_monthly_percentile.txt'): # annual row f.write('Annual & '+str(Var_P5)+' & '+str(Var_P50)+' & '+str(Var_mean)+' & '+str(Var_P95)+' & '+str(Var_P99)+' \\\\' + '\n') - f.write('\hline' + '\n') - f.write('\end{tabular}' + '\n') + f.write(r'\hline' + '\n') + f.write(r'\end{tabular}' + '\n') if output_file.split('.')[1] == 'csv': convert_latexTab_to_csv(temp_file, output_file) @@ -319,7 +319,7 @@ def table_monthly_min_mean_max(data, var,output_file='montly_min_mean_max.txt') with open(temp_file, 'w') as f : f.write('\\begin{tabular}{l | c c c }' + '\n') f.write('Month & Minimum & Mean & Maximum \\\\' + '\n') - f.write('\hline' + '\n') + f.write(r'\hline' + '\n') for i in range(len(months)): f.write(months[i] + ' & ' + str(minimum.values[i]) + ' & ' + str(round(mean.values[i],1)) + ' & ' + str(maximum.values[i]) + ' \\\\' + '\n') @@ -330,8 +330,8 @@ def table_monthly_min_mean_max(data, var,output_file='montly_min_mean_max.txt') max_year = annual_max.max() f.write('Annual Max. & ' + str(min_year) + ' & ' + str(round(mean_year,1)) + ' & ' + str(max_year) + ' \\\\' + '\n') - f.write('\hline' + '\n') - f.write('\end{tabular}' + '\n') + f.write(r'\hline' + '\n') + f.write(r'\end{tabular}' + '\n') if output_file.split('.')[1] == 'csv': From 63331201c00a8800f9ab90ef8708ba9e168650a8 Mon Sep 17 00:00:00 2001 From: KonstantinChri Date: Sun, 24 Nov 2024 18:40:22 +0100 Subject: [PATCH 5/9] update --- examples/example_NORA_wind_waves.py | 14 +- examples/example_automatic_report.py | 326 ++++++++++++++------------- 2 files changed, 178 insertions(+), 162 deletions(-) diff --git a/examples/example_NORA_wind_waves.py b/examples/example_NORA_wind_waves.py index f63e582..d4e691d 100644 --- a/examples/example_NORA_wind_waves.py +++ b/examples/example_NORA_wind_waves.py @@ -12,12 +12,12 @@ #df = pd.read_csv('../path/to/NORA3.csv', comment="#", index_col=0, parse_dates=True) # Define names for each variable in the dataframe (df): -var_wind_dir = 'D10' -var_wind = 'W10' -var_hs = 'HS' -var_wave_dir='DIRM' -var_tp = 'TP' -output_folder = 'output_wind_waves' +var_wind_dir = 'D10' # for wind direction +var_wind = 'W10' # for wind speed +var_hs = 'HS' # for significant wave height +var_wave_dir= 'DIRM' # Mean wave direction +var_tp = 'TP' # Peak Wave Period +output_folder = 'output_report' # folder where output figures and tables will be saved # Check if the output directory exists, if not, create it @@ -34,7 +34,7 @@ # Wind: plots.var_rose(df,var_dir=var_wind_dir,var=var_wind,method='overall',max_perc=40,decimal_places=1, units='m/s',output_file=folder / 'wind_omni.png') plots.var_rose(df,var_dir=var_wind_dir,var=var_wind,method='monthly',max_perc=40,decimal_places=1, units='m/s',output_file=folder / 'wind_monthly.png') -plots.plot_directional_stats(df,var=var_wind,step_var=0.1,var_dir='D10',title = '', output_file=folder / 'directional_wind_stats.png') +plots.plot_directional_stats(df,var=var_wind,step_var=0.1,var_dir='D10',title = 'W10[m/s]', output_file=folder / 'directional_wind_stats.png') plots.table_directional_non_exceedance(df,var=var_wind,step_var=2,var_dir='D10',output_file=folder / 'table_wind_directional_non_exceedance.csv') plots.plot_monthly_stats(df,var=var_wind,title = 'Wind Speed at 10 m [m/s]', output_file=folder / 'monthly_wind_stats.png') tables.table_monthly_non_exceedance(df,var=var_wind,step_var=2,output_file=folder / 'table_monthly_non_exceedance.csv') diff --git a/examples/example_automatic_report.py b/examples/example_automatic_report.py index 59c56b4..4e7dbe2 100644 --- a/examples/example_automatic_report.py +++ b/examples/example_automatic_report.py @@ -11,16 +11,31 @@ from io import BytesIO import lxml.etree as ET from docx.enum.section import WD_ORIENTATION, WD_SECTION, WD_ORIENT +from pathlib import Path import warnings warnings.filterwarnings("ignore") -# relative path from file to example data -relative_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..","tests","data","NORA_test.txt") - -# Read data -ds = readNora10File(relative_path) -# ds = readNora10File("tests/data/NORA_test.txt") - +# Impot data (e.g., use metocean-api to download metocean data) +## For NORA10 data use: +df = readNora10File('../tests/data/NORA_test.txt') +## For NORA3 data use: +#import pandas as pd +#df = pd.read_csv('../path/to/NORA3.csv', comment="#", index_col=0, parse_dates=True) + +# Define names for each variable in the dataframe (df): +var_wind_dir = 'D10' # for wind direction +var_wind = 'W10' # for wind speed +var_hs = 'HS' # for significant wave height +var_wave_dir= 'DIRM' # Mean wave direction +var_tp = 'TP' # Peak Wave Period +output_folder = 'output_report' # folder where output report and figures will be saved + + +# Check if the output directory exists, if not, create it +folder = Path(__file__).parent / output_folder +if not folder.exists(): + folder.mkdir(parents=True) +folder = str(folder) # Create a new Document doc = Document() @@ -30,8 +45,8 @@ lon = 3 # endre manuelt fra område (lengegrad) lat = 60 # breddegrad label = ['NORA'] # dataset -starttime = str(ds.index[0]) -endtime = str(ds.index[-1]) +starttime = str(df.index[0]) +endtime = str(df.index[-1]) chapter = ["wind", "waves"] # Hvilke del/kap som skal være med i rapporten wave_depth = 100 # tables_in_report = [""] # putter in strings med tabellnavn i raporten @@ -123,7 +138,7 @@ # URL til bildet logo_url = "https://github.com/MET-OM/metocean-stats/raw/main/docs/files/logo.png" # Last ned bildet og lagre det midlertidig lokalt -logo_path = "output/local_logo.png" +logo_path = folder + "/" +"local_logo.png" response = requests.get(logo_url) with open(logo_path, "wb") as file: file.write(response.content) @@ -500,7 +515,7 @@ def add_table_to_doc(doc, df, col_width=50, row_height=0.7, header_text="", head # 1.1 Scope doc.add_heading('1.1 Scope', level=2) doc.add_paragraph( - 'This Metocean Design Basic (MDB) outlines metocean statistics and long-term metocean conditions which ' + 'This Metocean Design Basis (MDB) outlines metocean statistics and long-term metocean conditions which ' 'are applicable for related activities.' ) @@ -541,7 +556,7 @@ def add_table_to_doc(doc, df, col_width=50, row_height=0.7, header_text="", head #__________________________________________________________ # Add the map figure, figure 3.1 -output_file='output/map.png' +output_file=folder + '/' +'map.png' maps.plot_points_on_map(lon,lat,label,bathymetry='NORA3',output_file=output_file) doc.add_picture(output_file, width=Inches(6)) doc.add_heading('Figure 3.1: The figure shows the NORA3 grid points selected for the analysis', level=3) @@ -554,14 +569,14 @@ def add_table_to_doc(doc, df, col_width=50, row_height=0.7, header_text="", head ) doc.add_paragraph() -output_file='output/wind_100yrs.png' +output_file=folder + '/' +'wind_100yrs.png' maps.plot_extreme_wind_map(return_period=100, product='NORA3',z=10, title='100-yr return values Wind at 100 m (NORA3)', set_extent = [0,30,52,73], output_file=output_file) doc.add_picture(output_file, width=Inches(5)) doc.add_heading("Figure 3.2: 100-year return period for wind speed at 10 m in the Nordics based on NORA3 (period: 1991-2020) using Generalized " "Pareto distribution (POT; threshold is the minimum of all annual maxima, method described by [5]).", level=3) doc.add_paragraph() -output_file='output/wave_100yrs.png' +output_file=folder + '/' +'wave_100yrs.png' maps.plot_extreme_wave_map(return_period=100, product='NORA3', title='100-yr return values Hs (NORA3)', set_extent = [0,30,52,73],output_file=output_file) doc.add_picture(output_file, width=Inches(5)) doc.add_heading("Figure 3.3: 100-year return period for significant wave height in the Nordics based on NORA3 (period: 1991-2020) using Gumbel " @@ -580,8 +595,8 @@ def add_table_to_doc(doc, df, col_width=50, row_height=0.7, header_text="", head doc.add_paragraph( f"Wind data are available from the NORA10 hindcast model operated by the Norwegian Meteorological Institute. " f"The data cover the period {starttime} - {endtime}. The sample interval is 3 hours. The NORA10 model has " -"a spatial resolution of 10 km. \n\n" -f"Wind data from grid point position {lat} N, {lon} E (Figure 3.1) is used in the analysis. \n\n" +"a spatial resolution of 10 km. " +f"Wind data from grid point position {lat} N, {lon} E (Figure 3.1) is used in the analysis. " "The computed wind speed is considered to represent the 1-hour mean wind speed 10 m above sea level." ) @@ -591,25 +606,25 @@ def add_table_to_doc(doc, df, col_width=50, row_height=0.7, header_text="", head doc.add_heading(f"4.1.2 Wind data analysis", level=3) doc.add_paragraph( f"Figure 4.1 shows the (all-year) wind rose at 10 m above mean sea level for the period {starttime} - {endtime}. The wind " -"rose shows the percentage of observations within each 30° sector. \n\n" -"Table 4.1 shows the annual directional sample distribution of non-exceedance of 1-hour mean wind speed. \n\n" +"rose shows the percentage of observations within each 30° sector. " +"Table 4.1 shows the annual directional sample distribution of non-exceedance of 1-hour mean wind speed. " "Figure 4.2 shows the directional distribution of mean, P99 and maximum wind speed at 10 m above mean sea " -f"level at the {LocationX} field. \n\n" -"Table 4.2 shows the monthly distribution of non-exceedance of 1-hour mean wind speed. \n\n" -"Figure 4.3 shows monthly distribution of mean, P99 and maximum 1-hour mean wind speed. \n\n" +f"level at the {LocationX} field. " +"Table 4.2 shows the monthly distribution of non-exceedance of 1-hour mean wind speed. " +"Figure 4.3 shows monthly distribution of mean, P99 and maximum 1-hour mean wind speed. " "Wind roses for each month are displayed in Figure 4.4." ) doc.add_page_break() # Legg til Figur 4.1 -plots.var_rose(ds,var_dir='D10',var='W10',method='overall',max_perc=20,decimal_places=1, units='Wind speed (m/s)',output_file="output/wind_omni.png") -add_image_with_caption(doc, 'output/wind_omni.png', "Figure 4.1: All-year wind rose at 10 m above mean sea level for the " + LocationX + " field for the period " + starttime + "-" + endtime + ".", orientation="portrait") +plots.var_rose(df,var_dir=var_wind_dir,var=var_wind,method='overall',max_perc=20,decimal_places=1, units='Wind speed (m/s)',output_file=folder + "/" +"wind_omni.png") +add_image_with_caption(doc, folder + '/' +'wind_omni.png', "Figure 4.1: All-year wind rose at 10 m above mean sea level for the " + LocationX + " field for the period " + starttime + "-" + endtime + ".", orientation="portrait") doc.add_page_break() # Henter ut data til tabell 1 -df1 = tables.table_directional_non_exceedance(ds, var='W10',step_var=2,var_dir='D10',output_file=None) +df1 = tables.table_directional_non_exceedance(df, var=var_wind,step_var=2,var_dir=var_wind_dir,output_file=None) header_text = "Table 4.1: Annual directional sample distribution of non -exceedance [%] of 1-hour mean wind speed 10 m above sea level at the " + LocationX + "." # Legger til tabellen i word add_table_to_doc(doc, df1, col_width=50, row_height=0.7, header_color='D3D3D3', data_color='D2B48C') @@ -618,51 +633,51 @@ def add_table_to_doc(doc, df, col_width=50, row_height=0.7, header_text="", head doc.add_heading ("W10 [m/s] at the " + LocationX + " field") # Legg til Figur 4.2 -plots.plot_directional_stats(ds,var='HS',step_var=0.5, var_dir='DIRM', title = '$H_s$[m]', output_file="output/directional_stats.png") -add_image_with_caption(doc, 'output/directional_stats.png', "Figure 4.2: Directional distribution of mean, P99 and maximum wind speed at 10 m above mean sea level at the " + LocationX + " field.", orientation="portrait") +plots.plot_directional_stats(df,var=var_hs,step_var=0.5, var_dir=var_wave_dir, title = 'Hs[m]', output_file=folder + "/" +"directional_stats.png") +add_image_with_caption(doc, folder + '/' +'directional_stats.png', "Figure 4.2: Directional distribution of mean, P99 and maximum wind speed at 10 m above mean sea level at the " + LocationX + " field.", orientation="portrait") doc.add_page_break() # Hent DataFrame for andre tabell og legger til i word -df2 = tables.table_monthly_non_exceedance(ds, var='W10', step_var=2, output_file=None) +df2 = tables.table_monthly_non_exceedance(df, var=var_wind, step_var=2, output_file=None) header_text = "Table 4.2: Directional non-exceedance table with percentage of time each data level occurs in each direction." add_table_to_doc(doc, df2, col_width=50, row_height=0.7, header_color='D3D3D3', data_color='D2B48C') # Legge til figur 4.3 -plots.plot_monthly_stats(ds,var="W10",show=["min","mean","max"],fill_between=["25%","75%"],fill_color_like="mean",output_file='output/monthly_stats.png') -add_image_with_caption(doc, 'output/monthly_stats.png', "Figure 4.3: Monthly distribution of mean, P99 and maximum wind speed 10 m above mean sea level at the " + LocationX + " field.", orientation="portrait") +plots.plot_monthly_stats(df,var="W10",show=["min","mean","max"],title='Montly W10 [m/s]',fill_between=["25%","75%"],fill_color_like="mean",output_file=folder + '/' +'monthly_wind_stats.png') +add_image_with_caption(doc, folder + '/' +'monthly_wind_stats.png', "Figure 4.3: Monthly distribution of mean, P99 and maximum wind speed 10 m above mean sea level at the " + LocationX + " field.", orientation="portrait") # Legg til figur 4.4 -plots.var_rose(ds,var_dir='D10',var='W10',method='monthly',max_perc=15,decimal_places=1, units="Wind Speed (m/s)",output_file="output/wind_monthly.png") -add_image_with_caption(doc, 'output/wind_monthly.png', "Figure 4.4: Monthly wind roses for the " + LocationX + "field for the period " + starttime + "to " + endtime, orientation="landscape") +plots.var_rose(df,var_dir=var_wind_dir,var=var_wind,method='monthly',max_perc=15,decimal_places=1, units="Wind Speed (m/s)",output_file=folder + "/" +"wind_monthly.png") +add_image_with_caption(doc, folder + '/' +'wind_monthly.png', "Figure 4.4: Monthly wind roses for the " + LocationX + "field for the period " + starttime + "to " + endtime, orientation="landscape") # 4.1.3 Long-term wind statistics doc.add_heading(f"4.1.3 Long-term wind statistics", level=3) doc.add_paragraph( f"The long-term distribution of wind speed is modeled in terms of a 3-parameter Weibull distribution. The shape" "parameter is objectively forced (method of moments) to optimize the fit to the upper tail of the distribution." -f"\n\nFigure 4.5 shows the hindcast and fitted distributions of wind speed at the {LocationX} field.") +f"Figure 4.5 shows the hindcast and fitted distributions of wind speed at the {LocationX} field.") # Legg til figur 4.5 -plots.plot_prob_non_exceedance_fitted_3p_weibull(ds,var="W10",output_file="output/prob_non_exceedance_fitted_3p_weibull.png") -add_image_with_caption(doc, 'output/prob_non_exceedance_fitted_3p_weibull.png', f"Figure 4.5: Hindcast (red) and fitted (blue line) distributions of 1 -hour mean wind speed 10 m [m/s] above sea level at the {LocationX}" +plots.plot_prob_non_exceedance_fitted_3p_weibull(df,var="W10",output_file=folder + "/" +"prob_non_exceedance_wind_fitted_3p_weibull.png") +add_image_with_caption(doc, folder + '/' +'prob_non_exceedance_wind_fitted_3p_weibull.png', f"Figure 4.5: Hindcast (red) and fitted (blue line) distributions of 1 -hour mean wind speed 10 m [m/s] above sea level at the {LocationX}" "field.", orientation="portrait") doc.add_paragraph() -doc.add_paragraph("Figure 4.6 and Table 4.3 show directional Weibull parameters and corresponding extremes of 1-hour mean" +doc.add_paragraph("Figure 4.6 and Table 4.3 show directional Weibull parameters and corresponding extremes of 1-hour mean " f"wind speed at the {LocationX} field. The direction extremes are adjusted in agreement with NORSOK Standard" "N-003:2017.") # Legg til figur 4.6 -plots.plot_directional_return_periods(ds,var="W10",var_dir="D10",periods = [1,10,100,10000],output_file="output/W10_dir_extremes_Weibull_norsok.png",distribution="Weibull3P") -add_image_with_caption(doc, 'output/W10_dir_extremes_Weibull_norsok.png', f"Figure 4.6: Directional extreme values of 1 -hour mean wind speed with return period of 1, 10, 100 and 10 000 years, 10 m above sea " +plots.plot_directional_return_periods(df,var="W10",units = 'm/s', var_dir="D10",periods = [1,10,100,10000],output_file=folder + "/" +"W10_dir_extremes_Weibull_norsok.png",distribution="Weibull3P") +add_image_with_caption(doc, folder + '/' +'W10_dir_extremes_Weibull_norsok.png', f"Figure 4.6: Directional extreme values of 1 -hour mean wind speed with return period of 1, 10, 100 and 10 000 years, 10 m above sea " f"level at the {LocationX} field. The direction extremes are adjusted in agreement with NORSOK Standard N - 003:2017", orientation="portrait") doc.add_paragraph() doc.add_page_break() # Hent DataFrame for tabell 4.3 -df3= tables.table_directional_return_periods(ds,var='W10',periods=[1, 10, 100, 10000], units='m/s',var_dir = 'D10',distribution='Weibull3P_MOM', adjustment='NORSOK' ,output_file=None) +df3= tables.table_directional_return_periods(df,var=var_wind,periods=[1, 10, 100, 10000], units='m/s',var_dir = var_wind_dir,distribution='Weibull3P_MOM', adjustment='NORSOK' ,output_file=None) header_text = "Table 4.3: Weibull parameters and corresponding adjusted directional extreme values for 1-hour mean wind speed 10 m above sea level at the " + LocationX + " field. Duration of the event is 1 hour. The direction extremes are adjusted in agreement with NORSOK STandard N-003:2017" add_table_to_doc(doc, df3, col_width=50, row_height=0.7, header_color='D3D3D3', data_color='D2B48C') doc.add_paragraph() @@ -671,14 +686,14 @@ def add_table_to_doc(doc, df, col_width=50, row_height=0.7, header_text="", head doc.add_paragraph() # Legg til figur 4.7 -plots.plot_monthly_return_periods(data=ds,var="W10",periods=[1,10,100,10000],output_file="output/W10_monthly_extremes.png") -add_image_with_caption(doc, 'output/W10_monthly_extremes.png', f"Figure 4.7: Monthly extreme values of 1 -hour mean wind speed with return period of 1, 10, 100 and 10 000 years 10 m above sea " +plots.plot_monthly_return_periods(df,var="W10",units='m/s', periods=[1,10,100,10000],output_file=folder + "/" +"W10_monthly_extremes.png") +add_image_with_caption(doc, folder + '/' +'W10_monthly_extremes.png', f"Figure 4.7: Monthly extreme values of 1 -hour mean wind speed with return period of 1, 10, 100 and 10 000 years 10 m above sea " f"level at the {LocationX} field.", orientation="portrait") doc.add_paragraph() doc.add_page_break() # Legger til tabell 4.4 -df4= tables.table_monthly_joint_distribution_Hs_Tp_return_values(ds,var_hs='HS',var_tp='TP',periods=[1,10,100,10000],output_file=None) +df4= tables.table_monthly_joint_distribution_Hs_Tp_return_values(df,var_hs=var_hs,var_tp='TP',periods=[1,10,100,10000],output_file=None) header_text = "Table 4.4: Monthly and annual Weibull parameters and corresponding extreme values for 1-hour mean wind speed 10 m above sea level at the " + LocationX + " field. Duration of the event is 1 hour." add_table_to_doc(doc, df4, col_width=50, row_height=0.7, header_color='D3D3D3', data_color='D2B48C') @@ -691,7 +706,7 @@ def add_table_to_doc(doc, df, col_width=50, row_height=0.7, header_text="", head doc.add_page_break() # Tabell 4.5 -df5 = tables.table_profile_return_values(ds,var=['W10','W50','W80','W100','W150'], z=[10, 50, 80, 100, 150], periods=[1, 10, 100, 10000], output_file=None) +df5 = tables.table_profile_return_values(df,var=[var_wind,'W50','W80','W100','W150'], z=[10, 50, 80, 100, 150], periods=[1, 10, 100, 10000], output_file=None) header_text = "Table 4.5: Omni-directional extreme values for 1 - hour mean wind speed as function of height above mean sea level at " + LocationX + " field." add_table_to_doc(doc, df5, col_width=50, row_height=0.7, header_color='D3D3D3', data_color='D2B48C') @@ -720,43 +735,43 @@ def add_table_to_doc(doc, df, col_width=50, row_height=0.7, header_text="", head # Legg til figur 4.8 # Lager ny variabel slik at man kan endre verdiene i figuren som hentes ut -fig1 = 'output/NORA10_monthly_weather_window4_10_12_plot.png' -plots.plot_monthly_weather_window(ds,var='W10',threshold=10, window_size=12,output_file=fig1) +fig1 = folder + '/' +'NORA10_monthly_weather_window4_10_12_plot.png' +plots.plot_monthly_weather_window(df,var=var_wind,threshold=10, window_size=12,output_file=fig1) add_image_with_caption(doc, fig1, f"Figure 4.8: Characteristic durations, including waiting time, to perform operations limited by a wind speed of 10 m/s for 12 hours at " f"the {LocationX} field.", orientation="portrait") doc.add_paragraph() # Legg til figur 4.9 på samme måte som 4.8 med annderleses verdier -fig2 = 'output/NORA10_monthly_weather_window4_15_12_plot.png' -plots.plot_monthly_weather_window(ds,var='W10',threshold=15, window_size=12,output_file= fig2) +fig2 = folder + '/' +'NORA10_monthly_weather_window4_15_12_plot.png' +plots.plot_monthly_weather_window(df,var=var_wind,threshold=15, window_size=12,output_file= fig2) add_image_with_caption(doc, fig2, f"Figure 4.9: Characteristic durations, including waiting time, to perform operations limited by a wind speed of 15 m/s for 12 hours at " f"the {LocationX} field.", orientation="portrait") doc.add_paragraph() # Legg til figur 4.10 -fig3 = 'output/NORA10_monthly_weather_window4_10_24_plot.png' -plots.plot_monthly_weather_window(ds,var='W10',threshold=10, window_size=24,output_file= fig3) +fig3 = folder + '/' +'NORA10_monthly_weather_window4_10_24_plot.png' +plots.plot_monthly_weather_window(df,var=var_wind,threshold=10, window_size=24,output_file= fig3) add_image_with_caption(doc, fig3, f"Figure 4.10: Characteristic durations, including waiting time, to perform operations limited by a wind speed of 10 m/s for 24 hours at " f"the {LocationX} field.", orientation="portrait") doc.add_paragraph() # Legg til figur 4.11 -fig4 = 'output/NORA10_monthly_weather_window4_15_24_plot.png' -plots.plot_monthly_weather_window(ds,var='W10',threshold=15, window_size=24,output_file= fig4) +fig4 = folder + '/' +'NORA10_monthly_weather_window4_15_24_plot.png' +plots.plot_monthly_weather_window(df,var=var_wind,threshold=15, window_size=24,output_file= fig4) add_image_with_caption(doc, fig4, f"Figure 4.11: Characteristic durations, including waiting time, to perform operations limited by a wind speed of 15 m/s for 24 hours at " f"the {LocationX} field.", orientation="portrait") doc.add_paragraph() # Legg til figur 4.12 -fig5 = 'output/NORA10_monthly_weather_window4_10_48_plot.png' -plots.plot_monthly_weather_window(ds,var='W10',threshold=10, window_size=48,output_file= fig5) +fig5 = folder + '/' +'NORA10_monthly_weather_window4_10_48_plot.png' +plots.plot_monthly_weather_window(df,var=var_wind,threshold=10, window_size=48,output_file= fig5) add_image_with_caption(doc, fig5, f"Figure 4.12: Characteristic durations, including waiting time, to perform operations limited by a wind speed of 10 m/s for 48 hours at " f"the {LocationX} field.", orientation="portrait") doc.add_paragraph() # Legg til figur 4.13 -fig6 = 'output/NORA10_monthly_weather_window4_15_48_plot.png' -plots.plot_monthly_weather_window(ds,var='W10',threshold=15, window_size=48,output_file= fig6) +fig6 = folder + '/' +'NORA10_monthly_weather_window4_15_48_plot.png' +plots.plot_monthly_weather_window(df,var=var_wind,threshold=15, window_size=48,output_file= fig6) add_image_with_caption(doc, fig6, f"Figure 4.13: Characteristic durations, including waiting time, to perform operations limited by a wind speed of 15 m/s for 48 hours at " f"the {LocationX} field.", orientation="portrait") doc.add_paragraph() @@ -771,8 +786,8 @@ def add_table_to_doc(doc, df, col_width=50, row_height=0.7, header_text="", head doc.add_paragraph() # Legg til figur 4.14 -plots.plot_monthly_stats(ds,var="T2m",show=["Maximum","Mean","Minimum"],output_file="output/T2m_monthly_max_mean_min.png") -add_image_with_caption(doc, 'output/T2m_monthly_max_mean_min.png', f"Figure 4.14: Monthly minimum, mean and maximum air temperature at the {LocationX} field.", orientation="portrait") +plots.plot_monthly_stats(df,var="T2m",show=["Maximum","Mean","Minimum"],title = 'Montly T2m [C]' , output_file=folder + "/" +"T2m_monthly_max_mean_min.png") +add_image_with_caption(doc, folder + '/' +'T2m_monthly_max_mean_min.png', f"Figure 4.14: Monthly minimum, mean and maximum air temperature at the {LocationX} field.", orientation="portrait") doc.add_paragraph() @@ -780,21 +795,21 @@ def add_table_to_doc(doc, df, col_width=50, row_height=0.7, header_text="", head f"The extreme air temperatures are estimated with the annual/monthly minimum values. The annual/monthly " "minimum values are fitted to a Gumbel distribution with maximum likelihood estimation as described in the " "appendix (Gumbel Distribution)." -"\n\nFigure 4.15 and Figure 4.16 shows the monthly distribution of extreme negative and positive air temperatures " +"Figure 4.15 and Figure 4.16 shows the monthly distribution of extreme negative and positive air temperatures " f"for the {LocationX} field. Table 4.8 and Table 4.9 shows the monthly and annual Gumbel parameters and return " "values for extreme negative air temperature and positive air temperature.") doc.add_paragraph() # Legg til figur 4.15 -plots.plot_monthly_return_periods(ds,var="T2m",output_file = "output/T2m_monthly_extremes_neg.png",method="minimum",periods=[1,10,100]) -add_image_with_caption(doc, 'output/T2m_monthly_extremes_neg.png', f"Figure 4.15: Monthly distribution of extreme negative air temperature with return period 1, 10 and 100 years (annual probability of " +plots.plot_monthly_return_periods(df,var="T2m",units='C', output_file = folder + "/" +"T2m_monthly_extremes_neg.png",method="minimum",periods=[1,10,100]) +add_image_with_caption(doc, folder + '/' +'T2m_monthly_extremes_neg.png', f"Figure 4.15: Monthly distribution of extreme negative air temperature with return period 1, 10 and 100 years (annual probability of " f"exceedance 0.63, 10 -1 and 10-2) for the {LocationX} field.", orientation="portrait") doc.add_paragraph() # Legg til figur 4.16 -plots.plot_monthly_return_periods(ds,var="T2m",output_file="output/T2m_monthly_extremes_pos.png",method="maximum",periods=[1,10,100]) -add_image_with_caption(doc, 'output/T2m_monthly_extremes_pos.png', f"Figure 4.16: Monthly distribution of extreme positive air temperature with return period 1, 10 and 100 years (annual probability of " +plots.plot_monthly_return_periods(df,var="T2m", units ='C', output_file=folder + "/" +"T2m_monthly_extremes_pos.png",method="maximum",periods=[1,10,100]) +add_image_with_caption(doc, folder + '/' +'T2m_monthly_extremes_pos.png', f"Figure 4.16: Monthly distribution of extreme positive air temperature with return period 1, 10 and 100 years (annual probability of " f"exceedance 0.63, 10 -1 and 10-2) for the {LocationX} field.", orientation="portrait") doc.add_paragraph() @@ -810,7 +825,7 @@ def add_table_to_doc(doc, df, col_width=50, row_height=0.7, header_text="", head doc.add_paragraph( f"Wave data for Norwegian coastal waters are available from the NORA10 hindcast model operated by the " f"Norwegian Meteorological Institute [10]. The data cover the period {starttime} – {endtime}. The sample interval " -"is 3 hours. The NORA10 model has a spatial resolution of 10 km.)\n\n" +"is 3 hours. The NORA10 model has a spatial resolution of 10 km.)" f"Wave data from grid point position {lat}°N, {lon}°E is used in the analysis. A reference water depth of {wave_depth} m " "below MSL is used.") doc.add_paragraph() @@ -819,50 +834,51 @@ def add_table_to_doc(doc, df, col_width=50, row_height=0.7, header_text="", head doc.add_heading(f"5.1.2 Wave data analysis", level=3) doc.add_paragraph( "Figure 5.1 shows the all-year wave rose, i.e. the sample direction distribution of significant wave height, at the " -f"{LocationX} field. \n\n" -"Table 5.1 shows the direction sample distribution of non-exceedance of significant wave height. \n\n" -"Figure 5.3 shows the monthly sample density distribution and basic statistics of significant wave height. \n\n" -"Table 5.2 shows the monthly sample distribution of non-exceedance of significant wave height. \n\n" +f"{LocationX} field. " +"Table 5.1 shows the direction sample distribution of non-exceedance of significant wave height. " +"Figure 5.3 shows the monthly sample density distribution and basic statistics of significant wave height. " +"Table 5.2 shows the monthly sample distribution of non-exceedance of significant wave height. " "Wave roses for each month are displayed in Figure 5.4." ) doc.add_paragraph() # Legg til figur 5.1 -fig7 = 'output/wind_omni.png' -plots.var_rose(ds,var_dir='D10',var='W10',method='overall',max_perc=20,decimal_places=1, units='Wave height (m)',output_file=fig7) +fig7 = folder + '/' +'wind_omni.png' +plots.var_rose(df,var_dir=var_wind_dir,var=var_wind,method='overall',max_perc=20,decimal_places=1, units='Wave height (m)',output_file=fig7) add_image_with_caption(doc, fig7, f"Figure 5.1: All-year wave rose for the {LocationX} field for the period {starttime} – {endtime}", orientation="portrait") doc.add_paragraph() # Legg til figur 5.2 -add_image_with_caption(doc, 'output/directional_stats.png', f"Figure 5.2: Directional distribution of mean, P99 and maximum of significant wave height at the {LocationX} field.", orientation="portrait") +add_image_with_caption(doc, folder + '/' +'directional_stats.png', f"Figure 5.2: Directional distribution of mean, P99 and maximum of significant wave height at the {LocationX} field.", orientation="portrait") doc.add_paragraph() # MANGLER EN TABELL_________________ # Legg til figur 5.3 -fig8 = 'output/directional_stats.png' -plots.plot_directional_stats(ds,var='HS',step_var=0.5, var_dir='DIRM', title = '$H_s$[m]', output_file=fig8) +fig8 = folder + '/' +'directional_stats.png' +plots.plot_directional_stats(df,var=var_hs,step_var=0.5, var_dir=var_wave_dir, title = 'Hs[m]', output_file=fig8) add_image_with_caption(doc, fig8, f"Figure 5.3: Monthly data distribution (top), mean, P99 and maximum of significant wave height at the {LocationX} field.", orientation="portrait") doc.add_paragraph() # MANGLER EN TABELL_________________ # Legg til figur 5.4 -fig9 = 'output/wind_monthly.png' -plots.var_rose(ds,var_dir='D10',var='W10',method='monthly',max_perc=15,decimal_places=1, units="Wave height (m)",output_file=fig9) +fig9 = folder + '/' +'wind_monthly.png' +plots.var_rose(df,var_dir=var_wind_dir,var=var_wind,method='monthly',max_perc=15,decimal_places=1, units="Wave height (m)",output_file=fig9) add_image_with_caption(doc, fig9, f"Figure 5.4: Monthly wave roses for the {LocationX} field for the period {starttime} to {endtime}.", orientation="landscape") # 5.1.3 Long-term statistics doc.add_heading(f"5.1.3 Long-term statistics", level=3) doc.add_paragraph( - "The long-term distribution of significant wave height is modeled in terms of a Weibull distribution. The shape" + "The long-term distribution of significant wave height is modeled in terms of a Weibull distribution. The shape " "parameter is objectively forced (method of moments) to optimize the fit to the upper tail of the distribution." f"Figure 5.5 shows the hindcast and fitted distributions of significant wave height at the {LocationX} field." ) doc.add_paragraph() # Legg til figur 5.5 -add_image_with_caption(doc, "output/prob_non_exceedance_fitted_3p_weibull.png", f"Figure 5.5: Hindcast (red dots) and fitted (black line) distributions of significant wave height at the {LocationX} field.", orientation="portrait") +plots.plot_prob_non_exceedance_fitted_3p_weibull(df,var="HS",output_file=folder + "/" +"prob_non_exceedance_Hs_fitted_3p_weibull.png") +add_image_with_caption(doc, folder + "/" +"prob_non_exceedance_Hs_fitted_3p_weibull.png", f"Figure 5.5: Hindcast (red dots) and fitted (black line) distributions of significant wave height at the {LocationX} field.", orientation="portrait") doc.add_paragraph() doc.add_paragraph( @@ -874,16 +890,16 @@ def add_table_to_doc(doc, df, col_width=50, row_height=0.7, header_text="", head doc.add_paragraph() # Legg til figur 5.6 -plots.plot_directional_return_periods(ds,var="hs",var_dir="DIRP",distribution="Weibull3P",output_file="output/dir_extremes_Weibull_norsok.png") -add_image_with_caption(doc, 'output/dir_extremes_Weibull_norsok.png', f"Figure 5.6: Adjusted directional extreme values of significant wave height with return period 1, 10, 100 and 10 000 years at the " +plots.plot_directional_return_periods(df,var="HS",var_dir="DIRP",distribution="Weibull3P",output_file=folder + "/" +"dir_extremes_Weibull_norsok.png") +add_image_with_caption(doc, folder + '/' +'dir_extremes_Weibull_norsok.png', f"Figure 5.6: Adjusted directional extreme values of significant wave height with return period 1, 10, 100 and 10 000 years at the " f"{LocationX} field. The direction extremes are adjusted in agreement with NORSOK Standard N -003:2017.", orientation="portrait") doc.add_paragraph() # MANGLER 1 TABELL___________ # Legg til figur 5.7 -plots.plot_monthly_return_periods(ds,var="hs",periods=[1,10,100,10000],distribution="Weibull3P_MOM",output_file="output/HS_monthly_extremes.png") -add_image_with_caption(doc, 'output/HS_monthly_extremes.png', f"Figure 5.7: Monthly extreme values of significant wave height with return period of 1, 10, 100, and 10 000 years.", orientation="portrait") +plots.plot_monthly_return_periods(df,var="HS",periods=[1,10,100,10000],distribution="Weibull3P_MOM",output_file=folder + "/" +"HS_monthly_extremes.png") +add_image_with_caption(doc, folder + '/' +'HS_monthly_extremes.png', f"Figure 5.7: Monthly extreme values of significant wave height with return period of 1, 10, 100, and 10 000 years.", orientation="portrait") doc.add_paragraph() # MANGLER 1 TABELL___________ @@ -893,21 +909,21 @@ def add_table_to_doc(doc, df, col_width=50, row_height=0.7, header_text="", head doc.add_paragraph( "A short-term sea state is for most practical purposes reasonably well characterized by the significant wave " "height, Hs, and the spectral peak period, Tp." -"\n\nTable 5.5 shows the annual omni-directional scatter table of HS and Tp for 65 years. The scatter table is " +"Table 5.5 shows the annual omni-directional scatter table of Hs and Tp for 65 years. The scatter table is " "obtained from the 65-year NORA10 hindcast data, and the interval is 3 hours." -"\n\nThe conditional distribution of spectral peak period (Tp) given significant wave height (Hs) is modeled by a lognormal " +"The conditional distribution of spectral peak period (Tp) given significant wave height (Hs) is modeled by a lognormal " "distribution, as described in the Appendix (Log-normal distribution)." -"\n\nTable 5.6 shows the parameters in the log-normal distribution of Tp given HS." -"\n\nFigure 5.8 and Table 5.7 show spectral peak period as a function of significant wave height." -"\n\nTable 5.8 shows omni-directional extreme significant wave heights and associated spectral peak periods." -"\n\nTable 5.9 and Table 5.10 show directional and monthly extreme significant wave heights and associated " -"spectral peak periods.") +"Table 5.6 shows the parameters in the log-normal distribution of Tp given HS." +"Figure 5.8 and Table 5.7 show spectral peak period as a function of significant wave height." +"Table 5.8 shows omni-directional extreme significant wave heights and associated spectral peak period." +"Table 5.9 and Table 5.10 show directional and monthly extreme significant wave heights and associated " +"spectral peak period.") doc.add_paragraph() # Legg til figur 5.8 -plots.plot_scatter_diagram(ds,var1="hs",step_var1=0.5,var2="tp",step_var2=1,output_file="output/tp_for_given_hs.png") -add_image_with_caption(doc, 'output/tp_for_given_hs.png', f"Figure 5.8: Spectral peak period (Tp) for given significant wave height (Hs) at the {LocationX} field. Heat colormap indicates the density " +plots.plot_scatter_diagram(df,var1="hs",step_var1=0.5,var2="tp",step_var2=1,output_file=folder + "/" +"tp_for_given_hs.png") +add_image_with_caption(doc, folder + '/' +'tp_for_given_hs.png', f"Figure 5.8: Spectral peak period (Tp) for given significant wave height (Hs) at the {LocationX} field. Heat colormap indicates the density " "of observations", orientation="portrait") doc.add_paragraph() @@ -917,20 +933,20 @@ def add_table_to_doc(doc, df, col_width=50, row_height=0.7, header_text="", head "The LoNoWe model is used to simulate the long-term joint distribution of Hs and Tp, the conditional " "distribution of spectral peak period (Tp) given significant wave height (Hs). This LoNoWe model is described in" "Appendix (LoNoWe - Joint distribution of Hs and Tp)." -"\n\nFigure 5.10 and Table 5.12 shows the omni-directional contour lines of Hs - Tp for return periods of 1, 10, 100" +"Figure 5.10 and Table 5.12 shows the omni-directional contour lines of Hs - Tp for return periods of 1, 10, 100" "and 10 000 years with the steepness / wave breaking criterion applied.") doc.add_paragraph() # Legg til figur 5.10 plots.plot_joint_distribution_Hs_Tp( - ds, - var_hs='HS', + df, + var_hs=var_hs, var_tp='TP', periods=[1,10,100,1000], title='Hs-Tp joint distribution', - output_file='output/Hs.Tp.joint.distribution.png', + output_file=folder + '/' +'Hs.Tp.joint.distribution.png', density_plot=True) -add_image_with_caption(doc, 'output/Hs.Tp.joint.distribution.png', f"Figure 5.10: Contour lines of HS - Tp including wave breaking criteria/steepness , with return period 1, 10, 100 and 10 000 years for " +add_image_with_caption(doc, folder + '/' +'Hs.Tp.joint.distribution.png', f"Figure 5.10: Contour lines of Hs - Tp including wave breaking criteria/steepness , with return period 1, 10, 100 and 1000 years for " f"omni-directional waves at the {LocationX} field. Duration of sea state is 3 hours.", orientation="portrait") doc.add_paragraph() @@ -940,8 +956,8 @@ def add_table_to_doc(doc, df, col_width=50, row_height=0.7, header_text="", head "Table 5.13 shows the estimated design wave heights. Extreme value estimates for individual wave heights and " "wave crests are computed using the Forristal distribution. The wave periods, T_Hmax, are computed from " "T_Hmax = 0.90 ∙ Tp, where Tp is given in Table 5.8." -"\n\nExtreme individual wave heights versus direction sectors are given in Table 5.14. These wave heights are " -"determined from the significant wave heights given in Table 5.9 by assuming that Hmax/HS for each sector is " +"Extreme individual wave heights versus direction sectors are given in Table 5.14. These wave heights are " +"determined from the significant wave heights given in Table 5.9 by assuming that Hmax/Hs for each sector is " "equal to Hmax/Hs for omni-directional seas and reflect the same relative severity as shown by that table.") doc.add_paragraph() @@ -952,7 +968,7 @@ def add_table_to_doc(doc, df, col_width=50, row_height=0.7, header_text="", head "Table 5.16 and Table 5.17 show wave-induced significant orbital velocity Us and corresponding zero-crossing " "period Tu, based on JONSWAP and Torsethaugen spectra. The significant wave height and spectral peak data " "are as given in Table 5.7." -"\nWhen the associated spectral peak period is larger than the mean period given in Table 5.14, the most " +"When the associated spectral peak period is larger than the mean period given in Table 5.14, the most " "unfavorable orbital velocity from the JONSWAP spectrum should be applied.") doc.add_paragraph() @@ -963,108 +979,108 @@ def add_table_to_doc(doc, df, col_width=50, row_height=0.7, header_text="", head "possible increase in the duration of the operations. Marine operations which must be completed without break " "are called critical. Otherwise, they are termed non-critical. The duration statistics presented in this report is " "restricted to critical operations only." -"\n\nFigure 5.11 to Figure 5.24 show characteristic durations of operations limited by significant wave heights of 2.0, " +"Figure 5.11 to Figure 5.24 show characteristic durations of operations limited by significant wave heights of 2.0, " "3.0 and 4.0, 4.5 and 5.5m for 6 hours, and 2.0, 3.0 and 4.0 m for 12, 24 and 48 hours. The figures show the " "expected mean duration and 10, 50 and 90 percentiles." -"\n\nThe figures show duration characteristics for completing a critical operation including waiting time. Duration is " +"The figures show duration characteristics for completing a critical operation including waiting time. Duration is " "measured from the day the operation is ready to start. The starting day is considered to be an arbitrary day " "within the relevant month.") doc.add_paragraph() # Legg til figur 5.11 -fig10 = 'output/NORA10_monthly_weather_window4_12_plot.png' -plots.plot_monthly_weather_window(ds,var='HS',threshold=2, window_size=6,output_file= fig10) +fig10 = folder + '/' +'NORA10_monthly_weather_window4_12_plot.png' +plots.plot_monthly_weather_window(df,var=var_hs,threshold=2, window_size=6,output_file= fig10) add_image_with_caption(doc, fig10, f"Figure 5.11: Characteristic durations, including waiting time, to perform operations limited by a significant wave height (Hs) of 2.0 m " f"for 6 hours at the {LocationX} field.", orientation="portrait") doc.add_paragraph() # Legg til figur 5.12 -fig11 = 'output/NORA10_monthly_weather_window4_12_plot.png' -plots.plot_monthly_weather_window(ds,var='HS',threshold=3, window_size=6,output_file= fig11) +fig11 = folder + '/' +'NORA10_monthly_weather_window4_12_plot.png' +plots.plot_monthly_weather_window(df,var=var_hs,threshold=3, window_size=6,output_file= fig11) add_image_with_caption(doc, fig11, f"Figure 5.12: Characteristic durations, including waiting time, to perform operations limited by a significant wave height (Hs) of 3.0 m " f"for 6 hours at the {LocationX} field.", orientation="portrait") doc.add_paragraph() # Legg til figur 5.13 -fig12 = 'output/NORA10_monthly_weather_window4_12_plot.png' -plots.plot_monthly_weather_window(ds,var='HS',threshold=4, window_size=6,output_file= fig12) +fig12 = folder + '/' +'NORA10_monthly_weather_window4_12_plot.png' +plots.plot_monthly_weather_window(df,var=var_hs,threshold=4, window_size=6,output_file= fig12) add_image_with_caption(doc, fig12, f"Figure 5.13: Characteristic durations, including waiting time, to perform operations limited by a significant wave height (Hs) of 4.0 m " f"for 6 hours at the {LocationX} field.", orientation="portrait") doc.add_paragraph() # Legg til figur 5.14 -fig13 = 'output/NORA10_monthly_weather_window4_12_plot.png' -plots.plot_monthly_weather_window(ds,var='HS',threshold=4.5, window_size=6,output_file= fig13) +fig13 = folder + '/' +'NORA10_monthly_weather_window4_12_plot.png' +plots.plot_monthly_weather_window(df,var=var_hs,threshold=4.5, window_size=6,output_file= fig13) add_image_with_caption(doc, fig13, f"Figure 5.14: Characteristic durations, including waiting time, to perform operations limited by a significant wave height (Hs) of 4.5 m " f"for 6 hours at the {LocationX} field.", orientation="portrait") doc.add_paragraph() # Legg til figur 5.15 -fig14 = 'output/NORA10_monthly_weather_window4_12_plot.png' -plots.plot_monthly_weather_window(ds,var='HS',threshold=5.5, window_size=6,output_file= fig14) +fig14 = folder + '/' +'NORA10_monthly_weather_window4_12_plot.png' +plots.plot_monthly_weather_window(df,var=var_hs,threshold=5.5, window_size=6,output_file= fig14) add_image_with_caption(doc, fig14, f"Figure 5.15: Characteristic durations, including waiting time, to perform operations limited by a significant wave height (Hs) of 5.5 m " f"for 6 hours at the {LocationX} field.", orientation="portrait") doc.add_paragraph() # Legg til figur 5.16 -fig15 = 'output/NORA10_monthly_weather_window4_12_plot.png' -plots.plot_monthly_weather_window(ds,var='HS',threshold=2, window_size=12,output_file= fig15) +fig15 = folder + '/' +'NORA10_monthly_weather_window4_12_plot.png' +plots.plot_monthly_weather_window(df,var=var_hs,threshold=2, window_size=12,output_file= fig15) add_image_with_caption(doc, fig15, f"Figure 5.16: Characteristic durations, including waiting time, to perform operations limited by a significant wave height (Hs) of 2.0 m " f"for 12 hours at the {LocationX} field.", orientation="portrait") doc.add_paragraph() # Legg til figur 5.17 -fig16 = 'output/NORA10_monthly_weather_window4_12_plot.png' -plots.plot_monthly_weather_window(ds,var='HS',threshold=3, window_size=12,output_file= fig16) +fig16 = folder + '/' +'NORA10_monthly_weather_window4_12_plot.png' +plots.plot_monthly_weather_window(df,var=var_hs,threshold=3, window_size=12,output_file= fig16) add_image_with_caption(doc, fig16, f"Figure 5.17: Characteristic durations, including waiting time, to perform operations limited by a significant wave height (Hs) of 3.0 m " f"for 12 hours at the {LocationX} field.", orientation="portrait") doc.add_paragraph() # Legg til figur 5.18 -fig17 = 'output/NORA10_monthly_weather_window4_12_plot.png' -plots.plot_monthly_weather_window(ds,var='HS',threshold=4, window_size=12,output_file= fig17) +fig17 = folder + '/' +'NORA10_monthly_weather_window4_12_plot.png' +plots.plot_monthly_weather_window(df,var=var_hs,threshold=4, window_size=12,output_file= fig17) add_image_with_caption(doc, fig17, f"Figure 5.18: Characteristic durations, including waiting time, to perform operations limited by a significant wave height (Hs) of 4.0 m " f"for 12 hours at the {LocationX} field.", orientation="portrait") doc.add_paragraph() # Legg til figur 5.19 -fig18 = 'output/NORA10_monthly_weather_window4_12_plot.png' -plots.plot_monthly_weather_window(ds,var='HS',threshold=2, window_size=24,output_file= fig18) +fig18 = folder + '/' +'NORA10_monthly_weather_window4_12_plot.png' +plots.plot_monthly_weather_window(df,var=var_hs,threshold=2, window_size=24,output_file= fig18) add_image_with_caption(doc, fig18, f"Figure 5.19: Characteristic durations, including waiting time, to perform operations limited by a significant wave height (Hs) of 2.0 m " f"for 24 hours at the {LocationX} field.", orientation="portrait") doc.add_paragraph() # Legg til figur 5.20 -fig19 = 'output/NORA10_monthly_weather_window4_12_plot.png' -plots.plot_monthly_weather_window(ds,var='HS',threshold=3, window_size=24,output_file= fig19) +fig19 = folder + '/' +'NORA10_monthly_weather_window4_12_plot.png' +plots.plot_monthly_weather_window(df,var=var_hs,threshold=3, window_size=24,output_file= fig19) add_image_with_caption(doc, fig19, f"Figure 5.20: Characteristic durations, including waiting time, to perform operations limited by a significant wave height (Hs) of 3.0 m " f"for 24 hours at the {LocationX} field.", orientation="portrait") doc.add_paragraph() # Legg til figur 5.21 -fig20 = 'output/NORA10_monthly_weather_window4_12_plot.png' -plots.plot_monthly_weather_window(ds,var='HS',threshold=4, window_size=24,output_file= fig20) +fig20 = folder + '/' +'NORA10_monthly_weather_window4_12_plot.png' +plots.plot_monthly_weather_window(df,var=var_hs,threshold=4, window_size=24,output_file= fig20) add_image_with_caption(doc, fig20, f"Figure 5.21: Characteristic durations, including waiting time, to perform operations limited by a significant wave height (Hs) of 4.0 m " f"for 24 hours at the {LocationX} field.", orientation="portrait") doc.add_paragraph() # Legg til figur 5.22 -fig21 = 'output/NORA10_monthly_weather_window4_12_plot.png' -plots.plot_monthly_weather_window(ds,var='HS',threshold=2, window_size=48,output_file= fig21) +fig21 = folder + '/' +'NORA10_monthly_weather_window4_12_plot.png' +plots.plot_monthly_weather_window(df,var=var_hs,threshold=2, window_size=48,output_file= fig21) add_image_with_caption(doc, fig21, f"Figure 5.22: Characteristic durations, including waiting time, to perform operations limited by a significant wave height (Hs) of 2.0 m " f"for 48 hours at the {LocationX} field.", orientation="portrait") doc.add_paragraph() # Legg til figur 5.23 -fig22 = 'output/NORA10_monthly_weather_window4_12_plot.png' -plots.plot_monthly_weather_window(ds,var='HS',threshold=3, window_size=48,output_file= fig22) +fig22 = folder + '/' +'NORA10_monthly_weather_window4_12_plot.png' +plots.plot_monthly_weather_window(df,var=var_hs,threshold=3, window_size=48,output_file= fig22) add_image_with_caption(doc, fig22, f"Figure 5.23: Characteristic durations, including waiting time, to perform operations limited by a significant wave height (Hs) of 3.0 m " f"for 48 hours at the {LocationX} field.", orientation="portrait") doc.add_paragraph() # Legg til figur 5.24 -fig23 = 'output/NORA10_monthly_weather_window4_12_plot.png' -plots.plot_monthly_weather_window(ds,var='HS',threshold=4, window_size=48,output_file= fig23) +fig23 = folder + '/' +'NORA10_monthly_weather_window4_12_plot.png' +plots.plot_monthly_weather_window(df,var=var_hs,threshold=4, window_size=48,output_file= fig23) add_image_with_caption(doc, fig23, f"Figure 5.24: Characteristic durations, including waiting time, to perform operations limited by a significant wave height (Hs) of 4.0 m " f"for 48 hours at the {LocationX} field.", orientation="portrait") doc.add_paragraph() @@ -1081,10 +1097,10 @@ def add_superscript(paragraph, base_text, superscript_text): doc.add_paragraph( "Significant wave height (Hs) and wind speed (U) at the Luna field based on the NORA10 hindcast data, from " f"{starttime} to {endtime}." -"\n\nThe relationship between significant wave height for a given wind speed, denoted HS(U), is modeled by the " +"The relationship between significant wave height for a given wind speed, denoted HS(U), is modeled by the " "power functions for mean (μ) and standard deviation (σ):") -# "\n\nμ(𝐻𝑠(𝑈)) = 𝑎 + 𝑏 𝑈^(𝑐+𝑑.𝑈)" -# "\n\nσ(𝐻𝑠(𝑈)) = 𝑎 + 𝑏 𝑈^(𝑐+𝑑.𝑈)" +# "μ(𝐻𝑠(𝑈)) = 𝑎 + 𝑏 𝑈^(𝑐+𝑑.𝑈)" +# "σ(𝐻𝑠(𝑈)) = 𝑎 + 𝑏 𝑈^(𝑐+𝑑.𝑈)" # Function to add superscript text # Adding the mean (μ) formula with superscripts @@ -1101,20 +1117,20 @@ def add_superscript(paragraph, base_text, superscript_text): # MANGLER EN TABELL___________ doc.add_paragraph( - "An approximation to the 90% confidence interval is obtained under the assumption of a Gaussian distribution:" -"\n\n𝐻𝑆(𝑈)5% = μ(𝐻𝑠(𝑈)) − 1. 65 σ 𝐻𝑠( (𝑈))" -"\n𝐻𝑆(𝑈)5% = μ 𝐻𝑠( (𝑈)) + 1. 65 σ 𝐻𝑠( (𝑈))" -"\n\nTable 5.19 shows the scatter table of significant wave height and wind speed." -"\n\nFigure 5.25 shows the scatter plot of HS and U with mean HS and 90% confidence interval and the " -"corresponding modeled HS overlain. HS(U) is tabulated in Table 5.20." -"\n\nThe modeled significant wave height for estimated extreme wind speed return values are given in Table 5.21.") + r"An approximation to the 90% confidence interval is obtained under the assumption of a Gaussian distribution:" +r"𝐻𝑆(𝑈)5% = μ(𝐻𝑠(𝑈)) − 1. 65 σ 𝐻𝑠( (𝑈))" +r"\n𝐻𝑆(𝑈)5% = μ 𝐻𝑠( (𝑈)) + 1. 65 σ 𝐻𝑠( (𝑈))" +r"Table 5.19 shows the scatter table of significant wave height and wind speed." +r"Figure 5.25 shows the scatter plot of Hs and U with mean Hs and 90\% confidence interval and the " +r"corresponding modeled Hs overlain. HS(U) is tabulated in Table 5.20." +r"The modeled significant wave height for estimated extreme wind speed return values are given in Table 5.21.") doc.add_paragraph() # MANGLER 1 TABELL___________ # Legg til figur 5.25 -plots.plot_hs_for_given_wind(ds,var_hs="hs",var_wind="W10",output_file="output/hs_for_given_wind.png") -add_image_with_caption(doc, 'output/hs_for_given_wind.png', f"Figure 5.25: Relationship between significant wave height H S for a given wind speed U at the Luna field; data and model " +plots.plot_hs_for_given_wind(df,var_hs="hs",var_wind="W10",output_file=folder + "/" +"hs_for_given_wind.png") +add_image_with_caption(doc, folder + '/' +'hs_for_given_wind.png', f"Figure 5.25: Relationship between significant wave height H S for a given wind speed U at the Luna field; data and model " "extrapolation.", orientation="portrait") doc.add_paragraph() @@ -1126,39 +1142,39 @@ def add_superscript(paragraph, base_text, superscript_text): "1. Sanne Muis, Maialen Irazoqui Apecechea, José Antonio Álvarez, Martin Verlaan, Kun Yan, Job Dullaart, " "Jeroen Aerts, Trang Duong, Rosh Ranasinghe, Dewi le Bars, Rein Haarsma, Malcolm Roberts, (2022): Global sea " "level change time series from 1950 to 2050 derived from reanalysis and high resolution CMIP6 climate " -"projections. Copernicus Climate Change Service (C3S) Climate Data Store (CDS). DOI: 10.24381/cds.a6d42d60 " -"(Accessed on 01-July-2024). \n\n" +"projections. Copernicus Climate Change Service (C3S) Climate Data Store (CDS). DOI: 10.24381/cdf.a6d42d60 " +"(Accessed on 01-July-2024). " "2. NORSOK Standard N-003:2017, Action and action effects. Revision No. 3, April 2017. URL: " -"http://www.standard.no/ \n\n" +"http://www.standard.no/ " "3. ISO 19901-1:2015, Petroleum and natural gas industries - Specific requirements for offshore structures Part " "1: Metocean design and operating conditions. International Organization for Standardization. URL " -"http://www.standard.no/ \n\n" +"http://www.standard.no/ " "4. DNV-RP-C205 Environmental conditions and environmental loads, April 2014. URL: " -"https://rules.dnvgl.com/servicedocuments/dnv \n\n" +"https://rules.dnvgl.com/servicedocuments/dnv " "5. Outten, Stephen & Sobolowski, Stefan. (2021). Extreme wind projections over Europe from the Euro-CORDEX " -"regional climate models. Weather and Climate Extremes. 33. 100363. 10.1016/j.wace.2021.100363. \n\n" +"regional climate models. Weather and Climate Extremes. 33. 100363. 10.1016/j.wace.2021.100363. " "6. T. Moan, Z. Gao, and E. Ayala-Uraga. Uncertainty of wave-induced response of marine structures due to " "long-term variation of extratropical wave conditions. Marine structures, 18(4):359–382, 2005. ISSN 0951-8339. " -"doi:10.1016/j.marstruc.2005.11.001. \n\n" -"7. G. L. DNV. Recommended practice DNVGL-RP-C205 environmental conditions and environmental loads. " -"Høvik: DNV GL AS, 2017. \n\n" -"8. G. L. DNV. Recommended practice DNVGL-RP-C205 environmental conditions and environmental loads. " -"Høvik: DNV GL AS, 2019. \n\n" +"doi:10.1016/j.marstruc.2005.11.001. " +"7. G. L. DNV. Recommended practice DNVGL-RP-C205 environmental conditions and environmental loadf. " +"Høvik: DNV GL AS, 2017. " +"8. G. L. DNV. Recommended practice DNVGL-RP-C205 environmental conditions and environmental loadf. " +"Høvik: DNV GL AS, 2019. " "9. Forristall, G. Z. (1978), On the statistical distribution of wave heights in a storm, Journal of Geophysical " -"Research, Vol. 83, No. C5, pp. 2353-2358. \n\n" +"Research, Vol. 83, No. C5, pp. 2353-2358. " "10. Meer, Ruurd & de Boer, M. & Liebich, Viola & Hallers, Cato & Veldhuis, Marcel & Ree, Karin. (2016). Ballast " -"Water Risk Indication for the North Sea. Coastal Management. 44. 1-22. 10.1080/08920753.2016.1233794. \n\n" +"Water Risk Indication for the North Sea. Coastal Management. 44. 1-22. 10.1080/08920753.2016.1233794. " "11. ISO 19901-1:2015, Petroleum and natural gas industries - Specific requirements for offshore structures – " "Part 1: Metocean design and operating conditions. International Organization for Standardization. " "12. Kristensen et al (2024), NORA-Surge: A storm surge hindcast for the Norwegian Sea, the North Sea and the " -"Barents Sea. \n\n" +"Barents Sea. " "13. Breivik, Ø., Carrasco, A., Haakenstad, H., Aarnes, O. J., Behrens, A., Bidlot, J.-R., Björkqvist, J.-V., Bohlinger, P., " "Furevik, B. R., Staneva, J., and Reistad, M.(2022). The impact of a reduced high-wind Charnock parameter on " "wave growth with application to the North Sea, the Norwegian Sea, and the Arctic Ocean. Journal of " -"Geophysical Research: Oceans, 127, e2021JC018196. https://doi.org/10.1029/2021JC018196 \n\n" +"Geophysical Research: Oceans, 127, e2021JC018196. https://doi.org/10.1029/2021JC018196 " "14. Haakenstad, H., Breivik, Ø., Furevik, B., Reistad, M., Bohlinger, P., & Aarnes, O. J. (2021). NORA3: A " "nonhydrostatic high-resolution hindcast of the North Sea, the Norwegian Sea, and the Barents Sea. Journal of " -"Applied Meteorology and Climatology. https://doi.org/10.1175/JAMC-D-21-0029.1 \n\n" +"Applied Meteorology and Climatology. https://doi.org/10.1175/JAMC-D-21-0029.1 " "15. Reistad, M., Ø. Breivik, H. Haakenstad, O. J. Aarnes, B. R. Furevik, and J.-R. Bidlot, 2011: A high-resolution " "hindcast of wind and waves for the North Sea, the Norwegian Sea, and the Barents Sea. J. Geophys. Res., 116, " "C05019, https://doi.org/10.1029/2010JC006402. " @@ -1166,7 +1182,7 @@ def add_superscript(paragraph, base_text, superscript_text): #----- SAVE AND OPEN ---- # Save the document -output_filename = 'metocean-report' +output_filename = folder + '/' +'metocean-report' # if overwrite fails (file exists/permission) write new file try: From 49a2b719409e599444d468a28f4cccbf1d5bcc8e Mon Sep 17 00:00:00 2001 From: KonstantinChri Date: Sun, 24 Nov 2024 18:43:24 +0100 Subject: [PATCH 6/9] update --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index fab3a72..0f7568a 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,7 @@ [![Documentation Status](https://readthedocs.org/projects/metocean-stats/badge/?version=latest)](https://metocean-stats.readthedocs.io/en/latest/?badge=latest) ## Purpose 🎯 -Metocean-stats is a tool for comprehensive statistics and visualization of metocean data (wind, waves, ocean currents, tide levels, air and water temperature, sea ice, and more). The tool is also compatible with WEkEO Jupyter Lab, allowing seamless integration and use. -[metocean-stats in WEkEO](https://docs.google.com/document/d/1uEvG_YZ43eu3vE33Qv9t5Bzd0QAmspKjqjzFLHEkJys/edit?usp=sharing). +Metocean-stats is a tool for comprehensive statistics and visualization of metocean data (wind, waves, ocean currents, tide levels, air and water temperature, sea ice, and more). The tool is also compatible with WEkEO Jupyter Lab, allowing seamless integration and use. For instructions on how to install metocean-stats in WEkEO, please refer [here](https://docs.google.com/document/d/1uEvG_YZ43eu3vE33Qv9t5Bzd0QAmspKjqjzFLHEkJys/edit?usp=sharing). ![metocean-stats](https://github.com/MET-OM/metocean-stats/blob/main/docs/files/readme_plots.png) From 6474f50cbbf81ceee19f6257cbed820cf1cd4277 Mon Sep 17 00:00:00 2001 From: KonstantinChri Date: Sun, 24 Nov 2024 19:06:11 +0100 Subject: [PATCH 7/9] update --- metocean_stats/tables/general.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/metocean_stats/tables/general.py b/metocean_stats/tables/general.py index ea4dacb..a05fdb8 100644 --- a/metocean_stats/tables/general.py +++ b/metocean_stats/tables/general.py @@ -6,6 +6,7 @@ import matplotlib.pyplot as plt import calendar from math import floor,ceil +from pathlib import Path from ..stats.aux_funcs import * from ..stats.general import * @@ -66,15 +67,18 @@ def scatter_diagram(data: pd.DataFrame, var1: str, step_var1: float, var2: str, pass dfout = pd.DataFrame(data=np.round(tbl,2), index=rows, columns=cols) - if output_file.suffix=='csv': - dfout.to_csv(output_file,index_label=var1+'/'+var2) - elif output_file.suffix=='png': + output_file = Path(output_file) + if output_file.suffix == '.csv': + dfout.to_csv(output_file, index_label=var1+'/'+var2) + elif output_file.suffix == '.png': hi = sns.heatmap(data=dfout.where(dfout>0), cbar=True, cmap='Blues', fmt=".1f") plt.ylabel(var1) plt.xlabel(var2) plt.tight_layout() plt.savefig(output_file) plt.close() + else: + print(f"Unsupported file type: {output_file.suffix}") return dfout From 0f0451863cfe0ce51c33967f158c14812029061a Mon Sep 17 00:00:00 2001 From: KonstantinChri Date: Mon, 25 Nov 2024 00:18:36 +0100 Subject: [PATCH 8/9] update --- examples/example_NORA_wind_waves.py | 8 +- examples/example_automatic_report.py | 246 +++------------------------ examples/example_maps.py | 5 +- metocean_stats/stats/doc_funcs.py | 208 ++++++++++++++++++++++ 4 files changed, 237 insertions(+), 230 deletions(-) create mode 100644 metocean_stats/stats/doc_funcs.py diff --git a/examples/example_NORA_wind_waves.py b/examples/example_NORA_wind_waves.py index d4e691d..49ad96f 100644 --- a/examples/example_NORA_wind_waves.py +++ b/examples/example_NORA_wind_waves.py @@ -4,6 +4,7 @@ import warnings warnings.filterwarnings("ignore") +##############PROVIDE INFO BY THE USER################# # Impot data (e.g., use metocean-api to download metocean data) ## For NORA10 data use: df = readNora10File('../tests/data/NORA_test.txt') @@ -17,7 +18,8 @@ var_hs = 'HS' # for significant wave height var_wave_dir= 'DIRM' # Mean wave direction var_tp = 'TP' # Peak Wave Period -output_folder = 'output_report' # folder where output figures and tables will be saved +output_folder = 'output_wind_waves' # folder where output figures and tables will be saved +###################################################### # Check if the output directory exists, if not, create it @@ -26,10 +28,6 @@ folder.mkdir(parents=True) # The following code is used to generate various plots and tables for wind and wave data analysis. -# Map: -#maps.plot_points_on_map(lon=[3.35], lat=[60.40],label=['NORA'],bathymetry='NORA3',output_file=folder / 'map.png') -#maps.plot_extreme_wave_map(return_period=100, product='NORA3', title='100-yr return values Hs (NORA3)', set_extent = [0,30,52,73],output_file=folder / 'wave_100yrs.png') -#maps.plot_extreme_wind_map(return_period=100, product='NORA3',z=10, title='100-yr return values Wind at 100 m (NORA3)', set_extent = [0,30,52,73], output_file=folder / 'wind_100yrs.png') # Wind: plots.var_rose(df,var_dir=var_wind_dir,var=var_wind,method='overall',max_perc=40,decimal_places=1, units='m/s',output_file=folder / 'wind_omni.png') diff --git a/examples/example_automatic_report.py b/examples/example_automatic_report.py index 4e7dbe2..6048e67 100644 --- a/examples/example_automatic_report.py +++ b/examples/example_automatic_report.py @@ -1,20 +1,17 @@ from metocean_stats import plots, tables, stats, maps from metocean_stats.stats.aux_funcs import * +from metocean_stats.stats.doc_funcs import * from docx import Document from docx.enum.text import WD_ALIGN_PARAGRAPH -from docx.shared import Inches, Pt, RGBColor, Cm from datetime import datetime import os -from docx.oxml import OxmlElement from docx.oxml.ns import qn # Import the qn function for XML namespaces -import requests from io import BytesIO -import lxml.etree as ET -from docx.enum.section import WD_ORIENTATION, WD_SECTION, WD_ORIENT from pathlib import Path import warnings warnings.filterwarnings("ignore") +##############PROVIDE INFO BY THE USER################# # Impot data (e.g., use metocean-api to download metocean data) ## For NORA10 data use: df = readNora10File('../tests/data/NORA_test.txt') @@ -30,6 +27,15 @@ var_tp = 'TP' # Peak Wave Period output_folder = 'output_report' # folder where output report and figures will be saved +# Manually Define varibles for the text in the report +LocationX = "North Sea" # Location name +lon = 3 # Latitude +lat = 60 # Longitude +label = ['NORA'] # Dataset used +chapter = ["wind", "waves"] # Hvilke del/kap som skal være med i rapporten +water_depth = 100 +###################################################### + # Check if the output directory exists, if not, create it folder = Path(__file__).parent / output_folder @@ -39,20 +45,11 @@ # Create a new Document doc = Document() -#__________MANUELLE BESTEMMELSER____________ -LocationX = "North Sea" -lon = 3 # endre manuelt fra område (lengegrad) -lat = 60 # breddegrad -label = ['NORA'] # dataset + + starttime = str(df.index[0]) endtime = str(df.index[-1]) -chapter = ["wind", "waves"] # Hvilke del/kap som skal være med i rapporten -wave_depth = 100 -# tables_in_report = [""] # putter in strings med tabellnavn i raporten -# figures_in_report = [""] # putter in strings med figurnavn i raporten -# ^ en alternativ ide til chapter - # _________________FRONTPAGE_______________ #_____________________Bunntekst og sidetall______ @@ -143,42 +140,7 @@ with open(logo_path, "wb") as file: file.write(response.content) -# Topptekst -def add_header(doc, title, logo_url): - # Hent logoen fra URL og lagre den midlertidig - response = requests.get(logo_url) - logo_bytes = BytesIO(response.content) - - # Iterer over hver seksjon i dokumentet - for section in doc.sections: - header = section.header - - # Legg til en tabell med 1 rad og 2 kolonner - table = header.add_table(rows=1, cols=2, width=Inches(6)) # Juster bredden etter behov - table.autofit = True - - # Sett kolonnebredder - for column in table.columns: - for cell in column.cells: - cell.width = Inches(3) # Sett passende bredde for cellene - - # Første celle: Legg til tekst - cell_text = table.cell(0, 0) - p = cell_text.paragraphs[0] - p.alignment = WD_ALIGN_PARAGRAPH.LEFT - title_run = p.add_run(f"Title: {title}") - title_run.font.size = Pt(11) - - today = datetime.today().strftime('%d.%m.%Y') - date_run = p.add_run(f"\nDate: {today}") - date_run.font.size = Pt(11) - - # Andre celle: Legg til logo - cell_logo = table.cell(0, 1) - p_logo = cell_logo.paragraphs[0] - p_logo.alignment = WD_ALIGN_PARAGRAPH.RIGHT # Høyrejuster logoen - logo_run = p_logo.add_run() - logo_run.add_picture(logo_bytes, width=Inches(0.8)) # Juster størrelsen etter behov + # Legg til topptekst med tittel title = LocationX+" Metocean Design Basis" @@ -352,157 +314,8 @@ def add_header(doc, title, logo_url): # ___________TEXT CONTENT______________ -# Funksjon som legger til et bilde og bildetekst i en tabell -def add_image_with_caption(doc, image_path, caption_text, orientation="portrait"): - # Lag en ny seksjon om det er landskap - if orientation == "landscape": - # Opprett en ny seksjon med landskapsorientering - new_section = doc.add_section(WD_SECTION.NEW_PAGE) - new_section.orientation = WD_ORIENTATION.LANDSCAPE - new_section.page_width, new_section.page_height = new_section.page_height, new_section.page_width - - # Juster bildebredden slik at det passer til sidebredden - max_image_width = doc.sections[-1].page_width.inches - doc.sections[-1].left_margin.inches - doc.sections[-1].right_margin.inches - - # Lag en tabell med 2 rader og 1 kolonne - table = doc.add_table(rows=2, cols=1) - table.style = 'Table Grid' # Sett tabellstilen - - # Første celle: bilde - cell_image = table.cell(0, 0) - paragraph_image = cell_image.paragraphs[0] - paragraph_image.alignment = WD_ALIGN_PARAGRAPH.CENTER # Midtstill paragrafen som inneholder bildet - run_image = paragraph_image.add_run() - - # Legg til bildet i den første cellen - image_width = Inches(max_image_width * 0.95) if orientation == "landscape" else Inches(max_image_width) - run_image.add_picture(image_path, width=image_width) - - # Andre celle: bildetekst - cell_caption = table.cell(1, 0) - cell_caption.text = caption_text - - # Sentraliser bildeteksten - paragraph_caption = cell_caption.paragraphs[0] - paragraph_caption.alignment = WD_ALIGN_PARAGRAPH.CENTER # Sentralisert - - # Fjerne plass før og etter avsnitt - for row in table.rows: - for cell in row.cells: - for paragraph in cell.paragraphs: - paragraph.space_after = 0 # Fjerner eventuell plass etter avsnitt - paragraph.space_before = 0 # Fjerner eventuell plass før avsnitt - - # Sikre at tabellen ikke har ekstra mellomrom - table.autofit = True # Sett til True for å tilpasse størrelsen basert på innhold - cell_image.width = Inches(max_image_width) - cell_caption.width = Inches(max_image_width) - - # Legg til en ny seksjon i portrettorientering hvis nødvendig - if orientation == "landscape": - portrait_section = doc.add_section(WD_SECTION.NEW_PAGE) - portrait_section.orientation = WD_ORIENTATION.PORTRAIT - portrait_section.page_width, portrait_section.page_height = portrait_section.page_height, portrait_section.page_width - - -#-----------Funkjson for Tabell--------------- -def add_table_to_doc(doc, df, col_width=50, row_height=0.7, header_text="", header_color='D3D3D3', data_color=None): - - if df.index.name or df.index.names != [None]: - df = df.reset_index() # Dette flytter indeksen til en kolonne hvis indeksen har et navn - - num_columns = len(df.columns) # Legg til én ekstra kolonne til venstre - landscape_section = False - - # Opprett en ny seksjon i landskapmodus hvis det er mange kolonner - if num_columns > 10: - landscape_section = True - current_section = doc.add_section(WD_SECTION.NEW_PAGE) - current_section.orientation = WD_ORIENTATION.LANDSCAPE - current_section.page_width, current_section.page_height = current_section.page_height, current_section.page_width - current_section.top_margin = Cm(1.5) - current_section.bottom_margin = Cm(1.5) - - # Legg til hovedoverskriften i dokumentet - if header_text: - header_paragraph = doc.add_heading(header_text, level=3) - header_paragraph.paragraph_format.keep_with_next = True - - # Beregn tilgjengelig bredde for tabellen - section = doc.sections[-1] - available_width = section.page_width - section.left_margin - section.right_margin - column_width = available_width / num_columns - - # Opprett tabellen med riktig antall kolonner, men bare én header-rad - table = doc.add_table(rows=1, cols=num_columns) - table.style = 'Table Grid' - - # Fyll header-celler med kolonnenavnene fra DataFrame - hdr_cells = table.rows[0].cells - for i, column in enumerate(df.columns): - hdr_cells[i].text = column - run = hdr_cells[i].paragraphs[0].runs[0] - run.bold = True - run.font.size = Pt(9) - cell_pr = hdr_cells[i]._element.get_or_add_tcPr() - shd = OxmlElement('w:shd') - shd.set('{http://schemas.openxmlformats.org/wordprocessingml/2006/main}fill', header_color) - cell_pr.append(shd) - - # Fyll de øvrige header-cellene med kolonnenavnene fra DataFrame - for i, column in enumerate(df.columns): - hdr_cells[i].text = column - run = hdr_cells[i].paragraphs[0].runs[0] - run.bold = True - run.font.size = Pt(9) - cell_pr = hdr_cells[i]._element.get_or_add_tcPr() - shd = OxmlElement('w:shd') - shd.set('{http://schemas.openxmlformats.org/wordprocessingml/2006/main}fill', header_color) - cell_pr.append(shd) - - # Legg til data-rader og fyll venstre kolonne med indeksverdiene - for index, row in df.iterrows(): - row_cells = table.add_row().cells - row_cells[0].text = str(index) # Fyll første celle med indeks - run = row_cells[0].paragraphs[0].runs[0] - run.font.size = Pt(9) - if data_color: - cell_pr = row_cells[0]._element.get_or_add_tcPr() - shd = OxmlElement('w:shd') - shd.set('{http://schemas.openxmlformats.org/wordprocessingml/2006/main}fill', data_color) - cell_pr.append(shd) - - # Fyll resten av radene med verdier fra DataFrame - for j, value in enumerate(row): - if isinstance(value, (float, int)): - value = f"{value:.1f}" - row_cells[j].text = str(value) - run = row_cells[j].paragraphs[0].runs[0] - run.font.size = Pt(9) - - # Juster høyden på alle rader - row_height_cm = Cm(row_height) - height_twips = int(row_height_cm.pt * 20) - for row in table.rows: - tr = row._element - tr_pr = tr.get_or_add_trPr() - cant_split = OxmlElement('w:cantSplit') - cant_split.set('{http://schemas.openxmlformats.org/wordprocessingml/2006/main}val', 'true') - tr_pr.append(cant_split) - - height = OxmlElement('w:trHeight') - height.set('{http://schemas.openxmlformats.org/wordprocessingml/2006/main}val', str(height_twips)) - tr_pr.append(height) - - # Bytt tilbake til portrettmodus hvis landskap ble brukt - if landscape_section: - portrait_section = doc.add_section(WD_SECTION.NEW_PAGE) - portrait_section.orientation = WD_ORIENTATION.PORTRAIT - portrait_section.page_width, portrait_section.page_height = portrait_section.page_height, portrait_section.page_width - portrait_section.left_margin = Cm(2.5) - portrait_section.right_margin = Cm(2.5) - portrait_section.top_margin = Cm(1.5) - portrait_section.bottom_margin = Cm(1.5) + + #----------------------- @@ -558,8 +371,7 @@ def add_table_to_doc(doc, df, col_width=50, row_height=0.7, header_text="", head output_file=folder + '/' +'map.png' maps.plot_points_on_map(lon,lat,label,bathymetry='NORA3',output_file=output_file) -doc.add_picture(output_file, width=Inches(6)) -doc.add_heading('Figure 3.1: The figure shows the NORA3 grid points selected for the analysis', level=3) +add_image_with_caption(doc, output_file, 'Figure 3.1: The figure shows the NORA3 grid points selected for the analysis', orientation="portrait") ## Add a blank paragraph to ensure there is no extra spacing doc.add_paragraph() @@ -571,16 +383,13 @@ def add_table_to_doc(doc, df, col_width=50, row_height=0.7, header_text="", head doc.add_paragraph() output_file=folder + '/' +'wind_100yrs.png' maps.plot_extreme_wind_map(return_period=100, product='NORA3',z=10, title='100-yr return values Wind at 100 m (NORA3)', set_extent = [0,30,52,73], output_file=output_file) -doc.add_picture(output_file, width=Inches(5)) -doc.add_heading("Figure 3.2: 100-year return period for wind speed at 10 m in the Nordics based on NORA3 (period: 1991-2020) using Generalized " -"Pareto distribution (POT; threshold is the minimum of all annual maxima, method described by [5]).", level=3) +add_image_with_caption(doc, output_file, 'Figure 3.2: 100-year return period for wind speed at 10 m in the Nordics based on NORA3 (period: 1991-2020) using Generalized. Pareto distribution (POT; threshold is the minimum of all annual maxima, method described by [5]).', orientation="portrait") + doc.add_paragraph() output_file=folder + '/' +'wave_100yrs.png' maps.plot_extreme_wave_map(return_period=100, product='NORA3', title='100-yr return values Hs (NORA3)', set_extent = [0,30,52,73],output_file=output_file) -doc.add_picture(output_file, width=Inches(5)) -doc.add_heading("Figure 3.3: 100-year return period for significant wave height in the Nordics based on NORA3 (period: 1991-2020) using Gumbel " -"distribution (Annual maxima).", level=3) +add_image_with_caption(doc, output_file, "Figure 3.3: 100-year return period for significant wave height in the Nordics based on NORA3 (period: 1991-2020) using Gumbel distribution (Annual maxima).", orientation="portrait") doc.add_paragraph() doc.add_page_break() @@ -630,11 +439,9 @@ def add_table_to_doc(doc, df, col_width=50, row_height=0.7, header_text="", head add_table_to_doc(doc, df1, col_width=50, row_height=0.7, header_color='D3D3D3', data_color='D2B48C') -doc.add_heading ("W10 [m/s] at the " + LocationX + " field") - # Legg til Figur 4.2 -plots.plot_directional_stats(df,var=var_hs,step_var=0.5, var_dir=var_wave_dir, title = 'Hs[m]', output_file=folder + "/" +"directional_stats.png") -add_image_with_caption(doc, folder + '/' +'directional_stats.png', "Figure 4.2: Directional distribution of mean, P99 and maximum wind speed at 10 m above mean sea level at the " + LocationX + " field.", orientation="portrait") +plots.plot_directional_stats(df,var=var_wind,step_var=0.5, var_dir=var_wind_dir, title = 'W10[m/s]', output_file=folder + "/" +"directional_wind_stats.png") +add_image_with_caption(doc, folder + '/' +'directional_wind_stats.png', "Figure 4.2: Directional distribution of mean, P99 and maximum wind speed at 10 m above mean sea level at the " + LocationX + " field.", orientation="portrait") doc.add_page_break() @@ -645,7 +452,7 @@ def add_table_to_doc(doc, df, col_width=50, row_height=0.7, header_text="", head # Legge til figur 4.3 -plots.plot_monthly_stats(df,var="W10",show=["min","mean","max"],title='Montly W10 [m/s]',fill_between=["25%","75%"],fill_color_like="mean",output_file=folder + '/' +'monthly_wind_stats.png') +plots.plot_monthly_stats(df,var="W10",show=["min","mean","max"],title='Monthly W10 [m/s]',fill_between=["25%","75%"],fill_color_like="mean",output_file=folder + '/' +'monthly_wind_stats.png') add_image_with_caption(doc, folder + '/' +'monthly_wind_stats.png', "Figure 4.3: Monthly distribution of mean, P99 and maximum wind speed 10 m above mean sea level at the " + LocationX + " field.", orientation="portrait") # Legg til figur 4.4 @@ -826,7 +633,7 @@ def add_table_to_doc(doc, df, col_width=50, row_height=0.7, header_text="", head f"Wave data for Norwegian coastal waters are available from the NORA10 hindcast model operated by the " f"Norwegian Meteorological Institute [10]. The data cover the period {starttime} – {endtime}. The sample interval " "is 3 hours. The NORA10 model has a spatial resolution of 10 km.)" -f"Wave data from grid point position {lat}°N, {lon}°E is used in the analysis. A reference water depth of {wave_depth} m " +f"Wave data from grid point position {lat}°N, {lon}°E is used in the analysis. A reference water depth of {water_depth} m " "below MSL is used.") doc.add_paragraph() @@ -1086,11 +893,6 @@ def add_table_to_doc(doc, df, col_width=50, row_height=0.7, header_text="", head doc.add_paragraph() #_______________________________________ -# Function to add superscript text -def add_superscript(paragraph, base_text, superscript_text): - run = paragraph.add_run(base_text) - superscript_run = paragraph.add_run(superscript_text) - superscript_run.font.superscript = True # 5.1.8 Wind-wave correlation doc.add_heading(f"5.1.8 Wind-wave correlation", level=3) diff --git a/examples/example_maps.py b/examples/example_maps.py index fe7b7b2..809f82a 100644 --- a/examples/example_maps.py +++ b/examples/example_maps.py @@ -3,13 +3,12 @@ import warnings warnings.filterwarnings("ignore") -folder = Path(__file__).parent / 'output' / 'maps' +folder = Path(__file__).parent / 'maps' if not folder.exists(): folder.mkdir(parents=True) # Map: +maps.plot_points_on_map(lon=[3.35,3.10], lat=[60.40,60.90],label=['NORA3','NORKYST800'],bathymetry='NORA3',output_file= folder /'map.png') maps.plot_extreme_wave_map(return_period=100, product='NORA3', title='100-yr return values Hs (NORA3)', set_extent = [0,30,52,73],output_file= folder / 'wave_100yrs.png') - maps.plot_extreme_wind_map(return_period=100, product='NORA3',z=100, title='100-yr return values Wind at 100 m (NORA3)', set_extent = [0,30,52,73], output_file=folder / 'wind_100yrs_100m.png') - maps.plot_extreme_wind_map(return_period=100, product='NORA3',z=10, title='100-yr return values Wind at 10 m (NORA3)', set_extent = [0,30,52,73], output_file= folder / 'wind_100yrs_10m.png') diff --git a/metocean_stats/stats/doc_funcs.py b/metocean_stats/stats/doc_funcs.py new file mode 100644 index 0000000..fa24eb6 --- /dev/null +++ b/metocean_stats/stats/doc_funcs.py @@ -0,0 +1,208 @@ +from docx.enum.text import WD_ALIGN_PARAGRAPH +from docx.shared import Inches, Pt, RGBColor, Cm +from docx.enum.section import WD_ORIENTATION, WD_SECTION, WD_ORIENT +import requests +from io import BytesIO +from datetime import datetime +from docx.oxml import OxmlElement + +# Topptekst +def add_header(doc, title, logo_url): + # Hent logoen fra URL og lagre den midlertidig + response = requests.get(logo_url) + logo_bytes = BytesIO(response.content) + + # Iterer over hver seksjon i dokumentet + for section in doc.sections: + header = section.header + + # Legg til en tabell med 1 rad og 2 kolonner + table = header.add_table(rows=1, cols=2, width=Inches(6)) # Juster bredden etter behov + table.autofit = True + + # Sett kolonnebredder + for column in table.columns: + for cell in column.cells: + cell.width = Inches(3) # Sett passende bredde for cellene + + # Første celle: Legg til tekst + cell_text = table.cell(0, 0) + p = cell_text.paragraphs[0] + p.alignment = WD_ALIGN_PARAGRAPH.LEFT + title_run = p.add_run(f"Title: {title}") + title_run.font.size = Pt(11) + + today = datetime.today().strftime('%d.%m.%Y') + date_run = p.add_run(f"\nDate: {today}") + date_run.font.size = Pt(11) + + # Andre celle: Legg til logo + cell_logo = table.cell(0, 1) + p_logo = cell_logo.paragraphs[0] + p_logo.alignment = WD_ALIGN_PARAGRAPH.RIGHT # Høyrejuster logoen + logo_run = p_logo.add_run() + logo_run.add_picture(logo_bytes, width=Inches(0.8)) # Juster størrelsen etter behov + +# Funksjon som legger til et bilde og bildetekst i en tabell +def add_image_with_caption(doc, image_path, caption_text, orientation="portrait"): + # Lag en ny seksjon om det er landskap + if orientation == "landscape": + # Opprett en ny seksjon med landskapsorientering + new_section = doc.add_section(WD_SECTION.NEW_PAGE) + new_section.orientation = WD_ORIENTATION.LANDSCAPE + new_section.page_width, new_section.page_height = new_section.page_height, new_section.page_width + + # Juster bildebredden slik at det passer til sidebredden + max_image_width = doc.sections[-1].page_width.inches - doc.sections[-1].left_margin.inches - doc.sections[-1].right_margin.inches + + # Lag en tabell med 2 rader og 1 kolonne + table = doc.add_table(rows=2, cols=1) + table.style = 'Table Grid' # Sett tabellstilen + + # Første celle: bilde + cell_image = table.cell(0, 0) + paragraph_image = cell_image.paragraphs[0] + paragraph_image.alignment = WD_ALIGN_PARAGRAPH.CENTER # Midtstill paragrafen som inneholder bildet + run_image = paragraph_image.add_run() + + # Legg til bildet i den første cellen + image_width = Inches(max_image_width * 0.95) if orientation == "landscape" else Inches(max_image_width) + run_image.add_picture(image_path, width=image_width) + + # Andre celle: bildetekst + cell_caption = table.cell(1, 0) + cell_caption.text = caption_text + + # Sentraliser bildeteksten + paragraph_caption = cell_caption.paragraphs[0] + paragraph_caption.alignment = WD_ALIGN_PARAGRAPH.CENTER # Sentralisert + + # Fjerne plass før og etter avsnitt + for row in table.rows: + for cell in row.cells: + for paragraph in cell.paragraphs: + paragraph.space_after = 0 # Fjerner eventuell plass etter avsnitt + paragraph.space_before = 0 # Fjerner eventuell plass før avsnitt + + # Sikre at tabellen ikke har ekstra mellomrom + table.autofit = True # Sett til True for å tilpasse størrelsen basert på innhold + cell_image.width = Inches(max_image_width) + cell_caption.width = Inches(max_image_width) + + # Legg til en ny seksjon i portrettorientering hvis nødvendig + if orientation == "landscape": + portrait_section = doc.add_section(WD_SECTION.NEW_PAGE) + portrait_section.orientation = WD_ORIENTATION.PORTRAIT + portrait_section.page_width, portrait_section.page_height = portrait_section.page_height, portrait_section.page_width + + + + +#-----------Funkjson for Tabell--------------- +def add_table_to_doc(doc, df, col_width=50, row_height=0.7, header_text="", header_color='D3D3D3', data_color=None): + + if df.index.name or df.index.names != [None]: + df = df.reset_index() # Dette flytter indeksen til en kolonne hvis indeksen har et navn + + num_columns = len(df.columns) # Legg til én ekstra kolonne til venstre + landscape_section = False + + # Opprett en ny seksjon i landskapmodus hvis det er mange kolonner + if num_columns > 10: + landscape_section = True + current_section = doc.add_section(WD_SECTION.NEW_PAGE) + current_section.orientation = WD_ORIENTATION.LANDSCAPE + current_section.page_width, current_section.page_height = current_section.page_height, current_section.page_width + current_section.top_margin = Cm(1.5) + current_section.bottom_margin = Cm(1.5) + + # Legg til hovedoverskriften i dokumentet + if header_text: + header_paragraph = doc.add_heading(header_text, level=3) + header_paragraph.paragraph_format.keep_with_next = True + + # Beregn tilgjengelig bredde for tabellen + section = doc.sections[-1] + available_width = section.page_width - section.left_margin - section.right_margin + column_width = available_width / num_columns + + # Opprett tabellen med riktig antall kolonner, men bare én header-rad + table = doc.add_table(rows=1, cols=num_columns) + table.style = 'Table Grid' + + # Fyll header-celler med kolonnenavnene fra DataFrame + hdr_cells = table.rows[0].cells + for i, column in enumerate(df.columns): + hdr_cells[i].text = column + run = hdr_cells[i].paragraphs[0].runs[0] + run.bold = True + run.font.size = Pt(9) + cell_pr = hdr_cells[i]._element.get_or_add_tcPr() + shd = OxmlElement('w:shd') + shd.set('{http://schemas.openxmlformats.org/wordprocessingml/2006/main}fill', header_color) + cell_pr.append(shd) + + # Fyll de øvrige header-cellene med kolonnenavnene fra DataFrame + for i, column in enumerate(df.columns): + hdr_cells[i].text = column + run = hdr_cells[i].paragraphs[0].runs[0] + run.bold = True + run.font.size = Pt(9) + cell_pr = hdr_cells[i]._element.get_or_add_tcPr() + shd = OxmlElement('w:shd') + shd.set('{http://schemas.openxmlformats.org/wordprocessingml/2006/main}fill', header_color) + cell_pr.append(shd) + + # Legg til data-rader og fyll venstre kolonne med indeksverdiene + for index, row in df.iterrows(): + row_cells = table.add_row().cells + row_cells[0].text = str(index) # Fyll første celle med indeks + run = row_cells[0].paragraphs[0].runs[0] + run.font.size = Pt(9) + if data_color: + cell_pr = row_cells[0]._element.get_or_add_tcPr() + shd = OxmlElement('w:shd') + shd.set('{http://schemas.openxmlformats.org/wordprocessingml/2006/main}fill', data_color) + cell_pr.append(shd) + + # Fyll resten av radene med verdier fra DataFrame + for j, value in enumerate(row): + if isinstance(value, (float, int)): + value = f"{value:.1f}" + row_cells[j].text = str(value) + run = row_cells[j].paragraphs[0].runs[0] + run.font.size = Pt(9) + + # Juster høyden på alle rader + row_height_cm = Cm(row_height) + height_twips = int(row_height_cm.pt * 20) + for row in table.rows: + tr = row._element + tr_pr = tr.get_or_add_trPr() + cant_split = OxmlElement('w:cantSplit') + cant_split.set('{http://schemas.openxmlformats.org/wordprocessingml/2006/main}val', 'true') + tr_pr.append(cant_split) + + height = OxmlElement('w:trHeight') + height.set('{http://schemas.openxmlformats.org/wordprocessingml/2006/main}val', str(height_twips)) + tr_pr.append(height) + + # Bytt tilbake til portrettmodus hvis landskap ble brukt + if landscape_section: + portrait_section = doc.add_section(WD_SECTION.NEW_PAGE) + portrait_section.orientation = WD_ORIENTATION.PORTRAIT + portrait_section.page_width, portrait_section.page_height = portrait_section.page_height, portrait_section.page_width + portrait_section.left_margin = Cm(2.5) + portrait_section.right_margin = Cm(2.5) + portrait_section.top_margin = Cm(1.5) + portrait_section.bottom_margin = Cm(1.5) + + + + +# Function to add superscript text +def add_superscript(paragraph, base_text, superscript_text): + run = paragraph.add_run(base_text) + superscript_run = paragraph.add_run(superscript_text) + superscript_run.font.superscript = True + From 6122dcdf620eecb37fbec74fa82e6160a5b294b0 Mon Sep 17 00:00:00 2001 From: KonstantinChri Date: Mon, 25 Nov 2024 00:45:04 +0100 Subject: [PATCH 9/9] update --- metocean_stats/stats/extreme.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/metocean_stats/stats/extreme.py b/metocean_stats/stats/extreme.py index c1c343c..60dfd89 100644 --- a/metocean_stats/stats/extreme.py +++ b/metocean_stats/stats/extreme.py @@ -834,6 +834,8 @@ def directional_extremes(data: pd.DataFrame, var: str, var_dir: str, periods=[1, for dir in range(0,360,30): sector_data = data[data['direction_sector']==dir] + if sector_data.empty: + sector_data = data * 0 # fill with zeros, this will give 0 extremes for empety sectors if isinstance(threshold, str) and threshold.startswith('P'): threshold_value = sector_data[var].quantile(int(threshold.split('P')[1])/100) @@ -894,7 +896,6 @@ def directional_extremes(data: pd.DataFrame, var: str, var_dir: str, periods=[1, # Replace values in each column that exceed the thresholds for col in range(return_values.shape[1]): return_values[:, col] = np.minimum(return_values[:, col], thresholds[col]) - return params, return_values, sector_prob, threshold_values, num_events_per_year def monthly_joint_distribution_Hs_Tp_weibull(data, var='hs', periods=[1, 10, 100, 10000]):