Information
Transformation: | Weighted |
---|---|
Transformation Group: | InterpolationSpatial |
Description: | For each time step this transformation calculates the weighted average of the input variables. The weights are re-scaled so that the total weight becomes 1. If for a given time an input variable has a missing value, then for that time that input variable is ignored and the weights of the other input variables are re-scaled so that the total weight becomes 1. |
Hydrological Information
Purpose and use of Transformation: | This transformation can for example be used to calculate the weighted average of the amount of rainfall of a number of locations in a catchment. |
---|---|
Background and Exceptions: | Can only be used for scalar time series, not for grids |
Configuration
There are two possible ways to configure this transformation:
- Defining the input time series and the weight of each input time series in the module config file using <weightedInputVariable> elements.
- Using two multi-value attributes of the output time series location to determine the input time series and their weights respectively (available since 2017.02).
The way to configure the input and output variables for these two options will be explained separately. Note that the first option uses the <weightedInputVariable> elements in combination with a regular <outputVariable> element, while the second option uses a single (regular) <inputVariable> element in combination with an <attributedOutputVariable> element. It is not possible to combine the input and output variable element options in a different way.
Both configuration options support an optional element <minInputValuesRequired> which is the minimum number of input variables that should have a non-missing value for the calculation. If for a given time the number of input variables that have a non-missing value is less than this configured minimum, then for that time the output value will be a missing value. This can be used for example to avoid getting output values of calculations for which very few input variables are available, because such calculations would be inaccurate. If <minInputValuesRequired> is not specified, then it will be set to 1.
Configuration using weighted input variables
Input
One or more weighted input variables (<weightedInputVariable> elements). Each input variable has a weight.
Output
Weighted average (a regular <outputVariable> element).
Configuration Example
In the example below there are 4 input variables for locations 1 to 4. The weights for these locations are 0.3, 0.2, 0.1 and 0.4. The sum of these werights is 1.0. When the output time series is calculated, the series of locations 1 to 4 will be multiplied with the configured weight: 0.3 * location1, 0.2 * location2, 0.1 * location3 and 0.4 * location4. The result value will then be divided by the sum of the weights of non-missing time series. When all series have a value for the calculation timestep the sum will be divided by 1. When the value of location4 is missing the sum will be divided by 0.6.
<transformation id="interpolation spatial weighted"> <interpolationSpatial> <weighted> <weightedInputVariable> <inputVariable> <variableId>location1</variableId> </inputVariable> <weight>0.3</weight> </weightedInputVariable> <weightedInputVariable> <inputVariable> <variableId>location2</variableId> </inputVariable> <weight>0.2</weight> </weightedInputVariable> <weightedInputVariable> <inputVariable> <variableId>location3</variableId> </inputVariable> <weight>0.1</weight> </weightedInputVariable> <weightedInputVariable> <inputVariable> <variableId>location4</variableId> </inputVariable> <weight>0.4</weight> </weightedInputVariable> <minInputValuesRequired>2</minInputValuesRequired> <outputVariable> <variableId>average</variableId> </outputVariable> </weighted> </interpolationSpatial> </transformation>
Configuration using multi-value attributes
Available since 2017.02.
Input
A single <inputVariable> element should be configured, with a locationSet containing all possible input locations.
Output
An <attributedOutputVariable> element specifying the <outputVariable> and the attributes <locationIdAttribute> and <weightAttribute> used to determine the input locations and their weights respectively. Note that the attributes should be available for each location if a locationSet is used (the attributeExists constraint can be used to create a new locationSet from an existing locationSet if necessary). Also note that when configuring the multi-value attributes there should never be a an empty value for one of the attribute, otherwise the input locations and weights will not be combined correctly. Finally, note that <locationIdAttribute> should be a text attribute, while <weightAttribute> should be a number attribute.
Configuration Example
In the configuation example below where the <attributedOutputVariable> element is used instead of the <outputVariable>, the configuration uses location attribute information from meta data files. The function then loops over all locations in the locationSet of the output variable and retreives the input location ID's and weights from the location attributes. For output location output_id_2, there are two input locations with weights: input_id_1 * 0.5 and input_id_2 * 0.5. The calculated output value will then be divided by 0.5+0.5 if both input values are non-missing or 0.5 is input value for input_id_1 is missing.
<transformation id="interpolation spatial weighted"> <interpolationSpatial> <weighted> <inputVariable> <variableId>input</variableId> </inputVariable> <attributedOutputVariable> <outputVariable> <variableId>output</variableId> </outputVariable> <locationIdAttribute>LOCS</locationIdAttribute> <weightAttribute>WEIGHTS</weightAttribute> </attributedOutputVariable> </weighted> </interpolationSpatial> </transformation>
<locationSet id="WeightedWithAttributesOutputLocs"> <csvFile> <file>WeightedWithAttributesOutputLocs.csv</file> <id>%ID%</id> <x>%X%</x> <y>%Y%</y> <attributeFile> <csvFile>WeightedWithAttributesOutputLocs_Attributes.csv</csvFile> <id>%OUTID%</id> <attribute id="LOCS"> <text>%INID%</text> </attribute> <attribute id="WEIGHTS"> <number>%WEIGHT%</number> </attribute> </attributeFile> </csvFile> </locationSet>
OUTID, INID, WEIGHT output_id_1, input_id_1, 1 output_id_2, input_id_1, 0.5 output_id_2, input_id_2, 0.5 output_id_3, input_id_1, 0.5 output_id_3, input_id_3, 0.5 output_id_4, input_id_1, 0.1 output_id_4, input_id_2, 0.3 output_id_4, input_id_4, 0.6