ngiab-data-preprocess 3.2.1__tar.gz → 3.2.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 (51) hide show
  1. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/PKG-INFO +1 -1
  2. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/data_processing/forcings.py +11 -5
  3. ngiab_data_preprocess-3.2.3/modules/map_app/__init__.py +28 -0
  4. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/map_app/__main__.py +5 -31
  5. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/map_app/views.py +9 -5
  6. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/ngiab_data_preprocess.egg-info/PKG-INFO +1 -1
  7. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/ngiab_data_preprocess.egg-info/SOURCES.txt +2 -0
  8. ngiab_data_preprocess-3.2.3/modules/ngiab_data_preprocess.egg-info/entry_points.txt +3 -0
  9. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/pyproject.toml +5 -1
  10. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/.github/workflows/build_only.yml +0 -0
  11. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/.github/workflows/publish.yml +0 -0
  12. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/.gitignore +0 -0
  13. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/LICENSE +0 -0
  14. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/README.md +0 -0
  15. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/map.html +0 -0
  16. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/data_processing/create_realization.py +0 -0
  17. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/data_processing/file_paths.py +0 -0
  18. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/data_processing/gpkg_utils.py +0 -0
  19. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/data_processing/graph_utils.py +0 -0
  20. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/data_processing/s3fs_utils.py +0 -0
  21. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/data_processing/subset.py +0 -0
  22. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/data_processing/zarr_utils.py +0 -0
  23. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/data_sources/cfe-nowpm-realization-template.json +0 -0
  24. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/data_sources/cfe-template.ini +0 -0
  25. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/data_sources/em-catchment-template.yml +0 -0
  26. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/data_sources/em-config.yml +0 -0
  27. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/data_sources/em-realization-template.json +0 -0
  28. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/data_sources/forcing_template.nc +0 -0
  29. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/data_sources/ngen-routing-template.yaml +0 -0
  30. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/data_sources/noah-owp-modular-init.namelist.input +0 -0
  31. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/data_sources/source_validation.py +0 -0
  32. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/data_sources/template.sql +0 -0
  33. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/data_sources/triggers.sql +0 -0
  34. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/map_app/static/css/console.css +0 -0
  35. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/map_app/static/css/main.css +0 -0
  36. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/map_app/static/js/console.js +0 -0
  37. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/map_app/static/js/data_processing.js +0 -0
  38. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/map_app/static/js/main.js +0 -0
  39. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/map_app/static/resources/dark-style.json +0 -0
  40. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/map_app/static/resources/light-style.json +0 -0
  41. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/map_app/static/resources/loading.gif +0 -0
  42. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/map_app/static/resources/screenshot.png +0 -0
  43. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/map_app/templates/index.html +0 -0
  44. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/ngiab_data_cli/__main__.py +0 -0
  45. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/ngiab_data_cli/arguments.py +0 -0
  46. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/ngiab_data_cli/custom_logging.py +0 -0
  47. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/ngiab_data_preprocess.egg-info/dependency_links.txt +0 -0
  48. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/ngiab_data_preprocess.egg-info/requires.txt +0 -0
  49. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/modules/ngiab_data_preprocess.egg-info/top_level.txt +0 -0
  50. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/output/.gitkeep +0 -0
  51. {ngiab_data_preprocess-3.2.1 → ngiab_data_preprocess-3.2.3}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: ngiab_data_preprocess
3
- Version: 3.2.1
3
+ Version: 3.2.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
@@ -83,7 +83,7 @@ def get_index_chunks(data: xr.DataArray) -> list[tuple[int, int]]:
83
83
  # takes a data array and calculates the start and end index for each chunk
84
84
  # based on the available memory.
85
85
  array_memory_usage = data.nbytes
86
- # free_memory = psutil.virtual_memory().available * 0.8 # 80% of available memory
86
+ free_memory = psutil.virtual_memory().available * 0.8 # 80% of available memory
87
87
  # limit the chunk to 20gb, makes things more stable
88
88
  free_memory = min(free_memory, 20 * 1024 * 1024 * 1024)
89
89
  num_chunks = ceil(array_memory_usage / free_memory)
