How can I estimate density of target wind speed from daily weibull distributions for 13 years of large dataset

274 views Asked by At

Good day,

I want to create weibull distribution based on each day's wind speeds measured half hourly (48 wind speeds each day, sometimes few hours are missing).
And then based on the weibull distribution, I want to calculate the density of a certain target wind speed (in this dataset, 29km/hr) based on each daily weibull distribution.
To do this, I need to arrange 13 years of dataset each day to calculate two parameters for weibull distribution (scale = a and shape = b) to estimate density of the target point each day. As this is a large dataset, I need to use a certain function for automatically process it and put the everyday results in a different table (a, b, density of 29 km/hr) (Possibly 'return' function??)

My data looks like this:

    Time             windspeed direction    Date            day_index
1   24/07/2000 13:00    31       310    2000-07-24 13:00:00 2000_206
2   24/07/2000 13:30    41       320    2000-07-24 13:30:00 2000_206
3   24/07/2000 14:30    37       290    2000-07-24 14:30:00 2000_206
4   24/07/2000 15:00    30       300    2000-07-24 15:00:00 2000_206
5   24/07/2000 15:30    24       320    2000-07-24 15:30:00 2000_206
6   24/07/2000 16:00    22       330    2000-07-24 16:00:00 2000_206
7   24/07/2000 16:30    37       270    2000-07-24 16:30:00 2000_206  

This is the further question by this link webpage (How can I apply "sapply" in R with multiple codes in one function?)

Previous comments indicate that I might need to used 'aggregate' or 'ddply' functions. How can I put multiple arguments in the functions for my intention of analysis?

My function for multiple arguments is:

library(bReeze) 
library(xts) 
time_ballarat <- strptime(ballarat_alldata[,1], "%d/%m/%Y %H:%M")

multiple.function <- set1 <- createSet(height=10, v.avg=ballarat_alldata[,2], dir.avg=ballarat_alldata[,3]) + ballarat <- createMast(time.stamp=time_ballarat, set1) + ballarat <- clean(mast=ballarat) + ballarat.wb <- weibull(mast=ballarat, v.set=1, print=FALSE) + my.x <- density(ballarat_alldata$windspeed, from = 0, to = max(ballarat_alldata$windspeed))$x + my.y <- density(ballarat_alldata$windspeed, from = 0, to = max(ballarat_alldata$windspeed))$y + df <- data.frame(x = my.x, y = my.y) + my.nls <- nls(y ~ (a/b) * (x/b)^(a-1) * exp(- (x/b)^a), + data = df[df$x > 0, ], + start = c(a = ballarat.wb[13,2], b = ballarat.wb[13,1])) + xValues <- seq(from = 0, to = 40, length.out = 100) + my.predicted <- predict(my.nls, data.frame(x = xValues)) + my.coef <- coef(my.nls) + my.weibull.predict <- function(x, a, b) { + y <- (a/b) * (x/b)^(a-1) * exp(- (x/b)^a) + return(y)} + return(c(ballarat.parameter = my.coef[1], ballarat.scale= my.coef[2], + my29 = my.weibull.predict(29, my.coef[1], my.coef[2])))}

I am not sure this can calculate density of the target speed in each day.. Could you please check whether it fits with my intention? The primary concern of "multiple.function" is that weibull distribution codes should be created differently based on each day's different data. This is missing in the codes.

For example, in "createSet(height=10, v.avg=ballarat_alldata[,2], dir.avg=ballarat_alldata[,3])", v.avg and dir.avg should not contain all datasets for the calculation but I do not know how.

I am still a beginner in R so I apologise about my questions in advance. The questions might be too specific.. Please help me finding the way to solve my problems!

Regards,

Kangmin.

0

There are 0 answers