Skip to content

Commit

Permalink
Add var and std statistics (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
caspervdw committed Oct 9, 2020
1 parent d55c119 commit 95be72a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Changelog of dask-geomodeling

- Added Exp, Log and Log10 RasterBlocks.

- Added "std" and "var" statistics to TemporalAggregate.


2.2.12 (2020-09-29)
-------------------
Expand Down
8 changes: 5 additions & 3 deletions dask_geomodeling/raster/temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Snap(RasterBlock):
store (RasterBlock): Return cell values from this raster
index (RasterBlock): Snap values to the timestamps from this raster
Returns:
Returns:
RasterBlock with temporal properties of the index.
"""

Expand Down Expand Up @@ -335,7 +335,7 @@ def count_not_nan(x, *args, **kwargs):
class TemporalAggregate(BaseSingle):
"""
Resample a raster in time.
This operation performs temporal aggregation of rasters, for example a
hourly average of data that has a 5 minute resolution.. The timedelta of
the resulting raster is determined by the 'frequency' parameter.
Expand All @@ -348,7 +348,7 @@ class TemporalAggregate(BaseSingle):
with output timestamp at the end of the source raster period.
Defaults to None.
statistic (string): The type of statistic to perform. Can be one of
``{"sum", "count", "min", "max", "mean", "median", "p<percentile>"}``.
``{"sum", "count", "min", "max", "mean", "median", "std", "var", "p<percentile>"}``.
Defaults to ``"sum"``.
closed (string or None): Determines what side of the interval is closed.
Can be ``"left"`` or ``"right"``. The default depends on the frequency.
Expand All @@ -373,6 +373,8 @@ class TemporalAggregate(BaseSingle):
"max": {"func": np.nanmax, "extensive": False},
"mean": {"func": np.nanmean, "extensive": False},
"median": {"func": np.nanmedian, "extensive": False},
"std": {"func": np.nanstd, "extensive": False},
"var": {"func": np.nanvar, "extensive": False},
# 'percentile' is hardcoded to np.nanpercentile
}

Expand Down
10 changes: 10 additions & 0 deletions dask_geomodeling/tests/test_raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,16 @@ def test_get_data_median(self):
result = view.get_data(**self.request_all)
assert_equal(result["values"], [[[1.0, 0.0, result["no_data_value"]]]])

def test_get_data_std(self):
view = self.klass(self.raster, "M", statistic="std")
result = view.get_data(**self.request_all)
assert_equal(result["values"], [[[0.0, 0.0, result["no_data_value"]]]])

def test_get_data_var(self):
view = self.klass(self.raster, "M", statistic="var")
result = view.get_data(**self.request_all)
assert_equal(result["values"], [[[0.0, 0.0, result["no_data_value"]]]])

def test_get_data_percentile(self):
view = self.klass(self.raster, "M", statistic="p95")
result = view.get_data(**self.request_all)
Expand Down

0 comments on commit 95be72a

Please sign in to comment.