Skip to content

SIMBI

Overview

SIMBI is a hydrological dataset for Multiple Regions. Multi-region dataset providing hydrological data from diverse global catchments.

Dataset Information

  • Region: Multiple Regions
  • Module: hydrodataset.simbi
  • Class: simbi

Features

Static Attributes

Static catchment attributes include: - Basin area - Mean precipitation - Topographic characteristics - Land cover information - Soil properties - Climate indices

Dynamic Variables

Timeseries variables available: - Streamflow - Precipitation
- Temperature (min, max, mean) - Potential evapotranspiration - And additional variables depending on the dataset

Usage

Basic Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from hydrodataset.simbi import simbi
from hydrodataset import resolve_data_path

# Initialize dataset
data_path = resolve_data_path("simbi")
ds = simbi(data_path)

# Get basin IDs
basin_ids = ds.read_object_ids()
print(f"Number of basins: {len(basin_ids)}")

# Check available features
print("Static features:", ds.available_static_features)
print("Dynamic features:", ds.available_dynamic_features)

# Check default time range
print(f"Default time range: {ds.default_t_range}")

# Read timeseries data
timeseries = ds.read_ts_xrdataset(
    gage_id_lst=basin_ids[:5],
    t_range=ds.default_t_range,
    var_lst=["streamflow", "precipitation"]
)
print(timeseries)

# Read attribute data
attributes = ds.read_attr_xrdataset(
    gage_id_lst=basin_ids[:5],
    var_lst=["area", "p_mean"]
)
print(attributes)

Reading Specific Variables

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Read with specific time range
ts_data = ds.read_ts_xrdataset(
    gage_id_lst=basin_ids[:10],
    t_range=["1990-01-01", "2020-12-31"],
    var_lst=["streamflow", "precipitation", "temperature_mean"]
)

# Read basin area
areas = ds.read_area(gage_id_lst=basin_ids[:10])

# Read mean precipitation
mean_precip = ds.read_mean_prcp(gage_id_lst=basin_ids[:10])

Working with Multiple Data Sources

If the dataset provides multiple sources for variables:

1
2
3
4
5
6
7
8
9
# Request specific data source
ts_data = ds.read_ts_xrdataset(
    gage_id_lst=basin_ids[:5],
    t_range=["1990-01-01", "2000-12-31"],
    var_lst=[
        ("precipitation", "era5land"),  # Specify source
        "streamflow"  # Use default source
    ]
)

API Reference

hydrodataset.simbi.simbi

Bases: HydroDataset

simbi dataset class extending RainfallRunoff.

This class provides access to the simbi dataset, which contains hourly hydrological and meteorological data for various watersheds.

Attributes:

Name Type Description
region

Geographic region identifier

download

Whether to download data automatically

ds_description

Dictionary containing dataset file paths

