ras-commander 0.73.0__py3-none-any.whl → 0.74.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.
@@ -110,13 +110,17 @@ def standardize_input(file_type: str = 'plan_hdf'):
110
110
  except Exception as e:
111
111
  raise ValueError(f"RAS object is not initialized: {str(e)}")
112
112
 
113
+ # Extract the number part and strip leading zeros
113
114
  number_str = hdf_input if hdf_input.isdigit() else hdf_input[1:]
114
- number_int = int(number_str)
115
+ stripped_number = number_str.lstrip('0')
116
+ if stripped_number == '': # Handle case where input was '0' or '00'
117
+ stripped_number = '0'
118
+ number_int = int(stripped_number)
115
119
 
116
120
  if file_type == 'plan_hdf':
117
121
  try:
118
- # Convert plan_number column to integers for comparison
119
- plan_info = ras_obj.plan_df[ras_obj.plan_df['plan_number'].astype(int) == number_int]
122
+ # Convert plan_number column to integers for comparison after stripping zeros
123
+ plan_info = ras_obj.plan_df[ras_obj.plan_df['plan_number'].str.lstrip('0').astype(int) == number_int]
120
124
  if not plan_info.empty:
121
125
  # Make sure HDF_Results_Path is a string and not None
122
126
  hdf_path_str = plan_info.iloc[0]['HDF_Results_Path']
@@ -128,12 +132,35 @@ def standardize_input(file_type: str = 'plan_hdf'):
128
132
 
129
133
  elif file_type == 'geom_hdf':
130
134
  try:
131
- # Convert geometry_number column to integers for comparison
132
- geom_info = ras_obj.plan_df[ras_obj.plan_df['geometry_number'].astype(int) == number_int]
133
- if not geom_info.empty:
134
- hdf_path_str = ras_obj.geom_df.iloc[0]['hdf_path']
135
- if pd.notna(hdf_path_str):
136
- hdf_path = Path(str(hdf_path_str))
135
+ # First try to get the geometry number from the plan
136
+ from ras_commander import RasPlan
137
+ plan_info = ras_obj.plan_df[ras_obj.plan_df['plan_number'].astype(int) == number_int]
138
+ if not plan_info.empty:
139
+ # Extract the geometry number from the plan
140
+ geom_number = plan_info.iloc[0]['geometry_number']
141
+ if pd.notna(geom_number) and geom_number is not None:
142
+ # Handle different types of geom_number (string or int)
143
+ try:
144
+ # Get the geometry path using RasPlan
145
+ geom_path = RasPlan.get_geom_path(str(geom_number), ras_obj)
146
+
147
+ if geom_path is not None:
148
+ # Create the HDF path by adding .hdf to the geometry path
149
+ hdf_path = Path(str(geom_path) + ".hdf")
150
+ if hdf_path.exists():
151
+ logger.info(f"Found geometry HDF file for plan {number_int}: {hdf_path}")
152
+ else:
153
+ # Try to find it in the geom_df if direct path doesn't exist
154
+ geom_info = ras_obj.geom_df[ras_obj.geom_df['full_path'] == str(geom_path)]
155
+ if not geom_info.empty and 'hdf_path' in geom_info.columns:
156
+ hdf_path_str = geom_info.iloc[0]['hdf_path']
157
+ if pd.notna(hdf_path_str):
158
+ hdf_path = Path(str(hdf_path_str))
159
+ logger.info(f"Found geometry HDF file from geom_df for plan {number_int}: {hdf_path}")
160
+ except (TypeError, ValueError) as e:
161
+ logger.warning(f"Error processing geometry number {geom_number}: {str(e)}")
162
+ else:
163
+ logger.warning(f"No valid geometry number found for plan {number_int}")
137
164
  except Exception as e:
138
165
  logger.warning(f"Error retrieving geometry HDF path: {str(e)}")
139
166
  else:
@@ -153,8 +180,8 @@ def standardize_input(file_type: str = 'plan_hdf'):
153
180
 
154
181
  if file_type == 'plan_hdf':
155
182
  try:
156
- # Convert plan_number column to integers for comparison
157
- plan_info = ras_obj.plan_df[ras_obj.plan_df['plan_number'].astype(int) == number_int]
183
+ # Convert plan_number column to integers for comparison after stripping zeros
184
+ plan_info = ras_obj.plan_df[ras_obj.plan_df['plan_number'].str.lstrip('0').astype(int) == number_int]
158
185
  if not plan_info.empty:
159
186
  # Make sure HDF_Results_Path is a string and not None
160
187
  hdf_path_str = plan_info.iloc[0]['HDF_Results_Path']
