Skip to content

Commit

Permalink
delete logconfig; add plot_rainfall_runoff_xu
Browse files Browse the repository at this point in the history
  • Loading branch information
OuyangWenyu committed Jan 14, 2025
1 parent 5cd3e82 commit e6deabb
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 15 deletions.
16 changes: 3 additions & 13 deletions hydroutils/hydro_log.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
"""
Author: Wenyu Ouyang
Date: 2023-10-25 20:07:14
LastEditTime: 2023-10-27 14:53:05
LastEditTime: 2025-01-14 08:47:41
LastEditors: Wenyu Ouyang
Description: Use rich to log: https://rich.readthedocs.io/en/latest/
FilePath: /hydroutils/hydroutils/hydro_logger.py
FilePath: \hydroutils\hydroutils\hydro_log.py
Copyright (c) 2023-2024 Wenyu Ouyang. All rights reserved.
"""
from rich.logging import RichHandler
import logging

from rich.console import Console
from rich.text import Text

logging.basicConfig(
level="DEBUG", format="%(message)s", datefmt="[%X]", handlers=[RichHandler()]
)

hydro_logger = logging.getLogger("rich")


class HydroWarning:
def __init__(self):
Expand All @@ -41,6 +34,3 @@ def operation_successful(self, operation_detail, message=None):
if message is None:
message = Text(f"Operation Success: {operation_detail}", style="bold green")
self.console.print(message)


hydro_warning = HydroWarning()
52 changes: 50 additions & 2 deletions hydroutils/hydro_plot.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Author: Wenyu Ouyang
Date: 2022-12-02 10:59:30
LastEditTime: 2024-09-28 09:50:42
LastEditTime: 2025-01-14 09:06:45
LastEditors: Wenyu Ouyang
Description: Some common plots for hydrology
FilePath: \hydroutils\hydroutils\hydro_plot.py
Expand Down Expand Up @@ -1318,6 +1318,7 @@ def plot_rainfall_runoff(
title=None,
xlabel=None,
ylabel=None,
prcp_ylabel="prcp(mm/day)",
linewidth=1,
prcp_interval=20,
):
Expand Down Expand Up @@ -1384,11 +1385,58 @@ def plot_rainfall_runoff(
ax.set_ylabel(ylabel, fontsize=18)
if xlabel is not None:
ax.set_xlabel(xlabel, fontsize=18)
ax2.set_ylabel("prcp(mm/day)", fontsize=8, loc="top")
ax2.set_ylabel(prcp_ylabel, fontsize=8, loc="top")
# ax2.set_ylabel("precipitation (mm/day)", fontsize=12, loc='top')
# https://github.com/matplotlib/matplotlib/issues/12318
ax.tick_params(axis="x", labelsize=16)
ax.tick_params(axis="y", labelsize=16)
ax.legend(bbox_to_anchor=(0.01, 0.9), loc="upper left", fontsize=16)
ax.grid()
return fig, ax


def plot_rainfall_runoff_xu(
t,
p,
qs,
fig_size=(10, 6),
title="prcp-streamflow",
leg_lst=None,
ylabel="streamflow(m^3/s)",
prcp_ylabel="prcp(mm/day)",
):
obs, pred = qs

fig, ax1 = plt.subplots(figsize=fig_size)

ax1.bar(t, p, width=0.1, color="blue", alpha=0.6, label="Precipitation")
ax1.set_ylabel(prcp_ylabel, color="blue")
ax1.tick_params(axis="y", labelcolor="blue")

ax1.set_ylim(0, p.max() * 5)
ax1.invert_yaxis()

ax2 = ax1.twinx()

# transform the unit of obs and pred
ax2.plot(
t,
obs,
color="green",
linestyle="-",
label="observed value",
)
ax2.plot(
t,
pred,
color="red",
linestyle="--",
label="predicted value",
)

ax2.set_ylabel(ylabel, color="red")
ax2.tick_params(axis="y", labelcolor="red")

plt.title(title)

plt.legend(loc="upper left")

0 comments on commit e6deabb

Please sign in to comment.