I know what you're thinking. You're thinking, "hey wait a minute, that is EXACTLY the same image as the previous tutorial," which you of course already went through (right??). This is because we are going to end up rendering the exact same image but in a totally fancier way - using yt with in Blender itself.

Again, please make sure you are set up correctly first and you have read the first and second AstroBlend tutorials.

If you want to be able to export surfaces as OBJs that save their emission information, make sure you have modified your Blender's obj importer and exporter as described in the "Getting Started" section.

Current Code Support

Below is a summary of the level of support for each type of hydrodynamical code:

AstroBlend support for codes is an ongoing process, please find your code below to see if its supported.

Code/Formatyt Surface SupportAstroBlend Surface SupportSPH Support
FLASHYYNA
EnzoYYNA
AthenaYYNA
ArtioNNA - just loadsNA
FitsNNA - just loadsNA
GDFNNA - just loadsNA
MOABNNA - partial loadingNA
SPH Text FilesNNYes (see here)
TipsyNNY

yt Installation or Modification

The current version of yt supports compilation with python 3.4 in general (with more codes being included in AstroBlend as an ongoing process). To install or update your yt version to python 3.4, check out the following script here. Note: this will recompile your yt version in python 3.4, which you might not want to do, in which case make sure you change the DEST_SUFFIX parameter in this script. A few other parameters in the beginning of this script you should double check are (1) BLENDER_DIR which should point to your installed version of Blender (if not found the script will install Blender IF you are on a Mac, which is all that is supported at the moment), (2) ASTROBLEND_DIR should point at your forked or downloaded version of the AstroBlend library.

The basics of this script are that it (1) downloads yt and relevant packages, (2) converts yt in to python 3.4 and recompiles, (3) creates a file that Blender runs on startup which includes the relevant paths to the yt and AstroBlend directories, and (4) updates your bash file (.bash_profile on a Mac) to create a terminal runnable version of Blender which runs this library file on start up.

Before we move onto actually importing data in AstroBlend with yt, lets take a quick look at this library file.

import sys
vv = \
['', '/Users/jillnaiman/yt-x86_64/lib/python3.4/site-packages/distribute-0.6.32-py3.4.egg', '/Users/jillnaiman/yt-x86_64/lib/python3.4/site-packages/matplotlib-1.4.0-py3.4-macosx-10.9-x86_64.egg', '/Users/jillnaiman/yt-x86_64/lib/python3.4/site-packages/nose-1.3.4-py3.4.egg', '/Users/jillnaiman/yt-x86_64/lib/python3.4/site-packages/pyparsing-2.0.3-py3.4.egg', '/Users/jillnaiman/yt-x86_64/lib/python3.4/site-packages/python_dateutil-2.4.0-py3.4.egg', '/Users/jillnaiman/yt-x86_64/lib/python3.4/site-packages/six-1.9.0-py3.4.egg', '/Users/jillnaiman/yt-x86_64/lib/python3.4/site-packages/tornado-4.0.1-py3.4-macosx-10.9-x86_64.egg', '/Users/jillnaiman/yt-x86_64/lib/python3.4/site-packages/certifi-14.05.14-py3.4.egg', '/Users/jillnaiman/yt-x86_64/lib/python3.4/site-packages/h5py-2.3.1-py3.4-macosx-10.9-x86_64.egg', '/Users/jillnaiman/yt-x86_64/lib/python3.4/site-packages/Cython-0.20.2-py3.4-macosx-10.9-x86_64.egg', '/Users/jillnaiman/yt-x86_64/lib/python3.4/site-packages/yt-3.2dev-py3.4-macosx-10.9-x86_64.egg', '/Users/jillnaiman/yt-x86_64/lib/python3.4/site-packages', '/Users/jillnaiman/yt-x86_64/lib/python34.zip', '/Users/jillnaiman/yt-x86_64/lib/python3.4', '/Users/jillnaiman/yt-x86_64/lib/python3.4/plat-darwin', '/Users/jillnaiman/yt-x86_64/lib/python3.4/lib-dynload']
for i in range(0,len(vv)):
    if vv[i] not in sys.path:
        sys.path.append(vv[i])
