Different number of hazard inputs for RiskScape

I’m just working on a RiskScape function at the moment that has multiple hazard inputs. Each hazard is a geotiff showing daily rainfall, and I’m looking at how this fills up tanks. I was wondering if there is a way to set up the function so I can have a different amount of hazard layers eg. run the same functions for the next five days of rainfall or the next 20 days. I can just do a loop in the function so that bit will work okay just a bit unsure if it would work for having the same function with a different number of inputs and outputs? I wanted a column in the csv for each day and the volume of water in the tank.Thanks

So presumably you’re already using the following approach to read in multiple hazard files:
https://riskscape.org.nz/docs/advanced/probabilistic/multi-file-hazard.html#probabilistic-multi-file-hazard

I think you’d want to pass your function a list of the hazard/rainfall values, and return a list of the tank level for each day. On the function side of things, it’s pretty simple. You just want to declare your function something like this in your project.ini file:

[type rainfall_reading]
type.day = integer
type.rainfall = nullable(floating)

[function tank_forecast]
location = blah.py
argument-types = [tank: anything, rainfall: list(rainfall_reading)]
return-type = list(floating)

In your Python code, the argument and return value will just be regular Python lists, so you don’t have to do anything special there.

Then in your model pipeline you would have a group step after you have sampled all the rainfall/hazard layers, but before you call your function, e.g.

group(by: exposure, select: {
      exposure,
      to_list({day: event.day, rainfall: hazard}) as hazard
      })  

That should turn the all sampled hazard/rainfall values into a list for each exposure (tank). The one gotcha is that RiskScape will not guarantee the ordering of the list, due to the multi-threaded nature of processing your model. That’s why we need to include the day in the rainfall_reading type we pass to your function. Your function would then need to sort the list by day, to make sure it’s in the correct order.

Your function could return a list of the forecast tank-levels for each day. For outputting these results, you could use the list_to_tuple() function to turn the list back into columns. E.g.

list_to_tuple(consequence, 20, 'tank_forecast')

That would result in columns tank_forecast0, tank_forecast1, tank_forecast2, ... tank_forecast19. You need to specify the maximum number of columns up front (i.e. 20). If these don’t exist in the list, the columns will just be empty/null in the result file. You could potentially use a model parameter so that it adjusts to the eact number of days you want, e.g.

list_to_tuple(consequence, $num_days, 'tank_forecast')

Finally, note that the list_to_tuple() function is currently a beta feature. This means:

  • You have to enable the beta plugin in order to use it, i.e. in your settings.ini file you need:
[global]
plugin = beta

See https://riskscape.org.nz/docs/reference/config/settings.html#settings-plugins

  • It may change in future, e.g. we might rename it, change the arguments it takes, changes the results to be one-based instead of zero-based, etc