ras-commander 0.80.3__tar.gz → 0.81.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.
- {ras_commander-0.80.3/ras_commander.egg-info → ras_commander-0.81.0}/PKG-INFO +1 -1
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander/RasPrj.py +100 -28
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander/__init__.py +1 -1
- {ras_commander-0.80.3 → ras_commander-0.81.0/ras_commander.egg-info}/PKG-INFO +1 -1
- {ras_commander-0.80.3 → ras_commander-0.81.0}/setup.py +1 -1
- {ras_commander-0.80.3 → ras_commander-0.81.0}/LICENSE +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/README.md +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/pyproject.toml +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander/Decorators.py +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander/HdfBase.py +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander/HdfBndry.py +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander/HdfFluvialPluvial.py +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander/HdfInfiltration.py +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander/HdfMesh.py +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander/HdfPipe.py +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander/HdfPlan.py +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander/HdfPlot.py +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander/HdfPump.py +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander/HdfResultsMesh.py +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander/HdfResultsPlan.py +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander/HdfResultsPlot.py +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander/HdfResultsXsec.py +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander/HdfStruc.py +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander/HdfUtils.py +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander/HdfXsec.py +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander/LoggingConfig.py +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander/RasCmdr.py +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander/RasExamples.py +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander/RasGeo.py +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander/RasMap.py +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander/RasPlan.py +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander/RasUnsteady.py +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander/RasUtils.py +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander.egg-info/SOURCES.txt +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander.egg-info/dependency_links.txt +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander.egg-info/requires.txt +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/ras_commander.egg-info/top_level.txt +0 -0
- {ras_commander-0.80.3 → ras_commander-0.81.0}/setup.cfg +0 -0
|
@@ -116,7 +116,7 @@ class RasPrj:
|
|
|
116
116
|
self.suppress_logging = False # Add suppress_logging as instance variable
|
|
117
117
|
|
|
118
118
|
@log_call
|
|
119
|
-
def initialize(self, project_folder, ras_exe_path, suppress_logging=True):
|
|
119
|
+
def initialize(self, project_folder, ras_exe_path, suppress_logging=True, prj_file=None):
|
|
120
120
|
"""
|
|
121
121
|
Initialize a RasPrj instance with project folder and RAS executable path.
|
|
122
122
|
|
|
@@ -127,13 +127,16 @@ class RasPrj:
|
|
|
127
127
|
project_folder (str or Path): Path to the HEC-RAS project folder.
|
|
128
128
|
ras_exe_path (str or Path): Path to the HEC-RAS executable.
|
|
129
129
|
suppress_logging (bool, default=True): If True, suppresses initialization logging messages.
|
|
130
|
+
prj_file (str or Path, optional): If provided, use this specific .prj file instead of searching.
|
|
131
|
+
This is used when user specifies a .prj file directly.
|
|
130
132
|
|
|
131
133
|
Raises:
|
|
132
|
-
ValueError: If no HEC-RAS project file is found in the specified folder
|
|
134
|
+
ValueError: If no HEC-RAS project file is found in the specified folder,
|
|
135
|
+
or if the specified prj_file doesn't exist or is invalid.
|
|
133
136
|
|
|
134
137
|
Note:
|
|
135
138
|
This method sets up the RasPrj instance by:
|
|
136
|
-
1. Finding the project file (.prj)
|
|
139
|
+
1. Finding the project file (.prj) or using the provided prj_file
|
|
137
140
|
2. Loading project data (plans, geometries, flows)
|
|
138
141
|
3. Extracting boundary conditions
|
|
139
142
|
4. Setting the initialization flag
|
|
@@ -141,10 +144,21 @@ class RasPrj:
|
|
|
141
144
|
"""
|
|
142
145
|
self.suppress_logging = suppress_logging # Store suppress_logging state
|
|
143
146
|
self.project_folder = Path(project_folder)
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
147
|
+
|
|
148
|
+
# If user specified a .prj file directly, use it (Phase 2 optimization)
|
|
149
|
+
if prj_file is not None:
|
|
150
|
+
self.prj_file = Path(prj_file).resolve()
|
|
151
|
+
if not self.prj_file.exists():
|
|
152
|
+
logger.error(f"Specified .prj file does not exist: {self.prj_file}")
|
|
153
|
+
raise ValueError(f"Specified .prj file does not exist: {self.prj_file}. Please check the path and try again.")
|
|
154
|
+
logger.debug(f"Using specified .prj file: {self.prj_file}")
|
|
155
|
+
else:
|
|
156
|
+
# Search for .prj file (existing behavior)
|
|
157
|
+
self.prj_file = self.find_ras_prj(self.project_folder)
|
|
158
|
+
if self.prj_file is None:
|
|
159
|
+
logger.error(f"No HEC-RAS project file found in {self.project_folder}")
|
|
160
|
+
raise ValueError(f"No HEC-RAS project file found in {self.project_folder}. Please check the path and try again.")
|
|
161
|
+
|
|
148
162
|
self.project_name = Path(self.prj_file).stem
|
|
149
163
|
self.ras_exe_path = ras_exe_path
|
|
150
164
|
|
|
@@ -1274,13 +1288,18 @@ def init_ras_project(ras_project_folder, ras_version=None, ras_object=None):
|
|
|
1274
1288
|
Initialize a RAS project for use with the ras-commander library.
|
|
1275
1289
|
|
|
1276
1290
|
This is the primary function for setting up a HEC-RAS project. It:
|
|
1277
|
-
1. Finds the project file (.prj) in the specified folder
|
|
1278
|
-
2.
|
|
1279
|
-
3.
|
|
1280
|
-
4.
|
|
1291
|
+
1. Finds the project file (.prj) in the specified folder OR uses the provided .prj file
|
|
1292
|
+
2. Validates .prj files by checking for "Proj Title=" marker
|
|
1293
|
+
3. Identifies the appropriate HEC-RAS executable
|
|
1294
|
+
4. Loads project data (plans, geometries, flows)
|
|
1295
|
+
5. Creates dataframes containing project components
|
|
1281
1296
|
|
|
1282
1297
|
Args:
|
|
1283
|
-
ras_project_folder (str or Path):
|
|
1298
|
+
ras_project_folder (str or Path): Path to the RAS project folder OR direct path to a .prj file.
|
|
1299
|
+
If a .prj file is provided:
|
|
1300
|
+
- File is validated to have .prj extension
|
|
1301
|
+
- File content is checked for "Proj Title=" marker
|
|
1302
|
+
- Parent folder is used as the project folder
|
|
1284
1303
|
ras_version (str, optional): The version of RAS to use (e.g., "6.6") OR
|
|
1285
1304
|
a full path to the Ras.exe file (e.g., "D:/Programs/HEC/HEC-RAS/6.6/Ras.exe").
|
|
1286
1305
|
If None, will attempt to detect from plan files.
|
|
@@ -1290,25 +1309,71 @@ def init_ras_project(ras_project_folder, ras_version=None, ras_object=None):
|
|
|
1290
1309
|
|
|
1291
1310
|
Returns:
|
|
1292
1311
|
RasPrj: An initialized RasPrj instance.
|
|
1293
|
-
|
|
1312
|
+
|
|
1294
1313
|
Raises:
|
|
1295
|
-
FileNotFoundError: If the specified project folder doesn't exist.
|
|
1296
|
-
ValueError: If
|
|
1297
|
-
|
|
1314
|
+
FileNotFoundError: If the specified project folder or .prj file doesn't exist.
|
|
1315
|
+
ValueError: If the provided file is not a .prj file, does not contain "Proj Title=",
|
|
1316
|
+
or if no HEC-RAS project file is found in the folder.
|
|
1317
|
+
|
|
1298
1318
|
Example:
|
|
1299
|
-
>>> # Initialize using
|
|
1319
|
+
>>> # Initialize using project folder (existing behavior)
|
|
1300
1320
|
>>> init_ras_project("/path/to/project", "6.6")
|
|
1301
1321
|
>>> print(f"Initialized project: {ras.project_name}")
|
|
1302
1322
|
>>>
|
|
1303
|
-
>>> #
|
|
1304
|
-
>>>
|
|
1323
|
+
>>> # Initialize using direct .prj file path (new feature)
|
|
1324
|
+
>>> init_ras_project("/path/to/project/MyModel.prj", "6.6")
|
|
1325
|
+
>>> print(f"Initialized project: {ras.project_name}")
|
|
1326
|
+
>>>
|
|
1327
|
+
>>> # Create a new RasPrj instance with .prj file
|
|
1328
|
+
>>> my_project = init_ras_project("/path/to/project/MyModel.prj", "6.6", "new")
|
|
1305
1329
|
>>> print(f"Created project instance: {my_project.project_name}")
|
|
1306
1330
|
"""
|
|
1307
|
-
# Convert to
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1331
|
+
# Convert to Path object for consistent handling
|
|
1332
|
+
input_path = Path(ras_project_folder).resolve()
|
|
1333
|
+
|
|
1334
|
+
# Detect if input is a file or folder
|
|
1335
|
+
if input_path.is_file():
|
|
1336
|
+
# User provided a .prj file path
|
|
1337
|
+
if input_path.suffix.lower() != '.prj':
|
|
1338
|
+
error_msg = f"The provided file is not a HEC-RAS project file (.prj): {input_path}"
|
|
1339
|
+
logger.error(error_msg)
|
|
1340
|
+
raise ValueError(f"{error_msg}. Please provide either a project folder or a .prj file.")
|
|
1341
|
+
|
|
1342
|
+
# Enhanced validation: Check if file contains "Proj Title=" to verify it's a HEC-RAS project file
|
|
1343
|
+
try:
|
|
1344
|
+
content, encoding = read_file_with_fallback_encoding(input_path)
|
|
1345
|
+
if content is None or "Proj Title=" not in content:
|
|
1346
|
+
error_msg = f"The file does not appear to be a valid HEC-RAS project file (missing 'Proj Title='): {input_path}"
|
|
1347
|
+
logger.error(error_msg)
|
|
1348
|
+
raise ValueError(f"{error_msg}. Please provide a valid HEC-RAS .prj file.")
|
|
1349
|
+
logger.debug(f"Validated .prj file contains 'Proj Title=' marker")
|
|
1350
|
+
except Exception as e:
|
|
1351
|
+
error_msg = f"Error validating .prj file: {e}"
|
|
1352
|
+
logger.error(error_msg)
|
|
1353
|
+
raise ValueError(f"{error_msg}. Please ensure the file is a valid HEC-RAS project file.")
|
|
1354
|
+
|
|
1355
|
+
# Extract the parent folder to use as project_folder
|
|
1356
|
+
project_folder = input_path.parent
|
|
1357
|
+
specified_prj_file = input_path # Store for optimization
|
|
1358
|
+
logger.debug(f"User provided .prj file: {input_path}")
|
|
1359
|
+
logger.debug(f"Using parent folder as project_folder: {project_folder}")
|
|
1360
|
+
|
|
1361
|
+
elif input_path.is_dir():
|
|
1362
|
+
# User provided a folder path (existing behavior)
|
|
1363
|
+
project_folder = input_path
|
|
1364
|
+
specified_prj_file = None
|
|
1365
|
+
logger.debug(f"User provided folder path: {project_folder}")
|
|
1366
|
+
|
|
1367
|
+
else:
|
|
1368
|
+
# Path doesn't exist
|
|
1369
|
+
if input_path.suffix.lower() == '.prj':
|
|
1370
|
+
error_msg = f"The specified .prj file does not exist: {input_path}"
|
|
1371
|
+
logger.error(error_msg)
|
|
1372
|
+
raise FileNotFoundError(f"{error_msg}. Please check the path and try again.")
|
|
1373
|
+
else:
|
|
1374
|
+
error_msg = f"The specified RAS project folder does not exist: {input_path}"
|
|
1375
|
+
logger.error(error_msg)
|
|
1376
|
+
raise FileNotFoundError(f"{error_msg}. Please check the path and try again.")
|
|
1312
1377
|
|
|
1313
1378
|
# Determine which RasPrj instance to use
|
|
1314
1379
|
if ras_object is None:
|
|
@@ -1381,13 +1446,20 @@ def init_ras_project(ras_project_folder, ras_version=None, ras_object=None):
|
|
|
1381
1446
|
logger.warning("No valid HEC-RAS version was detected. Running HEC-RAS will fail.")
|
|
1382
1447
|
|
|
1383
1448
|
# Initialize or re-initialize with the determined executable path
|
|
1384
|
-
|
|
1385
|
-
|
|
1449
|
+
# Pass specified_prj_file to avoid re-searching when user provided .prj file directly
|
|
1450
|
+
if specified_prj_file is not None:
|
|
1451
|
+
ras_object.initialize(project_folder, ras_exe_path, prj_file=specified_prj_file)
|
|
1452
|
+
else:
|
|
1453
|
+
ras_object.initialize(project_folder, ras_exe_path)
|
|
1454
|
+
|
|
1386
1455
|
# Always update the global ras object as well
|
|
1387
1456
|
if ras_object is not ras:
|
|
1388
|
-
|
|
1457
|
+
if specified_prj_file is not None:
|
|
1458
|
+
ras.initialize(project_folder, ras_exe_path, prj_file=specified_prj_file)
|
|
1459
|
+
else:
|
|
1460
|
+
ras.initialize(project_folder, ras_exe_path)
|
|
1389
1461
|
logger.debug("Global 'ras' object also updated to match the new project.")
|
|
1390
|
-
|
|
1462
|
+
|
|
1391
1463
|
logger.debug(f"Project initialized. Project folder: {ras_object.project_folder}")
|
|
1392
1464
|
logger.debug(f"Using HEC-RAS executable: {ras_exe_path}")
|
|
1393
1465
|
return ras_object
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|