Report I/O
The report I/O module provides functions to save and load discharge and lateral inflow time series in Parquet format for efficient storage and analysis.
Overview
Report files store:
- Discharge time series: River discharge for selected reaches over simulation period
- Lateral inflow time series: Hillslope contributions to river reaches
- Time index: Datetime index for all time steps
- Reach selection: Configurable subset (all, from file, custom list)
- Metadata: Simulation details saved as separate JSON file
Parquet format offers:
- High compression: ~10-50× smaller than CSV
- Fast I/O: Columnar storage optimized for analytics
- Type preservation: Maintains datetime and numeric types
- Integration: Compatible with pandas, Dask, Apache Spark
Functions
Save discharge time series to file (Parquet or CSV).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
discharge_timeseries
|
ndarray
|
2D array of discharge values [m³/s], shape (n_timesteps, n_reaches) |
required |
time_stamps
|
list[datetime]
|
List of datetime objects for each time step |
required |
network
|
GeoDataFrame
|
River network GeoDataFrame with reach metadata |
required |
output_path
|
str | Path
|
Path to output file |
required |
reach_selection
|
str
|
Reach selection mode: “all”, “file”, or “list” |
'all'
|
selected_reaches
|
list[int] | None
|
List of reach IDs (mobidic_id) to include (used if reach_selection=”list”) |
None
|
reach_file
|
str | Path | None
|
Path to JSON file containing reach IDs (used if reach_selection=”file”) |
None
|
add_metadata
|
dict | None
|
Additional metadata to save (optional, saved as JSON in separate file) |
None
|
output_format
|
str
|
Output format: “Parquet” or “csv” (default: “Parquet”) |
'Parquet'
|
Examples:
>>> from mobidic import Simulation
>>> sim = Simulation(gisdata, forcing, config)
>>> results = sim.run("2020-01-01", "2020-12-31")
>>> from mobidic.io import save_discharge_report
>>> save_discharge_report(
... results.time_series["discharge"],
... results.time_series["time"],
... sim.network,
... "Arno_discharge.parquet",
... reach_selection="file",
... reach_file="reach_ids.json",
... output_format="Parquet"
... )
Source code in mobidic/io/report.py
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 | |
Load discharge time series from Parquet file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_path
|
str | Path
|
Path to input Parquet file |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with time as index and reach discharge as columns |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If input file does not exist |
Examples:
>>> from mobidic.io import load_discharge_report
>>> df = load_discharge_report("Arno_discharge.parquet")
>>> print(df.head())
Source code in mobidic/io/report.py
Save lateral inflow time series to file (Parquet or CSV).
Similar to save_discharge_report but for lateral inflows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lateral_inflow_timeseries
|
ndarray
|
2D array of lateral inflow [m³/s], shape (n_timesteps, n_reaches) |
required |
time_stamps
|
list[datetime]
|
List of datetime objects for each time step |
required |
network
|
GeoDataFrame
|
River network GeoDataFrame with reach metadata |
required |
output_path
|
str | Path
|
Path to output file |
required |
reach_selection
|
str
|
Reach selection mode: “all”, “file”, or “list” |
'all'
|
selected_reaches
|
list[int] | None
|
List of reach IDs to include (used if reach_selection=”list”) |
None
|
reach_file
|
str | Path | None
|
Path to JSON file containing reach IDs (used if reach_selection=”file”) |
None
|
output_format
|
str
|
Output format: “Parquet” or “csv” (default: “Parquet”) |
'Parquet'
|
Examples:
>>> save_lateral_inflow_report(
... lateral_inflow_ts,
... time_stamps,
... network,
... "lateral_inflow.parquet",
... output_format="Parquet"
... )
Source code in mobidic/io/report.py
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 246 247 248 249 250 251 252 253 254 255 256 257 | |
Design features
- Efficient storage: Parquet columnar format with compression
- Fast loading: Optimized for time series analysis
- Flexible selection: All reaches, from file, or custom list
- Type preservation: Maintains datetime and float64 types
- Metadata support: Optional JSON metadata file
- pandas integration: Seamless integration with pandas workflows
Integration with other tools
Load in R
Load in Apache Spark
from pyspark.sql import SparkSession
spark = SparkSession.builder.getOrCreate()
df_spark = spark.read.parquet("discharge.parquet")
df_spark.show()
Load in Dask
References
File format:
- Apache Parquet with Snappy compression
- Uses PyArrow engine for reading/writing
- Compatible with pandas, Dask, Spark, R (arrow package)
Related modules:
- Simulation - Generates time series for reports
- State I/O - Spatial state snapshots (NetCDF format)