Skip to content

Extract exposure by LSE#11554

Open
ptormene wants to merge 34 commits into
masterfrom
lse_by_tier
Open

Extract exposure by LSE#11554
ptormene wants to merge 34 commits into
masterfrom
lse_by_tier

Conversation

@ptormene

@ptormene ptormene commented Jun 16, 2026

Copy link
Copy Markdown
Member

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.

ptormene added 20 commits June 10, 2026 17:18
…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
…xpected reference files for liquefaction and landslide)
@ptormene ptormene added this to the Engine 3.26.0 milestone Jun 16, 2026
@ptormene ptormene requested a review from micheles June 16, 2026 09:19
@ptormene ptormene self-assigned this Jun 16, 2026
@ptormene ptormene changed the title Lse by tier Extract exposure by LSE Jun 16, 2026
'occupants_avg': 'Average number of occupants',
'mmi': ('Macroseismic intensity (MMI) to which the given group'
' of assets is subjected'),
'embodied_carbon': 'Embodied carbon',

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@catarinaquintela what's the measurement unit we are using for embodied carbon?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's Tonnes of CO2e

@ptormene ptormene marked this pull request as ready for review June 16, 2026 15:01
'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)',

@micheles micheles Jun 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This string appears in the command-line, it should not contain HTML tags, rather the WebUI should do the translation work if desired.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread openquake/risklib/asset.py Outdated
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]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you can start from 0 and not -inf

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, if we are sure that it is impossible to observe any tiny negative values due for instance to numerical approximations.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generating negative values would be an error, and it is always better not to hide it.

Comment thread openquake/server/views.py Outdated


def _decode(v):
return v.decode('utf-8') if isinstance(v, bytes) else v

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}')

@micheles micheles Jun 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread openquake/server/views.py
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just use decode(row), since baselib.decode is smart

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants