Skip to content

micahhsu/ReNeM_CBA

Repository files navigation

ReNeM Cost-Benefit Analysis Calculator

A Streamlit web app that helps water agencies and landowners evaluate the economic value of implementing a Recharge Net Metering (ReNeM) program. By entering district-specific parameters, users get a Net Present Value (NPV) estimate for both the sponsoring agency and participating rechargers, along with a sensitivity analysis showing how the result responds to each input.

The math is a direct port of the original Jupyter notebooks (ReNeM CBA Notebook_4.18.23.ipynb, ReNeM Sensitivity Notebook_7.11.23.ipynb, ReNeM basin projects_4.18.23.ipynb) which are kept in the repository for reference. The app wraps that math in an interactive UI so a non-technical user can explore scenarios without editing Python code.


What is Streamlit?

Streamlit is a Python framework for building data apps without writing any HTML, CSS, or JavaScript. You write a regular Python script that reads inputs (st.number_input, st.slider, …) and renders outputs (st.markdown, st.plotly_chart, …); Streamlit handles the web server, layout, and re-rendering on input changes.

This app is a multipage Streamlit app:

  • The entry-point script (1_01_About.py) is the landing page.
  • Any script inside the pages/ folder becomes an additional page that appears automatically in Streamlit's left-nav sidebar.

Repository layout

ReNeM_Calculator/
├── 1_01_About.py               # Landing page (entry point)
├── pages/
│   ├── 1_02_Documentation.py   # Variable reference tables (deep-linkable)
│   └── 2_03_Calculator.py      # Input form, NPV math, results, sensitivity
├── images/                      # Photos used on the About page
├── requirements.txt            # Python dependencies
├── ReNeM CBA Notebook_4.18.23.ipynb           # Source notebook (reference)
├── ReNeM Sensitivity Notebook_7.11.23.ipynb   # Source notebook (reference)
├── ReNeM basin projects_4.18.23.ipynb         # Source notebook (reference)
└── README.md

The three notebooks are the historical research basis for the app's formulas and are kept in the repo for reference. They are not executed by the deployed app.


Differences from the source notebooks

The Streamlit app's NPV math matches ReNeM CBA Notebook_4.18.23.ipynb verbatim with one deliberate exception: the app scales three project-level fixed costs by the number of projects (o); the CBA notebook does not.

The costs that differ:

Variable Meaning Notebook treatment App treatment
F One-time design and construction cost flat F · o
tpc_fc One-time third-party certification setup cost flat tpc_fc · o
tpc_ac Annual third-party certification cost flat tpc_ac · o

These show up on the agency / basin side of the NPV. Because the app multiplies them by o, programs with more than one project will report a lower Basin NPV in the app than the CBA notebook would for the same inputs (the gap grows with o). The Recharger NPV is unaffected — recharger-side costs are already per-project in both the notebook and the app.

The change is applied consistently across:

  • get_npvs_with_stochasticity() — the function that produces the displayed Total / Basin / Recharger NPVs
  • npvs() — the sensitivity-analysis function
  • The Agency Unit Cost per Acre-Foot card on the Calculator results page

To reproduce the notebook's numbers exactly, set o = 1 in the calculator.


Running locally

Prerequisites: Python 3.10 or newer. Check with python --version.

  1. Clone the repository:

    git clone https://github.com/micahhsu/ReNeM_CBA.git
    cd ReNeM_CBA
  2. (Recommended) create and activate a virtual environment so the app's dependencies don't conflict with anything else on your machine:

    # Windows (PowerShell)
    python -m venv .venv
    .venv\Scripts\Activate.ps1
    # macOS / Linux
    python -m venv .venv
    source .venv/bin/activate
  3. Install the dependencies:

    pip install -r requirements.txt
  4. Run the app:

    streamlit run 1_01_About.py

    Streamlit will open the app in your default browser at http://localhost:8501. Edits to any of the page files are picked up live — save the file and click "Rerun" (or enable "Always rerun") in the upper-right of the app.

To stop the app, return to the terminal and press Ctrl+C.


Deploying to Streamlit Community Cloud

Streamlit Community Cloud is a free hosting service for Streamlit apps backed by a GitHub repository. This is what I have been using to temporarily deploy the website.

  1. Push the repository to GitHub. If it is not already on GitHub, create a new repo and push.

  2. Sign in at https://share.streamlit.io with the same GitHub account that owns the repository.

  3. Click "New app" and fill in:

    • Repository: your GitHub repo (e.g. micahhsu/ReNeM_CBA)
    • Branch: usually main
    • Main file path: 1_01_About.py
  4. Click "Deploy". Streamlit Cloud will read requirements.txt automatically and install dependencies. The first build typically takes 2–4 minutes.

  5. Once deployed, the app is live at a *.streamlit.app URL. Pushing new commits to the configured branch redeploys automatically.

To update the deployment manually (e.g. after editing on Streamlit Cloud's side) or to check logs, use the "Manage app" menu in the lower-right of the live app.


Editing the app

  • Add a variable input: edit the appropriate sidebar tab (tab1 for Program variables, tab2 for Project variables) in pages/2_03_Calculator.py. Follow the existing st.container(horizontal=True)
    • _help_popover(…) pattern to keep the 📖 help button aligned.
  • Add a variable definition: add a row tuple to either program_rows or project_rows in pages/1_02_Documentation.py. The first element of the tuple (the var_key) becomes the deep-link target — calling _help_popover("myvar", …) in the Calculator links to ?var=myvar here.
  • Change a formula: all NPV math lives in the four functions near the top of pages/2_03_Calculator.py (npv, npv_list, get_npv_Qlist, get_npvs_with_stochasticity) and the sensitivity-analysis function (npvs). These mirror the equivalent cells in the source notebooks.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors