How can I define several turbine types in one wind farm in Floris? - floris

I did the exercises offered in the Floris documentation. All of them define only one turbine type per wind farm. The JSON configuration file has only one field for "turbine". Looking through the source code, it looks like Floris was never intended to allow the definition of a mixed type farm. Is this correct?
I have a small wind park of 5 machines, consisting of 3 different turbine types. Is there any hope to use Floris in this case?

It's true that the JSON input file only allows a single turbine type to be defined. But the individual turbine parameters can be changed after the Floris object has been instantiated using the Floris interface.
The following provides an example of how to change the turbine parameters through the list of turbines in the turbine_map property of the farm. The rotor diameter and hub height of the 3rd and 4th turbine are changed. Also, an example of how the Cp and Ct curves could be changed for each turbine is shown.
# Initialize the FLORIS interface fi
fi = wfct.floris_utilities.FlorisInterface("example_input.json")
D = fi.floris.farm.turbines[0].rotor_diameter
hh = fi.floris.farm.turbines[0].hub_height
rotor_diameters_new = [D, D, 0.5*D, 0.5*D]
hub_heights_new = [hh, hh, 0.75*hh, 0.75*hh]
# As an example, scaling the Cp and Ct curves by 90%
cp_new = [0.9*x for x in fi.floris.farm.turbines[0].power_thrust_table["power"]]
ct_new = [0.9*x for x in fi.floris.farm.turbines[0].power_thrust_table["thrust"]]
# Assign new parameters to turbines
for i_turb, turbine in enumerate(fi.floris.farm.turbine_map.turbines):
turbine.rotor_diameter = rotor_diameters_new[i_turb]
turbine.hub_height = hub_heights_new[i_turb]
turbine.power_thrust_table["power"] = cp_new
turbine.power_thrust_table["thrust"] = ct_new
After changing the turbine parameters you're interested in, the rest of the FLORIS calculations will use the new turbine types.

Related

Multilayer network specification in R

I have been trying to convert my supradjacency matrix of a multilayer network (not a multiplex! I have interactions between the layers) in order to investigate some properties such as centrality, communities etc.. I was thinking of using MuxViz or Multinet as a package. However, I do not understand how I can represent it in a way for the function to recognize my object as a network. I can get for instance my data to look like:
From layer
From Node
To Layer
To Node
Weight
A
X
B
Y
a
A
Y
B
Z
b
But I am not sure how to transform it into an object which would be readable for the functions.
Thanks

Drawing GRTS points within polygons with spsurvey

In previous versions of the spsurvey package, it was possible to draw random points within polygons in a shapefile using a somewhat complicated design specification. (See here for an example).
The newly updated version of spsurvey (5.0.1) appears very user-friendly, except I cannot figure out how to perform a GRTS draw of more than one point within polygons. Below is an example:
Suppose I want to draw 10 random points using GRTS within the states of Montana and Wyoming. The grts() call requires an sf object, so we can get an sf object first.
library(raster)
library(sf)
library(spsurvey)
## Get state outlines
US <- raster::getData(country = "United States", level = 1)
States.outline <- US[US$NAME_1 %in% c("Montana","Wyoming"),]
# convert to sf object
states.out <- st_as_sf(States.outline)
Then, if we want to stratify by state, and we want ten points from each, we need:
# Define the number of points to draw from each state
strata_n <- c(Montana = 10, Wyoming = 10)
The strata_n object then gets fed into the grts() call, with the NAME_1 variable being the state name.
# Attempt to make grts draw
grts(sframe = states.out,
stratum_var = "NAME_1",
n_base = strata_n
)
This returns an error message:
During the check of the input to grtspts, one or more errors were
identified. Enter the following command to view all input error
messages: stopprnt() To view a subset of the errors (e.g., errors 1
and 5) enter stopprnt(m=c(1,5))
Running stopprnt() gives the following message:
Input Error Message n_base : Each stratum must have a sample
size no larger than the number of rows in 'sframe' representing that
stratum
This is a wonderfully clear message -- we can't draw more than one point from each polygon because the sf object only has a single row per state.
So: with the new and improved spsurvey package, how does one draw multiple points from within a polygon? Any tips or direction would be appreciated.
This is a bug. I have updated the development version, which can be installed (after installing the remotes package) by running
remotes::install_github("USEPA/spsurvey", ref = "develop")
Likely a few weeks before the changes in spsurvey are reflected on CRAN. Thanks for finding this.

