# Solution to force a polynomial curve to end at a specific location

I require a solution (Python if possible) to force a polynomial to end at a specific point. I have read the solutions offered here to a similar question but have been unable to get any of these methods working on my data set as they are not defining end points but locations for a polynomial to pass through.

I therefore require a solution to force a polynomial curve to end at a specific location.

To put this in context the example that I need this for is shown in the image below, I require a line of best fit for the data below, the green points represent the raw data and the pink points are the mean of the green points for every x value. The best fit should be a 3rd order polynomial until the data becomes a horizontal linear line. The black line is my current attempt at a line of best fit using np.ployfit(), I have defined the polynomial to only plot until the location where I would then start the linear best fit line but as you can see the tail of the polynomial is far too low and hence I want to force it to end/go through a specific point.

Additional Information Added The rated power of the turbine is 280kW so this is the max power which you can get out of it regardless of how high the wind speed is. There is also a cut in windspeed of 3m/s before this the turbine isn't generating any electricity and a cut out of 25m/s to prevent oil temperatures overheating in the gear box and mechanical failure occurring the turbine shuts down. The data seen plotted below is for a single turbine and the mean wind speed is the average in all directions. SCADA data - Supervisory control and data acquisition is just data that is automatically recorded in this case every ten minutes from the turbines internal sensors and logged in a database. EGen Mean as can be seen plotted on the graph is simply the mean of the electricity generated for each distinct windspeed. It is from these means that I attempted to plot the line of best fit.

I am open to all options to get a nice mathematically sensible best fit as have been banging my head against this problem for too long now. • It's difficult to tell what you are asking for. You can force a polynomial (and even its derivatives) to have specific values at specific locations: see stats.stackexchange.com/questions/50447. But you really don't want to do this. You need a more suitable model for these data. It needs to handle the obvious upper limit in generation capacity, perhaps with a censored regression model, as well as the clear increase in variability of the response with increased wind speed.
– whuber
Dec 1, 2016 at 22:57
• Seems like a use case for smoothing splines. Dec 1, 2016 at 23:02
• It looks like there's clipping at approx. 270? Fit a two piece spline with a spline point around 9 or 10? Dec 1, 2016 at 23:03
• @Sycorax Splines might fit but they won't do a good job of explaining and they will be sensitive to the huge increase in variance with larger wind speeds. There are more fundamental issues to address before deciding what form the curve might take.
– whuber
Dec 1, 2016 at 23:05
• @DeltaIV Good questions, I didn't want to bog people down too much in the specifics of the question but as you asked I have added many of the answers to your question in additional information on the post. SCADA data on turbines can be notoriously dodgy, the high wind speed low power data points are something I've been questioning myself but have just at the moment declared them as noise. I have actually removed the points above a wind speed of 5m\s where the Electricity Generated = 0 kW as there were lots and these and tend to just be failed readings in the SCADA database. Dec 2, 2016 at 9:39

Estimating the power curve of a wind turbine is much more complicated than it looks at first sight, and I don't envy you for having to deal with that :P I'll try to help, but keep in mind that, as confirmed by reading the literature, the correct answer depends a lot on context, and you're the one who knows your turbines better.

So, first of all, as noted in the comments:

1. the V-P (wind speed-power) curve is nonlinear, with a sigmoidal shape: it flattens out below the cut-in speed, at the rated power and it doesn't extend beyond the cut-out speed.
2. wind speed actually explains just a moderate part of power variability: if you don't add other predictors, the residual variance is bound to be large.
3. the relationship is heteroskedastic, for various reasons: for example, you average the wind speed on all possible freestream wind directions. However, depending on the freestream wind direction, your turbine may or may not be in the wake of other turbines (if it's located on the boundary of the farm: if it's inside, it's always in some wake, but the freestream wind direction influences the extent and direction of the wake). Depending on the wake, the power generated by the turbine for the same wind speed changes drastically, and the change is larger for higher wind speed $\rightarrow$ heteroskedasticity.
4. Last, but definitely not least, anyone who had to deal with SCADA data for wind turbines (which are 10-mins averages of the sensor data) knows how noisy they are.

So, where do we go from here? My suggestion is to forget about a power curve, add more predictors and concentrate on a power response surface. In this case useful additional predictors are wind direction $D$, temperature $T$, pressure $p$, humidity $H$, turbulence intensity $I$ and wind shear $S$. $T$ and $p$ are usually summarized as just density $\rho$, because it's actually density which goes into the physical law of power generation:

$$P=\frac{1}{2}\pi C_P\rho R^2V^3$$

where $C_P$ is the power coefficient and $R$ is the turbine rotor radius. A well-performing approach to estimating the conditional expectation $E[P|V,D,\rho,H,I,S]$ is the kernel method described here:

Power Curve Estimation With Multivariate Environmental Factors for Inland and Offshore Wind Farms

A kernel plus method for quantifying wind turbine performance upgrades

Basically, let $\{(\mathbf{x_i},y_i)\}_{i=1}^N$ be your database of predictors-power couples. The idea is to use a slightly modified version of the Nadaraya-Watson kernel estimator

$$\hat{y}(\mathbf{x})=\sum_{i=1}^Nw_i(\mathbf{x})y_i$$

where

$$w_i(\mathbf{x})=\frac{K_\lambda(\mathbf{x},\mathbf{x_i})}{\sum_{i=1}^NK_\lambda(\mathbf{x},\mathbf{x_i})}$$

Now, in the usual NW estimator, you would obtain the multivariate kernel by simply multiplying univariate Gaussian kernels for each predictor:

$$K_\lambda(\mathbf{x},\mathbf{x_i})=\prod_{j=1}^6K_{\lambda_j}(x_j,x_{j,i})$$

with

$$K_{\lambda_j}(x_j,x_{j,i})=\frac{1}{\sqrt{2\pi\lambda_j^2}}\exp\left(-\frac{(x_j-x_{j,i})^2}{2\lambda_j^2}\right)$$

However, this model suffers from the curse of dimensionality. The clever solution of the authors is, instead of using the product of 6 univariate kernels, to sum together 4 kernels, each one obtained by multplying together the univariate kernels corresponding to 3 variables, where the first two are always $V$ and $D$, and the third one is one of the remaining four, i.e., $\rho$, $H$, $I$, $S$. They end up with quite a few kernel bandwiths to estimate, which however you can estimate with various metrics, such as for example cross-validation. The only remaining difficulty is that $D$ is a circular variable, thus a Gaussian kernel doesn't make a lot of sense (it doesn't recognize that $D_i=1°$ and $D_i=358°$ are two very close directions). Fix this by using the von Mises kernel:

