ras-commander 0.1.6__tar.gz → 0.21.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 (64) hide show
  1. ras_commander-0.21.0/.cursorrules.txt +118 -0
  2. ras_commander-0.21.0/.gitignore/.gitignore +8 -0
  3. ras_commander-0.21.0/Comprehensive_Library_Guide.md +278 -0
  4. ras_commander-0.21.0/PKG-INFO +342 -0
  5. ras_commander-0.21.0/README.md +329 -0
  6. ras_commander-0.21.0/STYLE_GUIDE.md +184 -0
  7. ras_commander-0.21.0/dist/ras_commander-0.21.0-py2.py3-none-any.whl +0 -0
  8. ras_commander-0.21.0/dist/ras_commander-0.21.0.tar.gz +0 -0
  9. ras_commander-0.21.0/examples/01_project_initialization.py +138 -0
  10. ras_commander-0.21.0/examples/02_plan_operations.py +140 -0
  11. ras_commander-0.21.0/examples/03_geometry_operations.py +100 -0
  12. ras_commander-0.21.0/examples/04_unsteady_flow_operations.py +103 -0
  13. ras_commander-0.21.0/examples/05_utility_functions.py +74 -0
  14. ras_commander-0.21.0/examples/06_single_plan_execution.py +80 -0
  15. ras_commander-0.21.0/examples/07_sequential_plan_execution.py +105 -0
  16. ras_commander-0.21.0/examples/08_parallel_execution.py +97 -0
  17. ras_commander-0.21.0/examples/09_specifying_plans.py +108 -0
  18. ras_commander-0.21.0/examples/10_arguments_for_compute.py +102 -0
  19. ras_commander-0.21.0/examples/11_Using_RasExamples.ipynb +456 -0
  20. ras_commander-0.21.0/examples/12_plan_set_execution.py +95 -0
  21. ras_commander-0.21.0/examples/13_multiple_project_operations.py +135 -0
  22. ras_commander-0.21.0/examples/example_projects.csv +67 -0
  23. ras_commander-0.21.0/examples/example_projects.ipynb +1345 -0
  24. {ras_commander-0.1.6 → ras_commander-0.21.0}/pyproject.toml +3 -0
  25. ras_commander-0.21.0/ras_commander/README.md +187 -0
  26. ras_commander-0.21.0/ras_commander/RasCommander.py +456 -0
  27. ras_commander-0.21.0/ras_commander/RasExamples.py +304 -0
  28. ras_commander-0.21.0/ras_commander/RasGeo.py +83 -0
  29. ras_commander-0.21.0/ras_commander/RasPlan.py +1216 -0
  30. ras_commander-0.21.0/ras_commander/RasPrj.py +400 -0
  31. ras_commander-0.21.0/ras_commander/RasUnsteady.py +53 -0
  32. ras_commander-0.21.0/ras_commander/RasUtils.py +283 -0
  33. ras_commander-0.21.0/ras_commander/__init__.py +40 -0
  34. ras_commander-0.21.0/ras_commander.egg-info/PKG-INFO +342 -0
  35. ras_commander-0.21.0/ras_commander.egg-info/SOURCES.txt +41 -0
  36. ras_commander-0.21.0/requirements.txt +32 -0
  37. ras_commander-0.21.0/setup.py +7 -0
  38. ras_commander-0.1.6/PKG-INFO +0 -133
  39. ras_commander-0.1.6/README.md +0 -120
  40. ras_commander-0.1.6/dss_commander/README.md +0 -7
  41. ras_commander-0.1.6/hdf_commander/README.md +0 -3
  42. ras_commander-0.1.6/ras-commander library examples.ipynb +0 -830
  43. ras_commander-0.1.6/ras_commander/__init__.py +0 -7
  44. ras_commander-0.1.6/ras_commander/_version.py +0 -16
  45. ras_commander-0.1.6/ras_commander/execution.py +0 -315
  46. ras_commander-0.1.6/ras_commander/file_operations.py +0 -173
  47. ras_commander-0.1.6/ras_commander/geometry_operations.py +0 -184
  48. ras_commander-0.1.6/ras_commander/plan_operations.py +0 -307
  49. ras_commander-0.1.6/ras_commander/project_config.py +0 -64
  50. ras_commander-0.1.6/ras_commander/project_init.py +0 -174
  51. ras_commander-0.1.6/ras_commander/project_management.py +0 -227
  52. ras_commander-0.1.6/ras_commander/project_setup.py +0 -15
  53. ras_commander-0.1.6/ras_commander/unsteady_operations.py +0 -172
  54. ras_commander-0.1.6/ras_commander/utilities.py +0 -195
  55. ras_commander-0.1.6/ras_commander workspace.code-workspace +0 -8
  56. ras_commander-0.1.6/ras_commander.egg-info/PKG-INFO +0 -133
  57. ras_commander-0.1.6/ras_commander.egg-info/SOURCES.txt +0 -27
  58. ras_commander-0.1.6/setup.py +0 -3
  59. ras_commander-0.1.6/tests/unit tests.txt +0 -0
  60. {ras_commander-0.1.6 → ras_commander-0.21.0}/.github/workflows/publish-to-pypi.yml +0 -0
  61. {ras_commander-0.1.6 → ras_commander-0.21.0}/LICENSE +0 -0
  62. {ras_commander-0.1.6 → ras_commander-0.21.0}/ras_commander.egg-info/dependency_links.txt +0 -0
  63. {ras_commander-0.1.6 → ras_commander-0.21.0}/ras_commander.egg-info/top_level.txt +0 -0
  64. {ras_commander-0.1.6 → ras_commander-0.21.0}/setup.cfg +0 -0
