100 lines
4 KiB
R
100 lines
4 KiB
R
|
|
library('readxl')
|
|
#chemba
|
|
if(project_dir == "chemba"){
|
|
message("Yield data for Chemba")
|
|
|
|
|
|
field_boundaries_sf <- st_read(here(data_dir, "pivot.geojson")) %>% dplyr::select(pivot, pivot_quadrant)%>%
|
|
mutate(sub_area = case_when(pivot %in% c("1.1", "1.2", "1.3", "1.4", "1.6", "1.7", "1.8", "1.9", "1.10", "1.11", "1.12", "1.13", "1.14" , "1.16" , "1.17" , "1.18" , "6.1", "6.2", "DL1.1", "DL1.3") ~ "estate",
|
|
TRUE ~ "Cooperative"))
|
|
names(field_boundaries_sf) <- c("field", "sub_field", "geometry", "sub_area")
|
|
|
|
field_boundaries <- field_boundaries_sf %>% vect()
|
|
names(field_boundaries) <- c("field", "sub_field", "sub_area")
|
|
|
|
# field_boundaries_merged <- st_read(here(data_dir, "pivot.geojson")) %>% dplyr::select(pivot, pivot_quadrant) %>% group_by(pivot) %>% summarise() %>% vect()
|
|
|
|
joined_spans <-st_read(here(data_dir, "span.geojson")) %>% st_transform(crs(field_boundaries_sf))
|
|
names(joined_spans) <- c("field", "area", "radius", "spans", "span", "geometry")
|
|
|
|
|
|
pivots_dates0 <- readRDS(here(harvest_dir, "harvest_data_new")) %>% filter(
|
|
pivot %in% c("1.1", "1.2", "1.3", "1.4", "1.6", "1.7", "1.8", "1.9", "1.10", "1.11", "1.12", "1.13",
|
|
"1.14" , "1.16" , "1.17" , "1.18" ,"2.1", "2.2", "2.3" , "2.4", "2.5", "3.1", "3.2", "3.3",
|
|
"4.1", "4.2", "4.3", "4.4", "4.5", "4.6", "5.1" ,"5.2", "5.3", "5.4", "6.1", "6.2", "DL1.1", "DL1.3")
|
|
)
|
|
|
|
harvesting_data <- pivots_dates0 %>%
|
|
dplyr::select(c("pivot_quadrant", "pivot", "season_start_2021", "season_end_2021", "season_start_2022",
|
|
"season_end_2022", "season_start_2023", "season_end_2023", "season_start_2024", "season_end_2024", "Age")) %>%
|
|
pivot_longer(cols = starts_with("season"), names_to = "Year", values_to = "value") %>%
|
|
separate(Year, into = c("name", "Year"), sep = "(?<=season_start|season_end)\\_", remove = FALSE) %>%
|
|
mutate(name = str_to_title(name)) %>%
|
|
pivot_wider(names_from = name, values_from = value) %>%
|
|
rename(Field = pivot,
|
|
subField = pivot_quadrant)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if (project_dir == "xinavane"){
|
|
library(readxl)
|
|
message("Yield data for Xinavane")
|
|
field_boundaries_sf <- st_read(here(data_dir, "pivot.geojson")) %>% dplyr::select(-Pivot)
|
|
names(field_boundaries_sf) <- c("field", "sub_field", "geometry")
|
|
|
|
field_boundaries <- field_boundaries_sf %>% vect()
|
|
|
|
joined_spans <- field_boundaries_sf %>% dplyr::select(Field)
|
|
|
|
pivots_dates0 <- read_excel(here(harvest_dir, "Yield data.xlsx"),
|
|
skip = 3,
|
|
col_types = c("numeric", "text", "skip", "text", "numeric", "numeric", "numeric", "numeric", "date",
|
|
"numeric", "skip", "numeric")) %>%
|
|
rename(
|
|
year = 1,
|
|
field = 2,
|
|
sub_area = 3,
|
|
hectares = 4,
|
|
tons = 5,
|
|
tcha = 6,
|
|
tchy = 7,
|
|
season_end = 8,
|
|
age = 9,
|
|
ratoon = 10
|
|
) %>%
|
|
mutate(Season_end = ymd(season_end),
|
|
Season_start = as.Date(season_end - (duration(months = age))),
|
|
subField = Field) #don't forget to add 2022 as a year for the 'curent' season
|
|
|
|
pivots_dates0 <- pivots_dates0 %>%
|
|
mutate(year = year + 6)
|
|
|
|
# Add 6 years to Season_end column
|
|
pivots_dates0 <- pivots_dates0 %>%
|
|
mutate(season_end = season_end + years(6))
|
|
|
|
# Add 6 years to Season_start column
|
|
pivots_dates0 <- pivots_dates0 %>%
|
|
mutate(season_start = season_start + years(6))
|
|
|
|
|
|
harvesting_data <- pivots_dates0 %>% dplyr::select(c("field","sub_field", "year", "season_start","season_end", "age" , "sub_area", "tcha"))
|
|
|
|
|
|
} else {
|
|
field_boundaries_sf <- st_read(here(data_dir, "pivot.geojson"))
|
|
names(field_boundaries_sf) <- c("field", "sub_field", "geometry")
|
|
field_boundaries <- field_boundaries_sf %>% vect()
|
|
harvesting_data <- read_excel(here(data_dir, "harvest.xlsx"),
|
|
col_types = c("numeric", "numeric", "numeric",
|
|
"date", "date", "numeric", "text",
|
|
"numeric", "numeric"))
|
|
}
|
|
|