Dataset Module🔗
Dataset processing classes for water timeseries analysis.
This module provides classes for processing and normalizing satellite-derived land cover and water classification data. It includes specialized handlers for different data sources and processing pipelines.
DWDataset
🔗
Bases: LakeDataset
Handler for Dynamic World land cover classification data.
Processes Dynamic World land cover classes including water, bare soil, snow/ice, trees, grass, flooded vegetation, crops, shrub/scrub, and built areas.
Attributes:
| Name | Type | Description |
|---|---|---|
water_column |
str
|
Fixed as "water" for DW data. |
data_columns |
list
|
All 9 DW land cover classes. |
Example
dw_data = DWDataset(xr.open_dataset("dynamic_world.nc")) water_time_series = dw_data.ds_normalized["water"] print(dw_data.data_columns) ['water', 'bare', 'snow_and_ice', 'trees', 'grass', 'flooded_vegetation', 'crops', 'shrub_and_scrub', 'built']
Source code in src/water_timeseries/dataset.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 | |
__init__(ds, mask_data=True)
🔗
Initialize DWDataset with Dynamic World data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Input xarray Dataset with at least the 9 DW class variables. |
required |
mask_data
|
bool
|
Whether to mask invalid data (default: True). |
True
|
Source code in src/water_timeseries/dataset.py
364 365 366 367 368 369 370 371 372 373 | |
plot_timeseries(id_geohash, breakpoints=None, plot_variables=None, save_path=None)
🔗
Plot the time series for a specific geohash using matplotlib.
Creates a static matplotlib figure showing the Dynamic World land cover time series for a single lake/location, with an optional vertical line indicating a breakpoint or specific date. The figure includes a 'Breakpoint' entry in the legend when a breakpoint is provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_geohash
|
str
|
The geohash identifier for the location. |
required |
breakpoints
|
BreakpointMethod | Timestamp | str | list
|
Breakpoint detection method to use, or a single date (pd.Timestamp or string in YYYY-MM-DD format), or a list of dates. If a list is provided, only the first date is used for plotting. When a BreakpointMethod is passed, the first detected breakpoint date is used. |
None
|
plot_variables
|
list
|
List of variables to plot. If None, defaults to all variables. Options include: 'water', 'bare', 'vegetation', 'snow_and_ice'. |
None
|
save_path
|
str | Path
|
Path to save the plot as an image file. If provided, the figure will be saved to this location. |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
plt.Figure: The matplotlib figure object. |
Example
Plot with automatic breakpoint detection🔗
fig = dw_dataset.plot_timeseries(id_geohash="abc123", breakpoints=bp_method)
Plot with a specific date🔗
fig = dw_dataset.plot_timeseries(id_geohash="abc123", breakpoints="2023-06-15")
Save the plot to a file🔗
fig = dw_dataset.plot_timeseries(id_geohash="abc123", save_path="plot.png")
Plot only water and bare🔗
fig = dw_dataset.plot_timeseries(id_geohash="abc123", plot_variables=["water", "bare"])
Source code in src/water_timeseries/dataset.py
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 | |
plot_timeseries_interactive(id_geohash, breakpoints=None, plot_variables=None, save_path=None)
🔗
Plot the interactive time series for a specific geohash using Plotly.
Creates an interactive Plotly figure showing the Dynamic World land cover time series for a single lake/location, with an optional vertical line indicating a breakpoint or specific date. Includes a 'Breakpoint' entry in the legend when a breakpoint is provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_geohash
|
str
|
The geohash identifier for the location. |
required |
breakpoints
|
BreakpointMethod | Timestamp | str | list
|
Breakpoint detection method to use, or a single date (pd.Timestamp or string in YYYY-MM-DD format), or a list of dates. If a list is provided, only the first date is used for plotting. When a BreakpointMethod is passed, the first detected breakpoint date is used. |
None
|
plot_variables
|
list
|
List of variables to plot. If None, defaults to all variables. Options include: 'water', 'bare', 'vegetation', 'snow_and_ice'. |
None
|
save_path
|
str | Path
|
Path to save the plot as HTML file. |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
go.Figure: Interactive Plotly figure. Includes a 'Breakpoint' entry in the legend when a breakpoint is provided. |
Example
Plot with automatic breakpoint detection🔗
fig = dw_dataset.plot_timeseries_interactive(id_geohash="abc123", breakpoints=bp_method)
Plot with a specific date🔗
fig = dw_dataset.plot_timeseries_interactive(id_geohash="abc123", breakpoints="2023-06-15")
Save the plot to an HTML file🔗
fig = dw_dataset.plot_timeseries_interactive(id_geohash="abc123", save_path="plot.html")
Plot only water and bare🔗
fig = dw_dataset.plot_timeseries_interactive(id_geohash="abc123", plot_variables=["water", "bare"])
Source code in src/water_timeseries/dataset.py
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 | |
JRCDataset
🔗
Bases: LakeDataset
Handler for JRC (Joint Research Centre) water classification data.
Processes JRC water occurrence data with separate classes for permanent water, seasonal water, and land.
Attributes:
| Name | Type | Description |
|---|---|---|
water_column |
str
|
Fixed as "area_water_permanent" for JRC data. |
data_columns |
list
|
['area_water_permanent', 'area_water_seasonal', 'area_land']. |
Example
jrc_data = JRCDataset(xr.open_dataset("jrc_water.nc")) permanent_water = jrc_data.ds_normalized["area_water_permanent"] seasonal_water = jrc_data.ds_normalized["area_water_seasonal"]
Source code in src/water_timeseries/dataset.py
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 | |
__init__(ds, mask_data=True)
🔗
Initialize JRCDataset with JRC water classification data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Input xarray Dataset with JRC water classification variables. |
required |
mask_data
|
bool
|
Whether to mask invalid data (default: True). |
True
|
Source code in src/water_timeseries/dataset.py
575 576 577 578 579 580 581 582 583 584 | |
create_timelapse(lake_gdf, id_geohash, timelapse_source='landsat', gif_outdir='gifs', buffer=100, start_year=2000, end_year=2025, start_date='07-01', end_date='08-31', frames_per_second=1, dimensions=512, overwrite_exists=False)
🔗
Create a timelapse GIF for a specific lake.
This method generates an animated GIF showing satellite imagery over a date range for a lake identified by its geohash. The timelapse captures the summer period (July-August) each year to maximize cloud-free observations.
Default timelapse_source is 'landsat' for JRC data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lake_gdf
|
GeoDataFrame
|
GeoDataFrame containing lake geometries with an 'id_geohash' column. |
required |
id_geohash
|
str
|
The geohash identifier for the specific lake to visualize. |
required |
timelapse_source
|
str
|
Image source for timelapse imagery ('sentinel2' or 'landsat'). |
'landsat'
|
gif_outdir
|
str | Path
|
Output directory for the GIF file (default: 'gifs'). |
'gifs'
|
buffer
|
float
|
Buffer distance in meters to expand the lake bounding box (default: 100). |
100
|
start_year
|
int
|
Start year for the timelapse (default: 2000). |
2000
|
end_year
|
int
|
End year for the timelapse (default: 2025). |
2025
|
start_date
|
str
|
Start date within each year (MM-DD format, default: '07-01'). |
'07-01'
|
end_date
|
str
|
End date within each year (MM-DD format, default: '08-31'). |
'08-31'
|
frames_per_second
|
int
|
Animation speed (default: 1). |
1
|
dimensions
|
int
|
Pixel dimensions for the output GIF (default: 512). |
512
|
overwrite_exists
|
bool
|
If False (default), skip download if output file already exists. If True, always re-download and overwrite existing file. |
False
|
Returns:
| Type | Description |
|---|---|
Path | None
|
Path | None: Path to the generated GIF file, or None if skipped due to existing file. |
Source code in src/water_timeseries/dataset.py
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 | |
plot_timeseries(id_geohash, breakpoints=None, plot_variables=None, save_path=None)
🔗
Plot the time series for a specific geohash using matplotlib.
Creates a static matplotlib figure showing the JRC water classification time series for a single lake/location, with an optional vertical line indicating a breakpoint or specific date. The figure includes a 'Breakpoint' entry in the legend when a breakpoint is provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_geohash
|
str
|
The geohash identifier for the location. |
required |
breakpoints
|
BreakpointMethod | Timestamp | str | list
|
Breakpoint detection method to use, or a single date (pd.Timestamp or string in YYYY-MM-DD format), or a list of dates. If a list is provided, only the first date is used for plotting. When a BreakpointMethod is passed, the first detected breakpoint date is used. |
None
|
plot_variables
|
list
|
List of variables to plot. If None, defaults to ["area_water_permanent", "area_water_seasonal", "area_land"]. |
None
|
save_path
|
str | Path
|
Path to save the plot as an image file. If provided, the figure will be saved to this location. |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
plt.Figure: The matplotlib figure object. |
Example
Plot with automatic breakpoint detection🔗
fig = jrc_dataset.plot_timeseries(id_geohash="abc123", breakpoints=bp_method)
Plot with a specific date🔗
fig = jrc_dataset.plot_timeseries(id_geohash="abc123", breakpoints="2023-06-15")
Save the plot to a file🔗
fig = jrc_dataset.plot_timeseries(id_geohash="abc123", save_path="plot.png")
Plot only permanent water🔗
fig = jrc_dataset.plot_timeseries(id_geohash="abc123", plot_variables=["area_water_permanent"])
Source code in src/water_timeseries/dataset.py
672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 | |
plot_timeseries_interactive(id_geohash, breakpoints=None, plot_variables=None, save_path=None)
🔗
Plot the interactive time series for a specific geohash using Plotly.
Creates an interactive Plotly figure showing the JRC water classification time series for a single lake/location, with an optional vertical line indicating a breakpoint or specific date. Includes a 'Breakpoint' entry in the legend when a breakpoint is provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_geohash
|
str
|
The geohash identifier for the location. |
required |
breakpoints
|
BreakpointMethod | Timestamp | str | list
|
Breakpoint detection method to use, or a single date (pd.Timestamp or string in YYYY-MM-DD format), or a list of dates. If a list is provided, only the first date is used for plotting. When a BreakpointMethod is passed, the first detected breakpoint date is used. |
None
|
plot_variables
|
list
|
List of variables to plot. If None, defaults to ["area_water_permanent", "area_water_seasonal", "area_land"]. |
None
|
save_path
|
str | Path
|
Path to save the plot as HTML file. |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
go.Figure: Interactive Plotly figure. |
Example
Plot with automatic breakpoint detection🔗
fig = jrc_dataset.plot_timeseries_interactive(id_geohash="abc123", breakpoints=bp_method)
Plot with a specific date🔗
fig = jrc_dataset.plot_timeseries_interactive(id_geohash="abc123", breakpoints="2023-06-15")
Save the plot to an HTML file🔗
fig = jrc_dataset.plot_timeseries_interactive(id_geohash="abc123", save_path="plot.html")
Plot only permanent water🔗
fig = jrc_dataset.plot_timeseries_interactive(id_geohash="abc123", plot_variables=["area_water_permanent"])
Source code in src/water_timeseries/dataset.py
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 | |
LakeDataset
🔗
Base class for processing lake and water body datasets.
Handles common operations for dataset preprocessing, normalization, and masking. Provides a framework that can be extended for different data sources.
Attributes:
| Name | Type | Description |
|---|---|---|
ds |
Dataset
|
The input xarray Dataset containing raw data. |
ds_normalized |
Dataset
|
Normalized version of the dataset (0-1 scale). |
preprocessed_ |
bool
|
Whether preprocessing has been completed. |
normalized_available_ |
bool
|
Whether normalized data is available. |
water_column |
str
|
Name of the water/water extent column. |
data_columns |
list
|
Names of all data columns in the dataset. |
ds_ismasked_ |
bool
|
Whether the original dataset has been masked. |
ds_normalized_ismasked_ |
bool
|
Whether the normalized dataset has been masked. |
Example
lake_data = LakeDataset(xr.Dataset(...)) normalized = lake_data.ds_normalized
Source code in src/water_timeseries/dataset.py
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 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | |
dates_
property
🔗
Get all valid dates from the dataset.
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
List of all dates from the 'date' coordinate. |
object_ids_
property
🔗
Get all valid object IDs from the dataset.
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
List of all object IDs from the id_field coordinate. |
__init__(ds, id_field='id_geohash', mask_data=True)
🔗
Initialize the LakeDataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Input xarray Dataset with land cover or water classification data. |
required |
id_field
|
str
|
Name of the coordinate field that identifies individual time series (default: "id_geohash"). |
'id_geohash'
|
mask_data
|
bool
|
Whether to mask invalid data (default: True). |
True
|
Source code in src/water_timeseries/dataset.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
create_timelapse(lake_gdf, id_geohash, timelapse_source='sentinel2', gif_outdir='gifs', buffer=100, start_year=2016, end_year=2025, start_date='07-01', end_date='08-31', frames_per_second=1, dimensions=512, overwrite_exists=False)
🔗
Create a timelapse GIF for a specific lake.
This method generates an animated GIF showing satellite imagery over a date range for a lake identified by its geohash. The timelapse captures the summer period (July-August) each year to maximize cloud-free observations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lake_gdf
|
GeoDataFrame
|
GeoDataFrame containing lake geometries with an 'id_geohash' column. |
required |
id_geohash
|
str
|
The geohash identifier for the specific lake to visualize. |
required |
timelapse_source
|
str
|
Image source for timelapse imagery ('sentinel2' or 'landsat'). |
'sentinel2'
|
gif_outdir
|
str | Path
|
Output directory for the GIF file (default: 'gifs'). |
'gifs'
|
buffer
|
float
|
Buffer distance in meters to expand the lake bounding box (default: 100). |
100
|
start_year
|
int
|
Start year for the timelapse (default: 2016). |
2016
|
end_year
|
int
|
End year for the timelapse (default: 2025). |
2025
|
start_date
|
str
|
Start date within each year (MM-DD format, default: '07-01'). |
'07-01'
|
end_date
|
str
|
End date within each year (MM-DD format, default: '08-31'). |
'08-31'
|
frames_per_second
|
int
|
Animation speed (default: 1). |
1
|
dimensions
|
int
|
Pixel dimensions for the output GIF (default: 512). |
512
|
overwrite_exists
|
bool
|
If False (default), skip download if output file already exists. If True, always re-download and overwrite existing file. |
False
|
Returns:
| Type | Description |
|---|---|
Path | None
|
Path | None: Path to the generated GIF file, or None if skipped due to existing file. |
Source code in src/water_timeseries/dataset.py
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 | |
merge(other, how='both')
🔗
Merge this LakeDataset with another LakeDataset.
Combines the .ds attributes of both datasets. Both datasets must have the same
variables. The merge strategy is determined by the how parameter.
Both datasets must be of the same type (e.g., both DWDataset or both JRCDataset).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
LakeDataset
|
Another LakeDataset instance to merge with. |
required |
how
|
str
|
Merge strategy. Options: - "both": Merge along both dimensions (date and id_geohash). Combines all data from both datasets, keeping all unique dates and id_geohashes. - "date": Merge along the "date" dimension only. Both datasets must have the same id_geohash values, but can have different dates. New dates are appended to the existing time series. - "id_geohash": Merge along the "id_geohash" dimension only. Both datasets must have the same dates, but can have different id_geohashes. New id_geohashes (lakes) are added with their time series. |
'both'
|
Returns:
| Name | Type | Description |
|---|---|---|
LakeDataset |
LakeDataset
|
A new LakeDataset with merged .ds data. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the datasets are of different types. |
ValueError
|
If the merge strategy is invalid or datasets are incompatible. |
Example
merged = dataset1.merge(dataset2, how="both") merged = dataset1.merge(dataset2, how="date") # Add new dates merged = dataset1.merge(dataset2, how="id_geohash") # Add new lakes
Source code in src/water_timeseries/dataset.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
plot_timeseries(id_geohash, breakpoints)
🔗
Plot the time series for a specific geohash.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_geohash
|
str
|
The geohash identifier for the location. |
required |
breakpoints
|
BreakpointMethod
|
Breakpoint detection method to use. |
required |
Source code in src/water_timeseries/dataset.py
227 228 229 230 231 232 233 | |
Merge Functionality🔗
The LakeDataset class and its subclasses (DWDataset, JRCDataset) provide a merge() method to combine two datasets. This is useful for:
- Combining datasets from different time periods
- Adding new lakes to an existing dataset
- Combining partial datasets into a complete one
Merge Strategies🔗
The merge() method accepts a how parameter with three options:
| Strategy | Description | Requirements |
|---|---|---|
"both" |
Merge along both dimensions (date and id_geohash). Combines all unique data from both datasets. | Same variables |
"date" |
Merge along the date dimension only. Adds new dates for the same lakes. | Same id_geohash values, same variables |
"id_geohash" |
Merge along the id_geohash dimension only. Adds new lakes with the same dates. | Same dates, same variables |
Examples🔗
from water_timeseries.dataset import DWDataset
import xarray as xr
# Load two datasets
ds1 = xr.open_dataset("data_2020_2022.zarr")
dataset1 = DWDataset(ds1)
ds2 = xr.open_dataset("data_2023_2024.zarr")
dataset2 = DWDataset(ds2)
# Merge along both dimensions
merged = dataset1.merge(dataset2, how="both")
# Add new dates to existing time series (same lakes)
# Both datasets must have the same id_geohash values
merged = dataset1.merge(dataset2, how="date")
# Add new lakes with the same temporal coverage
# Both datasets must have the same dates
merged = dataset1.merge(dataset2, how="id_geohash")
Warnings🔗
When there are overlapping values, a warning is issued:
how="date": Warns if there are duplicate dates between datasetshow="id_geohash": Warns if there are duplicate id_geohash values
In both cases, data from the second dataset will overwrite the first for overlapping values.
Requirements🔗
- Both datasets must be of the same type (both
DWDatasetor bothJRCDataset) - Both datasets must have the same variables
- The specific merge strategy may have additional requirements (see table above)
Return Value🔗
The merge() method returns a new LakeDataset instance (of the same type as the first dataset) with the combined data. The returned dataset is fully preprocessed and normalized.
Plot Time Series🔗
Both DWDataset and JRCDataset provide two methods for visualization:
- plot_timeseries() - Static matplotlib plots
- plot_timeseries_interactive() - Interactive Plotly plots
DWDataset.plot_timeseries() / plot_timeseries_interactive()🔗
from water_timeseries.dataset import DWDataset
import xarray as xr
# Load data
ds = xr.open_zarr("lakes_dw.zarr")
dataset = DWDataset(ds)
# Get a geohash from the dataset
geohash = dataset.object_ids_[0]
# Static matplotlib plot
fig = dataset.plot_timeseries(
id_geohash=geohash,
breakpoints=None # Optional: see breakpoints section below
)
# Interactive Plotly plot (returns go.Figure)
fig_interactive = dataset.plot_timeseries_interactive(
id_geohash=geohash,
breakpoints=None
)
JRCDataset.plot_timeseries() / plot_timeseries_interactive()🔗
from water_timeseries.dataset import JRCDataset
import xarray as xr
# Load data
ds = xr.open_zarr("lakes_jrc.zarr")
dataset = JRCDataset(ds)
# Get a geohash from the dataset
geohash = dataset.object_ids_[0]
# Static matplotlib plot
fig = dataset.plot_timeseries(
id_geohash=geohash,
breakpoints=None
)
# Interactive Plotly plot
fig_interactive = dataset.plot_timeseries_interactive(
id_geohash=geohash
)
Parameters🔗
| Parameter | Type | Description |
|---|---|---|
id_geohash |
str | The geohash identifier for the lake to plot |
breakpoints |
BreakpointMethod, pd.Timestamp, str, list, optional | Breakpoint(s) to overlay on the plot. Can be a BreakpointMethod instance (e.g., SimpleBreakpoint()), a single date string ("YYYY-MM-DD") or pd.Timestamp, or a list of dates. Only the first date is used. |
plot_variables |
list, optional | List of variables to plot. If None, uses all variables. For DWDataset: ["water", "bare", "vegetation", "snow_and_ice"]. For JRCDataset: ["area_water_permanent", "area_water_seasonal", "area_land"]. |
save_path |
str, Path, optional | If provided, saves the plot to this path (.png for static, .html for interactive) |
Return Values🔗
| Method | Return Type | Description |
|---|---|---|
plot_timeseries() |
matplotlib.figure.Figure |
Static matplotlib figure |
plot_timeseries_interactive() |
plotly.graph_objects.Figure |
Interactive Plotly figure (can be displayed in notebooks, saved as HTML, or used with Streamlit) |
With Breakpoint Detection🔗
The breakpoints parameter accepts a BreakpointMethod instance which will automatically detect and visualize the breakpoint:
from water_timeseries.dataset import DWDataset
from water_timeseries.breakpoint import SimpleBreakpoint
import xarray as xr
# Initialize dataset
dataset = DWDataset(xr.open_zarr("lakes_dw.zarr"))
geohash = dataset.object_ids_[0]
# Create breakpoint method and pass directly to plot
bp = SimpleBreakpoint()
# Static plot with breakpoint
fig = dataset.plot_timeseries(
id_geohash=geohash,
breakpoints=bp # Pass the BreakpointMethod, not the result!
)
# Interactive plot with breakpoint
fig_interactive = dataset.plot_timeseries_interactive(
id_geohash=geohash,
breakpoints=bp
)
With Specific Date🔗
Alternatively, you can pass a specific date or list of dates:
# Single date (string)
fig = dataset.plot_timeseries(
id_geohash=geohash,
breakpoints="2023-06-15"
)
# Single date (pd.Timestamp)
import pandas as pd
fig = dataset.plot_timeseries(
id_geohash=geohash,
breakpoints=pd.Timestamp("2023-06-15")
)
# List of dates (only first is used)
fig = dataset.plot_timeseries(
id_geohash=geohash,
breakpoints=["2023-06-15", "2020-09-01"]
)
With Custom plot_variables🔗
You can customize which variables are displayed using the plot_variables parameter:
# DWDataset: plot only water and bare (exclude vegetation and snow_and_ice)
fig = dataset.plot_timeseries_interactive(
id_geohash=geohash,
plot_variables=["water", "bare"]
)
# JRCDataset: plot only permanent water
fig = dataset.plot_timeseries_interactive(
id_geohash=geohash,
plot_variables=["area_water_permanent"]
)
Visual Output🔗
DWDataset Time Series

The DWDataset plot shows land cover class proportions: - Water (blue): Primary water extent indicator - Vegetation (green): Combined trees, grass, crops, shrub/scrub, flooded vegetation - Bare (brown): Bare soil - Snow and Ice (black): Snow/ice coverage - Values are shown in hectares (left axis) with optional percentage scale (right axis)
Use plot_variables to select which classes to display (e.g., plot_variables=["water", "bare", "vegetation"] to exclude snow_and_ice).
JRCDataset Time Series

The JRCDataset plot shows permanent vs seasonal water: - Permanent water (blue): Water present year-round - Seasonal water (light blue): Water present seasonally - Land (brown): Dry land area - Gray shading indicates no-data regions - Values are shown in hectares (left axis) with optional percentage scale (right axis)
With Breakpoint Overlay
When a breakpoint is provided, a vertical dashed black line marks the date: - Static plots: Includes "Breakpoint" entry in the legend - Interactive plots: Includes "Breakpoint" entry in the legend for hover inspection