-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsbi_testing.R
106 lines (88 loc) · 6.26 KB
/
sbi_testing.R
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# SBI testing
rm(list = ls())
library(bcsnowdata)
library(bcsnowstats)
library(bcsnowsbi)
SBI_2022 <- bcsnowsbi::sbi_bybasin_function(date_sbi = as.Date("2022-04-01"),
all_basins = "Yes", # What basin to analyze SBI values for. Can also be "Yes" to get all SBI values for all basins
exceptions = c(), # No sites to remove from analysis
incorrect_sites = c(),
incorrect_data = c(), # No incorrect manual sites. Otherwise, can specify the site name and data that a manual site should be (in cases where it data was incorrectly entered).
save_csv = "No", # Do you want to save
path = "G:/Snow/sbi_archive/")
t <- SBI_2022[[1]]
SBI_2022 <- sbi_bybasin_function(date_sbi = "01-04-2022",
all_basins = "Yes", # What basin to analyze SBI values for. Can also be "Yes" to get all SBI values for all basins
exceptions = c(), # No sites to remove from analysis
incorrect_sites = c(), incorrect_data = c(), # No incorrect manual sites. Otherwise, can specify the site name and data that a manual site should be (in cases where it data was incorrectly entered).
save_csv = "Yes", # Do you want to save
path = "C:/Users/AJOLLYMO/RProjects/SnowData_archive/SBI_cache", # Path where you want to save a csv version of the results
force = FALSE, # Force re-analysis of data rather than getting data from cache
use_sbi_cache = FALSE)
drive = "\\\\DRAIN.dmz\\Shared"
test <- sbi_bybasin_function(date_sbi = Sys.Date(),
all_basins = "Yes", # What basin to analyze SBI values for. Can also be "Yes" to get all SBI values for all basins
exceptions = c(), # No sites to remove from analysis
incorrect_sites = c(), incorrect_data = c(), # No incorrect manual sites. Otherwise, can specify the site name and data that a manual site should be (in cases where it data was incorrectly entered).
save_csv = "Yes", # Do you want to save
path = paste0(drive, "/Real-time_Data/ASP_daily_interactive/data/SBI/") # Path where you want to save a csv version of the results
)
t <- test[[1]]
drive = "\\\\DRAIN.dmz\\Shared"
vancouverisland <- sbi_bybasin_function(date_sbi = "2022-05-01",
all_basins = "Vancouver Island", # What basin to analyze SBI values for. Can also be "Yes" to get all SBI values for all basins
exceptions = c(), # No sites to remove from analysis
incorrect_sites = c(), incorrect_data = c(), # No incorrect manual sites. Otherwise, can specify the site name and data that a manual site should be (in cases where it data was incorrectly entered).
save_csv = "Yes", # Do you want to save
path = paste0(drive, "/Real-time_Data/ASP_daily_interactive/data/SBI/") # Path where you want to save a csv version of the results
)
va_t <- vancouverisland[[2]]
ASWE_sites <- bcsnowdata::snow_auto_location()$LOCATION_ID
manual <- bcsnowstats::get_snow_stats(station_id = manual_sites,
survey_period = time_period,
get_year = get_year,
normal_min = normal_min,
normal_max = normal_max, force = FALSE)
# Function to save historic SBI
historic_sbi <- function(date) {
t <- sbi_bybasin_function(date_sbi = as.Date("2021-12-01"),
all_basins = "Yes", # What basin to analyze SBI values for. Can also be "Yes" to get all SBI values for all basins
exceptions = c(), # No sites to remove from analysis
incorrect_sites = c(), incorrect_data = c(), # No incorrect manual sites. Otherwise, can specify the site name and data that a manual site should be (in cases where it data was incorrectly entered).
save_csv = "Yes", # Do you want to save
path = paste0("G:/Snow/sbi_archive/"))
}
year <- 2018
# function for calculating and saving the sbi by year. For calculating the historic SBI values
get_sbi_archive <- function(year) {
dates <- c(as.Date(paste0(year-1, "-12-01")), as.Date(paste0(year, "-01-01")),
as.Date(paste0(year, "-02-01")),
as.Date(paste0(year, "-03-01")), as.Date(paste0(year, "-04-01")),
as.Date(paste0(year, "-05-01")), as.Date(paste0(year, "-05-15")),
as.Date(paste0(year, "-06-01")), as.Date(paste0(year, "-06-15")))
sbi_year <- function(date) {
sbi_temp <- sbi_bybasin_function(date_sbi = as.Date(date),
all_basins = "Yes", # What basin to analyze SBI values for. Can also be "Yes" to get all SBI values for all basins
exceptions = c(), # No sites to remove from analysis
incorrect_sites = c(), incorrect_data = c(), # No incorrect manual sites. Otherwise, can specify the site name and data that a manual site should be (in cases where it data was incorrectly entered).
save_csv = "Yes", # Do you want to save
path = paste0("G:/Snow/sbi_archive/sbi_archive_bymonth"))
sbi_temp_s <- sbi_temp[[1]] %>%
dplyr::select(-Sitesused_SBInew_oldnormals,
-mean_percentnormal_sbiprev,
-InitialSitesused, -sites_with_data,
-mean_normal_prev)
}
sbi_archive_list <- lapply(dates,
sbi_year)
sbi_archive <- do.call(dplyr::bind_rows,
sbi_archive_list) %>%
dplyr::arrange(Survey_period)
# Save unfolded by year
write.csv(sbi_archive, file = paste0("G:/Snow/sbi_archive/sbi_archive_byyear/sbi_archive_", year, ".csv"))
}
test_2000 <- get_sbi_archive(year = 2000)
# Run over multiple years
years_test <- seq(2000, 2022, by = 1)
lapply(years_test,
get_sbi_archive)