@@ -162,14 +189,38 @@ def standardize_input(file_type: str = 'plan_hdf'):
162
189
  hdf_path = Path(str(hdf_path_str))
163
190
  except Exception as e:
164
191
  logger.warning(f"Error retrieving plan HDF path: {str(e)}")
192
+
165
193
  elif file_type == 'geom_hdf':
166
194
  try:
167
- # Convert geometry_number column to integers for comparison
168
- geom_info = ras_obj.plan_df[ras_obj.plan_df['geometry_number'].astype(int) == number_int]
169
- if not geom_info.empty:
170
- hdf_path_str = ras_obj.geom_df.iloc[0]['hdf_path']
171
- if pd.notna(hdf_path_str):
172
- hdf_path = Path(str(hdf_path_str))
195
+ # First try finding plan info to get geometry number
196
+ plan_info = ras_obj.plan_df[ras_obj.plan_df['plan_number'].astype(int) == number_int]
197
+ if not plan_info.empty:
198
+ # Extract the geometry number from the plan
199
+ geom_number = plan_info.iloc[0]['geometry_number']
200
+ if pd.notna(geom_number) and geom_number is not None:
201
+ # Handle different types of geom_number (string or int)
202
+ try:
203
+ # Get the geometry path using RasPlan
204
+ from ras_commander import RasPlan
205
+ geom_path = RasPlan.get_geom_path(str(geom_number), ras_obj)
206
+
207
+ if geom_path is not None:
208
+ # Create the HDF path by adding .hdf to the geometry path
209
+ hdf_path = Path(str(geom_path) + ".hdf")
210
+ if hdf_path.exists():
211
+ logger.info(f"Found geometry HDF file for plan {number_int}: {hdf_path}")
212
+ else:
213
+ # Try to find it in the geom_df if direct path doesn't exist
214
+ geom_info = ras_obj.geom_df[ras_obj.geom_df['full_path'] == str(geom_path)]
215
+ if not geom_info.empty and 'hdf_path' in geom_info.columns:
216
+ hdf_path_str = geom_info.iloc[0]['hdf_path']
217
+ if pd.notna(hdf_path_str):
218
+ hdf_path = Path(str(hdf_path_str))
219
+ logger.info(f"Found geometry HDF file from geom_df for plan {number_int}: {hdf_path}")
220
+ except (TypeError, ValueError) as e:
221
+ logger.warning(f"Error processing geometry number {geom_number}: {str(e)}")
222
+ else:
223
+ logger.warning(f"No valid geometry number found for plan {number_int}")
173
224
  except Exception as e:
174
225
  logger.warning(f"Error retrieving geometry HDF path: {str(e)}")
175
226
  else:
ras_commander/HdfPlan.py CHANGED
@@ -280,17 +280,18 @@ class HdfPlan:
280
280
  Raises:
281
281
  ValueError: If Geometry group is missing or there's an error reading attributes.
282
282
  """
283
- print(f"Getting geometry attributes from {hdf_path}")
283
+ logger.info(f"Getting geometry attributes from {hdf_path}")
284
284
  try:
285
285
  with h5py.File(hdf_path, 'r') as hdf_file:
286
286
  geom_attrs_path = "Geometry"
287
- print(f"Checking for Geometry group in {hdf_path}")
287
+ logger.info(f"Checking for Geometry group in {hdf_path}")
288
288
  if geom_attrs_path not in hdf_file:
289
+ logger.error(f"Geometry group not found in {hdf_path}")
289
290
  raise ValueError(f"Geometry group not found in {hdf_path}")
290
291
 
291
292
  attrs = {}
292
293
  geom_group = hdf_file[geom_attrs_path]
293
- print("Getting root level geometry attributes")
294
+ logger.info("Getting root level geometry attributes")
294
295
  # Get root level geometry attributes only
295
296
  for key, value in geom_group.attrs.items():
296
297
  if isinstance(value, bytes):
@@ -300,13 +301,16 @@ class HdfPlan:
300
301
  logger.warning(f"Failed to decode byte string for root attribute {key}")
301
302
  continue
302
303
  attrs[key] = value
304
+ logger.debug(f"Geometry attribute: {key} = {value}")
303
305
 
304
- print("Successfully extracted root level geometry attributes")
306
+ logger.info(f"Successfully extracted {len(attrs)} root level geometry attributes")
305
307
  return pd.DataFrame.from_dict(attrs, orient='index', columns=['Value'])
306
308
 
307
309
  except (OSError, RuntimeError) as e:
310
+ logger.error(f"Failed to read HDF file {hdf_path}: {str(e)}")
308
311
  raise ValueError(f"Failed to read HDF file {hdf_path}: {str(e)}")
309
312
  except Exception as e:
313
+ logger.error(f"Failed to get geometry attributes: {str(e)}")
310
314
  raise ValueError(f"Failed to get geometry attributes: {str(e)}")
311
315
 
312
316
 
ras_commander/RasPlan.py CHANGED
@@ -579,12 +579,12 @@ class RasPlan:
579
579
 
580
580
  @staticmethod
581
581
  @log_call
582
- def get_geom_path(geom_number: str, ras_object=None) -> Optional[str]:
582
+ def get_geom_path(geom_number: Union[str, int], ras_object=None) -> Optional[str]:
583
583
  """
