Extract exposure by LSE#11554
Conversation
…lide or liquefaction; use avg_gmf_array instead of gmf_data
…d to provide column descriptions only of the relevant items
… by landslide lse from the WebUI outputs_impact page
… they look numeric
…e data before presenting it
…xpected reference files for liquefaction and landslide)
| 'occupants_avg': 'Average number of occupants', | ||
| 'mmi': ('Macroseismic intensity (MMI) to which the given group' | ||
| ' of assets is subjected'), | ||
| 'embodied_carbon': 'Embodied carbon', |
There was a problem hiding this comment.
@catarinaquintela what's the measurement unit we are using for embodied carbon?
There was a problem hiding this comment.
There was a problem hiding this comment.
It's Tonnes of CO2e
…ata/scenario_risk/case_shakemap/sites.csv
| 'affectedpop': ('Number of people living in buildings ' | ||
| 'with moderate or higher damage'), | ||
| 'embodied_carbon': 'Embodied carbon loss', | ||
| 'embodied_carbon': 'Embodied carbon loss (tCO<sub>2</sub>e)', |
There was a problem hiding this comment.
This string appears in the command-line, it should not contain HTML tags, rather the WebUI should do the translation work if desired.
There was a problem hiding this comment.
I removed the html tags by using unicode characters in tCO₂e and m². It should be ok both when displayed in the browser and in the terminal.
| if secondary_peril == "liquefaction": | ||
| lse_col = "AllstadtEtAl2022Liquefaction_LSE" | ||
| tier_col = "liquefaction_lse_tier" | ||
| bins = [-numpy.inf, 0.005, 0.01, 0.02, 0.05, 0.1, 0.2, numpy.inf] |
There was a problem hiding this comment.
I guess you can start from 0 and not -inf
There was a problem hiding this comment.
Ok, if we are sure that it is impossible to observe any tiny negative values due for instance to numerical approximations.
There was a problem hiding this comment.
Generating negative values would be an error, and it is always better not to hide it.
…ds like tCO₂e and m², to avoid html tags
|
|
||
|
|
||
| def _decode(v): | ||
| return v.decode('utf-8') if isinstance(v, bytes) else v |
There was a problem hiding this comment.
We already have this function inside baselib.general
| # exposure_by_lse | ||
| for secondary_peril in ['liquefaction', 'landslide']: | ||
| df = extract(self.calc.datastore, | ||
| f'exposure_by_lse?secondary_peril={secondary_peril}') |
There was a problem hiding this comment.
There is a potential performance/memory issue here. Every time a user calls the API, the entire exposure and avg_gmf are read in memory and aggregated using pandas, which is very memory hungry. So the webserver can potentially explode (out of memory) and the user can potentially wait a lot of time even if the memory is enough, since the call is blocking. The solution is to use a "material view", i.e. performing the aggregation once at the end of the calculation and save it in the HDF5 file, similarly with how we save the PNG files instead of generating them at runtime in AELO. However, I would do that in a separate PR. We need a big calculation to test the performance.
| table_rows = [ | ||
| list(zip(table_header, [_decode(v) for v in row])) | ||
| list(zip(table_header, [decode(v) for v in row])) | ||
| for row in table_contents |
There was a problem hiding this comment.
You can just use decode(row), since baselib.decode is smart
I am adding the possibility to extract exposure aggregated by secondary peril LSE tiers and tags using a new API endpoint
GET /v1/calc/:calc_id/exposure_by_lse.Corresponding buttons are added to the oq-impact job outputs page, so the same results can be visualized similarly to
Show exposure by MMI table.