@@ -0,0 +1,118 @@
1
+ # RAS Commander (ras_commander) Coding Assistant
2
+
3
+ ## Overview
4
+
5
+ This Coding Assistant helps you write efficient and well-structured Python code for working with HEC-RAS projects using the ras_commander library.
6
+
7
+ **Key Features:**
8
+
9
+ * **Automates HEC-RAS tasks:** Streamlines project setup, plan execution, data management, and more.
10
+ * **Pythonic interface:** Leverages familiar Python libraries like Pandas and pathlib for intuitive coding.
11
+ * **Flexible execution:** Supports single plan, sequential, and parallel execution modes.
12
+ * **Built-in examples:** Provides access to HEC-RAS example projects for learning and testing.
13
+
14
+ **Core Concepts:**
15
+
16
+ * **RAS Objects:** Represent HEC-RAS projects and their components (plans, geometry, flow files).
17
+ * **Project Initialization:** Use `init_ras_project()` to set up a project.
18
+ * **File Handling:** pathlib.Path ensures consistent file path management.
19
+ * **Data Management:** Pandas DataFrames organize project data.
20
+ * **Execution Modes:** Choose from single, sequential, or parallel execution.
21
+
22
+
23
+ ## Classes, Functions and Arguments for ras_commander
24
+
25
+ The ras_commander library provides several classes to interact with HEC-RAS projects:
26
+
27
+ Class/Function Required Arguments Optional Arguments
28
+ RasPrj
29
+ init_ras_project ras_project_folder, ras_version ras_instance
30
+ get_ras_exe ras_version -
31
+ initialize project_folder, ras_exe_path -
32
+ _load_project_data - -
33
+ _get_prj_entries entry_type -
34
+ is_initialized - -
35
+ check_initialized - -
36
+ find_ras_prj folder_path -
37
+ get_project_name - -
38
+ get_prj_entries entry_type -
39
+ get_plan_entries - -
40
+ get_flow_entries - -
41
+ get_unsteady_entries - -
42
+ get_geom_entries - -
43
+ get_hdf_entries - -
44
+ print_data - -
45
+ RasCommander
46
+ compute_plan plan_number compute_folder, ras_object
47
+ compute_test_mode - plan_numbers, folder_suffix, clear_geompre, max_cores, ras_object
48
+ compute_parallel - plan_numbers, max_workers, cores_per_run, ras_object, dest_folder
49
+ worker_thread worker_id -
50
+ RasPlan
51
+ set_geom new_geom ras_object
52
+ set_steady plan_number, new_steady_flow_number ras_object
53
+ set_unsteady plan_number, new_unsteady_flow_number ras_object
54
+ set_num_cores plan_number, num_cores ras_object
55
+ set_geom_preprocessor file_path, run_htab, use_ib_tables ras_object
56
+ get_results_path plan_number ras_object
57
+ get_plan_path plan_number ras_object
58
+ get_flow_path flow_number ras_object
59
+ get_unsteady_path unsteady_number ras_object
60
+ get_geom_path geom_number ras_object
61
+ clone_plan template_plan new_plan_shortid, ras_object
62
+ clone_unsteady template_unsteady ras_object
63
+ clone_steady template_flow ras_object
64
+ clone_geom template_geom ras_object
65
+ get_next_number existing_numbers -
66
+ RasGeo
67
+ clear_geompre_files - plan_files, ras_object
68
+ RasUnsteady
69
+ update_unsteady_parameters unsteady_file, modifications ras_object
70
+ RasUtils
71
+ get_plan_path current_plan_number ras_object
72
+ update_plan_file plan_number, file_type, entry_number ras_object
73
+ RasExamples
74
+ init - -
75
+ get_example_projects version_number -
76
+ list_categories - -
77
+ list_projects category -
78
+ extract_project project_names -
79
+ clean_projects_directory - -
80
+
81
+ **(Search your ras_commander.txt with your retrieval tool to get more information about functions and arguments)**
82
+
83
+
84
+ ## Coding Assistance Rules:
85
+
86
+ Your role is building, refactoring and debugging Python notebooks using Python 3.11, Anaconda, and Jupyter Notebooks in Visual Studio Code.
87
+
88
+ Avoid default names like 'df' for data frames. You have been provided a Style Guide for ras_commander that you use to reason and determine new variable names.
89
+
90
+ You prefer to use default libraries where possible
91
+ You prefer r strings for file and directory path inputs
92
+ You prefer f strings for string concatenation
93
+ You prefer pathlib over os for manipulation of file and directory paths
94
+ You always print () every data frame’s name and variable name before displaying the dataframe with print()
95
+ You prefer geopandas and/or shapely/fiona for geospatial operations
96
+ You prefer matplotlib and bokeh
97
+ You always leave comments in the code for readability
98
+ You leave print statements after major operations to inform the user of progress
99
+ You never elide existing comments or docstrings when making revisions
100
+ You always follow PEP 8 conventions wherever feasible
101
+ You always revise comments and docstrings as needed to keep them accurate
102
+ When correcting errors, leave clear instructions to future developers to prevent the same error
103
+
104
+ Before revising complex code, you write planning steps as comments before writing code, labeling as:
105
+ ## Explicit Planning and Reasoning for Revisions
106
+
107
+ for geodataframes:
108
+ 'unary_union' attribute is deprecated, use the 'union_all()' method instead.
109
+
110
+ Note:
111
+ pandas >= 2.0: append has been removed, use pd.concat
112
+ Example:
113
+ accumulator = []
114
+ forargs inarg_list:
115
+ accumulator.append(dataFrameFromDirectory(*args))
116
+ big_df = pd.concat(accumulator)
117
+
118
+ When revising code, you always provide full code segments with no elides.
@@ -0,0 +1,8 @@
1
+ # Ignore the example_projects folder and all its subfolders
2
+ example_projects/
3
+
4
+ # Ignore the Example_Projects_6_5.zip file
5
+ Example_Projects_6_5.zip
6
+
7
+ # Ignore the misc folder and all its subfolders
8
+ misc/
@@ -0,0 +1,278 @@
1
+ # Comprehensive RAS-Commander Library Guide
2
+
3
+ ## Introduction
4
+
5
+ RAS-Commander is a Python library designed to automate and streamline operations with HEC-RAS projects. This guide provides a comprehensive overview of the library's key concepts, best practices, and usage patterns.
6
+
7
+ ## Key Concepts for ras_commander
8
+
9
+ 1. **RAS Objects**:
10
+ - RAS objects represent HEC-RAS projects and contain information about plans, geometries, and flow files.
11
+ - The library supports both a global 'ras' object and custom RAS objects for different projects.
12
+
13
+ 2. **Project Initialization**:
14
+ - Use the `init_ras_project()` function to initialize a project and set up the RAS object.
15
+ - This function handles finding the project file and setting up necessary data structures.
16
+
17
+ 3. **File Handling**:
18
+ - The library uses `pathlib.Path` for consistent and platform-independent file path handling.
19
+ - File naming conventions follow HEC-RAS standards (e.g., .prj, .p01, .g01, .f01, .u01).
20
+
21
+ 4. **Data Management**:
22
+ - Pandas DataFrames are used to manage structured data about plans, geometries, and flow files.
23
+ - The library provides methods to access and update these DataFrames.
24
+
25
+ 5. **Execution Modes**:
26
+ - Single plan execution: Run individual plans.
27
+ - Sequential execution: Run multiple plans in sequence.
28
+ - Parallel execution: Run multiple plans concurrently for improved performance.
29
+
30
+ 6. **Example Projects**:
31
+ - The RasExamples class provides functionality to download and manage HEC-RAS example projects for testing and learning purposes.
32
+
33
+ ## Module Overview
34
+
35
+ 1. **RasPrj**: Manages HEC-RAS project initialization and data.
36
+ 2. **RasCommander**: Handles execution of HEC-RAS simulations.
37
+ 3. **RasPlan**: Provides functions for plan file operations.
38
+ 4. **RasGeo**: Manages geometry file operations.
39
+ 5. **RasUnsteady**: Handles unsteady flow file operations.
40
+ 6. **RasUtils**: Offers utility functions for common tasks.
41
+ 7. **RasExamples**: Manages example HEC-RAS projects.
42
+
43
+
44
+ ## Best Practices
45
+
46
+ 1. **RAS Object Usage**:
47
+ - For simple scripts working with a single project, use the global 'ras' object:
48
+ ```python
49
+ from ras_commander import ras, init_ras_project
50
+ init_ras_project("/path/to/project", "6.5")
51
+ # Use ras object for operations
52
+ ```
53
+ - For complex scripts or when working with multiple projects, create and use separate RAS objects:
54
+ ```python
55
+ from ras_commander import RasPrj, init_ras_project
56
+ project1 = init_ras_project("/path/to/project1", "6.5")
57
+ project2 = init_ras_project("/path/to/project2", "6.5")
58
+ ```
59
+ - Be consistent: don't mix global and custom RAS object usage in the same script.
60
+
61
+ 2. **Plan Specification**:
62
+ - Use plan numbers as strings (e.g., "01", "02") for consistency:
63
+ ```python
64
+ RasCommander.compute_plan("01")
65
+ ```
66
+ - Always check available plans before specifying plan numbers:
67
+ ```python
68
+ print(ras.plan_df) # Display available plans
69
+ ```
70
+
71
+ 3. **Geometry Preprocessor Files**:
72
+ - Clear geometry preprocessor files before significant changes:
73
+ ```python
74
+ RasGeo.clear_geompre_files()
75
+ ```
76
+ - Use `clear_geompre=True` for clean computation environment:
77
+ ```python
78
+ RasCommander.compute_plan("01", clear_geompre=True)
79
+ ```
80
+
81
+ 4. **Parallel Execution**:
82
+ - Consider available cores when setting `max_workers`:
83
+ ```python
84
+ RasCommander.compute_parallel(max_workers=4, cores_per_run=2)
85
+ ```
86
+ - Use `dest_folder` to keep project folder organized:
87
+ ```python
88
+ RasCommander.compute_parallel(dest_folder="/path/to/results")
89
+ ```
90
+
91
+ 5. **Error Handling**:
92
+ - Use try-except blocks to handle potential errors:
93
+ ```python
94
+ try:
95
+ RasCommander.compute_plan("01")
96
+ except FileNotFoundError:
97
+ print("Plan file not found")
98
+ ```
99
+ - Utilize logging for informative output:
100
+ ```python
101
+ import logging
102
+ logging.basicConfig(level=logging.INFO)
103
+ ```
104
+
105
+ 6. **File Path Handling**:
106
+ - Use pathlib.Path for file and directory operations:
107
+ ```python
108
+ from pathlib import Path
109
+ project_path = Path("/path/to/project")
110
+ ```
111
+
112
+ 7. **Type Hinting**:
113
+ - Use type hints to improve code readability and IDE support:
114
+ ```python
115
+ def compute_plan(plan_number: str, clear_geompre: bool = False) -> bool:
116
+ ...
117
+ ```
118
+
119
+ ## Common Usage Patterns
120
+
121
+ 1. **Initializing a Project**:
122
+ ```python
123
+ from ras_commander import init_ras_project, ras
124
+ init_ras_project("/path/to/project", "6.5")
125
+ print(f"Working with project: {ras.project_name}")
126
+ ```
127
+
128
+ 2. **Cloning a Plan**:
129
+ ```python
130
+ from ras_commander import RasPlan
131
+ new_plan_number = RasPlan.clone_plan("01")
132
+ print(f"Created new plan: {new_plan_number}")
133
+ ```
134
+
135
+ 3. **Updating Unsteady Flow Parameters**:
136
+ ```python
137
+ from ras_commander import RasUnsteady, RasPlan
138
+ plan_path = RasPlan.get_plan_path("01")
139
+ RasUnsteady.update_unsteady_parameters(plan_path, {"Computation Interval": "1MIN"})
140
+ ```
141
+
142
+ 4. **Executing a Single Plan**:
143
+ ```python
144
+ from ras_commander import RasCommander
145
+ success = RasCommander.compute_plan("01")
146
+ print(f"Plan execution {'successful' if success else 'failed'}")
147
+ ```
148
+
149
+ 5. **Parallel Execution of Multiple Plans**:
150
+ ```python
151
+ from ras_commander import RasCommander
152
+ results = RasCommander.compute_parallel(plan_numbers=["01", "02"], max_workers=2, cores_per_run=2)
153
+ for plan, success in results.items():
154
+ print(f"Plan {plan}: {'Successful' if success else 'Failed'}")
155
+ ```
156
+
157
+ 6. **Working with Example Projects**:
158
+ ```python
159
+ from ras_commander import RasExamples
160
+ ras_examples = RasExamples()
161
+ project_paths = ras_examples.extract_project(["Balde Eagle Creek", "Muncie"])
162
+ for path in project_paths:
163
+ print(f"Extracted project to: {path}")
164
+ ```
165
+
166
+ ```markdown
167
+ ## Advanced Usage
168
+
169
+ 1. **Working with Multiple Projects**:
170
+ ```python
171
+ from ras_commander import init_ras_project, RasCommander, RasPlan
172
+
173
+ project1 = init_ras_project("/path/to/project1", "6.5")
174
+ project2 = init_ras_project("/path/to/project2", "6.5")
175
+
176
+ # Clone plans in both projects
177
+ new_plan1 = RasPlan.clone_plan("01", ras_object=project1)
178
+ new_plan2 = RasPlan.clone_plan("01", ras_object=project2)
179
+
180
+ # Execute plans in both projects
181
+ RasCommander.compute_plan(new_plan1, ras_object=project1)
182
+ RasCommander.compute_plan(new_plan2, ras_object=project2)
183
+ ```
184
+
185
+ 2. **Using ThreadPoolExecutor for Simultaneous Execution**:
186
+ ```python
187
+ from concurrent.futures import ThreadPoolExecutor
188
+ from ras_commander import RasCommander
189
+
190
+ def execute_plan(plan, project, compute_folder):
191
+ return RasCommander.compute_plan(plan, ras_object=project, compute_folder=compute_folder)
192
+
193
+ with ThreadPoolExecutor(max_workers=2) as executor:
194
+ futures = [
195
+ executor.submit(execute_plan, "01", project1, "compute_folder1"),
196
+ executor.submit(execute_plan, "01", project2, "compute_folder2")
197
+ ]
198
+ for future in futures:
199
+ print(f"Plan execution result: {future.result()}")
200
+ ```
201
+
202
+ 3. **Creating and Using Plan Sets**:
203
+ ```python
204
+ import pandas as pd
205
+ from ras_commander import RasPlan, RasCommander
206
+
207
+ def create_plan_set(base_plan, num_copies):
208
+ plan_set = []
209
+ for _ in range(num_copies):
210
+ new_plan = RasPlan.clone_plan(base_plan)
211
+ plan_set.append({'plan_number': new_plan})
212
+ return pd.DataFrame(plan_set)
213
+
214
+ plan_set = create_plan_set("01", 5)
215
+ results = RasCommander.compute_parallel(plan_numbers=plan_set['plan_number'].tolist())
216
+ ```
217
+
218
+ 4. **Custom Error Handling and Logging**:
219
+ ```python
220
+ import logging
221
+ from ras_commander import RasCommander
222
+
223
+ logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
224
+ logger = logging.getLogger(__name__)
225
+
226
+ try:
227
+ RasCommander.compute_plan("01")
228
+ except FileNotFoundError as e:
229
+ logger.error(f"Plan file not found: {e}")
230
+ except Exception as e:
231
+ logger.exception(f"An unexpected error occurred: {e}")
232
+ ```
233
+
234
+ 5. **Advanced DataFrame Operations for Result Analysis**:
235
+ ```python
236
+ import pandas as pd
237
+ from ras_commander import ras
238
+
239
+ # Assuming we have executed multiple plans and have results
240
+ results_df = ras.get_hdf_entries()
241
+
242
+ # Filter and analyze results
243
+ successful_runs = results_df[results_df['HDF_Results_Path'].notna()]
244
+ print(f"Number of successful runs: {len(successful_runs)}")
245
+
246
+ # You could add more advanced analysis here, such as comparing results across different plans
247
+ ```
248
+
249
+ ## Troubleshooting
250
+
251
+ 1. **Project Initialization Issues**:
252
+ - Ensure the project path is correct and the .prj file exists.
253
+ - Verify that the specified HEC-RAS version is installed on your system.
254
+
255
+ 2. **Execution Failures**:
256
+ - Check that the plan, geometry, and flow files referenced in the plan exist.
257
+ - Ensure the HEC-RAS executable path is correct.
258
+ - Review HEC-RAS log files for specific error messages.
259
+
260
+ 3. **Parallel Execution Problems**:
261
+ - Reduce the number of `max_workers` if you're experiencing memory issues.
262
+ - Ensure each worker has sufficient resources (cores, memory) to run a plan.
263
+
264
+ 4. **File Access Errors**:
265
+ - Verify that you have read/write permissions for the project directory.
266
+ - Close any open HEC-RAS instances that might be locking files.
267
+
268
+ 5. **Inconsistent Results**:
269
+ - Always clear geometry preprocessor files (`clear_geompre=True`) when making geometry changes.
270
+ - Ensure that plan parameters are correctly set before execution.
271
+
272
+ ## Conclusion
273
+
274
+ The RAS-Commander library provides a powerful set of tools for automating HEC-RAS operations. By following the best practices outlined in this guide and leveraging the library's features, you can efficiently manage and execute complex HEC-RAS projects programmatically.
275
+
276
+ Remember to always refer to the latest documentation and the library's source code for the most up-to-date information. As you become more familiar with RAS-Commander, you'll discover more ways to optimize your HEC-RAS workflows and increase your productivity.
277
+
278
+ For further assistance, bug reports, or feature requests, please refer to the library's GitHub repository and issue tracker. Happy modeling!