1+ import os
2+
3+ import numpy as np
4+
5+ import matplotlib as mpl
6+ mpl .use ('Agg' )
7+ import matplotlib .pyplot as plt
8+
9+ from hyperion .model import ModelOutput
10+ from hyperion .util .constants import pc
11+
12+ # Create output directory if it does not already exist
13+ if not os .path .exists ('frames' ):
14+ os .mkdir ('frames' )
15+
16+ # Open model
17+ m = ModelOutput ('tutorial_model.rtout' )
18+
19+ # Read image from model
20+ wav , nufnu = m .get_image (group = 2 , distance = 300 * pc )
21+
22+ # nufnu is now an array with four dimensions (n_view, n_wav, n_y, n_x)
23+
24+ # Fix the wavelength to the first one and cycle through viewing angles
25+ iwav = 0
26+ print "Wavelength is %g microns" % wav [iwav ]
27+
28+ for iview in range (nufnu .shape [0 ]):
29+
30+ # Open figure and create axes
31+ fig = plt .figure ()
32+ ax = fig .add_subplot (1 , 1 , 1 )
33+
34+ # This is the command to show the image. The parameters vmin and vmax are
35+ # the min and max levels for the grayscale (remove for default values).
36+ # The colormap is set here to be a heat map. Other possible heat maps
37+ # include plt.cm.gray (grayscale), plt.cm.gist_yarg (inverted grayscale),
38+ # plt.cm.jet (default, colorful). The np.sqrt() is used to plot the
39+ # images on a sqrt stretch.
40+ ax .imshow (np .sqrt (nufnu [iview , :, :, iwav ]), vmin = 0 , vmax = np .sqrt (1.e-11 ), \
41+ cmap = plt .cm .gist_heat , origin = 'lower' )
42+
43+ # Save figure. The facecolor='black' and edgecolor='black' are for
44+ # esthetics, and hide the axes
45+ fig .savefig ('frames/frame_%05i.png' % iview , \
46+ facecolor = 'black' , edgecolor = 'black' )
47+
48+ # Close figure
49+ plt .close (fig )
0 commit comments