Source code in hydrodataset/simbi.py
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
class simbi(HydroDataset):
    """simbi dataset class extending RainfallRunoff.

    This class provides access to the simbi dataset, which contains hourly
    hydrological and meteorological data for various watersheds.

    Attributes:
        region: Geographic region identifier
        download: Whether to download data automatically
        ds_description: Dictionary containing dataset file paths
    """

    # OSS dataset folder (uploaded raw data)
    _DATA_REL = "Simbi"
    _ATTR_REL = "Simbi/03_SIMBI_ATTRIBUTE"
    _OTHERS_REL = "Simbi/03_SIMBI_ATTRIBUTE/02_OTHERS"
    _DAILY_REL = "Simbi/03_SIMBI_ATTRIBUTE/01_CLIMATIC_SIGNATURE/02_DAILY"
    _MONTHLY_REL = "Simbi/03_SIMBI_ATTRIBUTE/01_CLIMATIC_SIGNATURE/01_MONTHLY"
    _Q_REL = "Simbi/00_SIMBI_OBSERVED_DATA/02_DAILY_STREAMFLOW"
    _PCP_REL = "Simbi/00_SIMBI_OBSERVED_DATA/01_DAILY_RAINFALL"
    _TEMP_REL = "Simbi/00_SIMBI_OBSERVED_DATA/05_DAILY_LONG_TERM_AVERAGE_TEMPERATURE"

    # static attribute files mirroring AquaFetch Simbi._static_data:
    # other_attributes() then clim_sigs() (daily then monthly).
    # each is (relative_dir, filename, column_suffix); every file is read with
    # index_col=0 and the index normalised via id.split("-")[1].
    _STATIC_FILES = [
        (_OTHERS_REL, "stream_density.csv", ""),
        (_OTHERS_REL, "Percent_land_cover_98.csv", "_lc_98"),
        (_OTHERS_REL, "Percent_land_cover_95.csv", "_lc_95"),
        (_OTHERS_REL, "Percent_geologic_class.csv", "_geol"),
        (_OTHERS_REL, "location_and_topography.csv", ""),
        (_OTHERS_REL, "hypsometric_curve.csv", ""),
        (_OTHERS_REL, "Percent_aquifer_class.csv", ""),
        (_OTHERS_REL, "Percent_carb_sediment_magma.csv", ""),
        (_DAILY_REL, "baseflow_index.csv", "_d"),
        (_DAILY_REL, "high_q_dur.csv", "_d_hq_dur"),
        (_DAILY_REL, "high_q_freq.csv", "_d_hq_freq"),
        (_DAILY_REL, "low_q_dur.csv", "_d_lq_dur"),
        (_DAILY_REL, "low_q_freq.csv", "_d_lq_freq"),
        (_DAILY_REL, "q_mean.csv", "_d_mean"),
        (_DAILY_REL, "quantile_5.csv", "_d_q5"),
        (_DAILY_REL, "quantile_95.csv", "_d_q95"),
        (_MONTHLY_REL, "aridity_runoff.csv", "_mon_arid"),
        (_MONTHLY_REL, "average.csv", "_mon_avg"),
        (_MONTHLY_REL, "QMNA5.csv", "_mon_QMNA5"),
        (_MONTHLY_REL, "QMXA10.csv", "_mon_QMXA10"),
        (_MONTHLY_REL, "quantile_5.csv", "_mon_q5"),
        (_MONTHLY_REL, "quantile_95.csv", "_mon_q95"),
    ]
    # AquaFetch Simbi.static_map (raw column -> standard name)
    _STATIC_RENAME = {
        "Area": "area_km2",
        "Lat_Cent": "lat",
        "Lon_Cent": "long",
        "Slope": "slope_degrees",
    }

    def __init__(
        self, uri: str, region: Optional[str] = None, download: bool = False
    ) -> None:
        """Initialize simbi dataset.

        Args:
            uri: Path to the data directory
            region: Geographic region identifier (optional)
            download: Whether to download data automatically (default: False)
        """
        super().__init__(uri)
        self.region = region
        self.download = download
        # aqua_fetch only supports local paths
        if not str(uri).startswith("s3://"):
            self.aqua_fetch = Simbi(uri)

    def read_object_ids(self) -> np.ndarray:
        """Station IDs: the 24 catchments with boundary + static data.

        Derived from the topography attribute file index (id.split('-')[1]),
        which matches AquaFetch Simbi.boundary_stations().
        """
        if self._is_cloud():
            fs = self._make_s3fs()
            uri = str(self.data_source_dir).rstrip("/")
            path = f"{uri}/{self._OTHERS_REL}/location_and_topography.csv".removeprefix(
                "s3://"
            )
            with fs.open(path) as fh:
                idx = pd.read_csv(fh, index_col=0).index
            ids = sorted(str(i).split("-")[1] for i in idx)
            return np.array(ids)
        return super().read_object_ids()

    def cache_attributes_to_zarr(self) -> None:
        import zarr

        fs = self._make_s3fs()
        uri = str(self.data_source_dir).rstrip("/")
        dfs = []
        for rel, fname, suffix in self._STATIC_FILES:
            path = f"{uri}/{rel}/{fname}".removeprefix("s3://")
            try:
                with fs.open(path) as fh:
                    df = pd.read_csv(fh, index_col=0)
                df.index = [str(i).split("-")[1] for i in df.index]
                if suffix:
                    df.columns = [f"{c}{suffix}" for c in df.columns]
                dfs.append(df)
            except Exception as e:
                print(f"  WARN {fname}: {e}")
        static = pd.concat(dfs, axis=1)
        static = static.loc[~static.index.duplicated(keep="first")]
        static = static.rename(columns=self._STATIC_RENAME)
        static.index = static.index.astype(str)
        static.columns = self._clean_feature_names(list(static.columns))
        static = static.loc[:, ~static.columns.duplicated(keep="first")]

        zarr_name = self._attributes_cache_filename.replace(".nc", ".zarr")
        out, opts = self._zarr_path_and_opts(zarr_name)
        ids = static.index.tolist()
        n = len(ids)
        root = zarr.open_group(out, mode="w", storage_options=opts, zarr_format=2)
        for col in static.columns:
            vals = static[col].values.astype(str) if static[col].dtype == object else static[col].values
            arr = root.create_array(col, shape=(n,), chunks=(n,), dtype=vals.dtype)
            arr[:] = vals
            arr.attrs["_ARRAY_DIMENSIONS"] = ["basin"]
        basin_arr = root.create_array("basin", shape=(n,), chunks=(n,), dtype=str)
        basin_arr[:] = ids
        basin_arr.attrs["_ARRAY_DIMENSIONS"] = ["basin"]
        root.attrs["coordinates"] = "basin"
        self._write_zarr_units(root, "static")
        print(f"Attributes zarr written to: {out}")

    def cache_timeseries_to_zarr(self) -> None:
        import zarr
        from tqdm import tqdm

        fs = self._make_s3fs()
        uri = str(self.data_source_dir).rstrip("/")
        q_base = f"{uri}/{self._Q_REL}"
        pcp_dirs = [f"{uri}/{self._PCP_REL}/1920_1940", f"{uri}/{self._PCP_REL}/1948_1966"]
        temp_base = f"{uri}/{self._TEMP_REL}"

        stations = self.read_object_ids().tolist()
        all_times = pd.date_range(self.default_t_range[0], self.default_t_range[1], freq="D")
        n, nt = len(stations), len(all_times)
        times_ns = all_times.asi8

        def _read_one(path, col_out):
            try:
                with fs.open(path.removeprefix("s3://")) as fh:
                    df = pd.read_csv(fh, index_col=0, parse_dates=True)
                s = df.iloc[:, 0]
                s.index = pd.to_datetime(s.index)
                s = s[~s.index.duplicated(keep="first")]
                return s
            except Exception:
                return None

        # cleaned zarr var names from dynamic mapping
        q_vn, pcp_vn, temp_vn = "q_cms_obs", "pcp_mm", "airtemp_c_mean"
        data = {vn: np.full((n, nt), np.nan) for vn in (q_vn, pcp_vn, temp_vn)}

        for i, stn in enumerate(tqdm(stations, desc="simbi")):
            q = _read_one(f"{q_base}/Q_{stn}.csv", q_vn)
            if q is not None:
                data[q_vn][i] = pd.to_numeric(q.reindex(all_times), errors="coerce").values
            # precipitation: concat the two period folders
            parts = [_read_one(f"{d}/P_{stn}.csv", pcp_vn) for d in pcp_dirs]
            parts = [p for p in parts if p is not None]
            if parts:
                pcp = pd.concat(parts)
                pcp = pcp[~pcp.index.duplicated(keep="first")]
                data[pcp_vn][i] = pd.to_numeric(pcp.reindex(all_times), errors="coerce").values
            t = _read_one(f"{temp_base}/P_{stn}.csv", temp_vn)
            if t is not None:
                data[temp_vn][i] = pd.to_numeric(t.reindex(all_times), errors="coerce").values

        zarr_name = self._timeseries_cache_filename.replace(".nc", ".zarr")
        out, opts = self._zarr_path_and_opts(zarr_name)
        root = zarr.open_group(out, mode="w", storage_options=opts, zarr_format=2)
        for vn in (q_vn, pcp_vn, temp_vn):
            arr = root.create_array(vn, shape=(n, nt), chunks=(n, min(nt, 365)),
                                    dtype="float64", fill_value=np.nan)
            arr[:] = data[vn]
            arr.attrs["_ARRAY_DIMENSIONS"] = ["basin", "time"]
        time_arr = root.create_array("time", shape=(nt,), chunks=(min(nt, 365),), dtype="int64")
        time_arr[:] = times_ns
        time_arr.attrs["_ARRAY_DIMENSIONS"] = ["time"]
        time_arr.attrs["units"] = "nanoseconds since 1970-01-01"
        time_arr.attrs["calendar"] = "proleptic_gregorian"
        basin_arr = root.create_array("basin", shape=(n,), chunks=(n,), dtype=str)
        basin_arr[:] = stations
        basin_arr.attrs["_ARRAY_DIMENSIONS"] = ["basin"]
        root.attrs["coordinates"] = "basin time"
        self._write_zarr_units(root, "dynamic")
        print(f"Timeseries zarr written to: {out}")

    @property
    def _attributes_cache_filename(self):
        return "simbi_attributes.nc"

    @property
    def _timeseries_cache_filename(self):
        return "simbi_timeseries.nc"

    @property
    def default_t_range(self):
        return ["1920-01-01", "2005-12-31"]

    # get the information of features from dataset file "SIMBI_README"
    _subclass_static_definitions = {
        "area": {"specific_name": "area_km2", "unit": "km^2"},
        "p_mean": {"specific_name": "p_mon_avg", "unit": "mm/month"},
    }

    _dynamic_variable_mapping = {
        StandardVariable.STREAMFLOW: {
            "default_source": "observations",
            "sources": {
                "observations": {"specific_name": "q_cms_obs", "unit": "m^3/s"}
            },
        },
        StandardVariable.PRECIPITATION: {
            "default_source": "observations",
            "sources": {"observations": {"specific_name": "pcp_mm", "unit": "mm/day"}},
        },
        StandardVariable.TEMPERATURE_MEAN: {
            "default_source": "observations",
            "sources": {
                "observations": {"specific_name": "airtemp_c_mean", "unit": "°C"}
            },
        },
    }

