# coding: utf-8
# This demonstrates the use of the humlicek, weideman, and sdv modules and how to generate the contour plots.
# Ideally you should have started the IPython interpreter with the --pylab option
# to automatically pre-load matplotlib and numpy for interactive use:
#
# ipython --pylab
# ipython qtconsole --pylab &
# ipython notebook --pylab &
from matplotlib import ticker # possibly its already imported automtically
from ir import *
from humlicek import *
from weideman import *
from sdv import * # this also imports the wofz reference from scipy!
# define the standard Voigt variables on a linear and logarithmic grid
x=np.linspace(0.,25.,251)
y=np.logspace(-6,2,81)
# kind of 'matrices' required for the contour plots (note Python is case sensitive!)
X, Y = np.meshgrid(x, y)
Z = X +1j*Y
# lets start with the Voigt function, just compare the Humlicek and wofz reference for y=1
wRef = wofz(x+1j).real
wTest = humlicek(x+1j).real
plot (x, wTest, 'r', x, wRef, 'b--')
# possibly its better to close the figure before looking at the differences
semilogy(x,abs(wTest-wRef)/wRef)
# the same, but for all y
wRef = wofz(Z).real
wTest= humlicek(Z).real
contourf(X,log10(Y), abs(wTest-wRef)/wRef) # first try!
# Use the levels as in the paper and change to the red-blue color map
contourLevels = logspace(-12,4,17)
set_cmap('RdBu_r') # if you have already closed the figure this will give a RuntimeError, ignore it
# now try a Humlicek-Weideman combination
wTest = hum1wei32a(Z).real
contourf(X,log10(Y), abs(wTest-wRef)/wRef, contourLevels, locator=ticker.LogLocator())
colorbar()
# and now the speed-dependent Voigt
sdvRef = sdv_axy_naive(X,Y,10.,wofz)
sdvTest = sdv_axy_naive(X,Y,10.,hum2wei32a)
contourf(X,log10(Y), abs(sdvTest-sdvRef)/sdvRef, contourLevels, locator=ticker.LogLocator()); colorbar()