Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main changes to dev #21

Closed
wants to merge 103 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
6274b82
move temp_index to it's own file
PaulMelloy Mar 8, 2024
24f38a9
move moisture_index to own file
PaulMelloy Mar 8, 2024
38eb985
auxilary functions, keep in `dev`
PaulMelloy Mar 8, 2024
febb76d
remove spore_rate and inf_rate for racca methods
PaulMelloy Mar 8, 2024
bf93c41
remove racca method functionality from 'main'
PaulMelloy Mar 8, 2024
bdeacde
remove auxillary functions and tests
PaulMelloy Mar 8, 2024
02b0d01
remove extra line breaks
PaulMelloy Mar 8, 2024
541a422
remove auxiually docs
PaulMelloy Mar 8, 2024
466d2e2
wrap calculation with list DT
PaulMelloy Mar 8, 2024
8183832
move packages to suggests
PaulMelloy Mar 8, 2024
251d0c2
remove aux functions
PaulMelloy Mar 8, 2024
e80948d
amend tests without racca outputs
PaulMelloy Mar 8, 2024
e9d7a62
remove racca ref from vig
PaulMelloy Mar 8, 2024
99b8f78
doc
PaulMelloy Mar 8, 2024
e4ece37
Update README.md
ReneHeim Mar 8, 2024
bc72052
deploy pkgdown site
PaulMelloy Mar 8, 2024
efbe9a1
Update title and DESCRIPTION use Ropen template
PaulMelloy Mar 10, 2024
010a84e
Merge branch 'main' of https://github.com/PaulMelloy/cercospoRa
PaulMelloy Mar 10, 2024
d11082d
logo and negative pm
PaulMelloy Mar 11, 2024
e7aa014
github doc
PaulMelloy Mar 11, 2024
14073b4
fix image
PaulMelloy Mar 11, 2024
76d77fc
missed !
PaulMelloy Mar 11, 2024
cb1176d
add raw address
PaulMelloy Mar 11, 2024
79c8674
change theme
PaulMelloy Mar 11, 2024
1e3e4ad
use_github_pages
PaulMelloy Mar 11, 2024
081b9c3
try installing epiphytoolR on actions
PaulMelloy Mar 11, 2024
bb72eb5
extra repositories
PaulMelloy Mar 11, 2024
d15630a
try again for extra_packages and remotes Des
PaulMelloy Mar 11, 2024
4a74c47
missing comma
PaulMelloy Mar 11, 2024
995822d
another
PaulMelloy Mar 11, 2024
5e6275a
no quotes
PaulMelloy Mar 11, 2024
da7f590
add logo
PaulMelloy Mar 11, 2024
53b3871
remove duplicated heading
PaulMelloy Mar 11, 2024
7016480
transparent hex background
PaulMelloy Mar 11, 2024
ed60505
add some linebreaks
PaulMelloy Mar 11, 2024
ab82750
add more line breaks and sp
PaulMelloy Mar 11, 2024
5c7a8e3
use renes logo
PaulMelloy Mar 12, 2024
b383798
Initial commit
nathanokole Mar 13, 2024
13bd306
initial commit
nathanokole Mar 13, 2024
f338d5b
generalize from two to several images
nathanokole Mar 13, 2024
f260a6a
initial commit
nathanokole Mar 14, 2024
cdd8842
minor edits
nathanokole Mar 14, 2024
b30912c
minor edits
nathanokole Mar 14, 2024
4725233
documentation edits
nathanokole Mar 14, 2024
72fb244
documentation edits
nathanokole Mar 14, 2024
396a6bb
minor edits
nathanokole Mar 14, 2024
6eb84b6
minor edits
nathanokole Mar 14, 2024
f9f8b71
minor udjustments
nathanokole Mar 14, 2024
d1498f2
minor edits
nathanokole Mar 14, 2024
16761e0
Edit on the example
nathanokole Mar 14, 2024
9b7ffde
added package sf to description
nathanokole Mar 14, 2024
39e9024
add package sf to description
nathanokole Mar 14, 2024
8ab52e2
Merge pull request #14 from nathanokole/main
PaulMelloy Mar 14, 2024
5ca1127
ensure different to internal data Tm1
PaulMelloy Mar 14, 2024
e1907c7
store randomised testing data
PaulMelloy Mar 14, 2024
5aa184b
Update `raster` functions to `terra`
PaulMelloy Mar 14, 2024
27e4bdc
use internal data for testing
PaulMelloy Mar 14, 2024
81fb018
init test
PaulMelloy Mar 14, 2024
86d26a6
init test
PaulMelloy Mar 14, 2024
e20058d
remove extra )
PaulMelloy Mar 14, 2024
5084828
Increment version number to 0.0.0.9002
PaulMelloy Mar 14, 2024
220aa2d
remove imports
PaulMelloy Mar 14, 2024
d1dd3fb
Solve error in calc_r_x0
nathanokole Mar 14, 2024
a3f8f2f
replace t by tm
nathanokole Mar 14, 2024
ec978ca
fix issues due to raster to terra change
nathanokole Mar 14, 2024
2dbdb68
solve NA due to terra::rast
nathanokole Mar 14, 2024
30c40ba
Example updates
nathanokole Mar 14, 2024
ed353f8
Add lower limit to minpack.lm::nlsLM
nathanokole Mar 15, 2024
9dc3082
use threshold from wolf paper
May 10, 2024
b9da6d2
provide moisture index options method
May 10, 2024
baf4dd1
add tests and check outputs
PaulMelloy Jul 21, 2024
13209a3
rh_threshold not parsed
PaulMelloy Jul 22, 2024
5b8d345
updated expected outputs
PaulMelloy Jul 22, 2024
a38cea0
tests for both moisture threshold methods
PaulMelloy Jul 22, 2024
22dcb27
Threshold updated effect on expected values
PaulMelloy Jul 22, 2024
0192408
incremented Roxy
PaulMelloy Jul 22, 2024
c5ff592
ignore Rprofile
PaulMelloy Jul 22, 2024
ff84a29
add pattern to file detection
PaulMelloy Jul 24, 2024
a04b79b
add parameter for respective img dates see #18
PaulMelloy Jul 24, 2024
582ecf5
amend test in line with function changes #18
PaulMelloy Jul 24, 2024
3c231d1
set the raster name as image date return raster
PaulMelloy Jul 24, 2024
a47c02d
replace img with param_r
PaulMelloy Jul 24, 2024
26b2cc5
use names
PaulMelloy Jul 24, 2024
6a9e7f7
lint
PaulMelloy Jul 24, 2024
7b029bf
adjust t0 assignment return object
PaulMelloy Jul 24, 2024
c7ff0d1
update tests in line with code changes
PaulMelloy Jul 24, 2024
5c612e0
Remove loop and use terra::app #19
PaulMelloy Jul 24, 2024
e2f2bc4
fix example
PaulMelloy Jul 24, 2024
0b3698f
return with t0 as posix
PaulMelloy Jul 26, 2024
dc78711
allow a vector to be supplied to c_closure
PaulMelloy Jul 27, 2024
3e3f64d
delete white space
PaulMelloy Jul 27, 2024
c96a774
sapply to loop for c_closure image processing
PaulMelloy Jul 27, 2024
f23344a
use terra::app for function
PaulMelloy Jul 27, 2024
141ab27
correct example with full names
PaulMelloy Jul 27, 2024
7b6b8f1
redoc passing all tests
PaulMelloy Jul 27, 2024
bc75d8f
alter tests to allow for new changes
PaulMelloy Jul 27, 2024
e43cf32
update return documentation #17
PaulMelloy Jul 27, 2024
0017775
updated vignette to show calc epidemic from LAI
PaulMelloy Jul 30, 2024
8f83eff
move DIV and nasa power example to new vignette
PaulMelloy Jul 30, 2024
0edd9ff
As per discussion in issue #22
PaulMelloy Jul 30, 2024
4ec861c
update licence to be explicit with CC-BY-SA
PaulMelloy Jul 30, 2024
6a03a78
correct citation format
PaulMelloy Jul 30, 2024
8121bae
remove redundant commented code
PaulMelloy Jul 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@
^Notes - Sim model for management C.beticola in SB.Rmd$
^Notes---Sim-model-for-management-C.beticola-in-SB.html$
^cercospora.bib$
^_pkgdown\.yml$
^docs$
^pkgdown$
^\.github$
.Rprofile
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
47 changes: 47 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
release:
types: [published]
workflow_dispatch:

