Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add band neighboorhood operator #59

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading