ngiab-data-preprocess 4.2.2__tar.gz → 4.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/.gitignore +2 -0
  2. ngiab_data_preprocess-4.4.0/PKG-INFO +308 -0
  3. ngiab_data_preprocess-4.4.0/README.md +267 -0
  4. ngiab_data_preprocess-4.4.0/ciroh-bgsafe.png +0 -0
  5. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/data_processing/create_realization.py +39 -22
  6. ngiab_data_preprocess-4.4.0/modules/data_processing/dask_utils.py +92 -0
  7. ngiab_data_preprocess-4.4.0/modules/data_processing/dataset_utils.py +329 -0
  8. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/data_processing/datasets.py +18 -29
  9. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/data_processing/file_paths.py +7 -7
  10. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/data_processing/forcings.py +40 -38
  11. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/data_processing/gpkg_utils.py +13 -13
  12. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/data_processing/graph_utils.py +4 -6
  13. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/data_processing/s3fs_utils.py +1 -1
  14. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/data_processing/subset.py +39 -8
  15. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/data_sources/ngen-routing-template.yaml +1 -1
  16. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/data_sources/source_validation.py +72 -34
  17. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/map_app/__main__.py +3 -2
  18. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/map_app/static/css/main.css +14 -3
  19. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/map_app/static/js/data_processing.js +31 -55
  20. ngiab_data_preprocess-4.4.0/modules/map_app/static/js/main.js +279 -0
  21. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/map_app/templates/index.html +10 -1
  22. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/map_app/views.py +17 -3
  23. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/ngiab_data_cli/__main__.py +32 -29
  24. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/ngiab_data_cli/arguments.py +0 -1
  25. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/ngiab_data_cli/forcing_cli.py +10 -19
  26. ngiab_data_preprocess-4.4.0/modules/ngiab_data_preprocess.egg-info/PKG-INFO +308 -0
  27. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/ngiab_data_preprocess.egg-info/SOURCES.txt +4 -1
  28. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/ngiab_data_preprocess.egg-info/requires.txt +2 -1
  29. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/pyproject.toml +11 -3
  30. ngiab_data_preprocess-4.4.0/tests/test_nan_impute.py +200 -0
  31. ngiab_data_preprocess-4.2.2/PKG-INFO +0 -258
  32. ngiab_data_preprocess-4.2.2/README.md +0 -218
  33. ngiab_data_preprocess-4.2.2/modules/data_processing/dataset_utils.py +0 -212
  34. ngiab_data_preprocess-4.2.2/modules/map_app/static/js/main.js +0 -161
  35. ngiab_data_preprocess-4.2.2/modules/ngiab_data_preprocess.egg-info/PKG-INFO +0 -258
  36. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/.github/workflows/build_only.yml +0 -0
  37. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/.github/workflows/publish.yml +0 -0
  38. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/LICENSE +0 -0
  39. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/data_sources/cfe-nowpm-realization-template.json +0 -0
  40. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/data_sources/cfe-template.ini +0 -0
  41. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/data_sources/em-catchment-template.yml +0 -0
  42. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/data_sources/em-config.yml +0 -0
  43. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/data_sources/em-realization-template.json +0 -0
  44. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/data_sources/forcing_template.nc +0 -0
  45. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/data_sources/noah-owp-modular-init.namelist.input +0 -0
  46. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/data_sources/template.sql +0 -0
  47. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/data_sources/triggers.sql +0 -0
  48. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/map_app/__init__.py +0 -0
  49. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/map_app/static/css/console.css +0 -0
  50. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/map_app/static/css/toggle.css +0 -0
  51. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/map_app/static/js/console.js +0 -0
  52. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/map_app/static/resources/loading.gif +0 -0
  53. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/map_app/static/resources/screenshot.jpg +0 -0
  54. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/ngiab_data_cli/custom_logging.py +0 -0
  55. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/ngiab_data_preprocess.egg-info/dependency_links.txt +0 -0
  56. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/ngiab_data_preprocess.egg-info/entry_points.txt +0 -0
  57. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/modules/ngiab_data_preprocess.egg-info/top_level.txt +0 -0
  58. {ngiab_data_preprocess-4.2.2 → ngiab_data_preprocess-4.4.0}/setup.cfg +0 -0
@@ -14,3 +14,5 @@ dist
14
14
  *.dat
