Skip to main content

Graphical Tools for creating Next Gen Water model input data.

Project description

NGIAB Data Preprocess

This repository contains tools for preparing data to run a next gen simulation using NGIAB. The tools allow you to select a catchment of interest on an interactive map, choose a date range, and prepare the data with just a few clicks!

map screenshot

Table of Contents

  1. What does this tool do?
  2. Requirements
  3. Installation and Running
  4. Development Installation
  5. Usage
  6. CLI Documentation

What does this tool do?

This tool prepares data to run a next gen simulation by creating a run package that can be used with NGIAB.
It uses geometry and model attributes from the v2.2 hydrofabric more information on all data sources here.
The raw forcing data is nwm retrospective v3 forcing data or the AORC 1km gridded data depending on user input

  1. Subset (delineate) everything upstream of your point of interest (catchment, gage, flowpath etc). Outputs as a geopackage.
  2. Calculates Forcings as a weighted mean of the gridded AORC forcings. Weights are calculated using exact extract and computed with numpy.
  3. Creates configuration files needed to run nextgen.
    • realization.json - ngen model configuration
    • troute.yaml - routing configuration.
    • per catchment model configuration
  4. Optionally Runs a non-interactive Next gen in a box.

What does it not do?

Evaluation

For automatic evaluation using Teehr, please run NGIAB interactively using the guide.sh script.

Visualisation

For automatic interactive visualisation, please run NGIAB interactively using the guide.sh script

Requirements

  • This tool is officially supported on macOS or Ubuntu (tested on 22.04 & 24.04). To use it on Windows, please install WSL.

Installation and Running

It is highly recommended to use Astral UV to install and run this tool. It works similarly to pip and conda, and I would also recommend you use it for other python projects as it is so useful.

# Install UV
curl -LsSf https://astral.sh/uv/install.sh | sh
# It can be installed via pip if that fails
# pip install uv

# Create a virtual environment in the current directory
uv venv

# Install the tool in the virtual environment 
uv pip install ngiab_data_preprocess

# To run the cli
uv run cli --help

# To run the map 
uv run map_app

UV automatically detects any virtual environments in the current directory and will use them when you use uv run.

Running without install

This package supports pipx and uvx which means you can run the tool without installing it. No virtual environment needed, just UV.

# run this from anywhere 
uvx --from ngiab_data_preprocess cli --help
# for the map
uvx --from ngiab_data_preprocess map_app

For legacy pip installation

Click here to expand
# If you're installing this on jupyterhub / 2i2c you HAVE TO DEACTIVATE THE CONDA ENV
(notebook) jovyan@jupyter-user:~$ conda deactivate
jovyan@jupyter-user:~$
# The interactive map won't work on 2i2c
# This tool is likely to not work without a virtual environment
python3 -m venv .venv
source .venv/bin/activate
# installing and running the tool
pip install 'ngiab_data_preprocess'
python -m map_app
# CLI instructions at the bottom of the README

Development Installation

Click to expand installation steps

To install and run the tool, follow these steps:

  1. Clone the repository:
    git clone https://github.com/CIROH-UA/NGIAB_data_preprocess
    cd NGIAB_data_preprocess
    
  2. Create a virtual environment:
    uv venv
    
  3. Install the tool:
    uv pip install -e .
    
  4. Run the map app:
    uv run map_app
    

Usage

Running the command uv run map_app will open the app in a new browser tab.

To use the tool:

  1. Select the catchment you're interested in on the map.
  2. Pick the time period you want to simulate.
  3. Click the following buttons in order:
    1. Create subset gpkg
    2. Create Forcing from Zarrs
    3. Create Realization

Once all the steps are finished, you can run NGIAB on the folder shown underneath the subset button.

Note: When using the tool, the default output will be stored in the ~/ngiab_preprocess_output/<your-input-feature>/ folder. There is no overwrite protection on the folders.

CLI Documentation

