Skip to content

Commit

Permalink
debug workflow for Dataset objects
Browse files Browse the repository at this point in the history
  • Loading branch information
jsta committed Apr 8, 2024
1 parent bbdd46c commit fc6bbfa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ or MERIT-Hydro:

```python
python -m pytest
python -m pytest -k "test_img"
```

### Local docs build
Expand Down
8 changes: 6 additions & 2 deletions rabpro/basin_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions tests/test_basin_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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

0 comments on commit fc6bbfa

Please sign in to comment.