how to plot specific segment from density.lpp

I use density.lpp for kernel density estimation. I want to pick specific segment in that and plot the estimation through chosen segment. As an example, I have a road which is a combination of two segments. each segments have different length so I don't know how many pieces each of them are divided by.
here is the locations of vertices and road segment ids.
https://www.dropbox.com/s/fmuul0b6lus279c/R.csv?dl=0
here is the code I used to create spatial lines data frame and random points on the network and get density estimation.
Is there a way to know how many pieces each segment divided by? OR if I want to plot locations vs estimation for chosen segment how can I do? Using dimyx=100 created 199 estimation points but I don't know how many of them belongs to Swid=1 or Swid=2.
One approached I used was, using gDistance it works fine in this problem because these segments connected to one directions however, when there is 4 ways connection, some of the lambda values connects to another segments which is not belongs to that segment. I provided picture and circled 2 points, when I used gDistance, those points connected to other segments. Any ideas?
R=read.csv("R.csv",header=T,sep=",")
R2.1=dplyr::select(R, X01,Y01,Swid)
coordinates(R2.1) = c("X01", "Y01")
proj4string(R2.1)=CRS("+proj=utm +zone=17 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0")
plot(R2.1,main="nodes on the road")
##
LineXX <- lapply(split(R2.1, R2.1$Swid), function(x) Lines(list(Line(coordinates(x))), x$Swid[1L]))
##
linesXY <- SpatialLines(LineXX)
data <- data.frame(Swid = unique(R2.1$Swid))
rownames(data) <- data$Swid
lxy <- SpatialLinesDataFrame(linesXY, data)
proj4string(lxy)=proj4string(trtrtt.original)
W.1=as.linnet.SpatialLines(lxy)
Rand1=runiflpp(250, W.1)
Rand1XY=coords(Rand1)[,1:2]
W2=owin(xrange=c(142751.98, 214311.26), yrange=c(3353111, 3399329))
Trpp=ppp(x=Rand1XY$x, y=Rand1XY$y, window=W2) ### planar point object
L.orig=lpp(Trpp,W.1) # discrete
plot(L.orig,main="Original with accidents")
S1=bw.scott(L.orig)[1] # in case to change bandwitdh
Try274=density(L.orig,S1,distance="path",continuous=TRUE,dimyx=100)
L=as.linnet(L.orig)
length(Try274[!is.na(Try274$v)])
[1] 199
This is a question about the spatstat package.
The result of density.lpp is an object of class linim. For any such object, you can use as.data.frame to extract the data. This yields a data frame with one row for each sample point on the network. For each sample point, the data are xc, yc (coordinates of nearest pixel centre), x,y (exact coordinates of sample point on network), seg (identifier of segment), tp (relative position along segment) and values (the density value). If you split the data frame by the seg column, you will get the data for invididual segments of the network.
However, it seems that you may want information about the internal workings of density.lpp. In order to achieve adequate accuracy during the computation phase, density.lpp subdivides each network segment into many short segments (using a complex set of rules). This information is lost when the final results are discretised into a linim object and returned. The attribute "dx" reports the length of the short segments that were used in the computation phase, but that's all.
If you email me directly I can show you how to extract the internal information.

Derivative of Pressure and Temperature over depth