$$K_\nu(D,D_i)=\frac{\exp(\nu \cos(D-D_i))}{2\pi I_0(\nu)}$$

$\nu$ is the free parameter of the von Mises kernel, to be estimated from data, and $I_0(\nu)$ is the modified Bessel function of order 0.

If you definitely insist on performing univariate regression (which I don't recommend, but as said in the beginning, you're the only one that really knows your data), then you need to at least perform robust regression in order to take into account the heteroskedasticity. A reference:

A Bayesian Nonlinear Regression Model with Application to Wind Turbine Power Curve

Let me know what you end up doing, let's say I have personal reasons to be curious :)

• Thank you very much for taking the time to explain everything in such detail, by forming a power response surface rather than a power curve you therefore account for additional parameters which would help to build a better picture in regards to the causality of the power response. However for the analysis in which I wish to carry out I am not attempting to determine the reasoning / cause of a poorly preforming turbine at this stage I am simply trying to identify sub optimal power generation for a turbine based on its positional within the farm (wake effects). Dec 6, 2016 at 11:18
• Therefore once I have a power curve that has been adjusted to account for the wake effect of the turbine and it has been identified as performing sub optimally at this point I will plot a power response surface of the turbine in order to gain greater insight into the cause of the poor power generation performance. Dec 6, 2016 at 11:28
• Just out of my own curiosity what are your 'personal reasons to be curious' ? Dec 6, 2016 at 11:30
• @HenryQuekett, the addition of predictors is not done because one wants to answer causality questions. This is an observational study, thus causality cannot be assessed. It's done to reduce the residual variance. It's difficult to assess whether the turbine is performing sub-optimally, or whether the variation in power is just due to random chance (e.g. weather), if the residual variance is large. Anyway, if you want to go that way, the other reference shows you how. If you cannot get hold of the reference, I will add some details in my answer, but if I had to choose I wouldn't go that way. Dec 7, 2016 at 12:12

Maybe I'm missing something, but there is no such thing as a polynomial with an end point. The x axis goes out to infinity, and the polynomial has a value for every x. As noted, you can force it through any particular (x0,y0), but it will continue to have changing y values at higher x values.

I'm thinking you need at least two functions, one for x < x0, and a different one for x > x0. They can be forced to have the same slope at the crossover point.

Alternatively, if you are OK with doing it all numerically, just apply a moving average filter to generate a smoothed y value for every x. Savitsky-Golay filter functions are pretty easy to use.

• I think there is a bigger problem than how to fit the data. The measured power appears to be limited to a value of 275 kW for all windspeeds > 10 mph. That's very unphysical.
– Glen
Dec 2, 2016 at 1:30
• By design, turbines max out at moderate wind speeds.
– whuber
Dec 2, 2016 at 3:19
• @whuber Correct the rated power of the turbine is 280kW so this is the max power which you can get out of it regardless of how high the wind speed is. There is also a cut in windspeed of 3m/s before this the turbine isn't generating any electricity and a cut out of 25m/s were to prevent oil temperatures overheating in the gear box and mechanical failure occurring the turbine shuts down. (Although this is never reached in the data shown.) Dec 2, 2016 at 9:15
• The data collected at the higher windspeeds, where the turbine is maxed out, is leveraging the fitted models and should not be included. If you toss out all data points where output power exceeds, say, 275 kW, I think your fitted polynomials will do what you want. My eyeball says that a cubic should be sufficient; any higher power would be over-fitting.
– Glen
Dec 4, 2016 at 21:49
• A smart math modeler once told me that, with enough terms, you could fit an elephant.
– Glen
Dec 4, 2016 at 21:50