diff --git a/build_report.sh b/build_report.sh index a219bb4..6cb4097 100755 --- a/build_report.sh +++ b/build_report.sh @@ -12,7 +12,10 @@ for arg in "$@"; do --report_date=*) report_date="${arg#*=}" ;; - *) + --data_dir=*) + data_dir="${arg#*=}" + ;; + *) echo "Unknown option: $arg" exit 1 ;; @@ -20,8 +23,8 @@ for arg in "$@"; do done # Check if required arguments are set -if [ -z "$filename" ] || [ -z "$weeks_ago" ] || [ -z "$report_date" ]; then - echo "Missing arguments. Use: build_reports.sh --filename=hello.txt --weeks_ago=3 --report_date=2020-01-01" +if [ -z "$filename" ] || [ -z "$weeks_ago" ] || [ -z "$report_date" ] || [ -z "$data_dir" ]; then + echo "Missing arguments. Use: build_reports.sh --filename=hello.txt --weeks_ago=3 --report_date=2020-01-01 --data_dir=chemba" exit 1 fi @@ -29,6 +32,7 @@ fi echo "Filename: $filename" echo "Weeks ago: $weeks_ago" echo "Report date: $report_date" +echo "Data directory: $data_dir" if [ "$(uname)" == "Darwin" ]; then # Commando's voor Mac @@ -40,4 +44,4 @@ elif [ "$(uname)" == "Linux" ]; then else echo "Onbekend systeem" fi -Rscript -e "rmarkdown::render('CI_report_dashboard_planet.Rmd', output_file='$filename', params=list(ref='$ref', report_date='$report_date'))" \ No newline at end of file +Rscript -e "rmarkdown::render('CI_report_dashboard_planet.Rmd', output_file='$filename', params=list(ref='$ref', report_date='$report_date', data_dir='$data_dir'))" \ No newline at end of file diff --git a/r_app/2_CI_data_prep.R b/r_app/2_CI_data_prep.R index 2855179..45cc4c1 100644 --- a/r_app/2_CI_data_prep.R +++ b/r_app/2_CI_data_prep.R @@ -37,14 +37,15 @@ if (!is.character(project_dir)) { project_dir <- "chemba" } -laravel_storage_dir <- here("../laravel_app/storage/app", project_dir) + +laravel_storage_dir <- here("laravel_app/storage/app", project_dir) #preparing directories planet_tif_folder <- here(laravel_storage_dir, "merged_tif") merged_final <- here(laravel_storage_dir, "merged_final_tif") -new_project_question = TRUE -planet_tif_folder <- here(laravel_storage_dir, project, "merged_tif") -merged_final <- here(laravel_storage_dir, project,"merged_final_tif") +new_project_question = FALSE +planet_tif_folder <- here(laravel_storage_dir, "merged_tif") +merged_final <- here(laravel_storage_dir, "merged_final_tif") data_dir <- here(laravel_storage_dir, "Data") extracted_CI_dir <- here(data_dir, "extracted_ci") @@ -54,7 +55,6 @@ cumulative_CI_vals_dir <- here(extracted_CI_dir, "cumulative_vals") weekly_CI_mosaic <- here(laravel_storage_dir, "weekly_mosaic") daily_vrt <- here(data_dir, "vrt") harvest_dir <- here(data_dir, "HarvestData") - dir.create(here(data_dir)) dir.create(here(extracted_CI_dir)) dir.create(here(daily_CI_vals_dir)) @@ -66,12 +66,11 @@ dir.create(harvest_dir) - # Creating weekly mosaic dates <- date_list(weeks_ago) #load pivot geojson -pivot_sf_q <- st_read(here( "pivot_20210625.geojson")) %>% dplyr::select(pivot, pivot_quadrant) %>% vect() +pivot_sf_q <- st_read(here(data_dir, "pivot.geojson")) %>% dplyr::select(pivot, pivot_quadrant) %>% vect() raster_files <- list.files(planet_tif_folder,full.names = T, pattern = ".tif") head(raster_files) @@ -266,7 +265,7 @@ extract_rasters_daily <- function(file, field_geojson, quadrants = TRUE, save_di } # pivot_sf_q <- st_read(here("..", "Data", "pivot_20210625.geojson")) %>% dplyr::select(pivot, pivot_quadrant) %>% vect() -pivot_sf <- st_read(here(data_dir, "pivot_20210625.geojson")) %>% dplyr::select(pivot, pivot_quadrant) %>% group_by(pivot) %>% summarise() %>% vect() +pivot_sf <- st_read(here(data_dir, "pivot.geojson")) %>% dplyr::select(pivot, pivot_quadrant) %>% group_by(pivot) %>% summarise() %>% vect() message("pivot loaded") raster_files_NEW <- list.files(merged_final,full.names = T, pattern = ".tif") diff --git a/r_app/CI_report_dashboard_planet.Rmd b/r_app/CI_report_dashboard_planet.Rmd index 250af6a..cab0708 100644 --- a/r_app/CI_report_dashboard_planet.Rmd +++ b/r_app/CI_report_dashboard_planet.Rmd @@ -4,6 +4,7 @@ params: ref: word-styles-reference-var1.docx output_file: "CI_report.docx" report_date: "2023-12-12" + data_dir: "chemba" output: word_document: reference_docx: !expr file.path("word-styles-reference-var1.docx") @@ -45,12 +46,13 @@ library(CAST) ``` ```{r directories, message=FALSE, warning=FALSE, include=FALSE} -laravel_storage_dir <- here("../laravel_app/storage/app/chemba") -data_dir <- here(laravel_storage_dir, "../Data") -extracted_CI_dir <- here(data_dir, "extracted_ci") +laravel_storage_dir <- here("laravel_app/storage/app/",params$data_dir) + +data_dir_project <- here(laravel_storage_dir, "Data") +extracted_CI_dir <- here(data_dir_project, "extracted_ci") daily_CI_vals_dir <- here(extracted_CI_dir, "daily_vals") cumulative_CI_vals_dir <- here(extracted_CI_dir, "cumulative_vals") -harvest_dir <- here(data_dir, "HarvestData") +harvest_dir <- here(data_dir_project, "HarvestData") weekly_CI_mosaic <- here(laravel_storage_dir, "weekly_mosaic") @@ -116,11 +118,11 @@ CI_m3 <- brick(here(weekly_CI_mosaic, paste0("week_",week_minus_3, "_", year_3, last_week_dif_raster_abs <- (CI - CI_m1) three_week_dif_raster_abs <- (CI - CI_m3) -AllPivots0 <-st_read(here(data_dir, "pivot_20210625.geojson")) +AllPivots0 <-st_read(here(data_dir_project, "pivot.geojson")) AllPivots0$pivot <- factor(AllPivots0$pivot, levels = 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")) -joined_spans <-st_read(here(data_dir, "spans2.geojson")) %>% st_transform(crs(AllPivots0)) +joined_spans <-st_read(here(data_dir_project, "span.geojson")) %>% st_transform(crs(AllPivots0)) pivots_dates <- readRDS(here(harvest_dir, "harvest_data_new")) %>% filter( pivot %in% c("1.1", "1.2", "1.3", "1.4", "1.7", "1.8", "1.9", "1.10", "1.11", "1.12", "1.13", diff --git a/r_app/Rplots.pdf b/r_app/Rplots.pdf index 26a0533..bf8c066 100644 Binary files a/r_app/Rplots.pdf and b/r_app/Rplots.pdf differ