Skip to content

Commit

Permalink
more plot toggles
Browse files Browse the repository at this point in the history
  • Loading branch information
rileyhales committed Jul 14, 2021
1 parent daf046d commit 934bd47
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
author = 'Riley Hales'

# The full version, including alpha/beta/rc tags
release = '0.24.1'
release = '0.25.0'
master_doc = 'index'

# -- General configuration ---------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The tutorials are GitHub Gists which you can copy and launch in a Google Collabo
- Retrieve & plot GEOGloWS model data: `<https://gist.github.com/rileyhales/873896e426a5bd1c4e68120b286bc029>`_
- Finding Stream ID #'s programatically: `<https://gist.github.com/rileyhales/ad92d1fce3aa36ef5873f2f7c2632d31>`_
- Bias Evaluation and Calibration at a point: `<https://gist.github.com/rileyhales/d5290e12b5858d59960d0898fbd0ed69>`_
- Generate/Download High Res Plot Images: `<https://gist.github.com/rileyhales/9b5bbb0c5f307eb14b9f1ced39d641e4>`_

About GEOGloWS ECMWF Streamflow
===============================
Expand Down
3 changes: 1 addition & 2 deletions geoglows/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import geoglows.analysis

__all__ = ['bias', 'plots', 'streamflow', 'analysis']
__version__ = '0.24.1'
__version__ = '0.25.0'
__author__ = 'Riley Hales'
__license__ = 'BSD 3-Clause Clear License'

24 changes: 15 additions & 9 deletions geoglows/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

# FUNCTIONS THAT PROCESS THE RESULTS OF THE API INTO A PLOTLY PLOT OR DICTIONARY
def hydroviewer(recs: pd.DataFrame, stats: pd.DataFrame, ensem: pd.DataFrame, rperiods: pd.DataFrame = None,
record_days: int = 7, outformat: str = 'plotly', titles: dict = False) -> go.Figure:
record_days: int = 7, outformat: str = 'plotly', titles: dict = False, hide_ensem: bool = True,
hide_rperiods: bool = True) -> go.Figure:
"""
Creates the standard plot for a hydroviewer
Expand All @@ -30,6 +31,8 @@ def hydroviewer(recs: pd.DataFrame, stats: pd.DataFrame, ensem: pd.DataFrame, rp
record_days: (optional) number of days of forecast records to show before the start of the forecast
titles: (dict) Extra info to show on the title of the plot. For example:
{'Reach ID': 1234567, 'Drainage Area': '1000km^2'}
hide_ensem: Hide the ensemble members in the layout initially
hide_rperiods: Hide the return period labels in the layout initially
Return:
plotly.GraphObject: plotly object, especially for use with python notebooks and the .show() method
Expand Down Expand Up @@ -60,23 +63,24 @@ def hydroviewer(recs: pd.DataFrame, stats: pd.DataFrame, ensem: pd.DataFrame, rp
figure.add_trace(go.Scatter(
x=ensemble_data['x_1-51'],
y=ensemble_data['ensemble_01_m^3/s'],
visible='legendonly',
visible='legendonly' if hide_ensem else True,
legendgroup='ensembles',
name='Forecast Ensembles',
))
for i in range(2, 52):
figure.add_trace(go.Scatter(
x=ensemble_data['x_1-51'],
y=ensemble_data[f'ensemble_{i:02}_m^3/s'],
visible='legendonly',
visible='legendonly' if hide_ensem else True,
legendgroup='ensembles',
name=f'Ensemble {i}',
showlegend=False,
))
if rperiods is not None:
max_visible = max(stats['flow_75%_m^3/s'].max(), stats['flow_avg_m^3/s'].max(), stats['high_res_m^3/s'].max(),
recs['streamflow_m^3/s'].max())
for rp in _rperiod_scatters(startdate, enddate, rperiods, max_flow, max_visible):
for rp in _rperiod_scatters(startdate, enddate, rperiods, max_flow, max_visible,
visible='legendonly' if hide_rperiods else True):
figure.add_trace(rp)

figure.update_layout(
Expand Down Expand Up @@ -1081,14 +1085,16 @@ def _plot_colors():
}


def _rperiod_scatters(startdate: str, enddate: str, rperiods: pd.DataFrame, y_max: float, max_visible: float = 0):
def _rperiod_scatters(startdate: str, enddate: str, rperiods: pd.DataFrame, y_max: float, max_visible: float = 0,
visible: bool = None):
colors = _plot_colors()
x_vals = (startdate, enddate, enddate, startdate)
r2 = int(rperiods['return_period_2'].values[0])
if max_visible > r2:
visible = True
else:
visible = 'legendonly'
if visible is None:
if max_visible > r2:
visible = True
else:
visible = 'legendonly'

def template(name, y, color, fill='toself'):
return go.Scatter(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
setup(
name='geoglows',
packages=['geoglows'],
version='0.24.1',
version='0.25.0',
description='Package for accessing data and APIs developed for the GEOGloWS initiative',
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 934bd47

Please sign in to comment.