Python script to work as a function

Hey there,
I am having some issues with Riskscape using pandas as my Python script needs to read some csv files. Riskscape is claiming there is no module named pandas and is failing to continue when i am specifying a function.

Essentially I am trying to get Riskscape to read my Asset exposure data and read the estimated damage off the CSV file.

Cheers,
James

Kia ora James,

By default, RiskScape comes with a Java-based Python implementation called Jython. It’s a little different to the ‘normal’ Python (CPython) that you might be familiar with. There’s more about the difference here:
https://riskscape.org.nz/docs/reference/functions/python.html#jython-vs-cpython

RiskScape can use CPython (which will give you pandas support), but there’s an extra setup step to tell RiskScape where Python is installed on your system. Follow these setup instructions:
https://riskscape.org.nz/docs/reference/functions/cpython.html#configuring-cpython-support-in-riskscape

However, generally we don’t recommend trying to read your asset file from within your Python function, if that’s what you’re trying to do. The asset layer should be being read in as the exposure-layer for your model. The Python function gets called once for every individual asset in the exposure-layer. So if your Python function is trying to read in all the assets again, then your model could have strange behaviour.

If your asset data already contains a pre-computed damage, then you might be better off using a table model:
https://riskscape.org.nz/docs/intermediate/table-models.html

Hope that makes sense. If you’ve got more questions about this, it might help to provide a few more details about what you’re trying to do in your model.

Cheers,
Tim

1 Like