In this tutorial we will once again use yt directly in Blender, but in this example, we'll import some SPH code and plot some points in 3D instead of visualizing AMR surfaces.
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/Format||yt Surface Support||AstroBlend Surface Support||SPH Support|
|Artio||N||NA - just loads||NA|
|Fits||N||NA - just loads||NA|
|GDF||N||NA - just loads||NA|
|MOAB||N||NA - partial loading||NA|
|SPH Text Files||N||N||Yes (see here)|
yt Installation or Modification
The folowing is just a rehash of how to set up yt and AstroBlend to use both of them together in Blender as discussed in the first yt tutorial, so feel free to skip this section if you've already gone through that tutorial.
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)
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
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/')
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
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 "TipsyGalaxy" data found on the yt website (~10MB) here.
Generating SPH Visualizations with yt+AstroBlend
Loading in the SPH data directly from a simulation is very similar to loading it from a file with on difference - we need to specify what to color the SPH particles by as show in this snippet of code where we color them by temperature:
import science filename = '/Users/jillnaiman/data/TipsyGalaxy/galaxy.00300' color_field = ('Gas', 'Temperature') # color by temp color_log = True # take log of temp for mapping colors color_map = 'Rainbow' # these two things play off eachother! # larger halo size is needed when cam is far away halo_size = 0.108 # need to play with this and cam distance set_cam = (0,0,70) scale = [(1.0, 1.0, 1.0)] cam = science.Camera() cam.location = set_cam cam.clip_begin = 0.0001 lighting = science.Lighting('EMISSION') myobject = science.Load(filename, scale=scale, halo_sizes = halo_size, color_field = color_field, color_map = color_map, color_log = color_log, n_ref=8)
This results in the following setup in your Blender window:
Note that there are a few things that are different than when we imported things from a pre-formatted text file. In our "object selector" panel you'll notice that there are about 250 particle types listed. This is because our color maps are made up of 256 colors, so each particle type is made up of all the particles within that temperature bin, excluding colors where there are no particles in that temperature bin. For now, that is just how things need to be input. In the future, I'm hoping to figure out a way to mesh all of the particle types into one object.
One fun thing we can do is turn on "Render View" in our 3D viewer like so:
This allows for a rendered view as you move around the space using your number pad as discussed in the first tutorial. If you don't have a number pad but want to use the number keys to move around check out how to do this in the Blender Preferences under "Numpad emulation".
For fun, here is a short little movie of how you can move around your SPH simulation and check out things while its being rendered in real time:
One thing you may note is how the particles look all "fuzzy" when you are up close to them. This is
halo_sizes was set to give a good render when the camera was high above
the galaxy. The halo size and camera distance is something you can play around with to find a good
fit - too high and you just get a bunch of fuzzy lumps, but too small and nothing will show up on
your rendered image.