|
4 | 4 | import doctest |
5 | 5 | from pathlib import Path |
6 | 6 | from typing import Optional, List |
7 | | - |
8 | | -# --- Mock Function for Demonstration --- |
9 | | -# In your real environment, this import should find the actual |
10 | | -# adforce.mesh module. |
11 | | -try: |
12 | | - from adforce.mesh import swegnn_dg_from_mesh_ds_from_path |
13 | | - |
14 | | - print( |
15 | | - "Successfully imported 'swegnn_dg_from_mesh_ds_from_path' from 'adforce.mesh'." |
16 | | - ) |
17 | | -except ImportError: |
18 | | - print("Warning: Could not import 'adforce.mesh'.") |
19 | | - print("Using a MOCK function for demonstration purposes.") |
20 | | - |
21 | | - def swegnn_dg_from_mesh_ds_from_path(path=None, **kwargs): |
22 | | - """Mock function for demonstration.""" |
23 | | - print(f" (Mock) Calling swegnn_dg_from_mesh_ds_from_path(path='{path}')") |
24 | | - |
25 | | - # In a real run, this returns an xarray.Dataset. |
26 | | - # We return a mock object with a .to_netcdf() method. |
27 | | - class MockDataset: |
28 | | - def to_netcdf(self, output_path): |
29 | | - print(f" (Mock) Saving xarray.Dataset to {output_path}") |
30 | | - # Create a dummy file to show it worked |
31 | | - with open(output_path, "w") as f: |
32 | | - f.write(f"Mock SWE-GNN data from {path}") |
33 | | - |
34 | | - def close(self): |
35 | | - # Add a close method to mimic xarray.Dataset |
36 | | - pass |
37 | | - |
38 | | - # Check if the mock path exists, as the real function would |
39 | | - if path is None or not os.path.exists(path): |
40 | | - raise FileNotFoundError(f"Mock or real: Path not found at {path}") |
41 | | - |
42 | | - return MockDataset() |
43 | | - |
44 | | - |
45 | | -# --- Helper Function --- |
| 7 | +from adforce.mesh import swegnn_dg_from_mesh_ds_from_path |
46 | 8 |
|
47 | 9 |
|
48 | 10 | def find_best_run_from_json(json_path: str) -> Optional[str]: |
@@ -127,9 +89,6 @@ def find_best_run_from_json(json_path: str) -> Optional[str]: |
127 | 89 | return best_run_path |
128 | 90 |
|
129 | 91 |
|
130 | | -# --- Core Worker Function --- |
131 | | - |
132 | | - |
133 | 92 | def convert_best_bo_run_to_swegnn( |
134 | 93 | bayesopt_run_folder: str, output_nc_path: str |
135 | 94 | ) -> None: |
@@ -164,7 +123,9 @@ def convert_best_bo_run_to_swegnn( |
164 | 123 | swegnn_ds = None |
165 | 124 | try: |
166 | 125 | print(f" Converting {best_run_path} to SWE-GNN format...") |
167 | | - swegnn_ds = swegnn_dg_from_mesh_ds_from_path(path=best_run_path) |
| 126 | + swegnn_ds = swegnn_dg_from_mesh_ds_from_path( |
| 127 | + path=best_run_path, time_downsampling=7 |
| 128 | + ) |
168 | 129 |
|
169 | 130 | print(f" Saving to {output_nc_path}...") |
170 | 131 | swegnn_ds.to_netcdf(output_nc_path) |
|
0 commit comments