From f7c2298eed5bbf1489e08a0420d5f08396b59e3e Mon Sep 17 00:00:00 2001 From: Priyanka Seth Date: Mon, 4 May 2015 14:48:22 +0200 Subject: [PATCH] [doc] added another faq --- doc/faqs/faqs.rst | 10 +++- doc/faqs/plotting_spaghettis.py | 33 +++++++++++ doc/function_template.py | 98 --------------------------------- 3 files changed, 40 insertions(+), 101 deletions(-) create mode 100644 doc/faqs/plotting_spaghettis.py delete mode 100644 doc/function_template.py diff --git a/doc/faqs/faqs.rst b/doc/faqs/faqs.rst index 0d33ab4e..378bb04f 100644 --- a/doc/faqs/faqs.rst +++ b/doc/faqs/faqs.rst @@ -11,10 +11,14 @@ A hack solution is as follows: 3) `x lapw2 -almd -band` 4) `dmftproj -band` (add the fermi energy to file, it can be found by running `grep :FER *.scf`) -How do I do ..this..? ---------------------- +How do I plot the output of `spaghettis`? +----------------------------------------- -This is how you do this. +In python, you can do the following for example. You should pass the name of +the file written out by the spaghettis function. Of course, you should change +the parameters as desired. + +.. literalinclude:: plotting_spaghettis.py Why is my calculation not working? ---------------------------------- diff --git a/doc/faqs/plotting_spaghettis.py b/doc/faqs/plotting_spaghettis.py new file mode 100644 index 00000000..63acdd2e --- /dev/null +++ b/doc/faqs/plotting_spaghettis.py @@ -0,0 +1,33 @@ +from matplotlib import * +import matplotlib.pyplot as plt +import numpy as np + +filename = 'spaghettis_to_plot.dat' # Name of file +emin = -1.0 # Minimum of energy range to plot +emax = 1.5 # Maximum of energy range to plot +zmin = 0.0 #z.min() # Minimum of colour range +zmax = 5.0 #z.max() # Maximum of colour range +kpos = [0, 50, 100, 150, 200] # Position of high-symmetry k-point +kname = ['M', 'G', 'X', 'Z', 'M'] # Name of high-symmetry k-point + +b = np.loadtxt(filename) +n_k = int(b[:,0][-1] + 1) +mesh_size = len(b[:,0])/n_k +klist = b[:,0][::mesh_size] +elist = b[:,1][0:mesh_size] +x,y = np.meshgrid(klist,elist) +z = b[:,2].reshape(n_k,mesh_size) + +fig, ax = plt.subplots() +p = ax.pcolormesh(x,y,z.T, cmap=cm.Blues, vmin=zmin, vmax=zmax) +cb = fig.colorbar(p, ax=ax) +ax.set_xlim(klist.min(),klist.max()) +ax.set_ylim(emin,emax) +ax.hlines(0.0,0,n_k-1) +plt.title(filename,fontsize=24) +for i in kpos: ax.vlines(i,emin,emax,alpha=0.5) +plt.xticks(kpos,kname,fontsize=16) +plt.ylabel('Energy (%s)'%'eV', fontsize=18) +plt.yticks(fontsize=16) +plt.grid() +plt.savefig(''.join(kname)+'_'+filename.replace('dat','png'),bbox_inches='tight') diff --git a/doc/function_template.py b/doc/function_template.py deleted file mode 100644 index 072c5acc..00000000 --- a/doc/function_template.py +++ /dev/null @@ -1,98 +0,0 @@ -class function_template(): - - def old_fft(name, state=None): - """This function does something. - - :param name: The name to use. - :type name: str. - :param state: Current state to be in. - :type state: bool. - :returns: int -- the return code. - :raises: AttributeError, KeyError - - """ - return 0 - - def fft(a, n=None, axis=-1): - - """ - Compute the one-dimensional discrete Fourier Transform. - This function computes the one-dimensional *n*-point discrete Fourier - Transform (DFT) with the efficient Fast Fourier Transform (FFT) - algorithm [CT]. - - Parameters - ---------- - a : array_like - Input array, can be complex. - n : int, optional - Length of the transformed axis of the output. - If `n` is smaller than the length of the input, the input is cropped. - If it is larger, the input is padded with zeros. If `n` is not given, - the length of the input along the axis specified by `axis` is used. - axis : int, optional - Axis over which to compute the FFT. If not given, the last axis is - used. - - Returns - ------- - out : complex ndarray - The truncated or zero-padded input, transformed along the axis - indicated by `axis`, or the last one if `axis` is not specified. - - Raises - ------ - IndexError - if `axes` is larger than the last axis of `a`. - - See Also - -------- - numpy.fft : for definition of the DFT and conventions used. - ifft : The inverse of `fft`. - fft2 : The two-dimensional FFT. - fftn : The *n*-dimensional FFT. - rfftn : The *n*-dimensional FFT of real input. - fftfreq : Frequency bins for given FFT parameters. - - Notes - ----- - FFT (Fast Fourier Transform) refers to a way the discrete Fourier - Transform (DFT) can be calculated efficiently, by using symmetries in the - calculated terms. The symmetry is highest when `n` is a power of 2, and - the transform is therefore most efficient for these sizes. - The DFT is defined, with the conventions used in this implementation, in - the documentation for the `numpy.fft` module. - - References - ---------- - .. [CT] Cooley, James W., and John W. Tukey, 1965, "An algorithm for the - machine calculation of complex Fourier series," *Math. Comput.* - 19: 297-301. - - Examples - -------- - >>> np.fft.fft(np.exp(2j * np.pi * np.arange(8) / 8)) - array([ -3.44505240e-16 +1.14383329e-17j, - 8.00000000e+00 -5.71092652e-15j, - 2.33482938e-16 +1.22460635e-16j, - 1.64863782e-15 +1.77635684e-15j, - 9.95839695e-17 +2.33482938e-16j, - 0.00000000e+00 +1.66837030e-15j, - 1.14383329e-17 +1.22460635e-16j, - -1.64863782e-15 +1.77635684e-15j]) - - >>> import matplotlib.pyplot as plt - >>> t = np.arange(256) - >>> sp = np.fft.fft(np.sin(t)) - >>> freq = np.fft.fftfreq(t.shape[-1]) - >>> plt.plot(freq, sp.real, freq, sp.imag) - [, ] - >>> plt.show() - In this example, real input has an FFT which is Hermitian, i.e., symmetric - in the real part and anti-symmetric in the imaginary part, as described in - the `numpy.fft` documentation. - - """ - - return 0