From fc6bbfa9c13f72dcaf9f0e61f8dbfe6d44d8ca07 Mon Sep 17 00:00:00 2001 From: Jemma Stachelek Date: Mon, 8 Apr 2024 10:38:38 -0600 Subject: [PATCH] debug workflow for Dataset objects --- README.md | 1 + rabpro/basin_stats.py | 8 ++++++-- tests/test_basin_stats.py | 6 ++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b935e9f6..08caaf37 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ or MERIT-Hydro: ```python python -m pytest +python -m pytest -k "test_img" ``` ### Local docs build diff --git a/rabpro/basin_stats.py b/rabpro/basin_stats.py index 795ec505..5dc91fa9 100644 --- a/rabpro/basin_stats.py +++ b/rabpro/basin_stats.py @@ -85,6 +85,9 @@ def __init__( self.prepend = prepend_label self.type = gee_type + def __str__(self): + return str(self.__class__) + ": " + str(self.__dict__) + def dataset_to_filename(prepend, data_id, band=None): """ @@ -405,10 +408,11 @@ def compute( else: imgcol = ee.ImageCollection(d.data_id).select(d.band) - if d.mosaic == True: # Don't use 'is' because numpy booleans aren't the same object type, == bypasses this + if ( + d.mosaic == True + ): # Don't use 'is' because numpy booleans aren't the same object type, == bypasses this imgcol = ee.ImageCollection(imgcol.mosaic()) - if len(d.time_stats) > 0: time_reducer = _parse_reducers(base=getattr(ee.Reducer, d.time_stats[0])()) imgcol = imgcol.reduce(time_reducer) diff --git a/tests/test_basin_stats.py b/tests/test_basin_stats.py index c51a76c1..1792bf0a 100644 --- a/tests/test_basin_stats.py +++ b/tests/test_basin_stats.py @@ -128,12 +128,13 @@ def test_nontimeindexed_imgcol(): def test_img(): + stat_list = ["min", "max", "range", "std", "sum", "pct50", "pct3"] data, _ = rabpro.basin_stats.compute( [ Dataset( "JRC/GSW1_4/GlobalSurfaceWater", "occurrence", - stats=["min", "max", "range", "std", "sum", "pct50", "pct3"], + stats=stat_list, ) ], gee_feature_path="users/jstacompute/basins", @@ -143,4 +144,5 @@ def test_img(): res = pd.DataFrame(data[0]["features"][0]["properties"], index=[0]) assert float(res["mean"]) > 0 - assert res.shape[1] == 11 + # mean, count, id, and id_outlet are automatically returned + assert res.shape[1] == len(stat_list) + 4