Skip to content

Commit

Permalink
enhance test and ghactions
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasK committed Oct 31, 2023
1 parent 627c6fd commit d3577f6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 32 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: pytest-dev
name: pytest

on:
push:
branches:
- dev
- [main,dev]

jobs:
pytest:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ruff.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Ruff
name: ruff

on:
push:
Expand All @@ -23,4 +23,4 @@ jobs:
args: format
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: 'ghactions/auto fix with ruff'
commit_message: 'gh-actions/python format using ruff'
1 change: 0 additions & 1 deletion examples/first_steps_create_datacube.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
intersects=geometry,
datetime=["2022-08-01", "2022-08-09"],
mask_with="native", # equal to "scl" for sentinel-2
mask_statistics=True,
clear_cover=50,
)

Expand Down
40 changes: 13 additions & 27 deletions tests/test_zonalstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,38 +43,24 @@ def test_numpy(self):
self.datacube,
self.gdf,
all_touched=True,
operations=dict(mean=np.nanmean, max=np.nanmax, min=np.nanmin),
)
self.assertTrue(
np.all(
zonalstats["first_var"].sel(stats="max").values
== np.asarray([[8, self.constant], [23, self.constant]])
)
)
self.assertTrue(
np.all(
zonalstats["first_var"].sel(stats="min").values
== np.asarray([[0, self.constant], [9, self.constant]])
)
operations=dict(mean=np.nanmean, max=np.nanmax, min=np.nanmin, mode=np.mode),
)

for operation in ['min','max', 'mode']:
self._check_results(zonalstats["first_var"].sel(stats=operation).values, operation=operation)

def test_basic(self):
zonalstats = earthdaily.earthdatastore.cube_utils.zonal_stats(
self.datacube, self.gdf, all_touched=True, operations=["min", "max", "mean"]
self.datacube, self.gdf, all_touched=True, operations=["min", "max", "mode"]
)
self.assertTrue(
np.all(
zonalstats["first_var"].sel(stats="max").values
== np.asarray([[8, self.constant], [23, self.constant]])
)
)
self.assertTrue(
np.all(
zonalstats["first_var"].sel(stats="min").values
== np.asarray([[0, self.constant], [9, self.constant]])
)
)

for operation in ['min','max','mode']:
self._check_results(zonalstats["first_var"].sel(stats=operation).values, operation=operation)

def _check_results(self, stats_values,operation='min'):
results = {"min":np.asarray([[0, self.constant], [9, self.constant]]),
"max":np.asarray([[8, self.constant], [23, self.constant]]),
"mode":np.asarray([[0, self.constant], [9, self.constant]])}
self.assertTrue(np.all(stats_values == results[operation]))

if __name__ == "__main__":
unittest.main()

0 comments on commit d3577f6

Please sign in to comment.