Skip to content

Instantly share code, notes, and snippets.

@ConorIA
Last active December 16, 2021 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ConorIA/3713d2f4a0028b68f666ce3d561ddbbf to your computer and use it in GitHub Desktop.
Save ConorIA/3713d2f4a0028b68f666ce3d561ddbbf to your computer and use it in GitHub Desktop.
Last time it was > 15°C at UTSC in December
library(readr)
library(purrr)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

files <- paste0("https://weather.utsc.utoronto.ca/data/", 2013:2020,
                "/Hourly_", 2013:2020, "_12.dat")
files[7] <- "https://weather.utsc.utoronto.ca/data/2019/Hourly_2019_12_CR1000.dat"

# The files have an inconsistent file structure. This is really sloppy.
names13 <- colnames(read_csv(files[2], skip = 1, show_col_types = FALSE))
dat13 <- read_csv(files[1], skip = 1, show_col_types = FALSE)
dat14to18 <- map_df(files[2:6], ~read_csv(., skip = 3, show_col_types = FALSE))
#> New names:
#> * `` -> ...1
#> * `` -> ...2
#> * `` -> ...3
#> * `` -> ...4
#> * `` -> ...5
#> * ...
#> New names:
#> * `` -> ...1
#> * `` -> ...2
#> * `` -> ...3
#> * `` -> ...4
#> * `` -> ...5
#> * ...
#> New names:
#> * `` -> ...1
#> * `` -> ...2
#> * `` -> ...3
#> * `` -> ...4
#> * `` -> ...5
#> * ...
#> New names:
#> * `` -> ...1
#> * `` -> ...2
#> * `` -> ...3
#> * `` -> ...4
#> * `` -> ...5
#> * ...
#> New names:
#> * `` -> ...1
#> * `` -> ...2
#> * `` -> ...3
#> * `` -> ...4
#> * `` -> ...5
#> * ...
names(dat13) <- names13
names(dat14to18) <- names13
names22 <- colnames(read_csv(files[7], skip = 1, show_col_types = FALSE))
dat19to20 <- map_df(files[7:8], ~read_csv(., skip = 3, show_col_types = FALSE))
#> New names:
#> * `` -> ...1
#> * `` -> ...2
#> * Avg -> Avg...3
#> * Max -> Max...4
#> * TMx -> TMx...5
#> * ...
#> New names:
#> * `` -> ...1
#> * `` -> ...2
#> * Avg -> Avg...3
#> * Max -> Max...4
#> * TMx -> TMx...5
#> * ...
names(dat19to20) <- names22

# Sloppy merge all of these
dat <- bind_rows(dat13, dat14to18, dat19to20)

dat %>% filter(AirTC_AVG > 15 | AirT_C_AVG > 15 | AirT_C_MAX > 15)
#> # A tibble: 3 × 32
#>   TIMESTAMP           RECORD AirTC_AVG    RH DewP_AVG BP_kPa_AVG Rain_mm_TOT
#>   <dttm>               <dbl>     <dbl> <dbl>    <dbl>      <dbl>       <dbl>
#> 1 2013-12-05 11:59:00   1701      15.0  81.4    12.6        100.           0
#> 2 2013-12-05 12:59:00   1702      15.7  74.2    11.8        100.           0
#> 3 2013-12-05 13:59:00   1703      15.5  62.5     9.02       100.           0
#> # … with 25 more variables: WS_kph_AVG <dbl>, WindDir <dbl>, SlrW_AVG <dbl>,
#> #   SlrkJ_2_TOT <dbl>, Hdex_C_AVG <dbl>, WC_C_AVG <dbl>, AirT_C_AVG <dbl>,
#> #   AirT_C_MAX <dbl>, AirT_C_TMx <dttm>, AirT_C_MIN <dbl>, AirT_C_TMn <dttm>,
#> #   DewP_C_AVG <dbl>, RH_% <dbl>, BP_kPa_Avg <dbl>, WS_kph_S_WVT <dbl>,
#> #   WindDir_D1_WVT <dbl>, Rain_mm_Tot <dbl>, Slr_W_AVG <dbl>, Slr_kJ_TOT <dbl>,
#> #   WC_C_Avg <dbl>, Snow_Depth_cm_AVG <dbl>, Snow_Depth_cm_MAX <dbl>,
#> #   Snow_Depth_TMx <dttm>, Snow_Depth_cm_MIN <dbl>, Snow_Depth_TMn <dttm>

Created on 2021-12-16 by the reprex package (v2.0.1)

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