@@ -223,7 +223,12 @@ def compute_zonal_stats(
223
223
  concatenated_da.to_dataset(name=variable).to_netcdf(forcings_dir/ "temp" / f"{variable}_{i}.nc")
224
224
  # Merge the chunks back together
225
225
  datasets = [xr.open_dataset(forcings_dir / "temp" / f"{variable}_{i}.nc") for i in range(len(time_chunks))]
226
- xr.concat(datasets, dim="time").to_netcdf(forcings_dir / f"{variable}.nc")
226
+ result = xr.concat(datasets, dim="time")
227
+ result.to_netcdf(forcings_dir / f"{variable}.nc")
228
+ # close the datasets
229
+ result.close()
230
+ _ = [dataset.close() for dataset in datasets]
231
+
227
232
  for file in forcings_dir.glob("temp/*.nc"):
228
233
  file.unlink()
229
234
  progress.remove_task(chunk_task)
@@ -237,6 +242,7 @@ def compute_zonal_stats(
237
242
  )
238
243
  write_outputs(forcings_dir, variables)
239
244
 
245
+
240
246
  def write_outputs(forcings_dir, variables):
241
247
 
242
248
  # start a dask cluster if there isn't one already running
@@ -289,9 +295,9 @@ def write_outputs(forcings_dir, variables):
289
295
  final_ds["Time"].attrs["epoch_start"] = "01/01/1970 00:00:00" # not needed but suppresses the ngen warning
290
296
 
291
297
  final_ds.to_netcdf(output_folder / "forcings.nc", engine="netcdf4")
292
- # delete the individual variable files
293
- for file in forcings_dir.glob("*.nc"):
294
- file.unlink()
298
+ # close the datasets
299
+ _ = [result.close() for result in results]
300
+ final_ds.close()
295
301
 
296
302
 
297
303
  def setup_directories(cat_id: str) -> file_paths:
@@ -0,0 +1,28 @@
1
+ from flask import Flask
2
+ import logging
3
+ from map_app.views import main, intra_module_db
4
+ from data_sources.source_validation import validate_all
5
+
6
+ with open("app.log", "w") as f:
7
+ f.write("")
8
+ f.write("Starting Application!\n")
9
+
10
+ logging.basicConfig(
11
+ level=logging.INFO,
12
+ format="%(name)-12s: %(levelname)s - %(message)s",
13
+ filename="app.log",
14
+ filemode="a",
15
+ ) # Append mode
16
+ # Example: Adding a console handler to root logger (optional)
17
+ console_handler = logging.StreamHandler()
18
+ console_handler.setLevel(logging.INFO) # Or any other level
19
+ formatter = logging.Formatter("%(name)-12s: %(levelname)-8s %(message)s")
20
+ console_handler.setFormatter(formatter)
21
+ logging.getLogger("").addHandler(console_handler)
22
+
23
+ validate_all()
24
+
25
+ app = Flask(__name__)
26
+ app.register_blueprint(main)
27
+
28
+ intra_module_db["app"] = app
@@ -5,36 +5,8 @@ import webbrowser
5
5
  from threading import Timer
6
6
 
7
7
  from data_processing.file_paths import file_paths
8
- from data_sources.source_validation import validate_all
9
8
  from data_processing.graph_utils import get_graph
10
- from flask import Flask
11
-
12
- from .views import intra_module_db, main
13
-
14
- validate_all()
15
-
16
- with open("app.log", "w") as f:
17
- f.write("")
18
- f.write("Starting Application!\n")
19
-
20
-
21
- app = Flask(__name__)
22
- app.register_blueprint(main)
23
-
24
- intra_module_db["app"] = app
25
-
26
- logging.basicConfig(
27
- level=logging.INFO,
28
- format="%(name)-12s: %(levelname)s - %(message)s",
29
- filename="app.log",
30
- filemode="a",
31
- ) # Append mode
32
- # Example: Adding a console handler to root logger (optional)
33
- console_handler = logging.StreamHandler()
34
- console_handler.setLevel(logging.INFO) # Or any other level
35
- formatter = logging.Formatter("%(name)-12s: %(levelname)-8s %(message)s")
36
- console_handler.setFormatter(formatter)
37
- logging.getLogger("").addHandler(console_handler)
9
+ from map_app import app, console_handler
38
10
 
39
11
 
40
12
  def open_browser():
@@ -59,8 +31,7 @@ def set_logs_to_warning():
59
31
  console_handler.setLevel(logging.DEBUG)
60
32
 
61
33
 
62
- if __name__ == "__main__":
63
-
34
+ def main():
64
35
  # call this once to cache the graph
65
36
  Timer(1, get_graph).start()
66
37
 
@@ -74,3 +45,6 @@ if __name__ == "__main__":
74
45
  with open("app.log", "a") as f:
75
46
  f.write("Running in production mode\n")
76
47
  app.run(host="0.0.0.0", port="0")
48
+
49
+ if __name__ == "__main__":
50
+ main()
@@ -1,6 +1,7 @@
1
1
  import json
2
2
  import logging
3
3
  from datetime import datetime
4
+ from pathlib import Path
4
5
 
5
6
  from data_processing.create_realization import create_realization
6
7
  from data_processing.file_paths import file_paths
@@ -43,7 +44,7 @@ def subset_selection():
43
44
  subset_name = cat_ids[0]
44
45
  run_paths = file_paths(subset_name)
45
46
  subset(cat_ids, output_gpkg_path=run_paths.geopackage_path)
46
- return run_paths.geopackage_path, 200
47
+ return str(run_paths.geopackage_path), 200
47
48
 
48
49
 
49
50
  @main.route("/subset_to_file", methods=["POST"])
@@ -65,7 +66,9 @@ def subset_to_file():
65
66
  def get_forcings():
66
67
  # body: JSON.stringify({'forcing_dir': forcing_dir, 'start_time': start_time, 'end_time': end_time}),
67
68
  data = json.loads(request.data.decode("utf-8"))
68
- cat_id = data.get("forcing_dir").split("/")[-1]
69
+ subset_gpkg = Path(data.get("forcing_dir").split("subset to ")[-1])
70
+ output_folder = subset_gpkg.parent.parent.stem
71
+
69
72
  start_time = data.get("start_time")
70
73
  end_time = data.get("end_time")
71
74
  # get the forcings
@@ -77,7 +80,7 @@ def get_forcings():
77
80
  app.debug = False
78
81
  logger.info(f"get_forcings() disabled debug mode at {datetime.now()}")
79
82
  try:
80
- create_forcings(start_time, end_time, cat_id)
83
+ create_forcings(start_time, end_time, output_folder)
81
84
  except Exception as e:
82
85
  logger.info(f"get_forcings() failed with error: {str(e)}")
83
86
  return jsonify({"error": str(e)}), 500
@@ -90,13 +93,14 @@ def get_forcings():
90
93
  def get_realization():
91
94
  # body: JSON.stringify({'forcing_dir': forcing_dir, 'start_time': start_time, 'end_time': end_time}),
92
95
  data = json.loads(request.data.decode("utf-8"))
93
- cat_id = data.get("forcing_dir").split("/")[-1]
96
+ subset_gpkg = Path(data.get("forcing_dir").split("subset to ")[-1])
97
+ output_folder = subset_gpkg.parent.parent.stem
94
98
  start_time = data.get("start_time")
95
99
  end_time = data.get("end_time")
96
100
  # get the forcings
97
101
  start_time = datetime.strptime(start_time, "%Y-%m-%dT%H:%M")
98
102
  end_time = datetime.strptime(end_time, "%Y-%m-%dT%H:%M")
99
- create_realization(cat_id, start_time, end_time)
103
+ create_realization(output_folder, start_time, end_time)
100
104
  return "success", 200
101
105
 
102
106
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: ngiab_data_preprocess
3
- Version: 3.2.1
3
+ Version: 3.2.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
@@ -24,6 +24,7 @@ modules/data_sources/noah-owp-modular-init.namelist.input
24
24
  modules/data_sources/source_validation.py
25
25
  modules/data_sources/template.sql
26
26
  modules/data_sources/triggers.sql
27
+ modules/map_app/__init__.py
27
28
  modules/map_app/__main__.py
28
29
  modules/map_app/views.py
29
30
  modules/map_app/static/css/console.css
@@ -42,6 +43,7 @@ modules/ngiab_data_cli/custom_logging.py
42
43
  modules/ngiab_data_preprocess.egg-info/PKG-INFO
43
44
  modules/ngiab_data_preprocess.egg-info/SOURCES.txt
44
45
  modules/ngiab_data_preprocess.egg-info/dependency_links.txt
46
+ modules/ngiab_data_preprocess.egg-info/entry_points.txt
45
47
  modules/ngiab_data_preprocess.egg-info/requires.txt
46
48
  modules/ngiab_data_preprocess.egg-info/top_level.txt
47
49
  output/.gitkeep
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ cli = ngiab_data_cli.__main__:main
3
+ map_app = map_app.__main__:main
@@ -12,7 +12,7 @@ exclude = ["tests*"]
12
12
 
13
13
  [project]
14
14
  name = "ngiab_data_preprocess"
15
- version = "v3.2.1"
15
+ version = "v3.2.3"
16
16
  authors = [{ name = "Josh Cunningham", email = "jcunningham8@ua.edu" }]
17
17
  description = "Graphical Tools for creating Next Gen Water model input data."
18
18
  readme = "README.md"
@@ -54,6 +54,10 @@ plot = ["ngiab_eval[plot]"]
54
54
  Homepage = "https://github.com/CIROH-UA/NGIAB_data_preprocess"
55
55
  Issues = "https://github.com/CIROH-UA/NGIAB_data_preprocess/issues"
56
56
 
57
+ [project.scripts]
58
+ cli = "ngiab_data_cli.__main__:main"
59
+ map_app = "map_app.__main__:main"
60
+
57
61
  [build-system]
58
62
  # scm adds files tracked by git to the package
59
63
  requires = ["setuptools>=69.0", "setuptools-scm>=8.0"]