mirror of
https://github.com/dylanbenzi/hurricane_normalization_app.git
synced 2026-07-30 05:08:57 +00:00
update growth map to use indirect landfall states
This commit is contained in:
+131
-82
@@ -30,6 +30,8 @@ fips.counties <- tbl(con, I("fips.counties"))
|
|||||||
fips.states <- tbl(con, I("fips.states"))
|
fips.states <- tbl(con, I("fips.states"))
|
||||||
|
|
||||||
gis.affected_area_landfalls <- tbl(con, I("gis.affected_area_landfalls"))
|
gis.affected_area_landfalls <- tbl(con, I("gis.affected_area_landfalls"))
|
||||||
|
gis.indirect_landfalls <- tbl(con, I("gis.indirect_landfalls"))
|
||||||
|
gis.us_states_boundary <- tbl(con, I("gis.us_states_boundary"))
|
||||||
|
|
||||||
hurdat.best_track <- tbl(con, I("hurdat.best_track"))
|
hurdat.best_track <- tbl(con, I("hurdat.best_track"))
|
||||||
hurdat.hurdat_storms <- tbl(con, I("hurdat.hurdat_storms"))
|
hurdat.hurdat_storms <- tbl(con, I("hurdat.hurdat_storms"))
|
||||||
@@ -54,6 +56,7 @@ view.all_lf_type_landfalls <- tbl(con, "all_lf_type_landfalls")
|
|||||||
view.lf_id_location <- tbl(con, "lf_id_location")
|
view.lf_id_location <- tbl(con, "lf_id_location")
|
||||||
view.lf_landfall_gis <- tbl(con, "lf_landfall_gis")
|
view.lf_landfall_gis <- tbl(con, "lf_landfall_gis")
|
||||||
view.best_track_summary <- tbl(con, "best_track_summary")
|
view.best_track_summary <- tbl(con, "best_track_summary")
|
||||||
|
view.yearly_state_metrics <- tbl(con, "yearly_state_metrics")
|
||||||
#qry <- econ.storm_base_loss %>%
|
#qry <- econ.storm_base_loss %>%
|
||||||
# left_join(view.hurdat_track, by = c("storm_basin", "storm_year", "storm_name"))
|
# left_join(view.hurdat_track, by = c("storm_basin", "storm_year", "storm_name"))
|
||||||
|
|
||||||
@@ -417,91 +420,137 @@ get_hurdat_track <- function(storm) {
|
|||||||
get_normalized_metric_growth <- function(storm, full_lf_id) {
|
get_normalized_metric_growth <- function(storm, full_lf_id) {
|
||||||
lf_id_parts <- split_full_lf_id(full_lf_id)
|
lf_id_parts <- split_full_lf_id(full_lf_id)
|
||||||
|
|
||||||
affected_counties <- gis.affected_area_landfalls %>%
|
if (lf_id_parts$lf_type == 'LF') {
|
||||||
filter(
|
affected_counties <- gis.affected_area_landfalls %>%
|
||||||
storm_basin == storm$storm_basin,
|
filter(
|
||||||
storm_year == storm$storm_year,
|
storm_basin == storm$storm_basin,
|
||||||
storm_name == storm$storm_name,
|
storm_year == storm$storm_year,
|
||||||
lf_type == lf_id_parts$lf_type,
|
storm_name == storm$storm_name,
|
||||||
lf_id == lf_id_parts$lf_id
|
lf_type == lf_id_parts$lf_type,
|
||||||
) %>%
|
lf_id == lf_id_parts$lf_id
|
||||||
select(state_fips, county_fips)
|
) %>%
|
||||||
|
select(state_fips, county_fips)
|
||||||
|
|
||||||
baseline_metrics <- metrics.pop_and_housing %>%
|
baseline_metrics <- metrics.pop_and_housing %>%
|
||||||
filter(
|
filter(
|
||||||
year == storm$storm_year
|
year == storm$storm_year
|
||||||
) %>%
|
) %>%
|
||||||
inner_join(affected_counties, by = c("state_fips", "county_fips")) %>%
|
inner_join(affected_counties, by = c("state_fips", "county_fips")) %>%
|
||||||
select(
|
select(
|
||||||
state_fips,
|
state_fips,
|
||||||
county_fips,
|
county_fips,
|
||||||
baseline_population = population,
|
baseline_population = population,
|
||||||
baseline_housing = housing_units
|
baseline_housing = housing_units
|
||||||
)
|
|
||||||
|
|
||||||
normalized_metrics <- metrics.pop_and_housing %>%
|
|
||||||
filter(
|
|
||||||
year >= storm$storm_year
|
|
||||||
) %>%
|
|
||||||
inner_join(affected_counties, by = c("state_fips", "county_fips")) %>%
|
|
||||||
inner_join(baseline_metrics, by = c("state_fips", "county_fips")) %>%
|
|
||||||
mutate(
|
|
||||||
normalized_population = as.numeric(population) /
|
|
||||||
as.numeric(baseline_population),
|
|
||||||
normalized_housing = as.numeric(housing_units) /
|
|
||||||
as.numeric(baseline_housing)
|
|
||||||
) %>%
|
|
||||||
select(
|
|
||||||
state_fips,
|
|
||||||
county_fips,
|
|
||||||
year,
|
|
||||||
population,
|
|
||||||
housing_units,
|
|
||||||
normalized_population,
|
|
||||||
normalized_housing
|
|
||||||
)
|
|
||||||
|
|
||||||
query <- normalized_metrics %>%
|
|
||||||
inner_join(
|
|
||||||
public.counties,
|
|
||||||
by = c("state_fips" = "statefp", "county_fips" = "countyfp")
|
|
||||||
) %>%
|
|
||||||
mutate(
|
|
||||||
geom_wkt = sql(
|
|
||||||
"ST_AsText(ST_SimplifyPreserveTopology(ST_Transform(geom, 4326), .001))"
|
|
||||||
)
|
)
|
||||||
) %>%
|
|
||||||
select(
|
|
||||||
state_fips,
|
|
||||||
county_fips,
|
|
||||||
year,
|
|
||||||
population,
|
|
||||||
housing_units,
|
|
||||||
normalized_population,
|
|
||||||
normalized_housing,
|
|
||||||
geom_wkt
|
|
||||||
) %>%
|
|
||||||
arrange(state_fips, county_fips, year)
|
|
||||||
|
|
||||||
#query <- normalized_metrics %>%
|
normalized_metrics <- metrics.pop_and_housing %>%
|
||||||
# inner_join(
|
filter(
|
||||||
# public.counties,
|
year >= storm$storm_year
|
||||||
# by = c("state_fips" = "statefp", "county_fips" = "countyfp")
|
) %>%
|
||||||
# ) %>%
|
inner_join(affected_counties, by = c("state_fips", "county_fips")) %>%
|
||||||
# mutate(
|
inner_join(baseline_metrics, by = c("state_fips", "county_fips")) %>%
|
||||||
# geom_wkt = sql("ST_AsText(ST_Transform(geom, 4326))")
|
mutate(
|
||||||
# ) %>%
|
normalized_population = as.numeric(population) /
|
||||||
# select(
|
as.numeric(baseline_population),
|
||||||
# state_fips,
|
normalized_housing = as.numeric(housing_units) /
|
||||||
# county_fips,
|
as.numeric(baseline_housing)
|
||||||
# year,
|
) %>%
|
||||||
# population,
|
select(
|
||||||
# housing_units,
|
state_fips,
|
||||||
# normalized_population,
|
county_fips,
|
||||||
# normalized_housing,
|
year,
|
||||||
# geom_wkt
|
population,
|
||||||
# ) %>%
|
housing_units,
|
||||||
# arrange(state_fips, county_fips, year)
|
normalized_population,
|
||||||
|
normalized_housing
|
||||||
|
)
|
||||||
|
|
||||||
|
query <- normalized_metrics %>%
|
||||||
|
inner_join(
|
||||||
|
public.counties,
|
||||||
|
by = c("state_fips" = "statefp", "county_fips" = "countyfp")
|
||||||
|
) %>%
|
||||||
|
mutate(
|
||||||
|
geom_wkt = sql(
|
||||||
|
"ST_AsText(ST_SimplifyPreserveTopology(ST_Transform(geom, 4326), .001))"
|
||||||
|
)
|
||||||
|
) %>%
|
||||||
|
select(
|
||||||
|
state_fips,
|
||||||
|
county_fips,
|
||||||
|
year,
|
||||||
|
population,
|
||||||
|
housing_units,
|
||||||
|
normalized_population,
|
||||||
|
normalized_housing,
|
||||||
|
geom_wkt
|
||||||
|
) %>%
|
||||||
|
arrange(state_fips, county_fips, year)
|
||||||
|
} else {
|
||||||
|
affected_state <- gis.indirect_landfalls %>%
|
||||||
|
filter(
|
||||||
|
storm_basin == storm$storm_basin,
|
||||||
|
storm_year == storm$storm_year,
|
||||||
|
storm_name == storm$storm_name,
|
||||||
|
lf_type == lf_id_parts$lf_type,
|
||||||
|
lf_id == lf_id_parts$lf_id
|
||||||
|
) %>%
|
||||||
|
select(
|
||||||
|
state_fips
|
||||||
|
)
|
||||||
|
|
||||||
|
baseline_metrics <- view.yearly_state_metrics %>%
|
||||||
|
filter(year == storm$storm_year) %>%
|
||||||
|
inner_join(affected_state, by = "state_fips") %>%
|
||||||
|
select(
|
||||||
|
state_fips,
|
||||||
|
baseline_population = state_population,
|
||||||
|
baseline_housing = state_housing_units
|
||||||
|
)
|
||||||
|
|
||||||
|
normalized_metrics <- view.yearly_state_metrics %>%
|
||||||
|
filter(
|
||||||
|
year >= storm$storm_year
|
||||||
|
) %>%
|
||||||
|
inner_join(affected_state, by = "state_fips") %>%
|
||||||
|
inner_join(baseline_metrics, by = "state_fips") %>%
|
||||||
|
mutate(
|
||||||
|
normalized_population = as.numeric(state_population) /
|
||||||
|
as.numeric(baseline_population),
|
||||||
|
normalized_housing = as.numeric(state_housing_units) /
|
||||||
|
as.numeric(baseline_housing)
|
||||||
|
) %>%
|
||||||
|
select(
|
||||||
|
state_fips,
|
||||||
|
year,
|
||||||
|
population = state_population,
|
||||||
|
housing_units = state_housing_units,
|
||||||
|
normalized_population,
|
||||||
|
normalized_housing
|
||||||
|
)
|
||||||
|
|
||||||
|
query <- normalized_metrics %>%
|
||||||
|
inner_join(
|
||||||
|
gis.us_states_boundary %>%
|
||||||
|
rename(state_fips = statefp),
|
||||||
|
by = "state_fips"
|
||||||
|
) %>%
|
||||||
|
mutate(
|
||||||
|
geom_wkt = sql(
|
||||||
|
"ST_AsText(ST_SimplifyPreserveTopology(ST_Transform(wkb_geometry, 4326), .001))"
|
||||||
|
)
|
||||||
|
) %>%
|
||||||
|
select(
|
||||||
|
state_fips,
|
||||||
|
year,
|
||||||
|
population,
|
||||||
|
housing_units,
|
||||||
|
normalized_population,
|
||||||
|
normalized_housing,
|
||||||
|
geom_wkt
|
||||||
|
) %>%
|
||||||
|
arrange(state_fips, year)
|
||||||
|
}
|
||||||
|
|
||||||
result <- query %>% collect()
|
result <- query %>% collect()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user