def mymodel(xarr, b0, b1, amp1, xcen1, gw1, lw1, amp2, xcen2, gw2, lw2, amp3, xcen3, gw3, lw3, amp4, xcen4, gw4, lw4, return_components=False, normalized=False, **kwargs): """ docstring """ base = xarr * b1 + b0 v1 = voigt(xarr, amp1, xcen1, gw1, lw1, normalized=normalized) v2 = voigt(xarr, amp2, xcen2, gw2, lw2, normalized=normalized) v3 = voigt(xarr, amp3, xcen3, gw3, lw3, normalized=normalized) v4 = voigt(xarr, amp4, xcen4, gw4, lw4, normalized=normalized) if return_components: return np.array([base, v1, v2, v3, v4]) else: mod = base + v1 + v2 + v3 + v4 return mod
def voigt_line(x,wvl): amp = x[0] line_cen = x[1] fwhm = 0.4*abs(x[2]) ratio = abs(x[3]) Lfwhm = fwhm / (0.5346 + (0.2166 + (ratio**-2))**0.5) Gfwhm = fwhm / (0.5346*ratio + (0.2166*ratio**2.0 + 1)**0.5) line = voigt(wvl,amp,line_cen,Gfwhm,Lfwhm,normalized=False) line = amp*line/max(line) return line
try: import scipy scipyOK = True except ImportError: scipyOK = False if scipyOK: import numpy as np import pyspeckit.spectrum.models.inherited_voigtfitter as IV from pyspeckit.spectrum.units import SpectroscopicAxis xarr = SpectroscopicAxis(np.linspace(-100,100,1000)) dx = np.diff(xarr).mean() V1 = IV.voigt(xarr,1,0,1,1,normalized=False) V2 = IV.voigt(xarr,1,0,1,1,normalized=True) assert np.sqrt(2*np.pi) - 0.05 < V1.sum()*dx.value < np.sqrt(2*np.pi) + 0.05 assert 0.99 < V2.sum()*dx.value < 1.01 else: print("Skipped Voigt test because scipy could not be imported")
try: import scipy scipyOK = True except ImportError: scipyOK = False if scipyOK: import numpy as np import pyspeckit.spectrum.models.inherited_voigtfitter as IV from pyspeckit.spectrum.units import SpectroscopicAxis xarr = SpectroscopicAxis(np.linspace(-100, 100, 1000)) dx = np.diff(xarr).mean() V1 = IV.voigt(xarr, 1, 0, 1, 1, normalized=False) V2 = IV.voigt(xarr, 1, 0, 1, 1, normalized=True) assert np.sqrt(2 * np.pi) - 0.05 < V1.sum() * dx.value < np.sqrt( 2 * np.pi) + 0.05 assert 0.99 < V2.sum() * dx.value < 1.01 else: print("Skipped Voigt test because scipy could not be imported")