Hi there, I have two questions about aggregating outputs:
-
I am using a csv file for my exposure data and when I use the wizard to build a model I can’t see the field I want to aggregate.
-
My model is undertaking exposure analysis using the is_exposed function. I want to sum the value of buildings that are in my hazard vector (polygon) layer (i.e. are exposed). It seems I can sum the value but this returns both exposed and not exposed.
Thanks!
Hi Nick,
-
The wizard will only show you numeric attributes for some aggregation options. As your input data is from a CSV file, the attributes will default to text
type, which can’t be summed. The solution would be to add a line like set-attribute.replacement_cost = float(replacement_cost)
to your CSV bookmark in your project.ini file.
-
The simplest option is to filter the results first, so that you only include the exposed buildings. However, this is no good if you also want to count/sum the total portfolio (exposed + unexposed).
Another option is to manually edit the saved model config to do a more advanced aggregation (the wizard only lets you do simple aggregations). E.g. you can change the sum(exposure.replacement_cost)
bit in the model config into sum(if_then_else(consequence = 1, exposure.replacement_cost, 0.0))
Note that you’d need to turn the 0.0
into 0
if it’s an integer value rather than a floating-point value.
Another, slightly more advanced, option is to use a bucket()
aggregation that gives you total value of both exposed and unexposed assets, e.g.
bucket(pick: consequence = bucket, select: { sum(exposure.replacement_cost) as Total_value }, buckets: { exposed: 1, unexposed: 0 })
Hope that helps.
Tim