Arguments

  • -h, --help: Show the help message and exit.
  • -i INPUT_FEATURE, --input_feature INPUT_FEATURE: ID of feature to subset. Providing a prefix will automatically convert to catid, e.g., cat-5173 or gage-01646500 or wb-1234.
  • --vpu VPU_ID : The id of the vpu to subset e.g 01. 10 = 10L + 10U and 03 = 03N + 03S + 03W. --help will display all the options.
  • -l, --latlon: Use latitude and longitude instead of catid. Expects comma-separated values via the CLI, e.g., python -m ngiab_data_cli -i 54.33,-69.4 -l -s.
  • -g, --gage: Use gage ID instead of catid. Expects a single gage ID via the CLI, e.g., python -m ngiab_data_cli -i 01646500 -g -s.
  • -s, --subset: Subset the hydrofabric to the given feature.
  • -f, --forcings: Generate forcings for the given feature.
  • -r, --realization: Create a realization for the given feature.
  • --start_date START_DATE, --start START_DATE: Start date for forcings/realization (format YYYY-MM-DD).
  • --end_date END_DATE, --end END_DATE: End date for forcings/realization (format YYYY-MM-DD).
  • -o OUTPUT_NAME, --output_name OUTPUT_NAME: Name of the output folder.
  • --source : The datasource you want to use, either nwm for retrospective v3 or aorc. Default is nwm
  • -D, --debug: Enable debug logging.
  • --run: Automatically run Next Gen against the output folder.
  • --validate: Run every missing step required to run ngiab.
  • -a, --all: Run all operations: subset, forcings, realization, run Next Gen

Usage Notes

  • If your input has a prefix of gage-, you do not need to pass -g.
  • The -l, -g, -s, -f, -r flags can be combined like normal CLI flags. For example, to subset, generate forcings, and create a realization, you can use -sfr or -s -f -r.
  • When using the --all flag, it automatically sets subset, forcings, realization, and run to True.
  • Using the --run flag automatically sets the --validate flag.

Examples

  1. Prepare everything for a nextgen run at a given gage:

    python -m ngiab_data_cli -i gage-10154200 -sfr --start 2022-01-01 --end 2022-02-28 
    #         add --run or replace -sfr with --all to run nextgen in a box too
    # to name the folder, add -o folder_name
    
  2. Subset hydrofabric using catchment ID or VPU:

    python -m ngiab_data_cli -i cat-7080 -s
    python -m ngiab_data_cli --vpu 01 -s
    
  3. Generate forcings using a single catchment ID:

    python -m ngiab_data_cli -i cat-5173 -f --start 2022-01-01 --end 2022-02-28
    
  4. Create realization using a lat/lon pair and output to a named folder:

    python -m ngiab_data_cli -i 54.33,-69.4 -l -r --start 2022-01-01 --end 2022-02-28 -o custom_output
    
  5. Perform all operations using a lat/lon pair:

    python -m ngiab_data_cli -i 54.33,-69.4 -l -s -f -r --start 2022-01-01 --end 2022-02-28
    
  6. Subset hydrofabric using gage ID:

    python -m ngiab_data_cli -i 10154200 -g -s
    # or
    python -m ngiab_data_cli -i gage-10154200 -s
    
  7. Generate forcings using a single gage ID:

    python -m ngiab_data_cli -i 01646500 -g -f --start 2022-01-01 --end 2022-02-28
    
  8. Run all operations, including Next Gen and evaluation/plotting:

    python -m ngiab_data_cli -i cat-5173 -a --start 2022-01-01 --end 2022-02-28
    

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ngiab_data_preprocess-4.2.2.tar.gz (370.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ngiab_data_preprocess-4.2.2-py3-none-any.whl (373.4 kB view details)

Uploaded Python 3

File details

Details for the file ngiab_data_preprocess-4.2.2.tar.gz.

File metadata

  • Download URL: ngiab_data_preprocess-4.2.2.tar.gz
  • Upload date:
  • Size: 370.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ngiab_data_preprocess-4.2.2.tar.gz
Algorithm Hash digest
SHA256 e7b2edb36e36c6d5c1c4cd2f70db4b540598d4d2e948861cabc6ab2d87777b6d
MD5 872e6735e7d80ed4e0b750def8d5ef8a
BLAKE2b-256 469ef0b8fdb71ccbd3e3a6cfc2b7002c1d57d78fd85cbd1eb2d50a3428635bab

See more details on using hashes here.

Provenance

The following attestation bundles were made for ngiab_data_preprocess-4.2.2.tar.gz:

Publisher: publish.yml on CIROH-UA/NGIAB_data_preprocess

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ngiab_data_preprocess-4.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for ngiab_data_preprocess-4.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 74a617c4b081d93e4437bf835ddaa710a9d8d75ccf6edb1e0dc3f155e384bf98
MD5 cc2b2424ead4aab7e6de737dbe181ac6
BLAKE2b-256 dab501768f2a2e17d64e6114a56fff47964f10a253d5ab0bab76ddde8d336072

See more details on using hashes here.

Provenance

The following attestation bundles were made for ngiab_data_preprocess-4.2.2-py3-none-any.whl:

Publisher: publish.yml on CIROH-UA/NGIAB_data_preprocess

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page