Expand this to see code
library(tidyverse)
library(janitor)Note: The heat warning criteria we used here is not the same as when we studied precautionary measures. It does not consider how many days the temperatures or heat index value was reached.
Here we enhance our weather station data to include prison protocol data. We do this both for our hourly readings and our daily summaries.
Will decide later if we add the prison info. That may need to be in more specific analysis.
library(tidyverse)
library(janitor)Here we want a function that will create the flags, once fed a tmp and heat index.
set_protocol_flag <- function(df, tmp_name, hi_name) {
df |> mutate(
tmp_flag = (case_when(
tmp_name >= 105 ~ TRUE,
.default = FALSE)),
hi_flag = (case_when(
hi_name >= 113 ~ TRUE,
.default = FALSE)),
protocol_flag = case_when(
tmp_flag == TRUE | hi_flag == TRUE ~ TRUE,
.default = FALSE)
)
}stations_hourly <- read_rds("data-processed/weather-logs/01-station-hourly-readings.rds")stations_hourly_protocol <- stations_hourly |>
mutate(
tmp_flag = (case_when(
tmp >= 105 ~ TRUE,
.default = FALSE)),
hi_flag = (case_when(
hi >= 113 ~ TRUE,
.default = FALSE)),
protocol_flag = case_when(
tmp_flag == TRUE | hi_flag == TRUE ~ TRUE,
.default = FALSE)
)
# check results
stations_hourly_protocol |>
select(-name) |>
filter(tmp > 100) |>
slice_sample(n = 10)stations_hourly_protocol |>
write_rds("data-processed/01-station-hourly-protocols.rds")stations_daily <- read_rds("data-processed/weather-logs/01-station-daily-summary.rds")
stations_daily |> glimpse()Rows: 17,453
Columns: 5
$ station_id <chr> "KABI", "KABI", "KABI", "KABI", "KABI", "KABI", "KABI", "KA…
$ name <chr> "ABILENE REGIONAL AIRPORT, TX US", "ABILENE REGIONAL AIRPOR…
$ date <date> 2023-01-01, 2023-01-02, 2023-01-03, 2023-01-04, 2023-01-05…
$ tmp_high <dbl> 78, 76, 60, 64, 63, 77, 63, 63, 77, 83, 83, 60, 64, 67, 67,…
$ hi_high <dbl> 76.7, 74.8, 56.9, 61.0, 60.2, 76.1, 62.1, 60.5, 75.3, 80.4,…
stations_daily_protocol <- stations_daily |>
mutate(
tmp_flag = (case_when(
tmp_high >= 105 ~ TRUE,
.default = FALSE)),
hi_flag = (case_when(
hi_high >= 113 ~ TRUE,
.default = FALSE)),
protocol_flag = case_when(
tmp_flag == "TRUE" | hi_flag == "TRUE" ~ TRUE,
.default = FALSE)
)
# check results
stations_daily_protocol |>
select(-name) |>
filter(tmp_high > 100) |>
slice_sample(n = 10)stations_hourly_protocol |>
filter(
station_id == "KUTS", date == "2023-06-07"
)stations_daily_protocol |> write_rds("data-processed/01-station-daily-protocols.rds")