584
584
  Return the full path for a given geometry number.
585
585
 
586
586
  Args:
587
- geom_number (str): The geometry number to search for.
587
+ geom_number (Union[str, int]): The geometry number to search for.
588
588
  ras_object (RasPrj, optional): Specific RAS object to use. If None, uses the global ras instance.
589
589
 
590
590
  Returns:
@@ -601,17 +601,51 @@ class RasPlan:
601
601
  ... else:
602
602
  ... print("Geometry file not found.")
603
603
  """
604
- ras_obj = ras_object or ras
605
- ras_obj.check_initialized()
606
-
607
- # Use updated geom dataframe
608
- ras_obj.geom_df = ras_obj.get_prj_entries('Geom')
604
+ logger = get_logger(__name__)
609
605
 
610
- geom_path = ras_obj.geom_df[ras_obj.geom_df['geom_number'] == geom_number]
611
- if not geom_path.empty:
612
- full_path = geom_path['full_path'].iloc[0]
613
- return full_path
614
- else:
606
+ if geom_number is None:
607
+ logger.warning("Provided geometry number is None")
608
+ return None
609
+
610
+ try:
611
+ ras_obj = ras_object or ras
612
+ ras_obj.check_initialized()
613
+
614
+ # Ensure geom_number is a string with proper formatting
615
+ if isinstance(geom_number, int):
616
+ geom_number = f"{geom_number:02d}"
617
+ elif isinstance(geom_number, str):
618
+ # Strip any leading zeros and reformat
619
+ stripped = geom_number.lstrip('0')
620
+ if not stripped: # Handle case where input was '0' or '00'
621
+ geom_number = '00'
622
+ else:
623
+ geom_number = f"{int(stripped):02d}"
624
+ else:
625
+ # Handle unexpected types
626
+ logger.warning(f"Unexpected type for geom_number: {type(geom_number)}")
627
+ return None
628
+
629
+ # Use updated geom dataframe
630
+ ras_obj.geom_df = ras_obj.get_prj_entries('Geom')
631
+
632
+ # Find the geometry file path
633
+ geom_path = ras_obj.geom_df[ras_obj.geom_df['geom_number'] == geom_number]
634
+ if not geom_path.empty:
635
+ if 'full_path' in geom_path.columns and pd.notna(geom_path['full_path'].iloc[0]):
636
+ full_path = geom_path['full_path'].iloc[0]
637
+ logger.info(f"Found geometry path: {full_path}")
638
+ return full_path
639
+ else:
640
+ # Fallback to constructing path
641
+ constructed_path = str(ras_obj.project_folder / f"{ras_obj.project_name}.g{geom_number}")
642
+ logger.info(f"Constructed geometry path: {constructed_path}")
643
+ return constructed_path
644
+ else:
645
+ logger.warning(f"No geometry file found with number: {geom_number}")
646
+ return None
647
+ except Exception as e:
648
+ logger.error(f"Error in get_geom_path: {str(e)}")
615
649
  return None
616
650
 
617
651
  # Clone Functions to copy unsteady, flow, and geometry files from templates
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.73.0"
13
+ __version__ = "0.74.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.73.0
3
+ Version: 0.74.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.
@@ -1,11 +1,11 @@
1
- ras_commander/Decorators.py,sha256=EOYi20fyV6JgArpHO3lQEVAU6LPHbpa3wGlmIYS40K0,10115
1
+ ras_commander/Decorators.py,sha256=mhfM6A8jJTZ9b0srybB3u4DIaDnwweVQqYHERLR62Ck,14527
2
2
  ras_commander/HdfBase.py,sha256=Jws6Y8JFkharuiM6Br5ivp6MS64X2fL6y87FOpe3FQw,14219
3
3
  ras_commander/HdfBndry.py,sha256=FBNFoTz4sXVB-MOsbHJBP8P0dMqJUfBROloKTaxmzCo,16377
4
4
  ras_commander/HdfFluvialPluvial.py,sha256=dlqoFX5i7uSA2BvuRNrV-Fg-z2JaeUxY86_fbZAdGqI,25933
5
5
  ras_commander/HdfInfiltration.py,sha256=HiifhbzgUs4kdtJkKfhxo1IsE-FBp5XspKkrJnnCDuc,66171
6
6
  ras_commander/HdfMesh.py,sha256=zI_4AqxDxb2_31G9RUmWibyld6KDMGhDpI3F8qwzVAw,19139
7
7
  ras_commander/HdfPipe.py,sha256=m-yvPL2GIP23NKt2tcwzOlS7khvgcDPGAshlTPMUAeI,32154
8
- ras_commander/HdfPlan.py,sha256=_KIWMoMpAftUp2wc2PQ9psl78IvW0disN0yKt7sNfqU,11807
8
+ ras_commander/HdfPlan.py,sha256=WINI3lp865cE99QXztgvKKIhVUTOqu4X41ZPBfhYJGU,12145
9
9
  ras_commander/HdfPlot.py,sha256=7MNI5T9qIz-Ava1RdlnB6O9oJElE5BEB29QVF5Y2Xuc,3401
10
10
  ras_commander/HdfPump.py,sha256=Vc2ff16kRISR7jwtnaAqxI0p-gfBSuZKzR3rQbBLQoE,12951
11
11
  ras_commander/HdfResultsMesh.py,sha256=MKnSJxcWVDccHaRRGgAK0szm7B-VtrKBtgL1Uz0kAiw,44662
@@ -20,13 +20,13 @@ ras_commander/RasCmdr.py,sha256=37GnchoQ0fIAkPnssnCr1mRUXY8gm-hIMTmuHZlnYP8,3459
20
20
  ras_commander/RasExamples.py,sha256=6IZ96LcAsk5LYFehdD0zDW5wyZWxQa6OQu2N9upxWXA,17536
21
21
  ras_commander/RasGeo.py,sha256=CQ1VjJ4uWWyXC9KsoVStbhlRf_5AiDm8yWvtDM3l4ac,21675
22
22
  ras_commander/RasMap.py,sha256=4cVzaaQure-CXdXB1BY29iE20S00eldUqoL96PvJPbw,10635
23
- ras_commander/RasPlan.py,sha256=7cgwsKjD40ZSj9uOnsHd-OfmBJFxkS2xFhWmlHQflak,62179
23
+ ras_commander/RasPlan.py,sha256=GhAeUSvWRuBcYcOtBCo-qZGUefEWOlhw4ASJQHTGWzU,63872
24
24
  ras_commander/RasPrj.py,sha256=ivAHB3vexH6GQi-Aa4kqAabRwdthllMkTp8xphh5Ldc,57655
25
25
  ras_commander/RasUnsteady.py,sha256=TO08CT2GC4G5rcXO_Wbia2t4PhiWRu9-nC9F0IW7Gyo,37187
26
26
  ras_commander/RasUtils.py,sha256=0fm4IIs0LH1dgDj3pGd66mR82DhWLEkRKUvIo2M_5X0,35886
27
- ras_commander/__init__.py,sha256=Tl8kx5SQQ8UocWSQ1tFzg4FGNb702k2yikfD6_hwXIw,2039
28
- ras_commander-0.73.0.dist-info/licenses/LICENSE,sha256=_pbd6qHnlsz1iQ-ozDW_49r86BZT6CRwO2iBtw0iN6M,457
29
- ras_commander-0.73.0.dist-info/METADATA,sha256=GiwhfJNCCL8ZH9XY1bpVa3huCeU84E1oOr7zIlrj4vs,27365
30
- ras_commander-0.73.0.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
31
- ras_commander-0.73.0.dist-info/top_level.txt,sha256=i76S7eKLFC8doKcXDl3aiOr9RwT06G8adI6YuKbQDaA,14
32
- ras_commander-0.73.0.dist-info/RECORD,,
27
+ ras_commander/__init__.py,sha256=K6g6-GMFHnDKhLYvht8voqlGfY3N86UNS6ZQKvne3Mc,2039
28
+ ras_commander-0.74.0.dist-info/licenses/LICENSE,sha256=_pbd6qHnlsz1iQ-ozDW_49r86BZT6CRwO2iBtw0iN6M,457
29
+ ras_commander-0.74.0.dist-info/METADATA,sha256=qoAaqX8Z5ZCA88r1KAhcvatAh1WyAX75H0FK8HmC-8Y,27365
30
+ ras_commander-0.74.0.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
31
+ ras_commander-0.74.0.dist-info/top_level.txt,sha256=i76S7eKLFC8doKcXDl3aiOr9RwT06G8adI6YuKbQDaA,14
32
+ ras_commander-0.74.0.dist-info/RECORD,,