ras-commander 0.80.3__py3-none-any.whl → 0.81.0__py3-none-any.whl

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/RasPrj.py CHANGED
@@ -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
- self.prj_file = self.find_ras_prj(self.project_folder)
145
- if self.prj_file is None:
146
- logger.error(f"No HEC-RAS project file found in {self.project_folder}")
147
- raise ValueError(f"No HEC-RAS project file found in {self.project_folder}. Please check the path and try again.")
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. Identifies the appropriate HEC-RAS executable
1279
- 3. Loads project data (plans, geometries, flows)
1280
- 4. Creates dataframes containing project components
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): The path to the RAS project folder.
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 no HEC-RAS project file is found in the folder.
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 the global 'ras' object (most common)
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
- >>> # Create a new RasPrj instance
1304
- >>> my_project = init_ras_project("/path/to/project", "6.6", "new")
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 absolute path immediately to ensure consistent path handling
1308
- project_folder = Path(ras_project_folder).resolve()
1309
- if not project_folder.exists():
1310
- logger.error(f"The specified RAS project folder does not exist: {project_folder}")
1311
- raise FileNotFoundError(f"The specified RAS project folder does not exist: {project_folder}. Please check the path and try again.")
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
- ras_object.initialize(project_folder, ras_exe_path)
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
- ras.initialize(project_folder, ras_exe_path)
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
ras_commander/__init__.py CHANGED
@@ -10,7 +10,7 @@ try:
10
10
  __version__ = version("ras-commander")
11
11
  except PackageNotFoundError:
12
12
  # package is not installed
13
- __version__ = "0.80.3"
13
+ __version__ = "0.81.0"
14
14
 
15
15
  # Set up logging
16
16
  setup_logging()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ras-commander
3
- Version: 0.80.3
3
+ Version: 0.81.0
4
4
  Summary: A Python library for automating HEC-RAS 6.x operations
5
5
  Home-page: https://github.com/gpt-cmdr/ras-commander
6
6
  Author: William M. Katzenmeyer, P.E., C.F.M.
@@ -21,12 +21,12 @@ ras_commander/RasExamples.py,sha256=QFWnWnxACpQzewzA3QFMp4z4iEkg5PWf9cPDdMay7MA,
21
21
  ras_commander/RasGeo.py,sha256=Wy5N1yP7_St3cA3ENJliojQ2sb2w2dL8Fy8L_sZsykc,22208
22
22
  ras_commander/RasMap.py,sha256=20db61KkUz2CgjfCCYY8F-IYy5doHOtdnTKChiK0ENs,20257
23
23
  ras_commander/RasPlan.py,sha256=ogIpLqawXTsjLnKRZTqzZydn_EFVJZFZZGgHvJ_t_-c,65408
24
- ras_commander/RasPrj.py,sha256=g9J_ewWrT0K1OP4BdEauU6VWq67m_JUqFXEr1AVIy2k,63893
24
+ ras_commander/RasPrj.py,sha256=30y6kJ4jcfX7dE2BB5w7KHIHP1vUVlfB-YWM0xBNhbg,68031
25
25
  ras_commander/RasUnsteady.py,sha256=PdQQMiY7Mz1EsOQk6ygFQtlC2sFEa96Ntg-pznWVpLQ,37187
26
26
  ras_commander/RasUtils.py,sha256=0fm4IIs0LH1dgDj3pGd66mR82DhWLEkRKUvIo2M_5X0,35886
27
- ras_commander/__init__.py,sha256=v_fxJffY8lF74jv5gaihsKcLNE-b37dr5uJ6GvLx-Co,2039
28
- ras_commander-0.80.3.dist-info/licenses/LICENSE,sha256=_pbd6qHnlsz1iQ-ozDW_49r86BZT6CRwO2iBtw0iN6M,457
29
- ras_commander-0.80.3.dist-info/METADATA,sha256=kiXYlVO31V56GC9n0JmU-tjQucNV5yHnXyKqloi65bY,27941
30
- ras_commander-0.80.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
31
- ras_commander-0.80.3.dist-info/top_level.txt,sha256=i76S7eKLFC8doKcXDl3aiOr9RwT06G8adI6YuKbQDaA,14
32
- ras_commander-0.80.3.dist-info/RECORD,,
27
+ ras_commander/__init__.py,sha256=cceh-WJ7RMhQjPUH7ztMO5sWZDUx5jMsOEtrnOPMYMU,2039
28
+ ras_commander-0.81.0.dist-info/licenses/LICENSE,sha256=_pbd6qHnlsz1iQ-ozDW_49r86BZT6CRwO2iBtw0iN6M,457
29
+ ras_commander-0.81.0.dist-info/METADATA,sha256=pwshM3miZgeD-5tQAZaBLUb-HKzw5gaCM06OCFrkTgE,27941
30
+ ras_commander-0.81.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
31
+ ras_commander-0.81.0.dist-info/top_level.txt,sha256=i76S7eKLFC8doKcXDl3aiOr9RwT06G8adI6YuKbQDaA,14
32
+ ras_commander-0.81.0.dist-info/RECORD,,