name: pkgdown

jobs:
pkgdown:
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::., PaulMelloy/epiphytoolR
needs: website

- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/[email protected]
with:
clean: false
branch: gh-pages
folder: docs
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
.httr-oauth
.DS_Store
inst/doc
docs
24 changes: 17 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: cercospoRa
Title: What the Package Does (One Line, Title Case)
Version: 0.0.0.9001
Title: Mechanistic Epidemiological Model for Cercospora Leaf Spot of Sugar Beet
Version: 0.0.0.9002
Authors@R: c(
person(given = "Paul",
family = "Melloy",
Expand Down Expand Up @@ -30,25 +30,35 @@ Authors@R: c(
family = "Mahlein",
role = c("ctb"),
comment = c(ORCID = "0000-0003-1091-3690")))
Description: Mechanistic epidemiological model for Cercospora leaf spot of sugar beet
Description: This package provides functions to recreate the negative prognosis
epidemiological model for describing when the model can't be certain a
chance Cercospora leaf spot (_Cercospora beticola_) epidemic has not
commenced. The model is based on the work of Wolf and Verreet
(2005 <https://apsjournals.apsnet.org/doi/abs/10.1094/PHYTO-95-0269>).
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Suggests:
knitr,
rmarkdown,
testthat (>= 3.0.0),
lubridate,
remotes
remotes,
epiphytoolR,
stats,
Config/testthat/edition: 3
Imports:
data.table,
epiphytoolR,
Rdpack,
stats
sf,
terra,
minpack.lm
RdMacros: Rdpack
VignetteBuilder: knitr
Remotes:
PaulMelloy/epiphytoolR
Depends:
R (>= 2.10)
LazyData: true
URL: https://paulmelloy.github.io/cercospoRa/
5 changes: 4 additions & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License

Copyright (c) 2023 cercospoRa authors
Copyright (c)(CC-BY-SA-4.0) 2023 cercospoRa authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -12,6 +12,9 @@ furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

[Creative Commons Attribution-ShareAlike 4.0 International Public
License](https://www.r-project.org/Licenses/CC-BY-SA-4.0)

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down
12 changes: 5 additions & 7 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# Generated by roxygen2: do not edit by hand

export(calc_DIV)
export(calc_c_closure)
export(calc_epidemic_onset)
export(calc_inf_rate)
export(calc_pseudo_maturity)
export(calc_sb_emergence)
export(calc_spore_rate)
export(calc_sugarbeet_gdd)
export(cercospora_dk)
export(estimate_sb_drymatter)
export(calc_epidemic_onset_from_image)
export(calc_r_x0)
export(read_sb_growth_parameter)
import(data.table)
importFrom(Rdpack,reprompt)
importFrom(data.table,":=")
importFrom(terra,plot)
14 changes: 13 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# cercospoRa (development version)
- Four functions have been added to deal with spatial heterogeneity:
- `read_sb_growth_parameter`: read in and format raster images to allow
further computation.
- `calc_r_x0`: fit logistic growth curve to the date.
- `calc_c_closure`: to deduct canopy closure dates from the fitted curves.
- `calc_epidemic_onset_from_image`: builds on the existing `calc_epidemic_onset`
function to compute a value for each pixel.
- Example datasets have been provided to check the functions.
It consists of a folder containing two LAI maps computed from UAV images.


# cercospoRa 0.0.0.9001
Change package name
- Change package name
- Add pkgdown site
- Reduce functions to only those described by Wolf and Verreet (2005)

# cercosporaR 0.0.0.9000
17 changes: 5 additions & 12 deletions R/calc_DIV.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,12 @@ calc_DIV <- function(date_time, Tm,RH, rain,dat){
]

dat[, c("Tm_index",
"moist_ind",
"s_rate",
"inf_rate") := list(temperature_index(temp),
moisture_index(rh,rain),
calc_spore_rate(temp,rh),
calc_inf_rate(temp, RH = rh))]
"moist_ind") := list(temperature_index(temp),
moisture_index(rh,rain,70))]

DIV <- dat[, list(DIV = mean(fifelse(Tm_index == 0 | moist_ind == 0,
0, (Tm_index * moist_ind))),
DIV_racca = mean(Tm_index *
s_rate *
inf_rate)),
by = c("Year","Month","Day")]
DIV <- dat[, list(DIV = mean(fifelse(test = Tm_index == 0 | moist_ind == 0,
yes = 0, no = (Tm_index * moist_ind)))),
by = c("Year", "Month", "Day")]

return(DIV)
}
40 changes: 40 additions & 0 deletions R/calc_c_closure.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#' Calculate growth rate(r) and LAI0 at time t0
#'
#' @param param_rxt Output of the function \link{calc_r_x0}, which produces a
#' list containing parameters that are necessary to calculate `c_closure`.
#' These parameters are `r`, the growth rate, `x0`, the initial LAI value, and
#' `t0`, the initial date and the associated dates
#' @param x1 LAI value at which 90% canopy closure is reached. It is fixed to
#' 1.3 for sugar beet.
#' @param k carrying capacity, which is the maximum LAI that can be attained.
#' This value can be cultivar-dependent. The default is fixed to 6
#'
#' @return `c_closure` date at which 90% canopy closure is reached at each location.
#'
#' @export
#'
#'
#' @examples
#' img_dir <- system.file("extdata", "uav_img",package = "cercospoRa")
#' epidemic_onset_param <-
#' read_sb_growth_parameter(img_files = list.files(img_dir,pattern = "tif",
#' full.names = TRUE),
#' img_dates = as.POSIXct(
#' c("2022-06-14","2022-06-28"),tz = "UTC"),
#' target_res = 10)
#' param_rxt <- calc_r_x0(epidemic_onset_param,
#' min_r = 0.02,
#' max_r = 0.05,
#' k = 6)
#' c_closure <- calc_c_closure(param_rxt,
#' x1 = 1.3,
#' k=6 )
calc_c_closure <- function(param_rxt,
x1 = 1.3,
k=6 ){
x0 <- param_rxt$x0
r <- param_rxt$r
t0 <- param_rxt$t0
c_closure <- as.numeric(t0)/(24*60*60) + round(log( x1*(k-x0)/(x0*(k-x1)))/r,0)
return(c_closure)
}
29 changes: 15 additions & 14 deletions R/calc_epidemic_onset.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,26 @@ calc_epidemic_onset <- function(start,
warning("'c_closure' not supplied, setting 'start' as canopy closure date")
start <- c_closure
}
if(c_closure >= end) stop("'c_closure' is after last weather date")

