Skip to content

Instantly share code, notes, and snippets.

@jbkunst
Created August 18, 2023 22:09
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 jbkunst/4e44c7fac2bcfc9337c4655a1e6a850b to your computer and use it in GitHub Desktop.
Save jbkunst/4e44c7fac2bcfc9337c4655a1e6a850b to your computer and use it in GitHub Desktop.
library(tidyverse)
# DMC
agrometR::estaciones_agromet
agrometR::estaciones_dmc |>
filter(str_detect(nombreEstacion, "uinta"))
data <- agrometR::get_agro_data_dmc(
stations_id = 330020,
date_start = "2022-01-01 00:00:00",
date_end = "2023-08-30 23:59:59",
verbose = TRUE
)
data <- data |>
select(station_id, momento, contains("aguaCaida"))
glimpse(data)
data |>
# filter(day(momento) %in% c(21:23)) |>
pivot_longer(cols = contains("aguaCaida")) |>
ggplot(aes(momento, value, group = name)) +
geom_line() +
facet_wrap(vars(name), scales = "free", ncol = 1) +
theme_minimal()
data |>
# View()
# filter(day(momento) %in% c(21:23), month(momento) %in% 7) |>
mutate(
# utc?
# momento = momento - hours(4),
momento_dia = floor_date(momento, unit = "day"),
# desfase
# fecha_nueva = momento - hours(12),
# fecha_nueva_dia = ceiling_date(fecha_nueva, unit = "day"),
hora = case_when(
hour(momento) <= 6 ~ 1,
hour(momento) <= 12 ~ 2,
hour(momento) <= 18 ~ 3,
hour(momento) <= 24 ~ 4,
)
) |>
group_by(momento_dia, hora) |>
summarise(prec = max(aguaCaida6Horas)) |>
ungroup() |>
mutate(
m1 = momento_dia - hours(16),
# m2 = momento_dia - hours(20),
# m3 = momento_dia - hours(22),
# m4 = momento_dia - hours(24),
# m5 = momento_dia - hours(25)
momento_dia2 = floor_date(m1, unit = 'day')
) |>
group_by(momento_dia2) |>
summarise(prec = sum(prec)) |>
ungroup() |>
group_by(floor_date(momento_dia2, unit = 'month')) |>
summarise(prec = sum(prec)) |>
View()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment