Friday, 15 July 2011

python - Problems trying to calculate FWHM with scipy.interpolate -



python - Problems trying to calculate FWHM with scipy.interpolate -

i having problems trying find fwhm of data. tried fit curve using interpolate.interp1d. able create function when entered x value homecoming interpolated y value. issue need inverse of functionality. in other words, want switch independent , dependent variables. when seek switch them, errors because independent info has sorted. if sort data, lose indexes, , hence lose shape of graph.

i tried:

x = np.linspace(0, line.shape[0], line.shape[0]) self.x_curve = interpolate.interp1d(x, y, 'linear')

where y data.

to inverse, tried:

self.x_curve = interpolate.interp1d(sorted(y), x, 'linear')

but values off.

i moved on , tried utilize univariatespline , roots find fwhm (from question here: finding total width half maximum of peak), roots() method keeps giving me empty list [].

this used:

x_curve = interpolate.univariatespline(x, y) r = x_curve.roots() print(r)

here image of info (with univariatespline):

any ideas? thanks.

using univariatespline.roots() fwhm work if shift info value 0 @ fwhm.

seeing background of info noisy, i'd first estimate baseline. example:

y_baseline = y[(x<200) & (x>350)].mean()

(adjust limits x see fit). shift info middle of baseline , peak @ 0. seeing info has minimum , not maximum in example, i'm using y.min():

y_shifted = y - (y.min()+y_baseline)/2.0

now fit spline shifted info , roots() should able find roots, difference of fwhm.

x_curve = interpolate.univariatespline(x, y_shifted, s=0) x_curve.roots()

increase s parameter if want estimate fwhm smoothed data.

python image-processing scipy interpolation spline

No comments:

Post a Comment