Skip to content

Aggregation transformation

Description

This transformation can aggregate data across different dimensions, i.e. it produces a model with different set of items, and also potentially different temporal domain. Currently there are two main types of aggregation transformations: - aggregations across the time dimension - aggregations across the collection of items

Time dimension aggregations

Using these transformations you can aggregate data from all timesteps into one, using one of three predefined aggregation operators: Min, Max, Avg. The aggregation is done cell by cell, and the resulting model will have one or multiple items (depending on the selected aggregations) with a single timestep, representing the aggregated values. Other items are discarded.

Multiple aggregations are supported, e.g. you can produce a model which has one item with maximum values aggregated across all timesteps, and another item which has average values.

Example

This request to /api/conversion/upload-convert

{
    "readerName": "<reader name>",
    "writerName": "<writer name>",
    ...
    "transformations": [
    {
        "type": "AggregationTransformation",
        "aggregations": [
            { "aggregationType": "Max", "itemsFilter": { "type": "ItemNameFilter", "names": ["Item1", "Item2"] }}
        ]
    }
    ]
}

will produce a model with two items - one will have data aggregated from Item1, the other from Item2. In both cases each cell will contain the maximum value from all timesteps.

Item aggregations

It is possible to aggregate values from multiple items into one, on a cell-by-cell basis and timestep-per-timestep basis. So the resulting model will have the same temporal domain as the source model, but the collection of items will be defined by this transformation. Currently only one kind of aggregating operator is supported: WeightedSum. This operator will take values for each cell, apply a user-supplied weight and add them all together. The weights are supplied in property Expression and it should be a semicolon separated string of decimal values, with the same number of elements as the collection of items. Additionally the new item that results from the aggregation can have a custom name, defined in aggregatedItemName property of the aggregation object.

Example

This request to /api/conversion/upload-convert

{
    "readerName": "<reader name>",
    "writerName": "<writer name>",
    ...
    "transformations": [
    {
        "type": "AggregationTransformation",
        "aggregations": [
            { 
                "aggregationType": "WeightedSum", 
                "itemsFilter": { "type": "ItemNameFilter", "names": ["Item1", "Item2"] },
                "expression": "0.5;10",
                "aggregatedItemName": "MyWeightedSum"
            }
        ]
    }
    ]
}

will produce a model with one item (called MyWeightedSum). The data for this item will be created as a weighted sum, where each cell has value from original item Item1 multiplied by 0.5, and value from original Item2 multiplied by 10. Whenever the source data contains a fill value (data is missing), the resulting cell will also be empty / unfilled.

The Space dimension aggregation

Using this transformation you can aggregate data from a spatial domain into one value, using the defined aggregation operator MeanArea. The aggregation is done cell by cell, and the resulting model will have a single cell per item per time step. If the model has precalulated weights(see WeightedSpatialFiltering) then the weights are used in this transformation. This reduced spatial domain can be written into a Dfs0 file by MultidimensionalDfs0Writer. Combination of WeightedSpatialFilterTransformation and AggregationTransformation can be used for example to derive Dfs0 file with time series that are a result of mean area aggregated over a user defined polygon.

Example

This request to /api/metadata/dataset/{OresundHD.dfs2}/download-convert where {OresundHD.dfs2} is id of Multidimentional dataset from OresundHD.dfs2 sample file.

{
    "targetFileName": "OresundHD.dfs0",
    "readerName": "MDReader",
    "writerName": "MultidimensionalDfs0Writer",
    "transformations": [
        {
            "type": "AggregationTransformation",
            "Aggregations": [
                {
                    "type": "Aggregation",
                    "AggregationType": "MeanArea",
                    "ItemsFilter": {
                        "type": "ItemNameFilter",
                        "Names": [
                            "H Water Depth m",
                            "P Flux m^3/s/m",
                            "Q Flux m^3/s/m"
                        ]
                    }
                }
            ]
        }
    ]
}

will produce a model with three items (called MeanAre-H Water Depth m, MeanArea-P Flux m^3/s/m, MeanArea-Q Flux m^3/s/m). The data for this item will be created as a mean area aggregated over the whole spatial domain.