I am currently trying to create derivative curves for pressure temperature surveys of wells my company owns. However I had written a code to help me along in this process but have come to the realization something broke along the way. The code is cited below. However when I calculate the derivative of the normal pressure and temperature curves in a separate program I see a very stark contrast to the data. Linked in Image 1, the depths in the image are not the real depths, however the data is obviously quite different.
Left is derivative calculated in a separate program, right is calculated by R
#Up Curves
#read EXCEL
h<-as.data.frame(read_excel("PLT.xlsx",sheet = "UP"))
#setting boundaries for curves
xs<-seq(round(min(h[["Depth MD"]]),0),round(max(h[["Depth MD"]]),0),by=0.5)
final<-data.frame(depth=xs,Press=1:length(xs),Temp=1:length(xs))
final[,"Press"]<-spline(h[["Depth MD"]],h[,"Pressure"],xout=xs)$y
final[,"Temp"]<-spline(h[["Depth MD"]],h[,"Temp"],xout=xs)$y
#Derivative Pressure
spfun<-splinefun(final$depth,final$Press)
final[["PDeriv"]]<-spfun(final$Press,deriv = 1)
#Derivative Temperature
spfun2<-splinefun(final$depth,final$Temp)
final[["TDeriv"]]<-spfun2(final$Temp,deriv=1)
#Plotting Values temp and Press
#Temp<-ggplot(final,aes(Temp))+geom_point(aes(y=depth),col="red")+
# scale_y_reverse()+#limits=c(6000,5000)
# scale_x_continuous()+theme_bw()#limits=c(90,110)
#Press<-ggplot(final,aes(Press))+geom_point(aes(y=depth),col="blue")+
# scale_y_reverse()+theme_bw()
#grid.arrange(Temp,Press,ncol=2)
#Plotting Values Derivatives
#PDeriv<-ggplot(final,aes(PDeriv))+geom_point(aes(y=depth),col="purple")+
# scale_y_reverse()+theme_bw()
#TDeriv<-ggplot(final,aes(TDeriv))+geom_point(aes(y=depth),col="purple")+
# scale_y_reverse()+theme_bw()
#grid.arrange(TDeriv,PDeriv,ncol=2)
#what file would you like to write?
write.csv(final,file="PT_full_curves_UP.csv",row.names = F)
The excel spreadsheet I am using contains two sheets one for the "UP" pass and one for the "DOWN" pass. However the code is identical and I have only included one for the up.
So my question is did I mess up what I am doing with the deriv function in R? Or am I referencing something that isn't what I think it is. Also I am only looking for a first order derivative of the Pressure/Depth and Temperature/Depth.

Data format in soil.spec package in R

I would like to use the trans function of soil.spec package to transform spectra using continuum removal. But I don't understand data format of raw spectra "raw"
the function example is:
trans(raw, tr = "continuum removed", order = , gap = )
Could someone show me an example of "raw" matrix
for continuum removal you can alternatively use the prospectr package
require(prospectr)
data(NIRsoil)
If your spectral data is in absorbance units then:
crt <- continuumRemoval(X = NIRsoil$spc, type = 'A')
matplot(x = colnames(NIRsoil$spc), y = t(crt),
type = "l", lty = 1,
xlab = "Wavelengths (nm)",
ylab = "Absorbance (CR)",
col = palette(gray(seq(0, 0.9, len = 25))))
If the spectral data is in reflectance units the type argument must be set to 'R'.
I have to say the soil.spec package is very weak on documentation. But, based on this quote from one of the I/O tools,
read.spc reads binary spectral spc-files from a folder into R. The
spectra can be made compatible (see details in make.comp) either to
the first sample wavebands or to the standard wavebands of the ICRAF
spectral lab. Information from the scanning method is gathered to
check on spectral comparability. The default has been set to ICRAF
spectral bands
My suspicion is that you need to have your files in whatever "spectral spc-files" format is, assuming that is an industry standard. Best bet may be to contact the package maintainer directly.
To obtain continuum removal transformation on your spectra using the soil.spec library, proceed as follows:
Prepare the raw spectra table and ensure its columns contains the spectral data to be transformed. Remove all non-spectral columns and ensure that no missing values.
Make the column names of raw spectra table to numeric format.
Proceed to run the transformation as shown below
raw.cw <- trans(raw,tr="continuum removed", order=1, gap=21)
raw.cw contains the raw spectra prior to the transformation, and the transformed spectra matrix now in your case continuum removed and the transformation method used.
To see these three objects run:
names(raw.cw)
raw.cw is an arbitrary object name assigned to the results obtained via other trans function.
Your continuum removed spectra is extracted from the results using the standard syntax as used in R system:
cw.spectra<-raw.cw$trans
We are updating the documentation of the soil.spec package and some of these explanations will be included as we release the next updated version which will bring additional functionalities for handling spectral data.
Kindly let me know if this helps but if you face any difficult with following this guideline to get the expected results, I will be glad to help.
Best,
Andrew
ICRAF

Resources