15
15
  uv.lock
16
16
  /build
17
+ *.pmtiles
18
+ *style.json
@@ -0,0 +1,308 @@
1
+ Metadata-Version: 2.4
2
+ Name: ngiab_data_preprocess
3
+ Version: 4.4.0
4
+ Summary: Graphical Tools for creating Next Gen Water model input data.
5
+ Author-email: Josh Cunningham <jcunningham8@ua.edu>
6
+ Project-URL: Homepage, https://github.com/CIROH-UA/NGIAB_data_preprocess
7
+ Project-URL: Issues, https://github.com/CIROH-UA/NGIAB_data_preprocess/issues
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.10
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: pyogrio>=0.7.2
15
+ Requires-Dist: pyproj>=3.6.1
16
+ Requires-Dist: Flask==3.0.2
17
+ Requires-Dist: geopandas>=1.0.0
18
+ Requires-Dist: requests==2.32.4
19
+ Requires-Dist: igraph==0.11.4
20
+ Requires-Dist: s3fs==2024.3.1
21
+ Requires-Dist: xarray==2024.2.0
22
+ Requires-Dist: zarr==2.17.1
23
+ Requires-Dist: netCDF4>=1.6.5
24
+ Requires-Dist: dask==2024.4.1
25
+ Requires-Dist: dask[distributed]==2024.4.1
26
+ Requires-Dist: h5netcdf==1.3.0
27
+ Requires-Dist: exactextract==0.2.0
28
+ Requires-Dist: numpy>=1.26.4
29
+ Requires-Dist: tqdm==4.66.4
30
+ Requires-Dist: rich==13.7.1
31
+ Requires-Dist: colorama==0.4.6
32
+ Requires-Dist: bokeh==3.5.1
33
+ Requires-Dist: boto3
34
+ Requires-Dist: numcodecs<0.16.0
35
+ Requires-Dist: scipy>=1.15.3
36
+ Provides-Extra: eval
37
+ Requires-Dist: ngiab_eval; extra == "eval"
38
+ Provides-Extra: plot
39
+ Requires-Dist: ngiab_eval[plot]; extra == "plot"
40
+ Dynamic: license-file
41
+
42
+ # NGIAB Data Preprocess
43
+
44
+ This repository contains tools for preparing data to run a [NextGen](https://github.com/NOAA-OWP/ngen)-based simulation using [NGIAB](https://github.com/CIROH-UA/NGIAB-CloudInfra). 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!
45
+
46
+ ![map screenshot](https://github.com/CIROH-UA/NGIAB_data_preprocess/blob/main/modules/map_app/static/resources/screenshot.jpg)
47
+
48
+ | | |
49
+ | --- | --- |
50
+ | ![CIROH Logo](./ciroh-bgsafe.png) | Funding for this project was provided by the National Oceanic & Atmospheric Administration (NOAA), awarded to the Cooperative Institute for Research to Operations in Hydrology (CIROH) through the NOAA Cooperative Agreement with The University of Alabama (NA22NWS4320003). |
51
+
52
+ ## Table of Contents
53
+
54
+ 1. [What does this tool do?](#what-does-this-tool-do)
55
+ 2. [Limitations](#limitations)
56
+ - [Custom realizations](#custom-realizations)
57
+ - [Calibration](#calibration)
58
+ - [Evaluation](#evaluation)
59
+ - [Visualisation](#visualisation)
60
+ 3. [Requirements](#requirements)
61
+ 4. [Installation and running](#installation-and-running)
62
+ - [Running without install](#running-without-install)
63
+ - [For uv installation](#for-uv-installation)
64
+ - [For legacy pip installation](#for-legacy-pip-installation)
65
+ - [Development installation](#development-installation)
66
+ 5. [Map interface documentation](#map-interface-documentation)
67
+ - [Running the map interface app](#running-the-map-interface-app)
68
+ - [Using the map interace](#using-the-map-interface)
69
+ 6. [CLI documentation](#cli-documentation)
70
+ - [Running the CLI](#running-the-cli)
71
+ - [Arguments](#arguments)
72
+ - [Usage notes](#usage-notes)
73
+ - [Examples](#examples)
74
+ 7. [Realization information](#realization-information)
75
+ - [NOAH + CFE](#noah--cfe)
76
+
77
+ ## What does this tool do?
78
+
79
+ This tool prepares data to run a NextGen-based simulation by creating a run package that can be used with NGIAB.
80
+ It uses geometry and model attributes from the [v2.2 hydrofabric](https://lynker-spatial.s3-us-west-2.amazonaws.com/hydrofabric/v2.2/conus/conus_nextgen.gpkg) more information on [all data sources here](https://lynker-spatial.s3-us-west-2.amazonaws.com/hydrofabric/v2.2/hfv2.2-data_model.html).
81
+ The raw forcing data is [nwm retrospective v3 forcing](https://noaa-nwm-retrospective-3-0-pds.s3.amazonaws.com/index.html#CONUS/zarr/forcing/) data or the [AORC 1km gridded data](https://noaa-nws-aorc-v1-1-1km.s3.amazonaws.com/index.html) depending on user input
82
+
83
+ 1. **Subsets** (delineates) everything upstream of your point of interest (catchment, gage, flowpath etc) from the hydrofabric. This subset is output as a geopackage (.gpkg).
84
+ 2. Calculates **forcings** as a weighted mean of the gridded NWM or AORC forcings. Weights are calculated using [exact extract](https://isciences.github.io/exactextract/) and computed with numpy.
85
+ 3. Creates **configuration files** for a default NGIAB model run.
86
+ - realization.json - ngen model configuration
87
+ - troute.yaml - routing configuration.
88
+ - **per catchment** model configuration
89
+ 4. Optionally performs a non-interactive [Docker-based NGIAB](https://github.com/CIROH-UA/NGIAB-CloudInfra) run.
90
+
91
+ ## Limitations
92
+ This tool cannot do the following:
93
+
94
+ ### Custom realizations
95
+ This tool currently only outputs a single, default realization, which is described in "[Realization information](#realization-information)". Support for additional model configurations is planned, but not currently available.
96
+
97
+ ### Calibration
98
+ If available, this repository will download [calibrated parameters](https://communityhydrofabric.s3.us-east-1.amazonaws.com/index.html#hydrofabrics/community/gage_parameters/) from the [Community Hydrofabric](https://github.com/CIROH-UA/community_hf_patcher) AWS S3 bucket.
99
+ However, many gages and catchments will not have such parameters available. In these cases, Data Preprocess will output realizations with default values.
100
+
101
+ For automatic calibration, please see [ngiab-cal](https://github.com/CIROH-UA/ngiab-cal), which is under active development.
102
+
103
+ ### Evaluation
104
+ For automatic evaluation using [TEEHR](https://github.com/RTIInternational/teehr), please run [NGIAB](https://github.com/CIROH-UA/NGIAB-CloudInfra) interactively using the `guide.sh` script.
105
+
106
+ ### Visualisation
107
+ For automatic interactive visualisation, please run [NGIAB](https://github.com/CIROH-UA/NGIAB-CloudInfra) interactively using the `guide.sh` script
108
+
109
+ # Requirements
110
+
111
+ This tool is **officially supported** on **macOS** and **Ubuntu** (tested on 22.04 & 24.04). To use it on Windows, please install [**WSL**](https://learn.microsoft.com/en-us/windows/wsl/install).
112
+
113
+ It is also **highly recommended** to use [Astral UV](https://docs.astral.sh/uv/) to install and run this tool. Installing the project via `pip` without the use of a virtual environment creates a **severe risk** of dependency conflicts.
114
+
115
+ # Installation and running
116
+
117
+ ### Running without install
118
+ This package supports pipx and uvx, which means you can run the tool without installing it. No virtual environment needed, just UV.
119
+ ```bash
120
+ # Run these from anywhere!
121
+ uvx --from ngiab-data-preprocess cli --help # Running the CLI
122
+ uvx ngiab-prep --help # Alias for the CLI
123
+ uvx --from ngiab-data-preprocess map_app # Running the map interface
124
+ ```
125
+
126
+ ### For uv installation
127
+
128
+ <details>
129
+ <summary>Click here to expand</summary>
130
+
131
+ ```bash
132
+ # Install UV
133
+ curl -LsSf https://astral.sh/uv/install.sh | sh
134
+ # It can be installed via pip if that fails
135
+ # pip install uv
136
+
137
+ # Create a virtual environment in the current directory
138
+ uv venv
139
+
140
+ # Install the tool in the virtual environment
141
+ uv pip install ngiab_data_preprocess
142
+
143
+ # To run the cli
144
+ uv run cli --help
145
+
146
+ # To run the map
147
+ uv run map_app
148
+ ```
149
+
150
+ UV automatically detects any virtual environments in the current directory and will use them when you use `uv run`.
151
+
152
+ </details>
153
+
154
+ ### For legacy pip installation
155
+
156
+ <details>
157
+ <summary>Click here to expand</summary>
158
+
159
+ ```bash
160
+ # If you're installing this on jupyterhub / 2i2c you HAVE TO DEACTIVATE THE CONDA ENV
161
+ (notebook) jovyan@jupyter-user:~$ conda deactivate
162
+ jovyan@jupyter-user:~$
163
+ # The interactive map won't work on 2i2c
164
+ ```
165
+
166
+ ```bash
167
+ # This tool is likely to not work without a virtual environment
168
+ python3 -m venv .venv
169
+ source .venv/bin/activate
170
+ # installing and running the tool
171
+ pip install 'ngiab_data_preprocess'
172
+ python -m map_app
173
+ # CLI instructions at the bottom of the README
174
+ ```
175
+ </details>
176
+
177
+ ### Development installation
178
+
179
+ <details>
180
+ <summary>Click to expand installation steps</summary>
181
+
182
+ To install and run the tool, follow these steps:
183
+
184
+ 1. Clone the repository:
185
+ ```bash
186
+ git clone https://github.com/CIROH-UA/NGIAB_data_preprocess
187
+ cd NGIAB_data_preprocess
188
+ ```
189
+ 2. Create a virtual environment:
190
+ ```bash
191
+ uv venv
192
+ ```
193
+ 3. Install the tool:
194
+ ```bash
195
+ uv pip install -e .
196
+ ```
197
+ 4. Run the map app:
198
+ ```bash
199
+ uv run map_app
200
+ ```
201
+ </details>
202
+
203
+ # Map interface documentation
204
+
205
+ ## Running the map interface app
206
+
207
+ Running the `map_app` tool will open the app in a new browser tab.
208
+
209
+ Install-free: `uvx --from ngiab-data-preprocess map_app`
210
+ Installed with uv: `uv run map_app`
211
+
212
+ ## Using the map interface
213
+
214
+ 1. Select the catchment you're interested in on the map.
215
+ 2. Pick the time period you want to simulate.
216
+ 3. Click the following buttons in order:
217
+ 1) Create subset gpkg
218
+ 2) Create Forcing from Zarrs
219
+ 3) Create Realization
220
+
221
+ Once all the steps are finished, you can run NGIAB on the folder shown underneath the subset button.
222
+
223
+ **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.
224
+
225
+ # CLI documentation
226
+
227
+ ## Running the CLI
228
+
229
+ Install-free: `uvx ngiab-prep`
230
+ Installed with uv: `uv run cli`
231
+
232
+ ## Arguments
233
+
234
+ - `-h`, `--help`: Show the help message and exit.
235
+ - `-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.
236
+ - `--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.
237
+ - `-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`.
238
+ - `-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`.
239
+ - `-s`, `--subset`: Subset the hydrofabric to the given feature.
240
+ - `-f`, `--forcings`: Generate forcings for the given feature.
241
+ - `-r`, `--realization`: Create a realization for the given feature.
242
+ - `--start_date START_DATE`, `--start START_DATE`: Start date for forcings/realization (format YYYY-MM-DD).
243
+ - `--end_date END_DATE`, `--end END_DATE`: End date for forcings/realization (format YYYY-MM-DD).
244
+ - `-o OUTPUT_NAME`, `--output_name OUTPUT_NAME`: Name of the output folder.
245
+ - `--source` : The datasource you want to use, either `nwm` for retrospective v3 or `aorc`. Default is `nwm`
246
+ - `-D`, `--debug`: Enable debug logging.
247
+ - `--run`: Automatically run [NGIAB's docker distribution](https://github.com/CIROH-UA/NGIAB-CloudInfra) against the output folder.
248
+ - `--validate`: Run every missing step required to run NGIAB.
249
+ - `-a`, `--all`: Run all operations. Equivalent to `-sfr` and `--run`.
250
+
251
+ ## Usage notes
252
+ - If your input has a prefix of `gage-`, you do not need to pass `-g`.
253
+ - 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`.
254
+ - When using the `--all` flag, it automatically sets `subset`, `forcings`, `realization`, and `run` to `True`.
255
+ - Using the `--run` flag automatically sets the `--validate` flag.
256
+
257
+ ## Examples
258
+
259
+ 1. Prepare everything for an NGIAB run at a given gage:
260
+ ```bash
261
+ uvx ngiab-prep -i gage-10154200 -sfr --start 2022-01-01 --end 2022-02-28
262
+ # add --run or replace -sfr with --all to run NGIAB, too
263
+ # to name the folder, add -o folder_name
264
+ ```
265
+
266
+ 2. Subset the hydrofabric using a catchment ID or VPU:
267
+ ```bash
268
+ uvx ngiab-prep -i cat-7080 -s
269
+ uvx ngiab-prep --vpu 01 -s
270
+ ```
271
+
272
+ 3. Generate forcings using a single catchment ID:
273
+ ```bash
274
+ uvx ngiab-prep -i cat-5173 -f --start 2022-01-01 --end 2022-02-28
275
+ ```
276
+
277
+ 4. Create realization using a latitude/longitude pair and output to a named folder:
278
+ ```bash
279
+ uvx ngiab-prep -i 33.22,-87.54 -l -r --start 2022-01-01 --end 2022-02-28 -o custom_output
280
+ ```
281
+
282
+ 5. Perform all operations using a latitude/longitude pair:
283
+ ```bash
284
+ uvx ngiab-prep -i 33.22,-87.54 -l -s -f -r --start 2022-01-01 --end 2022-02-28
285
+ ```
286
+
287
+ 6. Subset the hydrofabric using a gage ID:
288
+ ```bash
289
+ uvx ngiab-prep -i 10154200 -g -s
290
+ # or
291
+ uvx ngiab-prep -i gage-10154200 -s
292
+ ```
293
+
294
+ 7. Generate forcings using a single gage ID:
295
+ ```bash
296
+ uvx ngiab-prep -i 01646500 -g -f --start 2022-01-01 --end 2022-02-28
297
+ ```
298
+
299
+ # Realization information
300
+
301
+ This tool currently offers one default realization.
302
+
303
+ ## NOAH + CFE
304
+
305
+ [This realization](https://github.com/CIROH-UA/NGIAB_data_preprocess/blob/main/modules/data_sources/cfe-nowpm-realization-template.json) is intended to be roughly comparable to earlier versions of the National Water Model.
306
+ - [NOAH-OWP-Modular](https://github.com/NOAA-OWP/NOAH-OWP-Modular): A refactoring of Noah-MP, a land-surface model. Used to model groundwater properties.
307
+ - [Conceptual Functional Equivalent (CFE)](https://github.com/NOAA-OWP/CFE): A simplified conceptual approximation of versions 1.2, 2.0, and 2.1 of the National Water Model. Used to model precipitation and evaporation.
308
+ - [SLoTH](https://github.com/NOAA-OWP/SLoTH): A module used to feed through unchanged values. In this default configuration, it simply forces certain soil moisture and ice fraction properties to zero.
@@ -0,0 +1,267 @@
1
+ # NGIAB Data Preprocess
2
+
3
+ This repository contains tools for preparing data to run a [NextGen](https://github.com/NOAA-OWP/ngen)-based simulation using [NGIAB](https://github.com/CIROH-UA/NGIAB-CloudInfra). 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!
4
+
5
+ ![map screenshot](https://github.com/CIROH-UA/NGIAB_data_preprocess/blob/main/modules/map_app/static/resources/screenshot.jpg)
6
+
7
+ | | |
8
+ | --- | --- |
9
+ | ![CIROH Logo](./ciroh-bgsafe.png) | Funding for this project was provided by the National Oceanic & Atmospheric Administration (NOAA), awarded to the Cooperative Institute for Research to Operations in Hydrology (CIROH) through the NOAA Cooperative Agreement with The University of Alabama (NA22NWS4320003). |
10
+
11
+ ## Table of Contents
12
+
13
+ 1. [What does this tool do?](#what-does-this-tool-do)
14
+ 2. [Limitations](#limitations)
15
+ - [Custom realizations](#custom-realizations)
16
+ - [Calibration](#calibration)
17
+ - [Evaluation](#evaluation)
18
+ - [Visualisation](#visualisation)
19
+ 3. [Requirements](#requirements)
20
+ 4. [Installation and running](#installation-and-running)
21
+ - [Running without install](#running-without-install)
22
+ - [For uv installation](#for-uv-installation)
23
+ - [For legacy pip installation](#for-legacy-pip-installation)
24
+ - [Development installation](#development-installation)
25
+ 5. [Map interface documentation](#map-interface-documentation)
26
+ - [Running the map interface app](#running-the-map-interface-app)
27
+ - [Using the map interace](#using-the-map-interface)
28
+ 6. [CLI documentation](#cli-documentation)
29
+ - [Running the CLI](#running-the-cli)
30
+ - [Arguments](#arguments)
31
+ - [Usage notes](#usage-notes)
32
+ - [Examples](#examples)
33
+ 7. [Realization information](#realization-information)
34
+ - [NOAH + CFE](#noah--cfe)
35
+
36
+ ## What does this tool do?
37
+
38
+ This tool prepares data to run a NextGen-based simulation by creating a run package that can be used with NGIAB.
39
+ It uses geometry and model attributes from the [v2.2 hydrofabric](https://lynker-spatial.s3-us-west-2.amazonaws.com/hydrofabric/v2.2/conus/conus_nextgen.gpkg) more information on [all data sources here](https://lynker-spatial.s3-us-west-2.amazonaws.com/hydrofabric/v2.2/hfv2.2-data_model.html).
40
+ The raw forcing data is [nwm retrospective v3 forcing](https://noaa-nwm-retrospective-3-0-pds.s3.amazonaws.com/index.html#CONUS/zarr/forcing/) data or the [AORC 1km gridded data](https://noaa-nws-aorc-v1-1-1km.s3.amazonaws.com/index.html) depending on user input
41
+
42
+ 1. **Subsets** (delineates) everything upstream of your point of interest (catchment, gage, flowpath etc) from the hydrofabric. This subset is output as a geopackage (.gpkg).
43
+ 2. Calculates **forcings** as a weighted mean of the gridded NWM or AORC forcings. Weights are calculated using [exact extract](https://isciences.github.io/exactextract/) and computed with numpy.
44
+ 3. Creates **configuration files** for a default NGIAB model run.
45
+ - realization.json - ngen model configuration
46
+ - troute.yaml - routing configuration.
47
+ - **per catchment** model configuration
48
+ 4. Optionally performs a non-interactive [Docker-based NGIAB](https://github.com/CIROH-UA/NGIAB-CloudInfra) run.
49
+
50
+ ## Limitations
51
+ This tool cannot do the following:
52
+
53
+ ### Custom realizations
54
+ This tool currently only outputs a single, default realization, which is described in "[Realization information](#realization-information)". Support for additional model configurations is planned, but not currently available.
55
+
56
+ ### Calibration
57
+ If available, this repository will download [calibrated parameters](https://communityhydrofabric.s3.us-east-1.amazonaws.com/index.html#hydrofabrics/community/gage_parameters/) from the [Community Hydrofabric](https://github.com/CIROH-UA/community_hf_patcher) AWS S3 bucket.
58
+ However, many gages and catchments will not have such parameters available. In these cases, Data Preprocess will output realizations with default values.
59
+
60
+ For automatic calibration, please see [ngiab-cal](https://github.com/CIROH-UA/ngiab-cal), which is under active development.
61
+
62
+ ### Evaluation
63
+ For automatic evaluation using [TEEHR](https://github.com/RTIInternational/teehr), please run [NGIAB](https://github.com/CIROH-UA/NGIAB-CloudInfra) interactively using the `guide.sh` script.
64
+
65
+ ### Visualisation
66
+ For automatic interactive visualisation, please run [NGIAB](https://github.com/CIROH-UA/NGIAB-CloudInfra) interactively using the `guide.sh` script
67
+
68
+ # Requirements
69
+
70
+ This tool is **officially supported** on **macOS** and **Ubuntu** (tested on 22.04 & 24.04). To use it on Windows, please install [**WSL**](https://learn.microsoft.com/en-us/windows/wsl/install).
71
+
72
+ It is also **highly recommended** to use [Astral UV](https://docs.astral.sh/uv/) to install and run this tool. Installing the project via `pip` without the use of a virtual environment creates a **severe risk** of dependency conflicts.
73
+
74
+ # Installation and running
75
+
76
+ ### Running without install
77
+ This package supports pipx and uvx, which means you can run the tool without installing it. No virtual environment needed, just UV.
78
+ ```bash
79
+ # Run these from anywhere!
80
+ uvx --from ngiab-data-preprocess cli --help # Running the CLI
81
+ uvx ngiab-prep --help # Alias for the CLI
82
+ uvx --from ngiab-data-preprocess map_app # Running the map interface
83
+ ```
84
+
85
+ ### For uv installation
86
+
87
+ <details>
88
+ <summary>Click here to expand</summary>
89
+
90
+ ```bash
91
+ # Install UV
92
+ curl -LsSf https://astral.sh/uv/install.sh | sh
93
+ # It can be installed via pip if that fails
94
+ # pip install uv
95
+
96
+ # Create a virtual environment in the current directory
97
+ uv venv
98
+
99
+ # Install the tool in the virtual environment
100
+ uv pip install ngiab_data_preprocess
101
+
102
+ # To run the cli
103
+ uv run cli --help
104
+
105
+ # To run the map
106
+ uv run map_app
107
+ ```
108
+
109
+ UV automatically detects any virtual environments in the current directory and will use them when you use `uv run`.
110
+
111
+ </details>
112
+
113
+ ### For legacy pip installation
114
+
115
+ <details>
116
+ <summary>Click here to expand</summary>
117
+
118
+ ```bash
119
+ # If you're installing this on jupyterhub / 2i2c you HAVE TO DEACTIVATE THE CONDA ENV
120
+ (notebook) jovyan@jupyter-user:~$ conda deactivate
121
+ jovyan@jupyter-user:~$
122
+ # The interactive map won't work on 2i2c
123
+ ```
124
+
125
+ ```bash
126
+ # This tool is likely to not work without a virtual environment
127
+ python3 -m venv .venv
128
+ source .venv/bin/activate
129
+ # installing and running the tool
130
+ pip install 'ngiab_data_preprocess'
131
+ python -m map_app
132
+ # CLI instructions at the bottom of the README
133
+ ```
134
+ </details>
135
+
136
+ ### Development installation
137
+
138
+ <details>
139
+ <summary>Click to expand installation steps</summary>
140
+
141
+ To install and run the tool, follow these steps:
142
+
143
+ 1. Clone the repository:
144
+ ```bash
145
+ git clone https://github.com/CIROH-UA/NGIAB_data_preprocess
146
+ cd NGIAB_data_preprocess
147
+ ```
148
+ 2. Create a virtual environment:
149
+ ```bash
150
+ uv venv
151
+ ```
152
+ 3. Install the tool:
153
+ ```bash
154
+ uv pip install -e .
155
+ ```
156
+ 4. Run the map app:
157
+ ```bash
158
+ uv run map_app
159
+ ```
160
+ </details>
161
+
162
+ # Map interface documentation
163
+
164
+ ## Running the map interface app
165
+
166
+ Running the `map_app` tool will open the app in a new browser tab.
167
+
168
+ Install-free: `uvx --from ngiab-data-preprocess map_app`
169
+ Installed with uv: `uv run map_app`
170
+
171
+ ## Using the map interface
172
+
173
+ 1. Select the catchment you're interested in on the map.
174
+ 2. Pick the time period you want to simulate.
175
+ 3. Click the following buttons in order:
176
+ 1) Create subset gpkg
177
+ 2) Create Forcing from Zarrs
178
+ 3) Create Realization
179
+
180
+ Once all the steps are finished, you can run NGIAB on the folder shown underneath the subset button.
181
+
182
+ **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.
183
+
184
+ # CLI documentation
185
+
186
+ ## Running the CLI
187
+
188
+ Install-free: `uvx ngiab-prep`
189
+ Installed with uv: `uv run cli`
190
+
191
+ ## Arguments
192
+
193
+ - `-h`, `--help`: Show the help message and exit.
194
+ - `-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.
195
+ - `--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.
196
+ - `-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`.
197
+ - `-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`.
198
+ - `-s`, `--subset`: Subset the hydrofabric to the given feature.
199
+ - `-f`, `--forcings`: Generate forcings for the given feature.
200
+ - `-r`, `--realization`: Create a realization for the given feature.
201
+ - `--start_date START_DATE`, `--start START_DATE`: Start date for forcings/realization (format YYYY-MM-DD).
202
+ - `--end_date END_DATE`, `--end END_DATE`: End date for forcings/realization (format YYYY-MM-DD).
203
+ - `-o OUTPUT_NAME`, `--output_name OUTPUT_NAME`: Name of the output folder.
204
+ - `--source` : The datasource you want to use, either `nwm` for retrospective v3 or `aorc`. Default is `nwm`
205
+ - `-D`, `--debug`: Enable debug logging.
206
+ - `--run`: Automatically run [NGIAB's docker distribution](https://github.com/CIROH-UA/NGIAB-CloudInfra) against the output folder.
207
+ - `--validate`: Run every missing step required to run NGIAB.
208
+ - `-a`, `--all`: Run all operations. Equivalent to `-sfr` and `--run`.
209
+
210
+ ## Usage notes
211
+ - If your input has a prefix of `gage-`, you do not need to pass `-g`.
212
+ - 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`.
213
+ - When using the `--all` flag, it automatically sets `subset`, `forcings`, `realization`, and `run` to `True`.
214
+ - Using the `--run` flag automatically sets the `--validate` flag.
215
+
216
+ ## Examples
217
+
218
+ 1. Prepare everything for an NGIAB run at a given gage:
219
+ ```bash
220
+ uvx ngiab-prep -i gage-10154200 -sfr --start 2022-01-01 --end 2022-02-28
221
+ # add --run or replace -sfr with --all to run NGIAB, too
222
+ # to name the folder, add -o folder_name
223
+ ```
224
+
225
+ 2. Subset the hydrofabric using a catchment ID or VPU:
226
+ ```bash
227
+ uvx ngiab-prep -i cat-7080 -s
228
+ uvx ngiab-prep --vpu 01 -s
229
+ ```
230
+
231
+ 3. Generate forcings using a single catchment ID:
232
+ ```bash
233
+ uvx ngiab-prep -i cat-5173 -f --start 2022-01-01 --end 2022-02-28
234
+ ```
235
+
236
+ 4. Create realization using a latitude/longitude pair and output to a named folder:
237
+ ```bash
238
+ uvx ngiab-prep -i 33.22,-87.54 -l -r --start 2022-01-01 --end 2022-02-28 -o custom_output
239
+ ```
240
+
241
+ 5. Perform all operations using a latitude/longitude pair:
242
+ ```bash
243
+ uvx ngiab-prep -i 33.22,-87.54 -l -s -f -r --start 2022-01-01 --end 2022-02-28
244
+ ```
245
+
246
+ 6. Subset the hydrofabric using a gage ID:
247
+ ```bash
248
+ uvx ngiab-prep -i 10154200 -g -s
249
+ # or
250
+ uvx ngiab-prep -i gage-10154200 -s
251
+ ```
252
+
253
+ 7. Generate forcings using a single gage ID:
254
+ ```bash
255
+ uvx ngiab-prep -i 01646500 -g -f --start 2022-01-01 --end 2022-02-28
256
+ ```
257
+
258
+ # Realization information
259
+
260
+ This tool currently offers one default realization.
261
+
262
+ ## NOAH + CFE
263
+
264
+ [This realization](https://github.com/CIROH-UA/NGIAB_data_preprocess/blob/main/modules/data_sources/cfe-nowpm-realization-template.json) is intended to be roughly comparable to earlier versions of the National Water Model.
265
+ - [NOAH-OWP-Modular](https://github.com/NOAA-OWP/NOAH-OWP-Modular): A refactoring of Noah-MP, a land-surface model. Used to model groundwater properties.
266
+ - [Conceptual Functional Equivalent (CFE)](https://github.com/NOAA-OWP/CFE): A simplified conceptual approximation of versions 1.2, 2.0, and 2.1 of the National Water Model. Used to model precipitation and evaporation.
267
+ - [SLoTH](https://github.com/NOAA-OWP/SLoTH): A module used to feed through unchanged values. In this default configuration, it simply forces certain soil moisture and ice fraction properties to zero.