Skip to content

Commit 98683e3

Browse files
add sum algorithm (#1212)
1 parent 3253b18 commit 98683e3

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## Unreleased
44

5+
## 0.23.1 (2025-08-27)
6+
7+
### titiler.core
8+
9+
* add `sum` algorithm
10+
511
## 0.23.0 (2025-08-26)
612

713
### titiler.core

docs/src/user_guide/algorithms.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ We added a set of custom algorithms:
2222
- `mean`: Return **Mean** values along the `bands` axis.
2323
- `std`: Return the **Standard Deviation** along the `bands` axis.
2424
- `var`: Return **Variance** along the `bands` axis.
25+
- `sum`: Return **Sum** along the `bands` axis.
2526

2627

2728
### Usage

src/titiler/core/tests/test_algorithms.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ def test_ops():
328328
("mean", numpy.ma.mean, {}),
329329
("std", numpy.ma.std, {"ddof": 1}),
330330
("var", numpy.ma.var, {"ddof": 1}),
331+
("sum", numpy.ma.sum, {}),
331332
],
332333
)
333334
def test_math_algorithm(name, numpy_method, options):

src/titiler/core/titiler/core/algorithm/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from titiler.core.algorithm.base import BaseAlgorithm
1414
from titiler.core.algorithm.dem import Contours, HillShade, Slope, TerrainRGB, Terrarium
1515
from titiler.core.algorithm.index import NormalizedIndex
16-
from titiler.core.algorithm.math import _Max, _Mean, _Median, _Min, _Std, _Var
16+
from titiler.core.algorithm.math import _Max, _Mean, _Median, _Min, _Std, _Sum, _Var
1717
from titiler.core.algorithm.ops import CastToInt, Ceil, Floor
1818

1919
default_algorithms: Dict[str, Type[BaseAlgorithm]] = {
@@ -32,6 +32,7 @@
3232
"mean": _Mean,
3333
"std": _Std,
3434
"var": _Var,
35+
"sum": _Sum,
3536
}
3637

3738

src/titiler/core/titiler/core/algorithm/math.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from titiler.core.algorithm.base import BaseAlgorithm
77

8-
__all__ = ["_Min", "_Max", "_Median", "_Mean", "_Std", "_Var"]
8+
__all__ = ["_Min", "_Max", "_Median", "_Mean", "_Std", "_Var", "_Sum"]
99

1010

1111
class _Min(BaseAlgorithm):
@@ -136,3 +136,24 @@ def __call__(self, img: ImageData) -> ImageData:
136136
metadata=img.metadata,
137137
cutline_mask=img.cutline_mask,
138138
)
139+
140+
141+
class _Sum(BaseAlgorithm):
142+
"""Return Sum values along the `bands` axis."""
143+
144+
title: str = "Sum"
145+
description: str = "Return Sum values along the `bands` axis."
146+
147+
output_nbands: int = 1
148+
149+
def __call__(self, img: ImageData) -> ImageData:
150+
"""Return Min."""
151+
return ImageData(
152+
numpy.ma.sum(img.array, axis=0, keepdims=True),
153+
assets=img.assets,
154+
crs=img.crs,
155+
bounds=img.bounds,
156+
band_names=["sum"],
157+
metadata=img.metadata,
158+
cutline_mask=img.cutline_mask,
159+
)

0 commit comments

Comments
 (0)