Skip to content

Update FEMA NRI analysis with new version of the data#879

Open
pmarchand1 wants to merge 1 commit intodevelopfrom
pmarchand1-eda-update
Open

Update FEMA NRI analysis with new version of the data#879
pmarchand1 wants to merge 1 commit intodevelopfrom
pmarchand1-eda-update

Conversation

@pmarchand1
Copy link
Copy Markdown
Collaborator

No description provided.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 25, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
datasci-earthquake Ready Ready Preview, Comment Mar 25, 2026 5:50pm

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request updates the exploratory data analysis of FEMA's National Risk Index for San Francisco, incorporating a newer version of the data and providing a more detailed explanation of the earthquake risk estimation methodology. It also introduces a new analysis that aggregates earthquake risk data by San Francisco neighborhoods, correlating it with renter occupancy rates to offer a more localized and socially nuanced perspective on earthquake vulnerability.

Highlights

  • Data Update: The FEMA National Risk Index (NRI) analysis has been updated to use the new v1.20 (December 2025) version of the data.
  • Enhanced Earthquake EAL Explanation: The explanation of the Expected Annual Loss (EAL) estimation for earthquakes has been significantly expanded, detailing the use of the Hazus model and its underlying methodologies.
  • New Neighborhood-Level Analysis: A new R Markdown file was added to summarize earthquake risk by San Francisco analysis neighborhood, incorporating additional census data on renter vs. owner-occupied households.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request significantly updates the EDA of FEMA earthquake risk index for San Francisco. The eda_fema_nri.Rmd document now includes more detailed documentation on the Hazus model for earthquake EAL estimation, introduces new per-capita and per-building-value loss ratios (EALP_ratio, EALB_ratio), and refines the commentary. A new R Markdown document, nri_neighborhoods.Rmd, has been added to aggregate the NRI data by San Francisco neighborhoods, integrate renter/owner occupancy data, and visualize the relationship between building loss ratio and renter percentage. The review comments point out several potential division-by-zero issues in the calculations for EALP_ratio, EALB_ratio, rent_pct, and EALB_PCT that could lead to Inf or NaN values, and suggest making the neighborhood data filename more maintainable.

### Expected damage to people

```{r, fig.width = 10}
nri <- mutate(nri, EALP_ratio = ERQK_EALP / ERQK_EXPP)
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.

medium

The calculation of EALP_ratio could result in division by zero if ERQK_EXPP is 0 for any census tract (e.g., for parks). This would produce Inf values, which might cause issues in plotting or subsequent analyses. It's safer to handle this case explicitly.

nri <- mutate(nri, EALP_ratio = if_else(ERQK_EXPP > 0, ERQK_EALP / ERQK_EXPP, 0))

### Expected damage to buildings

```{r, fig.width = 10}
nri <- mutate(nri, EALB_ratio = ERQK_EALB / ERQK_EXPB)
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.

medium

The calculation of EALB_ratio could result in division by zero if ERQK_EXPB (building exposure value) is 0 for any census tract. This would produce Inf values. To prevent potential issues in subsequent steps, it's better to handle this division by zero.

nri <- mutate(nri, EALB_ratio = if_else(ERQK_EXPB > 0, ERQK_EALB / ERQK_EXPB, 0))

The file matching each census tract to one of 42 analysis neighborhoods was downloaded from DataSF ([link](https://data.sfgov.org/Geographic-Locations-and-Boundaries/Analysis-Neighborhoods-2020-census-tracts-assigned/sevw-6tgi)).

```{r, message = FALSE}
neigh <- read_csv("Analysis_Neighborhoods_-_2020_census_tracts_assigned_to_neighborhoods_20251118.csv")
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.

medium

Hardcoding a filename with a date makes the script less maintainable. When the data is updated, this filename will need to be manually changed. It would be better to define the filename as a variable at the top of the script for easier updates.

"own", "rent")) %>%
select(TRACT, variable, estimate) %>%
pivot_wider(names_from = variable, values_from = estimate) %>%
mutate(rent_pct = rent / (rent + own) * 100)
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.

medium

The calculation for rent_pct could result in division by zero if rent + own is 0 (i.e., a tract with no households). Although you filter for population, this doesn't guarantee households are present. It's safer to add a check to prevent NaN values.

    mutate(rent_pct = if_else(rent + own > 0, rent / (rent + own) * 100, 0))

nri_neigh <- inner_join(nri, neigh) %>%
inner_join(own_rent) %>%
select(TRACT, neighborhood, POPULATION, RENT_PCT = rent_pct, ERQK_EALB, ERQK_EXPB) %>%
mutate(EALB_PCT = ERQK_EALB / ERQK_EXPB * 100)
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.

medium

The calculation of EALB_PCT could lead to division by zero if ERQK_EXPB is 0 for any tract. Even with a population filter, building exposure might be zero. It's safer to handle this case to prevent Inf or NaN values.

    mutate(EALB_PCT = if_else(ERQK_EXPB > 0, ERQK_EALB / ERQK_EXPB * 100, 0))

group_by(neighborhood) %>%
summarize(TOTAL_POP = sum(POPULATION),
RENT_PCT = weighted.mean(RENT_PCT, POPULATION),
EALB_PCT = sum(ERQK_EALB) / sum(ERQK_EXPB) * 100)
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.

medium

When summarizing by neighborhood, sum(ERQK_EXPB) could be zero if a neighborhood consists of tracts with no building value (e.g., a neighborhood that is entirely a park). This would cause a division-by-zero error. It's safer to add a check for this possibility.

              EALB_PCT = if_else(sum(ERQK_EXPB) > 0, sum(ERQK_EALB) / sum(ERQK_EXPB) * 100, 0))

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant