Better interpolation
Change-Id: I258a927fdc8912c0533df59ad832ddc739ddf146
This commit is contained in:
parent
8d4680ccc5
commit
eeb0ae7a58
|
@ -4,14 +4,6 @@ from numpy import linalg
|
||||||
from scipy.interpolate import interp1d
|
from scipy.interpolate import interp1d
|
||||||
|
|
||||||
|
|
||||||
class NoInterpolatedDataException(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class WrongWavelengthsInConf(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class OpusData(object):
|
class OpusData(object):
|
||||||
def __init__(self, raw_data, interp=None, meta=None):
|
def __init__(self, raw_data, interp=None, meta=None):
|
||||||
self.raw_data = raw_data
|
self.raw_data = raw_data
|
||||||
|
@ -25,38 +17,13 @@ class OpusData(object):
|
||||||
dist = linalg.norm(y_r - self.raw_data[1], ord=1)
|
dist = linalg.norm(y_r - self.raw_data[1], ord=1)
|
||||||
print("L1 distance between series:", dist)
|
print("L1 distance between series:", dist)
|
||||||
|
|
||||||
def gen_interp_waves(self, conf):
|
def interpolate(self, start, stop, num):
|
||||||
wunit = (conf.wave_start - conf.wave_end) / (float(conf.iwsize - 1))
|
|
||||||
a = conf.wave_start + wunit
|
|
||||||
iwavenumber = [0] * conf.iwsize
|
|
||||||
for i in range(len(iwavenumber)):
|
|
||||||
a -= wunit
|
|
||||||
iwavenumber[i] = a
|
|
||||||
return iwavenumber
|
|
||||||
|
|
||||||
def interpolate_spectra(self, conf):
|
|
||||||
xav, yav = self.raw_data[0], self.raw_data[1]
|
xav, yav = self.raw_data[0], self.raw_data[1]
|
||||||
ab_wavenumbers = self.raw_data[0]
|
iwavenumber = np.linspace(start,
|
||||||
iwavenumber = self.gen_interp_waves(conf)
|
stop,
|
||||||
|
num)
|
||||||
xa_min = min(ab_wavenumbers)
|
f2 = interp1d(xav, yav,
|
||||||
xa_max = max(ab_wavenumbers)
|
kind='cubic',
|
||||||
n_interp = conf.iwsize
|
assume_sorted=True,
|
||||||
yi = []
|
fill_value='extrapolate')
|
||||||
|
return iwavenumber, f2(iwavenumber)
|
||||||
f2 = interp1d(xav, yav, kind='cubic', assume_sorted=True)
|
|
||||||
|
|
||||||
for k in range(n_interp):
|
|
||||||
if iwavenumber[k] < xa_min:
|
|
||||||
if k == n_interp - 1:
|
|
||||||
yi.append(yav[0])
|
|
||||||
else:
|
|
||||||
print("Wrong wavelengths for interpolating data")
|
|
||||||
elif iwavenumber[k] > xa_max:
|
|
||||||
if k == 0:
|
|
||||||
yi.append(yav[-1])
|
|
||||||
else:
|
|
||||||
raise WrongWavelengthsInConf()
|
|
||||||
else:
|
|
||||||
yi.append(f2(iwavenumber[k]))
|
|
||||||
return iwavenumber, yi
|
|
||||||
|
|
Loading…
Reference in New Issue