Skip to content

Commit

Permalink
Bugfix, add new properties for basin file assets
Browse files Browse the repository at this point in the history
  • Loading branch information
Stevenray Janke committed Feb 18, 2025
1 parent 49886ef commit 64de934
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions hecstac/hms/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,19 @@ def files(self):
@property
def dss_files(self):
"""Return dss files."""
files = set(
[gage.attrs["Variant"]["Variant-1"]["DSS File Name"] for gage in self.gage.elements.elements.values()]
+ [pdata.attrs["DSS File"] for pdata in self.pdata.elements.elements.values()]
)
files = set()
if self.gage:
files.update(
[gage.attrs["Variant"]["Variant-1"]["DSS File Name"] for gage in self.gage.elements.elements.values()]
)
else:
logging.warning("No gage file to extract gages from.")

if self.pdata:
files.update([pdata.attrs["DSS File"] for pdata in self.pdata.elements.elements.values()])
else:
logging.warning("No pdata files found.")

if self.grid:
files.update(
[
Expand Down Expand Up @@ -716,6 +725,31 @@ def subbasin_bc_lines(self):
gdf = gpd.GeoDataFrame(df, geometry="geometry", crs=self.crs)
return gdf

@property
@lru_cache
def hms_methods(self):
"""Extract unique HMS methods from Subbasins and Reaches."""

methods = {
"Canopy": set(),
"Discretization": set(),
"Begin Snow": set(),
"Surface": set(),
"LossRate": set(),
"Transform": set(),
"Baseflow": set(),
"Route": set(),
}

for subbasin in self.subbasins:
for key in methods.keys():
if key in subbasin.attrs:
methods[key].add(subbasin.attrs[key])
for reach in self.reaches:
if "Route" in reach.attrs:
methods["Route"].add(reach.attrs["Route"])
return {f"hms_methods:{key.replace(' ', '_')}": list(values) for key, values in methods.items()}


class MetFile(BaseTextFile):
"""Class for parsing HEC-HMS meteorology files."""
Expand Down

0 comments on commit 64de934

Please sign in to comment.