minor visualistion chagnes

This commit is contained in:
Timon 2025-06-25 10:39:26 +02:00
parent b2fcd66d2b
commit ea6842af48
2 changed files with 26 additions and 17 deletions

View file

@ -357,7 +357,8 @@ CI values typically range from 0 (bare soil or severely stressed vegetation) to
Use these insights to identify areas that may need irrigation, fertilization, or other interventions, and to track the effectiveness of your management practices over time. Use these insights to identify areas that may need irrigation, fertilization, or other interventions, and to track the effectiveness of your management practices over time.
\pagebreak \newpage
# RGB Satellite Image - Current Week (if available) # RGB Satellite Image - Current Week (if available)
```{r render_rgb_map, echo=FALSE, fig.height=7, fig.width=10, message=FALSE, warning=FALSE} ```{r render_rgb_map, echo=FALSE, fig.height=7, fig.width=10, message=FALSE, warning=FALSE}
# Check if RGB bands are available and create RGB map # Check if RGB bands are available and create RGB map
@ -440,6 +441,7 @@ tryCatch({
``` ```
\newpage \newpage
# Chlorophyll Index (CI) Overview Map - Current Week # Chlorophyll Index (CI) Overview Map - Current Week
```{r render_ci_overview_map, echo=FALSE, fig.height=7, fig.width=10, message=FALSE, warning=FALSE} ```{r render_ci_overview_map, echo=FALSE, fig.height=7, fig.width=10, message=FALSE, warning=FALSE}
# Create overview chlorophyll index map # Create overview chlorophyll index map
@ -468,7 +470,6 @@ tryCatch({ # Base shape
``` ```
\newpage \newpage
\pagebreak
# Weekly Chlorophyll Index Difference Map # Weekly Chlorophyll Index Difference Map
```{r render_ci_difference_map, echo=FALSE, fig.height=7, fig.width=10, message=FALSE, warning=FALSE} ```{r render_ci_difference_map, echo=FALSE, fig.height=7, fig.width=10, message=FALSE, warning=FALSE}
@ -498,9 +499,8 @@ tryCatch({ # Base shape
``` ```
\newpage \newpage
\pagebreak
```{r generate_field_visualizations, eval=TRUE, fig.height=4.5, fig.width=12, message=FALSE,echo=FALSE, warning=FALSE, include=TRUE, results='asis'} ```{r generate_field_visualizations, eval=TRUE, fig.height=3.8, fig.width=10, message=FALSE,echo=FALSE, warning=FALSE, include=TRUE, results='asis'}
# Generate detailed visualizations for each field # Generate detailed visualizations for each field
tryCatch({ tryCatch({
# Merge field polygons for processing # Merge field polygons for processing
@ -509,18 +509,24 @@ tryCatch({
dplyr::summarise(.groups = 'drop') dplyr::summarise(.groups = 'drop')
# Generate plots for each field # Generate plots for each field
purrr::walk(AllPivots_merged$field, function(field_name) { for(i in seq_along(AllPivots_merged$field[1:3])) {
field_name <- AllPivots_merged$field[i]
tryCatch({ tryCatch({
cat("\n") # Add an empty line for better spacing # Add page break before each field (except the first one)
if(i > 1) {
cat("\\newpage\n\n")
}
# Call ci_plot with explicit parameters # Call ci_plot with explicit parameters (ci_plot will generate its own header)
ci_plot( ci_plot(
pivotName = field_name, pivotName = field_name,
field_boundaries = AllPivots0, field_boundaries = AllPivots0,
current_ci = CI, current_ci = CI,
ci_minus_1 = CI_m1, ci_minus_1 = CI_m1,
ci_minus_2 = CI_m2, ci_minus_2 = CI_m2,
last_week_diff = last_week_dif_raster_abs, three_week_diff = three_week_dif_raster_abs, last_week_diff = last_week_dif_raster_abs,
three_week_diff = three_week_dif_raster_abs,
harvesting_data = harvesting_data, harvesting_data = harvesting_data,
week = week, week = week,
week_minus_1 = week_minus_1, week_minus_1 = week_minus_1,
@ -529,7 +535,7 @@ tryCatch({
borders = borders borders = borders
) )
# cat("\n") cat("\n\n")
# Call cum_ci_plot with explicit parameters # Call cum_ci_plot with explicit parameters
cum_ci_plot( cum_ci_plot(
@ -539,15 +545,18 @@ tryCatch({
facet_on = FALSE facet_on = FALSE
) )
cat("\n\n")
}, error = function(e) { }, error = function(e) {
safe_log(paste("Error generating plots for field", field_name, ":", e$message), "ERROR") safe_log(paste("Error generating plots for field", field_name, ":", e$message), "ERROR")
cat(paste("## Error generating plots for field", field_name, "\n")) cat("\\newpage\n\n")
cat(paste(e$message, "\n")) cat("# Error generating plots for field ", field_name, "\n\n")
cat(e$message, "\n\n")
}) })
}) }
}, error = function(e) { }, error = function(e) {
safe_log(paste("Error in field visualization section:", e$message), "ERROR") safe_log(paste("Error in field visualization section:", e$message), "ERROR")
cat("Error generating field plots. See log for details.\n") cat("Error generating field plots. See log for details.\n\n")
}) })
``` ```

View file

@ -271,13 +271,13 @@ ci_plot <- function(pivotName,
nrow = 1, widths = c(0.23, 0.18, 0.18, 0.18, 0.23)) nrow = 1, widths = c(0.23, 0.18, 0.18, 0.18, 0.23))
# Output heading and map to R Markdown # Output heading and map to R Markdown
cat(paste("## Field", pivotName, "-", age, "weeks after planting/harvest", "\n")) cat(paste("## Field", pivotName, "-", age, "weeks after planting/harvest", "\n\n"))
print(tst) print(tst)
}, error = function(e) { }, error = function(e) {
safe_log(paste("Error creating CI plot for pivot", pivotName, ":", e$message), "ERROR") safe_log(paste("Error creating CI plot for pivot", pivotName, ":", e$message), "ERROR")
cat(paste("## Field", pivotName, "- Error creating visualization", "\n")) cat(paste("# Field", pivotName, "- Error creating visualization", "\n\n"))
cat(paste("Error:", e$message, "\n")) cat(paste("Error:", e$message, "\n\n"))
}) })
} }
@ -388,7 +388,7 @@ cum_ci_plot <- function(pivotName, ci_quadrant_data = CI_quadrant, plot_type = "
} }
# Output plot to R Markdown with reduced height # Output plot to R Markdown with reduced height
subchunkify(g, 3.2, 10) # Reduced from 3.2 to 2.8 subchunkify(g, 2.8, 10) # Reduced from 3.2 to 2.8
}, error = function(e) { }, error = function(e) {
safe_log(paste("Error creating CI trend plot for pivot", pivotName, ":", e$message), "ERROR") safe_log(paste("Error creating CI trend plot for pivot", pivotName, ":", e$message), "ERROR")