ncss-tech / sharpshootR

Miscellaneous soil data management, summary, visualization, and conversion utilities to support soil survey.
http://ncss-tech.github.io/sharpshootR/
17 stars 3 forks source link

updates to FFD() #43

Open dylanbeaudette opened 2 years ago

dylanbeaudette commented 2 years ago

Major TODO items:

acerru commented 2 years ago

Hi David, your package would be very useful for characterize environments in the southern hemisphere. I think it is a great work. In the south we usually get climate information from NASA. Below you will find the code to get Tmin data form Balcarce (my place in Argentina) linked to the function FFD. If you run the code you will note that the FFD that yields is far from being accurate. The first frost in Balcarce takes place at the end of april and the last frost occurs early during november. I you fix the function, we can also obtain thermometer measured data from a weather station (INTA Balcarce) with more than 40 years of data to validate Nasa power.

I Don't know if that is the way you need the code (protocode), Im just a crop physiologist starting with R. Anyway, let me know if it is ok, or if you need different information.

Thanks a lot

Anibal

packages

pacman::p_load(tidyverse, googlesheets4,ggridges, lubridate,sharpshootR, soilDB, plyr)

define time interval

dates <- seq.Date(lubridate::dmy("1-1-2000"), lubridate::dmy("31-12-2021"), by = "1 day")

get climate from nasa

df <- nasapower::get_power(
  community = "AG",
  lonlat = c(-58.3,-37.35) ,
  pars= c("ALLSKY_SFC_SW_DWN", "T2M_MAX","T2M_MIN","T2M","PRECTOTCORR" ),
  dates = c(min(dates), max(dates)),
  temporal_api = "DAILY"
) 

frost free period FFD (sharpshootR)

ffd <- df %>% 
       mutate(datetime = YYYYMMDD,  value=T2M_MIN) %>% mutate(datetime = as.Date(datetime)) 
x<-select(ffd,datetime,value)
x$year <- as.integer(format(x$datetime, "%Y"))
x<-select(x,datetime,year,value)
x.ffd <- FFD(x, returnDailyPr = TRUE, frostTemp=3)#,endSpringDOY=350,startFallDOY=80 )

Probability 50,80,90

par(mar=c(4,3.5,2,1))
FFDplot(x.ffd, 'NASA at (-58.55,-37.58)')
dylanbeaudette commented 2 years ago

Excellent, thank you for the example code. I'll work on this next week--curious to see how the underlying algorithm can be shifted in time.