Skip to content

Commit

Permalink
fixed reservoir ec and warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dwr-psandhu committed Oct 17, 2024
1 parent 1309c79 commit 80dde04
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
10 changes: 7 additions & 3 deletions pydsm/dsm2h5.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@ def get_model(h5f):
"""
if h5f.get("/hydro"): # hydro files have hydro at top level
return "hydro"
elif h5f.get("/output/channel concentration"):
return "gtm"
elif h5f.get("/output"): # qual files have output group not found in hydro
elif h5f.get(
"/output/channel avg concentration"
): # only qual h5 files have the avg concentration
return "qual"
elif h5f.get(
"/output/channel concentration"
): # qual and gtm files have output group not found in hydro
return "gtm"
else:
return "unknown"

Expand Down
10 changes: 5 additions & 5 deletions pydsm/hydroh5.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ def get_channel_locations(self):
self.channel_locs = pd.DataFrame(
self.h5.get(HydroH5._GEOM_PATH + "/channel_location")
)
self.channel_locs.iloc[:, 0] = self.channel_locs.iloc[:, 0].astype(object)
self.channel_locs.iloc[:, 0] = self.channel_locs.iloc[:, 0].str.decode("utf-8")
self.channel_locs = pd.DataFrame(
self.channel_locs.iloc[:, 0].str.decode("utf-8")
)
self.channel_location2number = self.channel_locs[0].to_dict()
self.channel_location2index = {
value: key for key, value in self.channel_location2number.items()
Expand All @@ -112,9 +113,8 @@ def get_reservoirs(self):
self.reservoirs = pd.DataFrame(
self.h5.get(HydroH5._GEOM_PATH + "/reservoir_names"), columns=["name"]
)
self.reservoirs.iloc[:, 0] = self.reservoirs.iloc[:, 0].astype(object)
self.reservoirs.iloc[:, 0] = self.reservoirs.iloc[:, 0].apply(
dsm2h5.decode_if_bytes
self.reservoirs = pd.DataFrame(
self.reservoirs.iloc[:, 0].apply(dsm2h5.decode_if_bytes), columns=["name"]
)
self.reservoir_node_connections = dsm2h5.read_table_as_df(
self.h5, HydroH5._GEOM_PATH + "/reservoir_node_connect"
Expand Down
11 changes: 7 additions & 4 deletions pydsm/qualh5.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ def get_channel_locations(self):
return pandas DataFrame of channel locations ( upstream or downstream)
"""
self.channel_locs = pd.DataFrame(self.h5.get("/output/channel_location"))
self.channel_locs.iloc[:, 0] = self.channel_locs.iloc[:, 0].astype(object)
self.channel_locs.iloc[:, 0] = self.channel_locs.iloc[:, 0].str.decode("utf-8")
self.channel_locs = pd.DataFrame(
self.channel_locs.iloc[:, 0].str.decode("utf-8")
)
self.channel_location2number = self.channel_locs[0].to_dict()
self.channel_location2index = {
value: key for key, value in self.channel_location2number.items()
Expand All @@ -117,8 +118,10 @@ def get_reservoirs(self):
self.reservoirs = pd.DataFrame(
self.h5.get("/output/reservoir_names"), columns=["name"]
)
self.reservoirs.iloc[:, 0] = self.reservoirs.iloc[:, 0].astype(object)
self.reservoirs.iloc[:, 0] = self.reservoirs.iloc[:, 0].str.decode("utf-8")
# Before the assignment, convert the values to the correct dtype
return pd.DataFrame(
self.reservoirs.iloc[:, 0].str.decode("utf-8"), columns=["name"]
)
return self.reservoirs

def get_channel_numbers(self):
Expand Down

0 comments on commit 80dde04

Please sign in to comment.