Skip to content

Commit

Permalink
lint and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jmccreight committed Sep 16, 2024
1 parent 6cf79bc commit 5df0c2f
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 60 deletions.
92 changes: 53 additions & 39 deletions test_data/sagehen_mf6/common/figspecs.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import sys
import numpy as np

import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np


class USGSFigure:
def __init__(
self, figure_type="map", family="Arial Narrow", font_path=None,
verbose=False
self,
figure_type="map",
family="Arial Narrow",
font_path=None,
verbose=False,
):
"""Create a USGSFigure object
Expand Down Expand Up @@ -58,7 +62,7 @@ def set_font_family(self, family="Arial Narrow", font_path=None):
"""
if font_path is not None:
errmsg = "specification of font_path is not implemented"
raise NotImplemented(errmsg)
raise NotImplementedError(errmsg)
self.family = self._set_fontfamily(family)

def graph_legend(self, ax=None, handles=None, labels=None, **kwargs):
Expand Down Expand Up @@ -121,7 +125,9 @@ def graph_legend_title(self, leg, title=None):
leg.set_title(title, prop=font)
return leg

def heading(self, ax=None, letter=None, heading=None, x=0.00, y=1.01, idx=None):
def heading(
self, ax=None, letter=None, heading=None, x=0.00, y=1.01, idx=None
):
"""Add a USGS-style heading to a matplotlib axis object
Parameters
Expand All @@ -133,14 +139,15 @@ def heading(self, ax=None, letter=None, heading=None, x=0.00, y=1.01, idx=None):
heading : str
text string
x : float
location of the heading in the x-direction in normalized plot dimensions
ranging from 0 to 1 (default is 0.00)
location of the heading in the x-direction in normalized plot
dimensions ranging from 0 to 1 (default is 0.00)
y : float
location of the heading in the y-direction in normalized plot dimensions
ranging from 0 to 1 (default is 1.01)
location of the heading in the y-direction in normalized plot
dimensions ranging from 0 to 1 (default is 1.01)
idx : int
index for programatically generating the heading letter when letter
is None and idx is not None. idx = 0 will generate A (default is None)
is None and idx is not None. idx = 0 will generate A (default is
None)
Returns
-------
Expand Down Expand Up @@ -192,18 +199,18 @@ def heading(self, ax=None, letter=None, heading=None, x=0.00, y=1.01, idx=None):
return text

def add_text(
self,
ax=None,
text="",
x=0.0,
y=0.0,
transform=True,
bold=True,
italic=True,
fontsize=9,
ha="left",
va="bottom",
**kwargs
self,
ax=None,
text="",
x=0.0,
y=0.0,
transform=True,
bold=True,
italic=True,
fontsize=9,
ha="left",
va="bottom",
**kwargs,
):
"""Add USGS-style text to a axis object
Expand All @@ -218,9 +225,9 @@ def add_text(
y : float
y-location of text string (default is 0.)
transform : bool
boolean that determines if a transformed (True) or data (False) coordinate
system is used to define the (x, y) location of the text string
(default is True)
boolean that determines if a transformed (True) or data (False)
coordinate system is used to define the (x, y) location of the
text string (default is True)
bold : bool
boolean indicating if bold font (default is True)
italic : bool
Expand Down Expand Up @@ -251,22 +258,29 @@ def add_text(
font = self._set_fontspec(bold=bold, italic=italic, fontsize=fontsize)

text_obj = ax.text(
x, y, text, va=va, ha=ha, fontdict=font, transform=transform, **kwargs
x,
y,
text,
va=va,
ha=ha,
fontdict=font,
transform=transform,
**kwargs,
)
return text_obj

def add_annotation(
self,
ax=None,
text="",
xy=None,
xytext=None,
bold=True,
italic=True,
fontsize=9,
ha="left",
va="bottom",
**kwargs
self,
ax=None,
text="",
xy=None,
xytext=None,
bold=True,
italic=True,
fontsize=9,
ha="left",
va="bottom",
**kwargs,
):
"""Add an annotation to a axis object
Expand Down Expand Up @@ -563,8 +577,8 @@ def _set_fontspec(self, bold=True, italic=True, fontsize=9):
return fontspec

def _set_fontfamily(self, family):
"""Set font family to Liberation Sans Narrow on linux if default Arial Narrow
is being used
"""Set font family to Liberation Sans Narrow on linux if default Arial
Narrow is being used
Parameters
----------
Expand Down
44 changes: 23 additions & 21 deletions test_data/sagehen_mf6/sagehen_postprocess_graphs.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
#!/usr/bin/env python
# coding: utf-8

import datetime
import os
import pathlib as pl
import sys
import datetime

import flopy
import geopandas as gpd

import matplotlib.dates as mdates
import matplotlib.pyplot as plt
import numpy as np

import netCDF4 as nc
import numpy as np
import pandas as pd
from IPython import get_ipython

import pywatershed as pws

# this requires an editable install:
pws_repo_root = pws.constants.__pywatershed_root__.parent

# import hydrofunctions as hf

get_ipython().run_line_magic("matplotlib", "inline")


sys.path.append(os.path.join("../common"))
from figspecs import USGSFigure

# this requires an editable install:
pws_root = pws.constants.__pywatershed_root__

get_ipython().run_line_magic("matplotlib", "inline")

fig_dir = pl.Path("figures")
fig_dir.mkdir(exist_ok=True)
Expand All @@ -39,10 +34,9 @@

fs = USGSFigure(figure_type="graph")


# Process the geodatabase
root_dir = pl.Path("../").resolve()
file = pws_repo_root / "Sagehen.gdb"
file = pws_root / "data/pywatershed_gis/sagehen_mf6/Sagehen.gdb"
hru = gpd.read_file(file, driver="FileGDB", layer="HRU")
river = gpd.read_file(file, driver="FileGDB", layer="stream")

Expand Down Expand Up @@ -100,8 +94,11 @@
site_name = f"Site {site}"
# sagehen = hf.NWIS(site, "dv", start, end)
# sagehen
# sagehenStreamFlow = (sagehen.df()["USGS:10343500:00060:00003"] / (m2ft**3)).to_frame()
# sagehenStreamFlow.rename(columns={"USGS:10343500:00060:00003": site_name}, inplace=True)
# sagehenStreamFlow = (
# sagehen.df()["USGS:10343500:00060:00003"]
# / (m2ft**3)).to_frame()
# sagehenStreamFlow.rename(columns={"USGS:10343500:00060:00003": site_name},
# inplace=True)
# sagehenStreamFlow.to_csv("sagehen_observed_streamflow.nc")

times_dt64 = (times + 365 * 10.755).astype("datetime64[D]")
Expand All @@ -112,7 +109,9 @@
[ss[0:10] for ss in sagehenStreamFlow["datetimeUTC"].tolist()],
dtype="datetime64[D]",
)
# sagehenStreamFlow["datetimeUTC"] = pd.to_datetime( sagehenStreamFlow["datetimeUTC"], utc=False)obs_times = sagehenStreamFlow["datetimeUTC"].values
# sagehenStreamFlow["datetimeUTC"] = pd.to_datetime(
# sagehenStreamFlow["datetimeUTC"], utc=False)
# obs_times = sagehenStreamFlow["datetimeUTC"].values
obs_times = sagehenStreamFlow["datetimeUTC"].values
wh_obs_mod = np.isin(obs_times, times_dt64)
sagehenStreamFlow = sagehenStreamFlow.set_index("datetimeUTC")
Expand Down Expand Up @@ -173,7 +172,8 @@ def streamflow_fig():
color=color,
label=name,
)
leg = fs.graph_legend(ax)
# leg = fs.graph_legend(ax)
_ = fs.graph_legend(ax)

ax.set_xlim(plt_times[0], plt_times[-1])
# ax.set_ylim(0, 10)
Expand Down Expand Up @@ -301,7 +301,7 @@ def cum_calc(v, i0=idx0):


def et_recharge_ppt_fig():
# #### Plot evapotranspiration terms with soil infiltration and precipitation
# Plot evapotranspiration terms with soil infiltration and precipitation
vtot = np.zeros(plt_times.shape, dtype=float)
colors = ("#c36f31", "#cab39f", "#b7bf5e")
for name, color in zip(dfObj.columns[1:4], colors):
Expand Down Expand Up @@ -484,7 +484,8 @@ def composite_fig():
)
zorder -= 10
# ax.set_ylim(0, ax.get_ylim()[1])
leg = fs.graph_legend(
# leg = fs.graph_legend(
_ = fs.graph_legend(
ax,
ncol=2,
loc="upper right",
Expand Down Expand Up @@ -564,7 +565,8 @@ def composite_fig():
"Groundwater ET",
)

# ax.plot(plt_times, cum_calc(dfObj["ppt"]), lw=1.25, color="cyan", label="Rainfall")
# ax.plot(plt_times,
# cum_calc(dfObj["ppt"]), lw=1.25, color="cyan", label="Rainfall")
for name, color, label in zip(names_met, colors_met, labels_met):
v = cum_calc(dfObj[name])
ax.fill_between(plt_times, vtot + v, y2=vtot, color=color)
Expand Down

0 comments on commit 5df0c2f

Please sign in to comment.