Skip to content

Commit af9617f

Browse files
committed
extracted SEDs, images, animations
1 parent 7f1711c commit af9617f

File tree

4 files changed

+116
-0
lines changed

4 files changed

+116
-0
lines changed

getanimation.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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)

getfits.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import pyfits
2+
3+
from hyperion.model import ModelOutput
4+
from hyperion.util.constants import pc
5+
6+
# Open the model - we specify the name without the .rtout extension
7+
m = ModelOutput('tutorial_model.rtout')
8+
9+
# Extract the image for the first inclination, and scale to 300pc. We
10+
# have to specify group=1 as there is no image in group 0
11+
wav, nufnu = m.get_image(group=1, inclination=0, distance=300 * pc)
12+
13+
# The image extracted above is a 3D array. We can write it out to FITS.
14+
# We need to swap some of the directions around so as to be able to use
15+
# the ds9 slider to change the wavelength of the image.
16+
pyfits.writeto('image_cube.fits', nufnu.swapaxes(0, 2).swapaxes(1, 2), \
17+
clobber=True)
18+
19+
# We can also just output one of the wavelengths
20+
pyfits.writeto('image_slice.fits', nufnu[:, :, 0], clobber=True)

getfitsWCS.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import pywcs
2+
import pyfits
3+
4+
from hyperion.model import ModelOutput
5+
from hyperion.util.constants import pc
6+
7+
m = ModelOutput('tutorial_model.rtout')
8+
wav, nufnu = m.get_image(group=1, inclination=0, distance=300 * pc)
9+
10+
# Initialize WCS information
11+
wcs = pywcs.WCS(naxis=2)
12+
13+
# Use the center of the image as projection center
14+
wcs.wcs.crpix = [nufnu.shape[2] / 2. + 0.5,
15+
nufnu.shape[1] / 2. + 0.5]
16+
17+
# Set the coordinates of the image center
18+
wcs.wcs.crval = [233.4452, 1.2233]
19+
20+
# Set the pixel scale (in deg/pix)
21+
wcs.wcs.cdelt = [1./3600., 1./3600.]
22+
23+
# Set the coordinate system
24+
wcs.wcs.ctype = ['GLON-CAR', 'GLAT-CAR']
25+
26+
# And produce a FITS header
27+
header = wcs.to_header()
28+
29+
# Write out to a file including the new header
30+
pyfits.writeto('image_slice_wcs.fits', nufnu[:, :, 0], header,
31+
clobber=True)

getsed.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import numpy as np
2+
3+
from hyperion.model import ModelOutput
4+
from hyperion.util.constants import pc
5+
6+
# Open the model - we specify the name without the .rtout extension
7+
m = ModelOutput('tutorial_model.rtout')
8+
9+
# Extract the SED for the smallest inclination and largest aperture, and
10+
# scale to 300pc. In Python, negative indices can be used for lists and
11+
# arrays, and indicate the position from the end. So to get the SED in the
12+
# largest aperture, we set aperture=-1.
13+
wav, nufnu = m.get_sed(inclination=1, aperture=-1, distance=300 * pc)
14+
15+
# Write out the SED to file
16+
np.savetxt('sed.txt', zip(wav, nufnu), fmt="%11.4e %11.4e")

0 commit comments

Comments
 (0)