Utility classes and functions

Trilinear interpolation

The class LinearInterpolationNOGrid supports linear, bilinear and trilinear interpolation for data on an even grid in 1D, 2D or 3D, with orthogonal or non-orthogonal lattice vectors. Please see the code reference for documentation.

Code reference

class envtb.quantumcapacitance.utilities.LinearInterpolationNOGrid(func, grid=1, start=None, default=None)[source]

The class takes a function on a uniform, rectangular grid (with orthogonal or non-orthogonal lattice vectors) and calculates the function at any point using linear interpolation. It can be a 1D, 2D or 3D grid.

See http://en.wikipedia.org/wiki/Trilinear_interpolation for the math.

Usage:

func=[[0,1],[2,3]]
start=[0,0]
latticevecs=[[1e-3,0],[0,1e-3]]
interp=LinearInterpolationNOGrid(func,latticevecs)

f=interp(0.3,0.6)

Note: the gridpoints on the upper boundary in each direction are not accessible by the interpolation function. TODO: fix that.

Also note: Pay attention to the ordering of the func array.

func: multi-dimensional array containing the function
values (list or numpy.array) in a right-handed coordinate system (e.g. x to the left, y up), with the indices in the same order as the grid sizes/lattice vectors (i.e. if the lattice vectors point in x,y and z direction, func will be called like func[x,y,z])
start: the start point of the coordinate system given by latticevecs
(list or numpy.array). Default is None, which means that the grid is starting at the coordinate origin.
grid: either 1) Lattice vectors (list or numpy.array)
or 2) a number, which is the gridsize. Default is 1.
default: The function value of points outside the area.
Default is None.
dim()[source]

Return the dimension of the interpolation function.

map_function_to_points(points)[source]

Return list of function values at given points.

points: list of points

Matplotlib tips

http://www.packtpub.com/article/advanced-matplotlib-part1

fig1 = pyplot.figure()
fig2 = pyplot.figure()
ax1 = fig1.add_subplot(2,1,1)
ax2 = fig1.add_subplot(2,1,2)
l, = ax2.plot(x, y)
m, = ax1.plot(x, y)
w, = ax1.plot(x, y+3)
t = ax2.set_title('random numbers')
l.set_color('red')
m.set_color('blue')
ax3=fig2.add_subplot(1,1,1)
n, = ax3.plot(x, y)
w.set_color('red')
fig1.legend([m,w], ["line 2", "line 1"])
ax2.legend([l],["line 3"])
The pyplot.someFunction() commands are equivalent to::
ax=pyplot.gca() ax.someFunction()

i.e. they are applied to the current axes.

The standard procedure would be:

  • Set up the plot “window” using figure() and subplot()
  • Execute the plot function (e.g. plot_bandstructure())
  • If the function returns lists of lines, you can style them.
  • The axes have a lines property which is a list of all the lines. You can style them here too.
  • Set other properties, like x and y limits, legend, other texts that belong to the figure or the subplot (=axes).

Workflow recommendation

This is not a utility class, but it’s the best place to put this information.

(Work on this!)

  • IPython web interface
  • Use ? for documentation
  • combine plots and use pyplot.show()
  • handle data, numpy.savetxt

Table Of Contents

Previous topic

Physics

This Page