ngiab-data-preprocess 4.3.1__tar.gz → 4.3.3__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 (52) hide show
  1. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/PKG-INFO +2 -2
  2. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/data_processing/dataset_utils.py +40 -7
  3. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/ngiab_data_cli/__main__.py +3 -3
  4. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/ngiab_data_preprocess.egg-info/PKG-INFO +2 -2
  5. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/pyproject.toml +2 -3
  6. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/.github/workflows/build_only.yml +0 -0
  7. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/.github/workflows/publish.yml +0 -0
  8. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/.gitignore +0 -0
  9. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/LICENSE +0 -0
  10. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/README.md +0 -0
  11. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/data_processing/create_realization.py +0 -0
  12. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/data_processing/dask_utils.py +0 -0
  13. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/data_processing/datasets.py +0 -0
  14. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/data_processing/file_paths.py +0 -0
  15. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/data_processing/forcings.py +0 -0
  16. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/data_processing/gpkg_utils.py +0 -0
  17. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/data_processing/graph_utils.py +0 -0
  18. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/data_processing/s3fs_utils.py +0 -0
  19. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/data_processing/subset.py +0 -0
  20. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/data_sources/cfe-nowpm-realization-template.json +0 -0
  21. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/data_sources/cfe-template.ini +0 -0
  22. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/data_sources/em-catchment-template.yml +0 -0
  23. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/data_sources/em-config.yml +0 -0
  24. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/data_sources/em-realization-template.json +0 -0
  25. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/data_sources/forcing_template.nc +0 -0
  26. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/data_sources/ngen-routing-template.yaml +0 -0
  27. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/data_sources/noah-owp-modular-init.namelist.input +0 -0
  28. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/data_sources/source_validation.py +0 -0
  29. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/data_sources/template.sql +0 -0
  30. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/data_sources/triggers.sql +0 -0
  31. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/map_app/__init__.py +0 -0
  32. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/map_app/__main__.py +0 -0
  33. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/map_app/static/css/console.css +0 -0
  34. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/map_app/static/css/main.css +0 -0
  35. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/map_app/static/css/toggle.css +0 -0
  36. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/map_app/static/js/console.js +0 -0
  37. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/map_app/static/js/data_processing.js +0 -0
  38. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/map_app/static/js/main.js +0 -0
  39. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/map_app/static/resources/loading.gif +0 -0
  40. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/map_app/static/resources/screenshot.jpg +0 -0
  41. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/map_app/templates/index.html +0 -0
  42. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/map_app/views.py +0 -0
  43. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/ngiab_data_cli/arguments.py +0 -0
  44. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/ngiab_data_cli/custom_logging.py +0 -0
  45. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/ngiab_data_cli/forcing_cli.py +0 -0
  46. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/ngiab_data_preprocess.egg-info/SOURCES.txt +0 -0
  47. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/ngiab_data_preprocess.egg-info/dependency_links.txt +0 -0
  48. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/ngiab_data_preprocess.egg-info/entry_points.txt +0 -0
  49. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/ngiab_data_preprocess.egg-info/requires.txt +0 -0
  50. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/modules/ngiab_data_preprocess.egg-info/top_level.txt +0 -0
  51. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/setup.cfg +0 -0
  52. {ngiab_data_preprocess-4.3.1 → ngiab_data_preprocess-4.3.3}/tests/test_nan_impute.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ngiab_data_preprocess
3
- Version: 4.3.1
3
+ Version: 4.3.3
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
@@ -8,7 +8,7 @@ Project-URL: Issues, https://github.com/CIROH-UA/NGIAB_data_preprocess/issues
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Classifier: License :: OSI Approved :: MIT License
10
10
  Classifier: Operating System :: OS Independent
11
- Requires-Python: >=3.10
11
+ Requires-Python: !=3.10.18,>=3.10
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
14
  Requires-Dist: pyogrio>=0.7.2
@@ -7,9 +7,9 @@ from typing import List, Literal, Optional, Tuple, Union
7
7
  import geopandas as gpd
8
8
  import numpy as np
9
9
  import xarray as xr
10
+ from dask.distributed import Client, Future, progress
11
+ from data_processing.dask_utils import no_cluster, use_cluster
10
12
  from xarray.core.types import InterpOptions
11
- from dask.distributed import Client, progress, Future
12
- from data_processing.dask_utils import use_cluster
13
13
 
14
14
  logger = logging.getLogger(__name__)
15
15
 
@@ -117,13 +117,14 @@ def clip_dataset_to_bounds(
117
117
  return dataset
118
118
 
119
119
 
120
+ @no_cluster
120
121
  def interpolate_nan_values(
121
122
  dataset: xr.Dataset,
122
123
  variables: Optional[List[str]] = None,
123
124
  dim: str = "time",
124
125
  method: InterpOptions = "nearest",
125
126
  fill_value: str = "extrapolate",
126
- ) -> None:
127
+ ) -> bool:
127
128
  """
128
129
  Interpolates NaN values in specified (or all numeric time-dependent)
129
130
  variables of an xarray.Dataset. Operates inplace on the dataset.
@@ -145,6 +146,7 @@ def interpolate_nan_values(
145
146
  Set to "extrapolate" to fill with the nearest valid value when using 'nearest' or 'linear'.
146
147
  Default is "extrapolate".
147
148
  """
