Skip to content

Commit

Permalink
Merge pull request #41 from IDEMSInternational/LC_changes
Browse files Browse the repository at this point in the history
Adding s_start_doy amendments
  • Loading branch information
lilyclements authored Oct 10, 2023
2 parents 7e76570 + b62dadf commit 3b7a89a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
4 changes: 3 additions & 1 deletion R/annual_rainfall_summaries.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ annual_rainfall_summaries <- function(country, station_id, summaries = c("annual
threshold = definitions$start_rains$threshold,
start_day = definitions$start_rains$start_day,
end_day = definitions$start_rains$end_day,
s_start_doy = definitions$start_rains$s_start_doy,
output = "doy",
total_rainfall = as.logical(definitions$start_rains$total_rainfall),
over_days = definitions$start_rains$over_days,
Expand Down Expand Up @@ -119,6 +120,7 @@ annual_rainfall_summaries <- function(country, station_id, summaries = c("annual
end_rains <- rpicsa::end_rains(daily, date_time = data_names$date, station = data_names$station, year = data_names$year, rain = data_names$rain,
start_day = definitions$end_rains$start_day,
end_day = definitions$end_rains$end_day,
s_start_doy = definitions$end_rains$s_start_doy,
output = "doy",
interval_length = definitions$end_rains$interval_length,
min_rainfall = definitions$end_rains$min_rainfall)
Expand All @@ -144,6 +146,7 @@ annual_rainfall_summaries <- function(country, station_id, summaries = c("annual
rain = data_names$rain,
start_day = definitions$end_season$start_day,
end_day = definitions$end_season$end_day,
s_start_doy = definitions$end_season$s_start_doy,
output = "doy",
capacity = definitions$end_season$capacity,
water_balance_max = definitions$end_season$water_balance_max,
Expand Down Expand Up @@ -210,7 +213,6 @@ annual_rainfall_summaries <- function(country, station_id, summaries = c("annual
stop("start_rains and at least one of end_season or end_rains is required to calculate seasonal_length")
}
}

list_return <- NULL
list_return[[1]] <- c(definitions)
list_return[[2]] <- summary_data
Expand Down
8 changes: 6 additions & 2 deletions tests/testthat/test-annual_rainfall_summaries.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
# summaries <- c("annual_rain")
# result <- epicsawrap::annual_rainfall_summaries(country, station_id, summaries)
#
# definitions <- definitions(country = "zm", station_id = "16",
# summaries = summaries)
# epicsadata::get_daily_data(country = country, station_id = station_id)
#
# country <- "zm"
# station_id_2 <- "16"
# summaries_2 <- c("start_rains", "end_rains", "annual_rain", "seasonal_rain")
Expand All @@ -22,10 +26,10 @@
# test_that("Error is thrown if undefined values", {
# # Test case 1: Error is thrown if undefined values
# expect_error(epicsawrap::annual_rainfall_summaries(country, station_id, "end_season"))
#
#
# # Test case 2: Error is thrown if start_ is not calculated but needed
# expect_error(epicsawrap::annual_rainfall_summaries(country, station_id_2, c("end_rains", "seasonal_rain")))
#
#
# # Test case 3: Warning if both end are given and seasonal wanted
# expect_warning(epicsawrap::annual_rainfall_summaries(country, station_id_2, c("start_rains", "end_rains", "end_season", "seasonal_rain")))
# })
12 changes: 9 additions & 3 deletions tests/testthat/test-crop_success_probabilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
# result <- epicsawrap::crop_success_probabilities(
# country = "zm",
# station_id = "16",
# planting_dates = c(1, 2, 3),
# water_requirements = c(100, 200, 300),
# planting_length = 10,
# planting_dates = c(92, 122, 153),
# water_requirements = c(300, 500, 700),
# planting_length = c(120, 180),
# start_before_season = TRUE
# )
#
Expand All @@ -32,3 +32,9 @@
# expect_no_error(result_2)
# expect_no_error(result_3)
# })
#
# # Define test cases
# test_that("crop_success_probabilities returns same results whether parameters are defined or not", {
# expect_identical(result[[2]], result_3[[2]])
# })
#
6 changes: 3 additions & 3 deletions tests/testthat/test-total_temperature_summaries.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# library(testthat)
#
# # Test case 1: Test with to = "annual"
# result <- total_temperature_summaries(
# result <- epicsawrap:::total_temperature_summaries(
# country = "zm",
# station_id = "23",
# summaries = c("mean_tmin", "mean_tmax"),
# to = "annual"
# )
#
# # Test case 2: Test with to = "monthly"
# result_2 <- total_temperature_summaries(
# result_2 <- epicsawrap:::total_temperature_summaries(
# country = "zm",
# station_id = "1",
# summaries = c("mean_tmin", "mean_tmax"),
Expand All @@ -21,7 +21,7 @@
# # Mock the necessary external functions or datasets if needed
# expect_length(result, 2)
# expect_length(result_2, 2)
#
#
# expect_no_error(result)
# expect_no_error(result_2)
# })

0 comments on commit 3b7a89a

Please sign in to comment.