ngiab-data-preprocess 4.6.6__py3-none-any.whl → 4.6.8__py3-none-any.whl

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.
@@ -107,9 +107,13 @@ def clip_dataset_to_bounds(
107
107
  """
108
108
  # check time range here in case just this function is imported and not the whole module
109
109
  start_time, end_time = validate_time_range(dataset, start_time, end_time)
110
+ samplex = dataset.x.values[:2]
111
+ intervalx = samplex[1] - samplex[0]
112
+ sampley = dataset.y.values[:2]
113
+ intervaly = sampley[1] - sampley[0]
110
114
  dataset = dataset.sel(
111
- x=slice(bounds[0], bounds[2]),
112
- y=slice(bounds[1], bounds[3]),
115
+ x=slice(bounds[0]-intervalx, bounds[2]+intervalx),
116
+ y=slice(bounds[1]-intervaly, bounds[3]+intervaly),
113
117
  time=slice(start_time, end_time),
114
118
  )
115
119
  logger.info("Selected time range and clipped to bounds")
@@ -530,7 +530,7 @@ def get_cat_to_nhd_feature_id(gpkg: Path = FilePaths.conus_hydrofabric) -> Dict[
530
530
  )
531
531
 
532
532
  table_name = list(tables)[0]
533
- sql_query = f"SELECT divide_id, hf_id FROM {table_name} WHERE divide_id IS NOT NULL AND hf_id IS NOT NULL"
533
+ sql_query = f"SELECT divide_id, hf_id FROM {table_name} WHERE divide_id IS NOT NULL AND hf_id IS NOT NULL ORDER BY hf_hydroseq DESC"
534
534
 
535
535
  with sqlite3.connect(gpkg) as conn:
536
536
  result: List[Tuple[str, str]] = conn.execute(sql_query).fetchall()
@@ -539,6 +539,7 @@ def get_cat_to_nhd_feature_id(gpkg: Path = FilePaths.conus_hydrofabric) -> Dict[
539
539
  for cat, feature in result:
540
540
  # the ids are stored as floats this converts to int to match nwm output
541
541
  # numeric ids should be stored as strings.
542
+ # Because of the ORDER BY above, the lowest hf_hydroseq "wins"
542
543
  mapping[cat] = int(feature)
543
544
 
544
545
  return mapping
map_app/__init__.py CHANGED
@@ -1,16 +1,19 @@
1
1
  from flask import Flask
2
2
  import logging
3
+ from pathlib import Path
3
4
  from map_app.views import main, intra_module_db
4
5
  from data_sources.source_validation import validate_all
5
6
 
6
- with open("app.log", "w") as f:
7
+ LOG_PATH = Path.home() / ".ngiab" / "app.log"
8
+
9
+ with open(LOG_PATH, "w") as f:
7
10
  f.write("")
8
11
  f.write("Starting Application!\n")
9
12
 
10
13
  logging.basicConfig(
11
14
  level=logging.INFO,
12
15
  format="%(name)-12s: %(levelname)s - %(message)s",
13
- filename="app.log",
16
+ filename=LOG_PATH,
14
17
  filemode="a",
15
18
  ) # Append mode
16
19
  # Example: Adding a console handler to root logger (optional)
map_app/__main__.py CHANGED
@@ -3,18 +3,20 @@
3
3
  import logging
4
4
  import webbrowser
5
5
  from threading import Timer
6
+ from pathlib import Path
6
7
 
7
8
  from data_processing.file_paths import FilePaths
8
9
  from data_processing.graph_utils import get_graph
9
10
 
10
11
  from map_app import app, console_handler
11
12
 
13
+ LOG_PATH = Path.home() / ".ngiab" / "app.log"
12
14
 
13
15
  def open_browser():
14
16
  # find the last line in the log file that contains the port number
15
17
  # * running on http://0.0.0.0:port_number
16
18
  port_number = None
17
- with open("app.log", "r") as f:
19
+ with open(LOG_PATH, 'r') as f:
18
20
  lines = f.readlines()
19
21
  for line in reversed(lines):
20
22
  if "Running on http" in line:
@@ -38,12 +40,12 @@ def main():
38
40
 
39
41
  if FilePaths.dev_file.is_file():
40
42
  Timer(2, set_logs_to_warning).start()
41
- with open("app.log", "a") as f:
43
+ with open(LOG_PATH, "a") as f:
42
44
  f.write("Running in debug mode\n")
43
45
  app.run(debug=True, host="0.0.0.0", port="8080") # type: ignore
44
46
  else:
45
47
  Timer(1, open_browser).start()
46
- with open("app.log", "a") as f:
48
+ with open(LOG_PATH, "a") as f:
47
49
  f.write("Running in production mode\n")
48
50
  app.run(host="0.0.0.0", port="0") # type: ignore
49
51
 
map_app/views.py CHANGED
@@ -136,7 +136,7 @@ def download_forcings(data_source, start_time, end_time, paths):
136
136
 
137
137
  def compute_forcings(cached_data, paths):
138
138
  create_forcings(cached_data, paths.output_dir.stem) # type: ignore
139
-
139
+
140
140
  @main.route("/forcings", methods=["POST"])
141
141
  def get_forcings():
142
142
  # body: JSON.stringify({'forcing_dir': forcing_dir, 'start_time': start_time, 'end_time': end_time}),
@@ -190,7 +190,7 @@ def get_catids_from_vpu():
190
190
 
191
191
  @main.route("/logs", methods=["GET"])
192
192
  def get_logs():
193
- log_file_path = "app.log"
193
+ log_file_path = Path.home() / ".ngiab" / "app.log"
194
194
  try:
195
195
  with open(log_file_path, "r") as file:
196
196
  lines = file.readlines()
@@ -177,7 +177,7 @@ def main() -> None:
177
177
  else:
178
178
  logging.info("Subsetting hydrofabric")
179
179
  include_outlet = True
180
- if args.gage:
180
+ if args.gage or args.subset_type == "catchment":
181
181
  include_outlet = False
182
182
  subset(
183
183
  feature_to_subset,
@@ -3,6 +3,7 @@ from datetime import datetime
3
3
 
4
4
  # Constants
5
5
  DATE_FORMAT = "%Y-%m-%d" # used for datetime parsing
6
+ DATE_FORMAT2 = "%Y-%m-%d %H:%M" # used for datetime parsing
6
7
  DATE_FORMAT_HINT = "YYYY-MM-DD" # printed in help message
7
8
 
8
9
 
@@ -91,13 +92,13 @@ def parse_arguments() -> argparse.Namespace:
91
92
  parser.add_argument(
92
93
  "--start_date",
93
94
  "--start",
94
- type=lambda s: datetime.strptime(s, DATE_FORMAT),
95
+ type=lambda s: datetime.strptime(s, DATE_FORMAT) if len(s) == 10 else datetime.strptime(s, DATE_FORMAT2),
95
96
  help=f"Start date for forcings/realization (format {DATE_FORMAT_HINT})",
96
97
  )
97
98
  parser.add_argument(
98
99
  "--end_date",
99
100
  "--end",
100
- type=lambda s: datetime.strptime(s, DATE_FORMAT),
101
+ type=lambda s: datetime.strptime(s, DATE_FORMAT) if len(s) == 10 else datetime.strptime(s, DATE_FORMAT2),
101
102
  help=f"End date for forcings/realization (format {DATE_FORMAT_HINT})",
102
103
  )
103
104
  parser.add_argument(
@@ -147,6 +148,13 @@ def parse_arguments() -> argparse.Namespace:
147
148
  choices=["aorc", "nwm"],
148
149
  default="nwm",
149
150
  )
151
+ parser.add_argument(
152
+ "--subset_type",
153
+ type=str,
154
+ help="By nexus: get everything flowing into the downstream nexus of the selected catchment. By catchment: get everything flowing into the selected catchment.",
155
+ choices=["nexus", "catchment"],
156
+ default="nexus",
157
+ )
150
158
  parser.add_argument(
151
159
  "-a",
152
160
  "--all",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ngiab_data_preprocess
3
- Version: 4.6.6
3
+ Version: 4.6.8
4
4
  Summary: Graphical Tools for creating Next Gen Water model input data.
5
5
  Author-email: Josh Cunningham <jcunningham8@ua.edu>
6
6
  Project-URL: Homepage, https://github.com/CIROH-UA/NGIAB_data_preprocess
@@ -13,6 +13,7 @@ Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
14
  Requires-Dist: pyogrio>=0.7.2
15
15
  Requires-Dist: pyproj>=3.6.1
16
+ Requires-Dist: pandas<3.0.0
16
17
  Requires-Dist: Flask==3.0.2
17
18
  Requires-Dist: geopandas>=1.0.0
18
19
  Requires-Dist: requests==2.32.4
@@ -28,7 +29,7 @@ Requires-Dist: numpy>=1.26.4
28
29
  Requires-Dist: tqdm==4.66.4
29
30
  Requires-Dist: rich==13.7.1
30
31
  Requires-Dist: colorama==0.4.6
31
- Requires-Dist: bokeh==3.5.1
32
+ Requires-Dist: bokeh==3.8.2
32
33
  Requires-Dist: boto3
33
34
  Requires-Dist: numcodecs<0.16.0
34
35
  Requires-Dist: scipy>=1.15.3
@@ -75,13 +76,13 @@ This repository contains tools for preparing data to run a [NextGen](https://git
75
76
 
76
77
  ## What does this tool do?
77
78
 
78
- This tool prepares data to run a NextGen-based simulation by creating a run package that can be used with NGIAB.
79
- 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).
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).
80
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
81
82
 
82
- 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).
83
- 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.
84
- 3. Creates **configuration files** for a default NGIAB model run.
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.
85
86
  - realization.json - ngen model configuration
86
87
  - troute.yaml - routing configuration.
87
88
  - **per catchment** model configuration
@@ -136,13 +137,13 @@ curl -LsSf https://astral.sh/uv/install.sh | sh
136
137
  # Create a virtual environment in the current directory
137
138
  uv venv
138
139
 
139
- # Install the tool in the virtual environment
140
+ # Install the tool in the virtual environment
140
141
  uv pip install ngiab_data_preprocess
141
142
 
142
143
  # To run the cli
143
144
  uv run cli --help
144
145
 
145
- # To run the map
146
+ # To run the map
146
147
  uv run map_app
147
148
  ```
148
149
 
@@ -160,7 +161,7 @@ UV automatically detects any virtual environments in the current directory and w
160
161
  (notebook) jovyan@jupyter-user:~$ conda deactivate
161
162
  jovyan@jupyter-user:~$
162
163
  # The interactive map won't work on 2i2c
163
- ```
164
+ ```
164
165
 
165
166
  ```bash
166
167
  # This tool is likely to not work without a virtual environment
@@ -205,7 +206,7 @@ To install and run the tool, follow these steps:
205
206
 
206
207
  Running the `map_app` tool will open the app in a new browser tab.
207
208
 
208
- Install-free: `uvx --from ngiab-data-preprocess map_app`
209
+ Install-free: `uvx --from ngiab-data-preprocess map_app`
209
210
  Installed with uv: `uv run map_app`
210
211
 
211
212
  ## Using the map interface
@@ -225,7 +226,7 @@ Once all the steps are finished, you can run NGIAB on the folder shown underneat
225
226
 
226
227
  ## Running the CLI
227
228
 
228
- Install-free: `uvx ngiab-prep`
229
+ Install-free: `uvx ngiab-prep`
229
230
  Installed with uv: `uv run cli`
230
231
 
231
232
  ## Arguments
@@ -236,6 +237,7 @@ Installed with uv: `uv run cli`
236
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`.
237
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`.
238
239
  - `-s`, `--subset`: Subset the hydrofabric to the given feature.
240
+ - `--subset_type`: Specify the subset type. `nexus`: get everything flowing into the downstream nexus of the selected catchment. `catchment`: get everything flowing into the selected catchment.
239
241
  - `-f`, `--forcings`: Generate forcings for the given feature.
240
242
  - `-r`, `--realization`: Create a realization for the given feature.
241
243
  - `--lstm`: Configures the data for the [python lstm](https://github.com/ciroh-ua/lstm/).
@@ -259,7 +261,7 @@ Installed with uv: `uv run cli`
259
261
 
260
262
  1. Prepare everything for an NGIAB run at a given gage:
261
263
  ```bash
262
- uvx ngiab-prep -i gage-10154200 -sfr --start 2022-01-01 --end 2022-02-28
264
+ uvx ngiab-prep -i gage-10154200 -sfr --start 2022-01-01 --end 2022-02-28
263
265
  # add --run or replace -sfr with --all to run NGIAB, too
264
266
  # to name the folder, add -o folder_name
265
267
  ```
@@ -1,10 +1,10 @@
1
1
  data_processing/create_realization.py,sha256=b1a9Wuld9saJ-zzVDPY_kba3-ZOVbRuobyR-QiHLXyY,11550
2
2
  data_processing/dask_utils.py,sha256=A2IP94WAz8W9nek3etXKEKTOxGPf0NWSFLh8cZ5S-xU,2454
3
- data_processing/dataset_utils.py,sha256=pZpY4xvOKp4Sd44olRvEHi4dXP-kmOylWzVqU9QT69w,8407
3
+ data_processing/dataset_utils.py,sha256=iLY_3dSRxd8O0wI24IM2zuJru8vtmRlph0O_ZU_mAr4,8597
4
4
  data_processing/datasets.py,sha256=_EJ1uZSWTU1HWpvF7TQSikneJqWZFikTrdo9usCV8A0,4665
5
5
  data_processing/file_paths.py,sha256=7MpwfIQewLRrDpAw1dxTjTperUwOk3EC_kthmnJSRII,4851
6
6
  data_processing/forcings.py,sha256=G_g3VSM_YN-k4FrbnUByrDR4n3fk1GVfv74kamit2CI,21775
7
- data_processing/gpkg_utils.py,sha256=VoQG53zaGcdmkU9M_7kRrk_vygRGJV9E-wX-T48Rzj8,20576
7
+ data_processing/gpkg_utils.py,sha256=uERtQAMz9msJib_suffILuhUY8EcrvYw-pqkJOm2s9E,20673
8
8
  data_processing/graph_utils.py,sha256=4D72wMSiCRKCPC7JUz7XCoaISRGLuqDx6wpeO_VP8fk,8301
9
9
  data_processing/s3fs_utils.py,sha256=ki1EmA0ezV0r26re6dRWIGzL5FudGdwF9Qw1eVLR0Bc,2747
10
10
  data_processing/subset.py,sha256=EwDii-EsOiJBaDMjvYWfz7V9wQSXb887w_fk28u8dlw,3789
@@ -19,9 +19,9 @@ data_sources/noah-owp-modular-init.namelist.input,sha256=Vb7mp40hFpJogruOrXrDHwV
19
19
  data_sources/source_validation.py,sha256=DMCTo-Tad9QSXFqSDB5guI8hMzY_kQE6aW78-5nqwlU,9457
20
20
  data_sources/template.sql,sha256=ZnFqAqleEq9wgmAhNO90Wue_L9k0JAn8KF99DYtcxgs,10457
21
21
  data_sources/triggers.sql,sha256=G0d_175eNsamKAFhsbphPATvzMPuPL_iCleIhlToduQ,14906
22
- map_app/__init__.py,sha256=OarJao9X98kcbLyiwewN4ObWNAYkKDichcxbuWywTsA,818
23
- map_app/__main__.py,sha256=5qJGypfesfdWDWRsbTQiMs3uL5zPZKRZQq31l7qXqCc,1649
24
- map_app/views.py,sha256=AxLsXL8ZSnRJzg5zVYDGfVFA_6amgae41AO_E1G7W58,7923
22
+ map_app/__init__.py,sha256=HvjuTiuf0vTvNLDsgmABqPPMQxOcTljX2nzgj6Pdp_g,888
23
+ map_app/__main__.py,sha256=9wnCunreKNtvI-NEFB-bTHoKXuI5PtPznj13ctrDAOc,1717
24
+ map_app/views.py,sha256=LRpHHw9FOzxEPY42LjJZ3XWFbKyZFKtPu9GZftdXrUY,7944
25
25
  map_app/static/css/console.css,sha256=xN6G2MMFyKc9YW9HEVpUUTUjx2o2nokBR4nCX5c18UM,803
26
26
  map_app/static/css/main.css,sha256=pYIIk-dXW6YMpliSJKATdvgPhFVY6K26NeUuHoYyJqg,8736
27
27
  map_app/static/css/toggle.css,sha256=aUIe9AL1-_mzKvWir3lJ9W8r2oXsOjkFbtvcrohnV10,4149
@@ -31,13 +31,13 @@ map_app/static/js/main.js,sha256=wtLZ18hPZbnyo28dRGsOf-CAHCGxqe1PWEAGa6-S4tg,109
31
31
  map_app/static/resources/loading.gif,sha256=ggdkZf1AD7rSwIpSJwfiIqANgmVV1WHlxGuKxQKv7uY,72191
32
32
  map_app/static/resources/screenshot.jpg,sha256=Ia358aX-OHM9BP4B8lX05cLnguF2fHUIimno9bnFLYw,253730
33
33
  map_app/templates/index.html,sha256=qgQxvaJgkU8Ul57dMLX5n0O3BrwMow-CxGPH7_8yjXc,12195
34
- ngiab_data_cli/__main__.py,sha256=_8IFqL2CGZGMsC71uutqHOIjZpfYBD91yKTk4dvEa3c,11318
35
- ngiab_data_cli/arguments.py,sha256=97BFzlj68tt9tRCR3rTPnK6o7zd7dUCdPg8Cypa2aKA,4782
34
+ ngiab_data_cli/__main__.py,sha256=FmHxibQtFm15aEUG1BrIIqIWNU_BoXzWCTXoR9EA-YI,11353
35
+ ngiab_data_cli/arguments.py,sha256=Bi_Q6FRXvRxI50Pgk7goyASe-2lfUh-oDdnYkaY4KTc,5262
36
36
  ngiab_data_cli/custom_logging.py,sha256=iS2XozaxudcxQj17qAsrCgbVK9LJAYAPmarJuVWJo1k,1280
37
37
  ngiab_data_cli/forcing_cli.py,sha256=eIWRxRWUwPqR16fihFDEIV4VzGlNuvcD6lJW5VYjkPU,3635
38
- ngiab_data_preprocess-4.6.6.dist-info/licenses/LICENSE,sha256=6dMSprwwnsRzEm02mEDbKHD9dUbL8bPIt9Vhrhb0Ulk,1081
39
- ngiab_data_preprocess-4.6.6.dist-info/METADATA,sha256=2TEVfZHKru4tHt300zQI_tW9SoT4SWKeFnE7cDOA_y8,14337
40
- ngiab_data_preprocess-4.6.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
41
- ngiab_data_preprocess-4.6.6.dist-info/entry_points.txt,sha256=spwlhKEJ3ZnNETQsJGeTjD7Vwy8O_zGHb9GdX8ACCtw,128
42
- ngiab_data_preprocess-4.6.6.dist-info/top_level.txt,sha256=CjhYAUZrdveR2fOK6rxffU09VIN2IuPD7hk4V3l3pV0,52
43
- ngiab_data_preprocess-4.6.6.dist-info/RECORD,,
38
+ ngiab_data_preprocess-4.6.8.dist-info/licenses/LICENSE,sha256=6dMSprwwnsRzEm02mEDbKHD9dUbL8bPIt9Vhrhb0Ulk,1081
39
+ ngiab_data_preprocess-4.6.8.dist-info/METADATA,sha256=SR4MIdIf-NJsmQIVblbUQkzQEorQymRjDhQRK4eJv8Y,14541
40
+ ngiab_data_preprocess-4.6.8.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
41
+ ngiab_data_preprocess-4.6.8.dist-info/entry_points.txt,sha256=spwlhKEJ3ZnNETQsJGeTjD7Vwy8O_zGHb9GdX8ACCtw,128
42
+ ngiab_data_preprocess-4.6.8.dist-info/top_level.txt,sha256=CjhYAUZrdveR2fOK6rxffU09VIN2IuPD7hk4V3l3pV0,52
43
+ ngiab_data_preprocess-4.6.8.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.9.0)
2
+ Generator: setuptools (80.10.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5