How do you calculate accumulated standard deviation for gdd, pet, ppet and precipitation

Sunday, March 17, 2019 - 14:57
Allan Odwar

The way accumulated standard deviation for accumulated gdd amount and average are straight forward. But when it comes to stdDev need to get a fomular from what you are doing

Answer Count: 
4
Saturday, March 23, 2019 - 01:13
Call Tutors

Hi Allen, the SD of accumulated GDD is done by calculating the accumulated GDD for each year considered independently and then calculated the SD for each day of the year. Below is R code that demonstrates this empirically. Please followup with any more questions you have.

load libraries

library(aWhereAPI) library(data.table) library(magrittr) library(lubridate)

load credentials for aWhere API

aWhereAPI::load_credentials(path_to_credentials = 'credentials/credentials.txt')

set params for location and dates to request data

lat <- 36 lon <- -78

yearsToRetrieveData <- seq(2008,2018,1) monthsToRetrieveData <- c(1,2) dayToRetrieveData <- 1

roundingPrecision <- 3

get daily data from API

returnedData <- list() for (x in 1:length(yearsToRetrieveData)) { returnedData[[x]] <- aWhereAPI::agronomic_values_latlng(latitude = lat ,longitude = lon ,day_start = paste(yearsToRetrieveData[x],min(monthsToRetrieveData),dayToRetrieveData,sep = '-') ,day_end = paste(yearsToRetrieveData[x],max(monthsToRetrieveData),dayToRetrieveData,sep = '-')) }

Combine list into single data structure

returnedData <- data.table::rbindlist(returnedData)

calculate the day of the year to be used in groupby

returnedData[,dayOfYear := lubridate::yday(date)]

select only the data columns

columnsToSD <- c(colnames(returnedData)[-c(1,2,3,4,5,8,11)])

Calculated SD of the data columns

calculatedSD % round(.,roundingPrecision)

Request API calculated SD info

returnedSD % data.table::as.data.table(.)

Create a day of year column. In this example since all days are prior to any possible leap year the year used is arbitrary

returnedSD[,dayOfYear := lubridate::yday(lubridate::ymd(paste('2008',day,sep = '-')))]

Parse column names to determine which to keep. Remove mean temp as not in other data structure

colsToKeep <- grep(pattern = 'accumulated|dayOfYear' ,x = grep(pattern = '.stdDev|dayOfYear' ,x = colnames(returnedSD) ,value = TRUE) ,value = TRUE)

Reorder columns to match the other data structure and subset data structure

returnedSD % round(.,roundingPrecision)

Test for equality by position between different data structures

all.equal(calculatedSD,returnedSD,check.attributes = FALSE)

Wednesday, March 20, 2019 - 14:05
Drew Marticorena