Advanced View3D TutorialΒΆ

For this tutorial, it is assumed that the reader is familar with the Overview of data using View3D tutorial. This tutorial seeks to introduce more advanced features for the view3D object. As shown below, one can e.g. specify whether or not a grid is to be plotted with the key word arguments grid but a lot of other parameters are possible.

[1]:
from MJOLNIR.Data import DataSet
from MJOLNIR import _tools # Usefull tools useful across MJOLNIR
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation


First, an animation function is create

[2]:
plt.ioff()

fig = plt.figure()
line = fig.gca().plot([], [], lw=2)

def View3DAnimator(V,name,folder,frames=None,keyFrame=None,fps=3):
    """Function to facilitate generation of animations for Viewer3D"""

    if not frames is None:
        Frames = frames

        nFrames = len(Frames)

    def animate(i,correct=False):
        if not correct:
            I = Frames[i]
        else:
            I = i

        V.Energy_slider.set_val(I)
        return line


    if not frames is None:
        fig = V.ax.get_figure()
        anim = animation.FuncAnimation(fig, animate,
                                       frames=nFrames, interval=10, blit=True)
        anim.save(folder+name+'.gif', fps=fps,dpi=100,writer='imagemagick')

    if not keyFrame is None:
        fig = V.ax.get_figure()
        animate(keyFrame,correct=True)
        fig.savefig('figure0.png',format='png')

plt.close(fig)

Data is loaded below and a view3D objec is provided to the animation function. Running this code does take quite some time to complete.

[3]:
numbers = '161-169'
# Load and convert data
fileName = _tools.fileListGenerator(numbers,folder=r'C:\Users\lass_j\Documents\CAMEA2018',year=2018)
ds = DataSet.DataSet(dataFiles=fileName)
ds.convertDataFile()

# Plotting data quickly in equi-sized voxels can be done by
Viewer = ds.View3D(0.03,0.03,0.09,grid=9,rlu=True)

#Generate the viewer with voxel size 0.03 1/AA x 0.03 1/AA x 0.05 meV, using
# the key word grid, one toggles the regular grid but providing the input
# as a number the zorder of the grid is specified (Data is plotted at 10).
# It is also possible to plot data without making use of reciprocal lattice
# units, chosen by rlu = True or False.

Viewer.caxis=(1e-8,5e-7)
nFrames = Viewer.Z.shape[-1] # Number of energy planes
frames = np.arange(3,nFrames-3)
frames = np.concatenate([frames,np.flip(frames[1:-1])]) #
# Generate animation as mp4 and create key frame as plane 75
View3DAnimator(Viewer,'ViewerAnimationEPlane',folder='',frames=frames,keyFrame=75,fps=7)
MovieWriter imagemagick unavailable; using Pillow instead.

The key frame generated corresponding to frame 75:

KeyFrame

However, the main output of this code is the animation shown below

f0ba1301f76c4b5eab1da1b0da77eb04