vv2 = ['']
for i in range(0,len(sys.path)):
    if sys.path[i].find('python2') is -1:
        vv2.append(sys.path[i])
sys.path = vv2
sys.path.append('/Users/jillnaiman/astroblend-stable/science/')
First, this little bit of code adds all the new python 3.4 and yt libraries that we will be using in Blender, and then it takes out any references to python 2 libraries so that AstroBlend doesn't get confused. Finally, it points to your install of the AstroBlend libraries, in my case these are stored in a folder in my home directory calld "astroblend-stable". You can also update this file to add or exclude your own libraries - for example, I've got a few installs of yt and I wanted to make sure Blender didn't use any of the libraries in my yt install labeled "yt3" so I simply added the following lines onto my version of this script:
vv2 = ['']
for i in range(0,len(sys.path)):
    if sys.path[i].find('yt3') is -1:
        vv2.append(sys.path[i])
sys.path = vv2
Now you can run Blender from the terminal with the command "blender" which is aliased in your bash file with something like:
alias blender='/Applications/Blender/blender.app/Contents/MacOS/blender -P /Users/jillnaiman/yt-x86_64/yt_blender_import.py'

Get the yt Data

The next step is to actually have some data to work with. For this example, we will be using the "IsolatedGalaxy" data found on the yt website (~300MB) here.

Generating Surfaces with yt+AstroBlend

Actually generating the surfaces in AstroBlend was covered in the previous tutorial so rather then rehashing it I'll simply post the relevant code below:

import science
import numpy as np

# Enzo data
filename = '~/data/IsolatedGalaxy/galaxy0030/galaxy0030'
sphere_rad = 200.0 # in kpc

# Density will be the isosurface determinant - so pick 2 densities
rho = [2e-27, 1e-27]
# transparencies of densities - inner is 100% opaque, outer is 50%
transparencies = [1.0, 0.5]

# how is emissivity calculated?
def _Emissivity(field, data):
    return (data['gas','density']*data['density']*np.sqrt(data['gas','temperature']))

# isosurfaces at 2 and 1 x 10^-27
myobject = science.Load(filename, scale = (50.0, 50.0, 50.0), isosurface_value = rho, 
                        surf_type='sphere', radius = sphere_rad, 
                        radius_units = "kpc", surface_field="density", 
                        meshname = 'Allen', transparency = transparencies, 
                        color_field='temperature', emit_field=_Emissivity) 

science.delete_object('Lamp')
science.delete_object('Cube')
light = science.Lighting('EMISSION')

cam = science.Camera()
cam.location = (-6,0,0)
cam.pointing = (0,0,0)

This results in the following setup in your Blender window:

Note that this results in the exact same setup as if we where to import from an OBJ file like in the previous tutorial. However, we now see that we have two names in the object selector panel: "Allen_0" and "Allen_1". This allows us to do some fun things. For example we could seperate the two surfaces and render both at the same time like so:

myobject.location = [(0,0,0), (0,4,0)]
cam.location = (-6, 2, 0)
cam.pointing = (0, 2, 0)

Note that in this case, the purple inner surface is being lit by the outer more emissive surface.

We can also scale them differently. For example, just for fun, lets make one really small and distort it with:

myobject.scale = [(10, 5, 15),myobject.scale[1]]

Exporting Surfaces

Finally, if you like your surfaces and want to export them as OBJ files for later, or to upload elsewhere like Sketchfab or MeshLab you can do this with the simple command like:

myobject.export_obj('/Users/jillnaiman/yt_files_local/mysurfs.obj')

Note that if you want to export each surface as its own OBJ file you can instead do the following:

myobject.export_obj('/Users/jillnaiman/yt_files_local/mysurfs0.obj', 
                      export_selected = True, export_selected_name = 'Allen_0')
myobject.export_obj('/Users/jillnaiman/yt_files_local/mysurfs1.obj', 
                      export_selected = True, export_selected_name = 'Allen_1')

SPH Movie from Text File

Previous Tutorial

Direct SPH with yt

Next Tutorial