Description Usage Arguments Value References Examples
View source: R/analyze_weather.R
The function analyze_weather
calculates some proxies for weather conditions based on
time series of snow depth, precipitation, and minimum, maximum, and average
temperature for a given year. The functions n_days
,
n_events
, and duration_events
calculate the number of days,
number of events, and duration of events of type 3 and 4 based on
the output of the function analyze_weather
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | analyze_weather(
date,
snow_depth,
precipitation,
temp_min,
temp_max,
temp_avg,
start = c("first_permanent_snow", "first_date", "other date")[1],
plot_first_snow = FALSE,
set_start = NULL,
ev3_temp_min_thr = -2,
ev3_temp_max_thr = +2,
ev3_prec_thr = 3,
ev4_temp_avg_day = +1,
ev4_temp_avg_next_day = -1,
ev4_prec_thr = 3,
evX_temp_max_thr_day = +1,
evX_temp_min_thr_next_day = -2,
evX_number_days_after = 3,
evX_prec_thr = 3,
...
)
n_days(weather_analyzed, event = 3, first_half = TRUE)
n_events(weather_analyzed, event = 3, first_half = TRUE)
duration_event(weather_analyzed, event = 3, first_half = TRUE)
|
date |
date object. vector. Vector of dates in a time series of a given winter. |
snow_depth |
numeric. vector. Daily snow depth, in mm. |
precipitation |
numeric. vector. Precipitation accumulated each day, in mm. |
temp_min |
numeric. vector. Minimum daily temperature, in Celsius. |
temp_max |
numeric. vector. Minimum daily temperature, in Celsius. |
temp_avg |
numeric. vector. Average daily temperature, in Celsius. |
start |
character. Whether the analysis should be done from the
"first_permanent_snow", from the "first_date" of the time series, or from
"other_date". In the first case, it uses the function
|
plot_first_snow |
logical. Whether or not to plot the time series of snow and the estimated start for analyzing the time series |
set_start |
POSIX. Starting date of the analysis, in case |
... |
other parameters for the functions
|
weather_analyzed |
list. output list from the function |
event |
numeric. Which type of event (3 or 4). |
first_half |
logical. Whether to get events from the whole winter (FALSE) or only from the first half of the winter (TRUE), when the effects of these events may be worse. |
A list with three elements:
weather_indices
a data.frame with the original data plus time series of some indices calculated: cumumative precipitation, the ratio between snow and cumulative precipitation, the ratio between cumulative precipitation and snow, the difference between cumulative precipitation and snow, and when events 3 and 4 happened.
events3
a list with information about events 3. See the output from the function
identify_winter_event3
.
events4
a list with information about events 4. See the output from the function
identify_winter_event4
.
Lundqvist, H., Norell, L., Danel, O. 2007. Multivariate characterisation of environmental conditions for reindeer husbandry in Sweden. Rangifer, 27(1): 5-23.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | library(tidyverse)
data(weather_mittadalen)
# select one year
weather <- weather_mittadalen %>%
dplyr::filter(year == 2015)
# analyze weather
weather_condition <-
with(weather, analyze_weather(date, snow_depth, prec, temp_min, temp_max,
temp_avg, start = "first_permanent_snow",
plot_first_snow = T))
weather_condition
n_days(weather_condition, event = 4)
n_events(weather_condition, event = 3)
n_events(weather_condition, event = 3, first_half = F)
# plot
weather_condition$weather_indices %>%
ggplot(aes(date)) +
geom_line(aes(y = snow_depth, color = "snow depth")) +
geom_line(aes(y = cumulative_precitation, color = "cum prec")) +
geom_line(aes(y = 100*prec_snow_ratio, color = "100*cum prec/snow depth")) +
geom_hline(yintercept = 100, linetype = 2) +
ylim(0, 250) +
labs(x = "Date", y = "Amount (mm)", color = "")
# plot with events
weather_condition %>%
plot_weather(term = c("snow_depth", "cum", "prec", "temp_max")) +
geom_vline(xintercept = weather_condition$events3$event_dates, linetype = 2)
weather_condition %>%
plot_weather(term = c("snow_depth", "cum", "prec", "temp_max"),
add_events = c("events3", "eventsX"), first_half = F)
# for several years
n_weather <- weather_mittadalen %>%
tidyr::nest(data = c(date, snow_depth, prec, temp_min, temp_max, temp_avg)) %>%
dplyr::mutate(
winter_conditions = purrr::map(data, ~ with(., analyze_weather(date, snow_depth, prec, temp_min, temp_max, temp_avg))),
n_days3 = purrr::map(winter_conditions, ~ n_days(., event = 3)),
n_days4 = purrr::map(winter_conditions, ~ n_days(., event = 4)),
n_events3 = purrr::map(winter_conditions, ~ n_events(., event = 3)),
n_events4 = purrr::map(winter_conditions, ~ n_events(., event = 4)),
duration3 = purrr::map(winter_conditions, ~ duration_event(., event = 3)),
duration4 = purrr::map(winter_conditions, ~ duration_event(., event = 4))
) %>%
tidyr::unnest(n_days3:n_events4)
n_weather %>%
dplyr::select(year, n_days3:n_events4) %>%
tidyr::pivot_longer(cols = n_days3:n_events4, names_to = "what", values_to = "val") %>%
ggplot(aes(x = year, y = val, color = what)) +
geom_line()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.