Skip to content

Commit

Permalink
make sure dataset have time and basin coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
OuyangWenyu committed Oct 19, 2023
1 parent c107c1e commit e4c4702
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion hydrodataset/caravan.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ def extract_unit(variable_name, units_string):

# Assign basin names as coordinate
combined_ds = combined_ds.assign_coords(basin=gage_id_lst)

combined_ds = combined_ds.rename({"date": "time"})
return combined_ds

@property
Expand All @@ -789,3 +789,22 @@ def read_area(self, gage_id_lst=None):

def read_mean_prcp(self, gage_id_lst=None):
return self.read_attr_xrdataset(gage_id_lst, ["p_mean"])


def check_coordinates(ds):
"""We uniformly use basin and time as coordinates
Parameters
----------
ds : xr.Dataset
the ds must have basin and time as coordinates
Raises
------
ValueError
coords not in ds
"""
required_coords = ["basin", "time"]
for coord in required_coords:
if coord not in ds.coords:
raise ValueError(f"Missing coordinate: {coord}")

0 comments on commit e4c4702

Please sign in to comment.