diff --git a/examples/hydrodynamic-models/test_case/inputs/gauges/discharge_long_ts/statistical-analysis-results/figures/F-444222.png b/examples/hydrodynamic-models/test_case/inputs/gauges/discharge_long_ts/statistical-analysis-results/figures/F-444222.png index 64c0fb4..9df7270 100644 Binary files a/examples/hydrodynamic-models/test_case/inputs/gauges/discharge_long_ts/statistical-analysis-results/figures/F-444222.png and b/examples/hydrodynamic-models/test_case/inputs/gauges/discharge_long_ts/statistical-analysis-results/figures/F-444222.png differ diff --git a/examples/hydrodynamic-models/test_case/inputs/gauges/discharge_long_ts/statistical-analysis-results/figures/F-888555.png b/examples/hydrodynamic-models/test_case/inputs/gauges/discharge_long_ts/statistical-analysis-results/figures/F-888555.png index d42b7d9..540e923 100644 Binary files a/examples/hydrodynamic-models/test_case/inputs/gauges/discharge_long_ts/statistical-analysis-results/figures/F-888555.png and b/examples/hydrodynamic-models/test_case/inputs/gauges/discharge_long_ts/statistical-analysis-results/figures/F-888555.png differ diff --git a/examples/hydrodynamic-models/test_case/inputs/gauges/discharge_long_ts/statistical-analysis-results/figures/F-999666.png b/examples/hydrodynamic-models/test_case/inputs/gauges/discharge_long_ts/statistical-analysis-results/figures/F-999666.png index 67eea81..6c1a9bb 100644 Binary files a/examples/hydrodynamic-models/test_case/inputs/gauges/discharge_long_ts/statistical-analysis-results/figures/F-999666.png and b/examples/hydrodynamic-models/test_case/inputs/gauges/discharge_long_ts/statistical-analysis-results/figures/F-999666.png differ diff --git a/tests/plot/__init__.py b/tests/plot/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/plot/conftest.py b/tests/plot/conftest.py new file mode 100644 index 0000000..f78edc6 --- /dev/null +++ b/tests/plot/conftest.py @@ -0,0 +1,27 @@ +import pytest + +# xs in segment 3 +fromxs = 230 +toxs = 235 +start = "1955-02-10" +end = "1955-02-11" + + +@pytest.fixture(scope="module") +def plot_xs_seg3_fromxs() -> int: + return fromxs + + +@pytest.fixture(scope="module") +def plot_xs_seg3_toxs() -> int: + return toxs + + +@pytest.fixture(scope="module") +def animate_start() -> str: + return start + + +@pytest.fixture(scope="module") +def animate_end() -> str: + return end diff --git a/tests/plot/map/__init__.py b/tests/plot/map/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/plot/test_visualiser.py b/tests/plot/test_visualiser.py new file mode 100644 index 0000000..b687543 --- /dev/null +++ b/tests/plot/test_visualiser.py @@ -0,0 +1,209 @@ +import matplotlib.pyplot as plt +from matplotlib.figure import Figure + +import serapis.river as R +from serapis.interface import Interface +from serapis.plot.visualizer import Visualize as V + + +def test_ground_surface( + version: int, + river_cross_section_path: str, + river_network_path: str, + dates: list, + segment3: int, + interface_bc_path: str, + interface_bc_folder: str, + interface_bc_date_format: str, + interface_laterals_table_path: str, + interface_laterals_folder: str, + interface_laterals_date_format: str, + read_1d_result_path: str, +): + River = R.River("HM", version=version, start=dates[0]) + River.read_xs(river_cross_section_path) + River.read_river_network(river_network_path) + River.one_d_result_path = read_1d_result_path + Sub = R.Reach(segment3, River) + + IF = Interface("Rhine", start=dates[0]) + IF.read_boundary_conditions_table(interface_bc_path) + IF.read_boundary_conditions( + path=interface_bc_folder, date_format=interface_bc_date_format + ) + + IF.read_xs(river_cross_section_path) + IF.read_laterals_table(interface_laterals_table_path) + IF.read_laterals( + path=interface_laterals_folder, date_format=interface_laterals_date_format + ) + + Sub.get_flow(IF) + Sub.read_1d_results(extension=".zip") + + Vis = V(resolution="Hourly") + Vis.plotGroundSurface( + Sub, floodplain=True, plot_lateral=True, xlabels_number=20, option=2 + ) + plt.close() + Vis.plotGroundSurface( + Sub, floodplain=True, plot_lateral=True, xlabels_number=20, option=1 + ) + plt.close() + + +def test_cross_sections( + version: int, + river_cross_section_path: str, + river_network_path: str, + dates: list, + segment3: int, + interface_bc_path: str, + interface_bc_folder: str, + interface_bc_date_format: str, + interface_laterals_table_path: str, + interface_laterals_folder: str, + interface_laterals_date_format: str, + read_1d_result_path: str, + plot_xs_seg3_fromxs: int, + plot_xs_seg3_toxs: int, +): + River = R.River("HM", version=version, start=dates[0]) + River.read_xs(river_cross_section_path) + River.read_river_network(river_network_path) + River.one_d_result_path = read_1d_result_path + Sub = R.Reach(segment3, River) + Vis = V(resolution="Hourly") + + fig, ax = Vis.plotCrossSections( + Sub, + bedlevel=True, + from_xs=plot_xs_seg3_fromxs, + to_xs=plot_xs_seg3_toxs, + same_scale=True, + text_spacing=[(1, 1), (1, 4)], + plotting_option=3, + ) + plt.close() + assert isinstance(fig, Figure) + + +# TODO: figure out how to close the animation after it finishes +# def test_WaterSurfaceProfile( +# version: int, +# river_cross_section_path: str, +# river_network_path: str, +# dates:list, +# segment3: int, +# interface_bc_path: str, +# interface_bc_folder: str, +# interface_bc_date_format: str, +# interface_laterals_table_path: str, +# interface_laterals_folder: str, +# interface_laterals_date_format: str, +# Read1DResult_path: str, +# usbc_path: str, +# animate_start: str, +# animate_end: str +# +# ): +# River = R.River('HM', version=version, start=dates[0]) +# River.ReadCrossSections(river_cross_section_path) +# River.RiverNetwork(river_network_path) +# River.one_d_result_path = Read1DResult_path +# River.us_bc_path = usbc_path +# Reach = R.Reach(segment3, River) +# +# IF = Interface('Rhine', start=dates[0]) +# IF.ReadBoundaryConditionsTable(interface_bc_path) +# IF.ReadBoundaryConditions(path=interface_bc_folder, date_format=interface_bc_date_format) +# +# IF.ReadCrossSections(river_cross_section_path) +# IF.ReadLateralsTable(interface_laterals_table_path) +# IF.ReadLaterals(path=interface_laterals_folder, date_format=interface_laterals_date_format) +# +# Reach.GetFlow(IF) +# Reach.Read1DResult() +# Reach.ReadBoundaryConditions(start=dates[0], end=dates[1]) +# +# Vis = V(resolution="Hourly") +# Anim = Vis.WaterSurfaceProfile(Reach, animate_start, animate_end, fps=2, xlabels_number=5, +# x_axis_label_size=10, text_location=(-1, -2),repeat=False) +# # rc('animation', html='jshtml') +# plt.close() +# assert isinstance(Anim, FuncAnimation) +# +# +# def test_WaterSurfaceProfile1Min( +# version: int, +# river_cross_section_path: str, +# river_network_path: str, +# dates:list, +# segment3: int, +# interface_bc_path: str, +# interface_bc_folder: str, +# interface_bc_date_format: str, +# interface_laterals_table_path: str, +# interface_laterals_folder: str, +# interface_laterals_date_format: str, +# Read1DResult_path: str, +# usbc_path: str, +# animate_start: str, +# animate_end: str, +# lastsegment: bool, +# subdailyresults_path: str, +# +# ): +# River = R.River('HM', version=version, start=dates[0]) +# River.ReadCrossSections(river_cross_section_path) +# River.RiverNetwork(river_network_path) +# River.one_d_result_path = Read1DResult_path +# River.one_min_result_path = subdailyresults_path +# River.us_bc_path = usbc_path +# Reach = R.Reach(segment3, River) +# +# IF = Interface('Rhine', start=dates[0]) +# IF.ReadBoundaryConditionsTable(interface_bc_path) +# IF.ReadBoundaryConditions(path=interface_bc_folder, date_format=interface_bc_date_format) +# +# IF.ReadCrossSections(river_cross_section_path) +# IF.ReadLateralsTable(interface_laterals_table_path) +# IF.ReadLaterals(path=interface_laterals_folder, date_format=interface_laterals_date_format) +# +# Reach.GetFlow(IF) +# Reach.Read1DResult() +# Reach.ReadSubDailyResults(animate_start, animate_end, last_river_reach=lastsegment) +# Reach.ReadBoundaryConditions(start=animate_start, end=animate_end) +# +# Vis = V(resolution="Hourly") +# Anim = Vis.WaterSurfaceProfile1Min(Reach, animate_start, animate_end, +# interval=0.000000000000000000000000000000000001, +# repeat=False) +# +# plt.close() +# assert isinstance(Anim, FuncAnimation) + + +def test_Plot1minProfile( + version: int, + river_cross_section_path: str, + river_network_path: str, + dates: list, + segment3: int, + subdailyresults_path: str, + usbc_path: str, + onemin_results_dates: list, + lastsegment: bool, +): + River = R.River("HM", version=version, start=dates[0]) + River.read_xs(river_cross_section_path) + River.read_river_network(river_network_path) + River.us_bc_path = usbc_path + River.one_min_result_path = subdailyresults_path + Sub = R.Reach(segment3, River) + Sub.read_sub_daily_results( + onemin_results_dates[0], onemin_results_dates[1], last_river_reach=lastsegment + ) + + Vis = V(resolution="Hourly") + Vis.plot1minProfile(Sub, dates[0], xlabels_number=20)