-
Notifications
You must be signed in to change notification settings - Fork 0
Description
End Goal: A Shiny module that expects daily flow data, identifies and trims events, summarizes AGWR in a table, plots results, and allows the user to plug in flow‑dependent AGWR values to forecast drought outlooks in an adjustable way.
Drought forecast module that can:
- Run the baseflow event ID script on a timeseries and summarize events in a
DT::datatable(). - Provide a plotly scatterplot illustrating AGWRC by flow regression analysis.
- Optionally open a modal to inspect individual events in detail.
- Allow users to enter a single AGWRC or AGWRC vs. Flow matrix and project flows forward at 15, 30, 45, and 90 days.
Progress Updates
Update for 1/25:
project environment code (will push this afternoon): updated app code
Quick summary:
The app now follows a modular, retrieval-only data architecture that separates precomputed analysis data from observed flow data. Baseflow event analyses are pulled from GitHub, while historical and anchoring flows are retrieved dynamically from USGS. This structure clarifies how each panel is driven, especially the Drought Forecast, and makes future refactors more straightforward.
Whole App Data Flow
graph TD;
%% =========================
%% Whole App Data Flow
%% =========================
subgraph UI[User Interface]
U1[User selects gage]
U2[User selects event]
U3[User sets forecast inputs]
end;
subgraph Core[Core Reactives]
GID[GageID reactive]
AP[AnalysisPoints reactive]
OD[OriginalDF reactive]
TD[TrimmedDF reactive]
ES[EventSummary reactive]
UD[USGSDaily reactive]
end;
subgraph Sources[Data Sources]
GH[GitHub Analysis CSV]
US[USGS Daily Flow Service]
end;
subgraph Funcs[Key Functions]
GET[bf_get_gage_analysis]
STD[bf_standardize_analysis_df]
NWIS[readNWISdv]
SUM[make_ben_event_summary]
end;
subgraph Panels[Panels and Outputs]
OV1[Overview flow plot]
OV2[Overview points plot]
EVT1[Events table]
EVT2[Event inspection plots]
REG1[Regression plot]
REG2[Regression summary text]
FC1[Forecast plot]
FC2[Forecast table]
end;
%% --- UI triggers ---
U1 --> GID;
%% --- Data retrieval branches ---
GID --> GET;
GET --> GH;
GH --> STD;
STD --> AP;
GID --> NWIS;
NWIS --> US;
US --> UD;
%% --- Derived reactives ---
AP --> OD;
AP --> TD;
TD --> SUM;
SUM --> ES;
%% --- Panel dependencies ---
UD --> OV1;
OD --> OV2;
ES --> EVT1;
TD --> EVT2;
ES --> REG1;
ES --> REG2;
U3 --> FC1;
U3 --> FC2;
UD --> FC1;
UD --> FC2;
%% --- Event selection path ---
EVT1 --> U2;
U2 --> EVT2;
%% =========================
%% Styling (GitHub-safe)
%% =========================
classDef source fill:#eef,stroke:#333,stroke-width:1px;
classDef reactive fill:#efe,stroke:#333,stroke-width:1px;
classDef func fill:#ffe,stroke:#333,stroke-width:1px;
classDef panel fill:#fef,stroke:#333,stroke-width:1px;
classDef ui fill:#eee,stroke:#333,stroke-width:1px;
class GH,US source;
class AP,OD,TD,ES,UD,GID reactive;
class GET,STD,NWIS,SUM func;
class OV1,OV2,EVT1,EVT2,REG1,REG2,FC1,FC2 panel;
class U1,U2,U3 ui;
Overview and Events Panel
graph TD;
%% =========================
%% Overview and Events Panel
%% =========================
subgraph Inputs[Inputs]
GID[GageID]
EVSEL[Selected Event GroupID]
end;
subgraph Sources[Sources]
GH[GitHub Analysis CSV]
US[USGS Daily Flow]
end;
subgraph Reactives[Reactives]
AP[AnalysisPoints]
TD[TrimmedDF]
ES[EventSummary]
UD[USGSDaily]
EVDF[EventData filtered]
end;
subgraph Outputs[Outputs]
HF[Historical flow plot]
TAB[Events table]
EP[Event inspection plots]
end;
%% Flow series
GID --> US;
US --> UD;
UD --> HF;
%% Event library
GID --> GH;
GH --> AP;
AP --> TD;
TD --> ES;
ES --> TAB;
%% Event inspection
TAB --> EVSEL;
EVSEL --> EVDF;
TD --> EVDF;
EVDF --> EP;
classDef source fill:#eef,stroke:#333,stroke-width:1px;
classDef reactive fill:#efe,stroke:#333,stroke-width:1px;
classDef output fill:#fef,stroke:#333,stroke-width:1px;
classDef input fill:#eee,stroke:#333,stroke-width:1px;
class GH,US source;
class AP,TD,ES,UD,EVDF reactive;
class HF,TAB,EP output;
class GID,EVSEL input;
Regression Panel
graph TD;
%% =========================
%% Regression Panel
%% =========================
subgraph Inputs[Inputs]
GID[GageID]
XSEL[X variable selection]
YSEL[Y variable selection]
end;
subgraph Source[Source]
GH[GitHub Analysis CSV]
end;
subgraph Reactives[Reactives]
AP[AnalysisPoints]
TD[TrimmedDF]
ES[EventSummary]
LM[Linear model]
end;
subgraph Outputs[Outputs]
RP[Regression plot]
RT[Regression text]
end;
GID --> GH;
GH --> AP;
AP --> TD;
TD --> ES;
XSEL --> LM;
YSEL --> LM;
ES --> LM;
LM --> RP;
LM --> RT;
classDef source fill:#eef,stroke:#333,stroke-width:1px;
classDef reactive fill:#efe,stroke:#333,stroke-width:1px;
classDef output fill:#fef,stroke:#333,stroke-width:1px;
classDef input fill:#eee,stroke:#333,stroke-width:1px;
class GH source;
class AP,TD,ES,LM reactive;
class RP,RT output;
class GID,XSEL,YSEL input;
Drought Forecast Panel
graph TD;
%% =========================
%% Drought Forecast Panel
%% =========================
subgraph Inputs[Inputs]
GID[GageID]
FSD[Forecast start date]
FH[Forecast horizon]
AG[AGWRC input]
end;
subgraph Sources[Sources]
US[USGS Daily Flow]
GH[GitHub Analysis CSV]
end;
subgraph Reactives[Reactives]
UD[USGSDaily]
Q0[Starting flow Q0]
DD[Delta days]
PROJ[Projection table]
ES[EventSummary]
end;
subgraph Outputs[Outputs]
FP[Forecast plot]
FT[Forecast table]
end;
%% Anchor to observed flow
GID --> US;
US --> UD;
FSD --> Q0;
UD --> Q0;
%% Projection scaffolding
FH --> DD;
AG --> PROJ;
Q0 --> PROJ;
DD --> PROJ;
%% Outputs
PROJ --> FP;
PROJ --> FT;
%% Event library (future enhancement)
GID --> GH;
GH --> ES;
classDef source fill:#eef,stroke:#333,stroke-width:1px;
classDef reactive fill:#efe,stroke:#333,stroke-width:1px;
classDef output fill:#fef,stroke:#333,stroke-width:1px;
classDef input fill:#eee,stroke:#333,stroke-width:1px;
class GH,US source;
class UD,Q0,DD,PROJ,ES reactive;
class FP,FT output;
class GID,FSD,FH,AG input;
Key updates (as of 2/10):
- Added a data source selector (Model vs Gage) that controls how both raw and analyzed data are loaded throughout the app.
- Implemented dual data ingestion logic:
- Raw model data pulled directly from GitHub CSVs (daily flows) and used for historical flow overlays and forecast initialization.
- Raw gage data pulled from USGS via dataRetrieval for equivalent historical context.
- Analyzed event data (baseflow events, AGWRC, regression inputs) pulled from GitHub for both model and gage cases.
- Fixed a critical issue with model raw data date parsing: model CSVs contained empty thisdate fields, so dates are now robustly constructed from year/month/day when needed. This restores full plotting and forecasting functionality for model runs.
- Confirmed that all plots (historical flow, AGWRC vs flow regression, and drought forecast) now render correctly for both data sources with no runtime errors.