## ----include = FALSE----------------------------------------------------------
# nolint start: indentation-linter
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 7,
  fig.height = 5
)
options(rmarkdown.html_vignette.check_title = FALSE)

## ----setup--------------------------------------------------------------------
library(daisytools)
library(ggplot2)

## -----------------------------------------------------------------------------
data_dir <- system.file("extdata", package="daisytools")
field_path <- file.path(data_dir, "daisy-course/03/field_LAI.csv")
field <- read.csv(field_path)
head(field)

## -----------------------------------------------------------------------------
field <- field[field$Nitrogen_Level == 160, ]

## -----------------------------------------------------------------------------
field$Date <- as.POSIXct(field$Date, "%Y-%m-%d %H:%M:%S", tz="utc")

## -----------------------------------------------------------------------------
ggplot(data=field, mapping=aes(x=Date, y=LAI_mean, group=Method, color=Method,
                                shape=Method)) + geom_point()

## -----------------------------------------------------------------------------
sim_dir <- file.path(data_dir, "daisy-course/03/Output")
sim <- read_dlf(sim_dir, pattern="crop\\.csv")
names(sim)
head(sim[[names(sim)[1]]]@data)

## -----------------------------------------------------------------------------
sim <- daisy_time_to_timestamp(sim, "Date")
head(sim[[names(sim)[1]]]$Date)

## -----------------------------------------------------------------------------
plot_dlf(sim, "Date", "LAI", "points")

## -----------------------------------------------------------------------------
plot_dlf(sim, "Date", "LAI", "points") +
  geom_point(data=field, mapping=aes(x=Date, y=LAI_mean, group=Method,
                                     fill=Method, color=Method, shape=Method))

## -----------------------------------------------------------------------------
ndvi <- field[field$Method == "NDVI_sensor", c("Date", "LAI_mean")]
plant <- field[field$Method == "Plant_sample", c("Date", "LAI_mean")]

field_dlfs <- list(
  NDVI=new("Dlf", header=list(info="Measured field data (NDVI sensor)"),
           units=data.frame(Date="", LAI="", Height="cm"),
           data=data.frame(Date=ndvi$Date, LAI=ndvi$LAI_mean,
                           Height=rep(NA, nrow(ndvi)))),
  Plant=new("Dlf", header=list(info="Measured field data (Plant samples)"),
            units=data.frame(Date="", LAI="", Height="cm"),
            data=data.frame(Date=plant$Date, LAI=plant$LAI_mean,
                            Height=rep(NA, nrow(plant)))))

## -----------------------------------------------------------------------------
plot_dlf(c(sim, field_dlfs), "Date", c("LAI", "Height"), "points")

## -----------------------------------------------------------------------------
# nolint end