149
+ interpolation_used = False
148
150
  for name, var in dataset.data_vars.items():
149
151
  # if the variable is non-numeric, skip
150
152
  if not np.issubdtype(var.dtype, np.number):
@@ -158,6 +160,32 @@ def interpolate_nan_values(
158
160
  method=method,
159
161
  fill_value=fill_value if method in ["nearest", "linear"] else None,
160
162
  )
163
+ interpolation_used = True
164
+ return interpolation_used
165
+
166
+
167
+ @no_cluster
168
+ def save_dataset_no_cluster(
169
+ ds_to_save: xr.Dataset,
170
+ target_path: Path,
171
+ engine: Literal["netcdf4", "scipy", "h5netcdf"] = "h5netcdf",
172
+ ):
173
+ """
174
+ This explicitly does not use dask distributed.
175
+ Helper function to compute and save an xarray.Dataset to a NetCDF file.
176
+ Uses a temporary file and rename for avoid leaving a half written file.
177
+ """
178
+ if not target_path.parent.exists():
179
+ target_path.parent.mkdir(parents=True, exist_ok=True)
180
+
181
+ temp_file_path = target_path.with_name(target_path.name + ".saving.nc")
182
+ if temp_file_path.exists():
183
+ os.remove(temp_file_path)
184
+
185
+ ds_to_save.to_netcdf(temp_file_path, engine=engine, compute=True)
186
+
187
+ os.rename(str(temp_file_path), str(target_path))
188
+ logger.info(f"Successfully saved data to: {target_path}")
161
189
 
162
190
 
163
191
  @use_cluster
@@ -206,13 +234,18 @@ def save_to_cache(
206
234
 
207
235
  # save dataset locally before manipulating it
208
236
  save_dataset(stores, cached_nc_path)
209
- stores = xr.open_mfdataset(cached_nc_path, parallel=True, engine="h5netcdf")
210
237
 
211
238
  if interpolate_nans:
212
- interpolate_nan_values(dataset=stores)
213
- save_dataset(stores, cached_nc_path)
214
- stores = xr.open_mfdataset(cached_nc_path, parallel=True, engine="h5netcdf")
239
+ stores = xr.open_mfdataset(
240
+ cached_nc_path,
241
+ parallel=True,
242
+ engine="h5netcdf",
243
+ )
244
+ was_interpolated = interpolate_nan_values(dataset=stores)
245
+ if was_interpolated:
246
+ save_dataset_no_cluster(stores, cached_nc_path)
215
247
 
248
+ stores = xr.open_mfdataset(cached_nc_path, parallel=True, engine="h5netcdf")
216
249
  return stores
217
250
 
218
251
 
@@ -1,13 +1,13 @@
1
1
  from typing import Tuple
2
+
2
3
  import rich.status
3
4
 
4
5
  # add a status bar for these imports so the cli feels more responsive
5
- with rich.status.Status("Initializing...") as status:
6
+ with rich.status.Status("loading") as status:
6
7
  import argparse
7
8
  import logging
8
9
  import subprocess
9
10
  import time
10
- from typing import List
11
11
 
12
12
  import geopandas as gpd
13
13
  from data_processing.create_realization import create_em_realization, create_realization
@@ -19,7 +19,7 @@ with rich.status.Status("Initializing...") as status:
19
19
  from data_processing.gpkg_utils import get_cat_from_gage_id, get_catid_from_point
20
20
  from data_processing.graph_utils import get_upstream_cats
21
21
  from data_processing.subset import subset, subset_vpu
22
- from data_sources.source_validation import validate_output_dir, validate_hydrofabric
22
+ from data_sources.source_validation import validate_hydrofabric, validate_output_dir
23
23
  from ngiab_data_cli.arguments import parse_arguments
24
24
  from ngiab_data_cli.custom_logging import set_logging_to_critical_only, setup_logging
25
25
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ngiab_data_preprocess
3
- Version: 4.3.1
3
+ Version: 4.3.3
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
@@ -8,7 +8,7 @@ Project-URL: Issues, https://github.com/CIROH-UA/NGIAB_data_preprocess/issues
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Classifier: License :: OSI Approved :: MIT License
10
10
  Classifier: Operating System :: OS Independent
11
- Requires-Python: >=3.10
11
+ Requires-Python: !=3.10.18,>=3.10
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
14
  Requires-Dist: pyogrio>=0.7.2
@@ -17,12 +17,11 @@ testpaths = ["tests"]
17
17
  filterwarnings = ['ignore::DeprecationWarning:geopandas._compat']
18
18
  [project]
19
19
  name = "ngiab_data_preprocess"
20
- version = "4.3.1"
21
- #dynamic = ["version"]
20
+ version = "4.3.3"
22
21
  authors = [{ name = "Josh Cunningham", email = "jcunningham8@ua.edu" }]
23
22
  description = "Graphical Tools for creating Next Gen Water model input data."
24
23
  readme = "README.md"
25
- requires-python = ">=3.10"
24
+ requires-python = ">=3.10,!=3.10.18"
26
25
  classifiers = [
27
26
  "Programming Language :: Python :: 3",
28
27
  "License :: OSI Approved :: MIT License",