Good Interpolation Method For Color Mixing?
Solution 1:
I'll expand my comment since nobody has answered.
From what I see in the figure, there is a pattern. The best way would be to fit a curve that fits that pattern as a whole. You can do this without any math using Eureqa (the free trial should be enough): http://www.nutonian.com/products/eureqa/
If you want to remain in python and fit an exponential distribution, you can do the following: How to do exponential and logarithmic curve fitting in Python? I found only polynomial fitting
So imagine you have for the wavelength 500nm the following values:
y = [10,20,30,30,50,60,70,80,90,100]
x = [0.,0.3,0.5,0.6,0.72,0.77,0.84,0.9,0.95,1]
Then the code to fit the exponential curve would be:
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
deffunc(x, a, b, c):
return a * np.exp(-b * x) + c
popt, pcov = curve_fit(func, x, y)
In this case we get that a,b, and c are:
popt = array([ 7.1907744 , -2.62804994, 2.45029842])
So to get the value of reflected light at a certain x (for instance 0.2), you can do:
func(0.2, 7.1907744 , -2.62804994, 2.45029842)
Which is 14.61
But you say it's a bad fit, if you don't need a model, you can do the following: If you don't really care about having a model you can use this: https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.interp1d.html#scipy.interpolate.interp1d
from scipy import interpolate
f = interpolate.interp1d(x, y, kind="quadratic") #you can try different kinds of interpolation
And then to find a value (for instance x=0.2):
ynew = f(0.2)
Which is 6.549
Or to have many values so you can plot them: ynew = f(np.linspace(0,1,1000)
Post a Comment for "Good Interpolation Method For Color Mixing?"