w <- copy(weather[times > as.POSIXct(start) &
times < (as.POSIXct(end) + 3600),][times >= as.POSIXct(c_closure)])
c_closure <- as.POSIXct(c_closure,tz = "UTC")

daily_inf_val <- calc_DIV(dat = w)
out <- sapply(c_closure,function(cc){
if(is.na(cc)) return(NA)
if(cc >= end) stop("'c_closure' is after last weather date")

div_cs <- daily_inf_val[first(which(cumsum(DIV) >cultivar_sus)),
as.POSIXct(paste(Year,Month,Day,sep = "-"), tz = "UTC")]
w <- copy(weather[times > as.POSIXct(start) &
times < (as.POSIXct(end) + 3600),][times >= as.POSIXct(cc)])

# return date when 5% of canopy is infected
div_cs_r <- daily_inf_val[first(which(cumsum(DIV_racca) > 0.05)),
as.POSIXct(paste(Year,Month,Day,sep = "-"), tz = "UTC")]
daily_inf_val <- calc_DIV(dat = w)

if(length(div_cs) == 0) div_cs <- sum(daily_inf_val$DIV, na.rm = TRUE) / cultivar_sus
# calculate percentage
if(length(div_cs_r) == 0) div_cs_r <- sum(daily_inf_val$DIV_racca,na.rm = TRUE) *100
div_cs <- daily_inf_val[first(which(cumsum(DIV) >cultivar_sus)),
as.POSIXct(paste(Year,Month,Day,sep = "-"), tz = "UTC")]

return(list(wolf_date = div_cs[1],
racca_date = div_cs_r[1]))
if(length(div_cs) == 0) div_cs <- sum(daily_inf_val$DIV, na.rm = TRUE) / cultivar_sus
# calculate percentage

return(div_cs[1])
})

