|
1 | 1 | # REGI-Headless |
2 | 2 |
|
3 | 3 | > [!IMPORTANT] |
4 | | -> **Notice: Project Refactor in Progress** |
5 | | -> This project is undergoing a large refactor for CWMS Data API support. |
6 | | -> It will transition from a Java project consuming Jython scripts to a **Python project** that |
7 | | -> utilizes **JPype** to call underlying REGI Java libraries. |
| 4 | +> **Project Refactor in Progress** |
| 5 | +> This project has transitioned from a Java project consuming Jython scripts to a **Python bridge** that utilizes **JPype** to call underlying REGI Java libraries. |
8 | 6 |
|
9 | | -`REGI-Headless` is a Java-based command-line tool and library designed to run |
10 | | -**REGI** calculations in a headless environment. |
11 | | -It allows users to execute complex hydrological calculations and manage gate settings via Jython |
12 | | -scripts without the need for a graphical interface. |
| 7 | +`REGI-Headless` provides a Python-based interface for running **REGI** calculations in a headless environment. It allows users to execute complex hydrological calculations and manage gate settings via Python scripts, leveraging the performance and stability of the original REGI Java libraries. |
13 | 8 |
|
14 | 9 | ## Features |
15 | 10 |
|
16 | | -- **Headless Execution**: Run REGI calculations as part of automated workflows or on servers. |
17 | | -- **Database Integration**: Connects to CWMS data retrieval and storage. |
18 | | -- **Modular Calculations**: Includes support for: |
| 11 | +- **Headless Execution**: Run REGI calculations as part of automated workflows, CI/CD pipelines, or on servers. |
| 12 | +- **Python-First API**: Write calculation scripts in standard Python 3. |
| 13 | +- **Java Interoperability**: Direct access to REGI Java libraries via JPype. |
| 14 | +- **Modular Calculations**: Full support for: |
19 | 15 | - Inflow calculations (Clone, Compute, Auto-Adjust, Balance All, etc.) |
20 | | - - Flow Group and gate settings calculations. |
| 16 | + - Flow Group |
| 17 | + - Gate settings calculations. |
21 | 18 |
|
22 | 19 | ## Project Structure |
23 | 20 |
|
24 | | -- `regi-headless/`: Core Java implementation, including `RegiCLI`. |
25 | | -- `district-scripts/`: Example scripts and district-specific configurations. |
| 21 | +- `regi-headless/`: Core implementation. |
| 22 | + - `src/main/python/`: The `regi-python` package source. |
| 23 | + - `src/main/java/`: Java-based headless support and factories. |
| 24 | +- `district-scripts/`: Legacy Jython scripts and district-specific configurations. |
26 | 25 | - `docs/`: Additional documentation. |
27 | 26 |
|
28 | 27 | ## Getting Started |
29 | 28 |
|
30 | 29 | ### Prerequisites |
31 | 30 |
|
32 | | -- Java JDK 21 or higher. |
33 | | -- Access to a CWMS |
| 31 | +- **Java JDK 21** or higher. |
| 32 | +- **Python 3.11** or higher. |
| 33 | +- Access to a **CWMS Data API (CDA)** instance. |
34 | 34 |
|
35 | 35 | ### Building |
36 | 36 |
|
| 37 | +The project uses Gradle to manage both Java and Python builds. To build the Python wheel including all Java dependencies: |
37 | 38 |
|
38 | 39 | ```powershell |
39 | | -./gradlew build |
| 40 | +./gradlew buildPythonWheel |
40 | 41 | ``` |
41 | 42 |
|
42 | | -Details TBD. |
| 43 | +The resulting wheel file will be located in `regi-headless/build/install/regi-python/dist/`. |
43 | 44 |
|
44 | 45 | ## Usage |
45 | 46 |
|
46 | | -TBD |
| 47 | +### Installation |
47 | 48 |
|
48 | | -### Command Line Options |
| 49 | +Install the built wheel into your Python environment: |
49 | 50 |
|
50 | | -TBD |
| 51 | +```powershell |
| 52 | +pip install regi_python-*.whl |
| 53 | +``` |
| 54 | + |
| 55 | +### Script Example |
| 56 | + |
| 57 | +The Python bridge uses a context manager to handle the JVM lifecycle and a callback mechanism for calculations. |
| 58 | + |
| 59 | +```python |
| 60 | +from regi_python import regi_session, run_headless |
| 61 | +from java.util import Calendar, TimeZone |
| 62 | + |
| 63 | +def my_calculations(registry): |
| 64 | + # 'registry' is a RegiCalcRegistry instance |
| 65 | + gate_calc = registry.getCalculation(1.0, "Gate Flow") |
| 66 | + |
| 67 | + # Configure time window |
| 68 | + tz = TimeZone.getTimeZone("US/Central") |
| 69 | + start = Calendar.getInstance(tz) |
| 70 | + start.set(2025, 0, 1) # Jan 1, 2025 |
| 71 | + |
| 72 | + end = Calendar.getInstance(tz) |
| 73 | + end.set(2025, 0, 2) # Jan 2, 2025 |
| 74 | + |
| 75 | + # Execute calculation |
| 76 | + gate_calc.computeAll("OFFICE", "PROJECT", start.getTimeInMillis(), end.getTimeInMillis()) |
| 77 | + |
| 78 | +if __name__ == "__main__": |
| 79 | + with regi_session(): |
| 80 | + run_headless(my_calculations) |
| 81 | +``` |
51 | 82 |
|
52 | | -### Example |
| 83 | +### Environment Variables |
53 | 84 |
|
54 | | -TBD |
| 85 | +- `JAVA_HOME`: Path to your Java installation (required for JPype). |
| 86 | +- `REGI_LOG_LEVEL`: Logging level (e.g., `DEBUG`, `INFO`, `ERROR`). |
| 87 | +- `CDA_URL`: URL for the CWMS Data API. |
| 88 | +- `CDA_API_KEY`: API Key for CDA authentication. |
| 89 | +- `OFFICE_ID`: Office ID for CDA authentication. |
55 | 90 |
|
56 | 91 | ## Testing |
57 | 92 |
|
58 | | -TBD |
| 93 | +To run the automated tests which build the wheel and execute a test script in a virtual environment: |
| 94 | + |
| 95 | +```powershell |
| 96 | +./gradlew testPythonWheel |
| 97 | +``` |
59 | 98 |
|
60 | 99 | ## Maintainers |
61 | 100 |
|
|
0 commit comments