Skip to content

Commit

Permalink
Merge pull request #5 from jisuoqing/master
Browse files Browse the repository at this point in the history
Add yt volume rendering ipynb for focus session
  • Loading branch information
teuben authored Jul 25, 2016
2 parents 1175702 + dab0555 commit d8378f8
Show file tree
Hide file tree
Showing 3 changed files with 349 additions and 0 deletions.
86 changes: 86 additions & 0 deletions yt-volume_rendering/1_simple_render_and_tf.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import yt\n",
"import numpy as np\n",
"from yt.testing import fake_vr_orientation_test_ds\n",
"\n",
"ds = fake_vr_orientation_test_ds()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# now we do volume rendering\n",
"sc = yt.create_scene(ds, field='density')\n",
"sc.render()\n",
"sc.show(sigma_clip=6.0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# now we do volume rendering\n",
"sc = yt.create_scene(ds, field='density')\n",
"# Change transfer function\n",
"tf = yt.ColorTransferFunction((np.log10(0.1), np.log10(1.)))\n",
"tf.sample_colormap(np.log10(0.9), 0.01, colormap=\"spectral\")\n",
"tf.sample_colormap(np.log10(0.8), 0.01, colormap=\"spectral\")\n",
"tf.sample_colormap(np.log10(0.6), 0.01, colormap=\"spectral\")\n",
"tf.sample_colormap(np.log10(0.2), 0.01, colormap=\"spectral\")\n",
"render_source = sc.get_source(0)\n",
"render_source.transfer_function = tf"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"sc.render()\n",
"sc.show(sigma_clip=6.0)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
135 changes: 135 additions & 0 deletions yt-volume_rendering/2_camera_and_lens.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import yt\n",
"import numpy as np\n",
"from yt.testing import fake_vr_orientation_test_ds\n",
"\n",
"ds = fake_vr_orientation_test_ds()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# now we do volume rendering\n",
"sc = yt.create_scene(ds, field='density')\n",
"# Change transfer function\n",
"tf = yt.ColorTransferFunction((np.log10(0.1), np.log10(1.)))\n",
"tf.sample_colormap(np.log10(0.9), 0.01, colormap=\"spectral\")\n",
"tf.sample_colormap(np.log10(0.8), 0.01, colormap=\"spectral\")\n",
"tf.sample_colormap(np.log10(0.6), 0.01, colormap=\"spectral\")\n",
"tf.sample_colormap(np.log10(0.2), 0.01, colormap=\"spectral\")\n",
"render_source = sc.get_source(0)\n",
"render_source.transfer_function = tf"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# plane-parallel lens\n",
"cam = sc.add_camera(ds, lens_type='plane-parallel')\n",
"cam.resolution = (500, 500) # equivalent with cam.set_resolution()\n",
"cam.width = ds.quan(4, 'code_length') # equivalent with cam.set_width()\n",
"cam.position = ds.arr([2.5, 0, 0], 'code_length') # equivalent with cam.set_position()\n",
"cam.switch_orientation(normal_vector=[-1, 0, 0],\n",
" north_vector=[0, 0, 1])\n",
"sc.render()\n",
"sc.show(sigma_clip=2.0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# perspective lens\n",
"cam = sc.add_camera(ds, lens_type='perspective')\n",
"cam.resolution = (500, 500)\n",
"cam.width = ds.arr([2, 2, 1], 'code_length')\n",
"cam.position = ds.arr([2.5, 0, 0], 'code_length')\n",
"cam.switch_orientation(normal_vector=[-1, 0, 0],\n",
" north_vector=[0 ,0, 1])\n",
"sc.render()\n",
"sc.show(sigma_clip=6.0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# spherical lens\n",
"cam = sc.add_camera(ds, lens_type='spherical')\n",
"cam.resolution = (1000, 500)\n",
"cam.position = ds.arr([0.5, 0, 0], 'code_length')\n",
"cam.switch_orientation(normal_vector=[-1 ,0 ,0],\n",
" north_vector=[0 ,0 ,1])\n",
"sc.render()\n",
"sc.show(sigma_clip=6.0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# stereo-spherical lens (another similar lens is stereo-perspective)\n",
"cam = sc.add_camera(ds, lens_type='stereo-spherical')\n",
"cam.disparity = ds.domain_width[0] * 1.5e-3 # separation between two eyes\n",
"cam.resolution = (1000, 1000)\n",
"cam.position = ds.arr([0.5, 0, 0], 'code_length')\n",
"cam.switch_orientation(normal_vector=[-1 ,0, 0],\n",
" north_vector=[0, 0, 1])\n",
"sc.render()\n",
"sc.show(sigma_clip=6.0)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
128 changes: 128 additions & 0 deletions yt-volume_rendering/3_move_camera.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import yt\n",
"import numpy as np\n",
"from yt.testing import fake_vr_orientation_test_ds\n",
"\n",
"ds = fake_vr_orientation_test_ds()\n",
"\n",
"# now we do volume rendering\n",
"sc = yt.create_scene(ds, field='density')\n",
"# Change transfer function\n",
"tf = yt.ColorTransferFunction((np.log10(0.1), np.log10(1.)))\n",
"tf.sample_colormap(np.log10(0.9), 0.01, colormap=\"spectral\")\n",
"tf.sample_colormap(np.log10(0.8), 0.01, colormap=\"spectral\")\n",
"tf.sample_colormap(np.log10(0.6), 0.01, colormap=\"spectral\")\n",
"tf.sample_colormap(np.log10(0.2), 0.01, colormap=\"spectral\")\n",
"render_source = sc.get_source(0)\n",
"render_source.transfer_function = tf"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# perspective camera\n",
"cam = sc.add_camera(ds, lens_type='perspective')\n",
"cam.resolution = (500, 500)\n",
"cam.width = ds.arr([2, 2, 1], 'code_length')\n",
"cam.position = ds.arr([2.5, 0, 0], 'code_length')\n",
"cam.switch_orientation(normal_vector=[-1, 0, 0],\n",
" north_vector=[0, 0, 1])\n",
"sc.render()\n",
"sc.show(sigma_clip=6.0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# move cam by one step\n",
"cam.position = ds.arr([4, 0, 0], 'code_length')\n",
"sc.render()\n",
"sc.show(sigma_clip=6.0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# move cam by several steps\n",
"final_position = ds.arr([2.5, 0, 0], 'code_length')\n",
"for i in cam.iter_move(final_position, 5):\n",
" sc.save('move_%04d' % i, sigma_clip=6.0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# rotate cam by one step\n",
"rot_center = ds.arr([0, 0, 0], 'code_length')\n",
"angle = np.pi / 4.\n",
"cam.rotate(angle, rot_vector=[0, 0, 1], rot_center=rot_center)\n",
"sc.render()\n",
"sc.show(sigma_clip=6.0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# rotate cam by several steps\n",
"final_angle = -np.pi / 2.\n",
"for i in cam.iter_rotate(final_angle, 5, rot_vector=[-1, 1, 0], rot_center=rot_center):\n",
" sc.save('rotation_%04d' % i, sigma_clip=6.0)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

0 comments on commit d8378f8

Please sign in to comment.