return(as.POSIXct(out,tz = "UTC"))
}
83 changes: 83 additions & 0 deletions R/calc_epidemic_onset_from_image.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#' Calculate epidemic onset from image
#'
#' @param start posixct, start date in which to begin calculating the epidemic
#' onset, if not specified, the first date in the weather data will be used.
#' @param end posixct, end date, last date to complete calculating the epidemic
#' onset, if not specified, the last date in the weather data will be used.
#' @param c_closure map of canopy closure dates formatted as number of days since
#' 1970-01-01. It defines the date to start running the model (Wolf)
#' @param weather data.table, formatted with `epiphytoolR::format_weather`
#' @param cultivar_sus character, susceptibility of the cultivar in "R" resistant,
#' "S" susceptible, "MR" moderately resistant ect.
#' @importFrom terra plot
#' @return `$wolf_date:` If the input weather is conducive for epidemic, the function returns a
#' POSIX_ct date when epidemic commences. If no epidemic occurs, a numeric,
#' proportion indicating the progress an epidemic is returned
#'
#' @export
#'
#' @examples
#' wethr <- read.csv(system.file("extdata", "clean_weather.csv",
#' package = "cercospoRa"))
#' wethr <- epiphytoolR::format_weather(wethr,time_zone = "UTC")
#'
#' img_dir <- system.file("extdata", "uav_img",package = "cercospoRa")
#'
#' epidemic_onset_param <-
#' read_sb_growth_parameter(
#' list.files(img_dir,pattern = "tif",
#' full.names = TRUE),
#' img_dates = as.POSIXct(c("2022-06-14","2022-06-28"),
#' tz = "UTC"),
#' 10)
#' param_rxt <- calc_r_x0(epidemic_onset_param,
#' min_r = 0.02,
#' max_r = 0.05,
#' k = 6)
#' c_closure <- calc_c_closure(param_rxt,
#' x1 = 1.3,
#' k=6 )
#'
#' epidemic_onset_map <- calc_epidemic_onset_from_image(start = as.POSIXct("2022-04-25",tz = "UTC"),
#' end = as.POSIXct("2022-09-30",tz = "UTC"),
#' c_closure = c_closure,
#' weather = wethr)
#'
#' terra::plot(epidemic_onset_map)
calc_epidemic_onset_from_image <- function(start,
end,
c_closure,
weather,
cultivar_sus = 5){
# initialise onset raster

Ep_onset <- terra::app(x = c_closure,
calc_r_onset,
start = start,
end = end,
weather = weather,
cultivar_sus = cultivar_sus)

return(Ep_onset)
}

#' Calculate epidemic onset from raster
#'
#' @details
#' Wrapper function to help internally calculate the earliest CLS onset date
#' from canopy closure dates supplied as integers with an origin date of 1970-01-01
#'
#' @param r SpatRaster with integer onset dates as values. This is usually the
#' output of `calc_c_closure`
#' @param ... additional arguments to be supplied to `calc_epidemic_onset()`
#'
#' @return SpatRaster with integer values representing days since origin "1970-01-01"
#' @noRd
calc_r_onset <- function(r, ...){
#cat(r," | ")
c_closure_date <- as.Date.numeric(round(r),
origin = '1970-01-01')
onset_epidemic_date <- calc_epidemic_onset(c_closure = c_closure_date, ...)
return(as.integer(onset_epidemic_date))
}

Loading