Skip to content

Commit

Permalink
Merge pull request #59 from geo-engine/band-neighborhood
Browse files Browse the repository at this point in the history
add band neighboorhood operator
  • Loading branch information
jdroenner authored Aug 9, 2024
2 parents c51e521 + 13c6130 commit 3a4e335
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

- [Operators](./operators/intro.md)

- [BandNeighborhoodAggregate](./operators/band-neighborhood-aggregate.md)
- [BandwiseExpression](./operators/bandwise-expression.md)
- [ColumnRangeFilter](./operators/columnrangefilter.md)
- [Expression](./operators/expression.md)
Expand Down
127 changes: 127 additions & 0 deletions src/operators/band-neighborhood-aggregate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# Band Neighborhood Agrgegate

The `BandNeighborhoodAggregate` operator performs a pixel-wise aggregate function over the neighboring bands.
The output is a raster time-series with the same number of bands as the input raster.
The pixel values are replaced by the result of the aggregate function.
This allows e.g. the computation of a moving average over the bands of a raster time-series.

## Parameters

| Parameter | Type | Description | Example Value |
| ----------- | ----------------------- | ------------------ | -------------------------------------- |
| `aggregate` | `NeighborhoodAggregate` | The aggrate method | `{"type": "average", "windowSize": 3}` |

## Types

The following describes the types used in the parameters.

### NeighborhoodAggregate

There are several types of neighborhood aggregate functions.

#### Average

This aggregate function computes the average of the neighboring bands.
The `windowSize` parameter defines the number of bands to consider for the average and must be an odd number.
For the borders, the window is reduced to the available bands.

##### Example

```json
{
"type": "average",
"windowSize": 3
}
```

#### FirstDerivative

This aggregate function computes and approximation of the first derivative of the neighboring bands using the central difference method.
Given the bands \\( x_i \\) and the pixel value \\( y_i \\) the derivative is computed as

\\[ f′(x_i​) \approx \frac{​y_{i+1} ​ − y_{i−1​​}}{x_{i+1}​ − x_{i−1}} \\]

and forward/backward difference for the endpoints

\\[ f′(x_1​) \approx \frac{y_2 - y_1}{x_2 - x_1} \\]

\\[ f′(x_n​) \approx \frac{y_n - y_{n-1}}{x_n - x_{n-1}} \\]

<!-- prettier-ignore -->
To compute the distance \\( x_{i+1}​ − x_{i−1} \\), a `bandDistance` parameter is required.

##### BandDistance

The `bandDistance` parameter defines the distance between the bands.
Currently, the band distance is assumed to be constant and can be specified in the following way:

```json
{
"type": "equallySpaced",
"distance": 1.0
}
```

#### Example

```json
{
"type": "firstDerivative",
"bandDistance": {
"type": "equallySpaced",
"distance": 1.0
}
}
```

## Inputs

The `BandNeighborhoodAggregate` operator expects a single raster input .

| Parameter | Type |
| --------- | -------------------- |
| `source` | `SingleRasterSource` |

## Errors

The operation fails if there are not enough bands in the input raster to compute the aggregate function or the number of bands does not match the requirements of the aggregate function.

## Example JSON

```json
{
"type": "BandNeighborhoodAggregate",
"params": {
"type": "average",
"windowSize": 3
},
"sources": {
"raster": {
"type": "RasterStacker",
"params": {},
"sources": {
"rasters": [
{
"type": "GdalSource",
"params": {
"data": "sentinel2-b8"
}
},
{
"type": "GdalSource",
"params": {
"data": "sentinel2-b4"
}
},
{
"type": "GdalSource",
"params": {
"data": "sentinel2-b2"
}
}
]
}
}
}
}
```
1 change: 1 addition & 0 deletions src/operators/band-neighborhood.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# BandNeighborhood

0 comments on commit 3a4e335

Please sign in to comment.