default_t_range property

__init__(uri, region=None, download=False)

Initialize simbi dataset.

Parameters:

Name Type Description Default
uri str

Path to the data directory

required
region Optional[str]

Geographic region identifier (optional)

None
download bool

Whether to download data automatically (default: False)

False
Source code in hydrodataset/simbi.py
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
def __init__(
    self, uri: str, region: Optional[str] = None, download: bool = False
) -> None:
    """Initialize simbi dataset.

    Args:
        uri: Path to the data directory
        region: Geographic region identifier (optional)
        download: Whether to download data automatically (default: False)
    """
    super().__init__(uri)
    self.region = region
    self.download = download
    # aqua_fetch only supports local paths
    if not str(uri).startswith("s3://"):
        self.aqua_fetch = Simbi(uri)

read_object_ids()

Station IDs: the 24 catchments with boundary + static data.

Derived from the topography attribute file index (id.split('-')[1]), which matches AquaFetch Simbi.boundary_stations().

Source code in hydrodataset/simbi.py
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def read_object_ids(self) -> np.ndarray:
    """Station IDs: the 24 catchments with boundary + static data.

    Derived from the topography attribute file index (id.split('-')[1]),
    which matches AquaFetch Simbi.boundary_stations().
    """
    if self._is_cloud():
        fs = self._make_s3fs()
        uri = str(self.data_source_dir).rstrip("/")
        path = f"{uri}/{self._OTHERS_REL}/location_and_topography.csv".removeprefix(
            "s3://"
        )
        with fs.open(path) as fh:
            idx = pd.read_csv(fh, index_col=0).index
        ids = sorted(str(i).split("-")[1] for i in idx)
        return np.array(ids)
    return super().read_object_ids()