yt.visualization.volume_rendering.camera module

Volume Rendering Camera Class

class yt.visualization.volume_rendering.camera.Camera(scene, data_source=None, lens_type='plane-parallel', auto=False)[source]

Bases: yt.utilities.orientation.Orientation

A representation of a point of view into a Scene.

It is defined by a position (the location of the camera in the simulation domain,), a focus (the point at which the camera is pointed), a width (the width of the snapshot that will be taken, a resolution (the number of pixels in the image), and a north_vector (the “up” direction in the resulting image). A camera can use a variety of different Lens objects.

Parameters:
  • scene (A yt.visualization.volume_rendering.scene.Scene object) – A scene object that the camera will be attached to.
  • data_source (AMR3DData or Dataset, optional) – This is the source to be rendered, which can be any arbitrary yt data object or dataset.
  • lens_type (string, optional) – This specifies the type of lens to use for rendering. Current options are ‘plane-parallel’, ‘perspective’, and ‘fisheye’. See yt.visualization.volume_rendering.lens.Lens for details. Default: ‘plane-parallel’
  • auto (boolean) – If True, build smart defaults using the data source extent. This can be time-consuming to iterate over the entire dataset to find the positional bounds. Default: False

Examples

In this example, the camera is set using defaults that are chosen to be reasonable for the argument Dataset.

>>> import yt
>>> from yt.visualization.volume_rendering.api import Scene
>>> ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
>>> sc = Scene()
>>> cam = sc.add_camera(ds)

Here, we set the camera properties manually:

>>> import yt
>>> from yt.visualization.volume_rendering.api import Scene
>>> sc = Scene()
>>> cam = sc.add_camera()
>>> cam.position = np.array([0.5, 0.5, -1.0])
>>> cam.focus = np.array([0.5, 0.5, 0.0])
>>> cam.north_vector = np.array([1.0, 0.0, 0.0])

Finally, we create a camera with a non-default lens:

>>> import yt
>>> from yt.visualization.volume_rendering.api import Scene
>>> ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
>>> sc = Scene()
>>> cam = sc.add_camera(ds, lens_type='perspective')
focus

The focus defines the point the Camera is pointed at.

Parameters:focus (number, YTQuantity, iterable, or 3 element YTArray) – The width of the volume rendering in the horizontal, vertical, and depth directions. If a scalar, assumes that the width is the same in all three directions. If an iterable, must contain only scalars or (length, unit) tuples.
get_focus()[source]

Returns the current camera focus

get_position()[source]

Return the current camera position

get_resolution()[source]

Returns the resolution of the volume rendering

get_width()[source]

Return the current camera width

iter_move(final, n_steps, exponential=False)[source]

Loop over an iter_move and return snapshots along the way.

This will yield n_steps until the current view has been moved to a final center of final.

Parameters:
  • final (YTArray) – The final center to move to after n_steps
  • n_steps (int) – The number of snapshots to make.
  • exponential (boolean) – Specifies whether the move/zoom transition follows an exponential path toward the destination or linear. Default is False.

Examples

>>> import yt
>>> import numpy as np
>>> ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
>>> final_position = ds.arr([0.2, 0.3, 0.6], 'unitary')
>>> im, sc = yt.volume_render(ds)
>>> cam = sc.camera
>>> for i in cam.iter_move(final_position, 10):
...     sc.render()
...     sc.save("move_%04i.png" % i)
iter_rotate(theta, n_steps, rot_vector=None, rot_center=None)[source]

Loop over rotate, creating a rotation

This will rotate n_steps until the current view has been rotated by an angle theta.

Parameters:
  • theta (float, in radians) – Angle (in radians) by which to rotate the view.
  • n_steps (int) – The number of snapshots to make.
  • rot_vector (array_like, optional) – Specify the rotation vector around which rotation will occur. Defaults to None, which sets rotation around the original north_vector
  • rot_center (array_like, optional) – Specify the center around which rotation will occur. Defaults to None, which sets rotation around the original camera position (i.e. the camera position does not change)

Examples

>>> import yt
>>> import numpy as np
>>> ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
>>>
>>> im, sc = yt.volume_render(ds)
>>> cam = sc.camera
>>> for i in cam.iter_rotate(np.pi, 10):
...     im = sc.render()
...     sc.save('rotation_%04i.png' % i)
iter_zoom(final, n_steps)[source]

Loop over a iter_zoom and return snapshots along the way.

This will yield n_steps snapshots until the current view has been zooming in to a final factor of final.

Parameters:
  • final (float) – The zoom factor, with respect to current, desired at the end of the sequence.
  • n_steps (int) – The number of zoom snapshots to make.

Examples

>>> import yt
>>> ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
>>> im, sc = yt.volume_render(ds)
>>> cam = sc.camera
>>> for i in cam.iter_zoom(100.0, 10):
...     sc.render()
...     sc.save("zoom_%04i.png" % i)
pitch(theta, rot_center=None)[source]

Rotate by a given angle about the horizontal axis

Pitch the view.

Parameters:
  • theta (float, in radians) – Angle (in radians) by which to pitch the view.
  • rot_center (array_like, optional) – Specify the center around which rotation will occur.

Examples

>>> import yt
>>> import numpy as np
>>> from yt.visualization.volume_rendering.api import Scene
>>> sc = Scene()
>>> sc.add_camera()
>>> # pitch the camera by pi / 4 radians:
>>> cam.pitch(np.pi/4.0)
>>> # pitch the camera about the origin instead of its own position:
>>> cam.pitch(np.pi/4.0, rot_center=np.array([0.0, 0.0, 0.0]))
position

The location of the camera.

Parameters:position (number, YTQuantity, iterable, or 3 element YTArray) – If a scalar, assumes that the position is the same in all three coordinates. If an iterable, must contain only scalars or (length, unit) tuples.
resolution

The resolution is the number of pixels in the image that will be produced. Must be a 2-tuple of integers or an integer.

roll(theta, rot_center=None)[source]

Rotate by a given angle about the view normal axis

Roll the view.

Parameters:
  • theta (float, in radians) – Angle (in radians) by which to roll the view.
  • rot_center (array_like, optional) – Specify the center around which rotation will occur.

Examples

>>> import yt
>>> import numpy as np
>>> from yt.visualization.volume_rendering.api import Scene
>>> sc = Scene()
>>> cam = sc.add_camera(ds)
>>> # roll the camera by pi / 4 radians:
>>> cam.roll(np.pi/4.0)
>>> # roll the camera about the origin instead of its own position:
>>> cam.roll(np.pi/4.0, rot_center=np.array([0.0, 0.0, 0.0]))
rotate(theta, rot_vector=None, rot_center=None)[source]

Rotate by a given angle

Rotate the view. If rot_vector is None, rotation will occur around the north_vector.

Parameters:
  • theta (float, in radians) – Angle (in radians) by which to rotate the view.
  • rot_vector (array_like, optional) – Specify the rotation vector around which rotation will occur. Defaults to None, which sets rotation around north_vector
  • rot_center (array_like, optional) – Specify the center around which rotation will occur. Defaults to None, which sets rotation around the original camera position (i.e. the camera position does not change)

Examples

>>> import yt
>>> import numpy as np
>>> from yt.visualization.volume_rendering.api import Scene
>>> sc = Scene()
>>> cam = sc.add_camera()
>>> # rotate the camera by pi / 4 radians:
>>> cam.rotate(np.pi/4.0)
>>> # rotate the camera about the y-axis instead of cam.north_vector:
>>> cam.rotate(np.pi/4.0, np.array([0.0, 1.0, 0.0]))
>>> # rotate the camera about the origin instead of its own position:
>>> cam.rotate(np.pi/4.0, rot_center=np.array([0.0, 0.0, 0.0]))
set_defaults_from_data_source(data_source)[source]

Resets the camera attributes to their default values

set_focus(new_focus)[source]

Sets the point the Camera is pointed at.

Parameters:focus (number, YTQuantity, iterable, or 3 element YTArray) – If a scalar, assumes that the focus is the same is all three coordinates. If an iterable, must contain only scalars or (length, unit) tuples.
set_lens(lens_type)[source]

Set the lens to be used with this camera.

Parameters:lens_type (string) – Must be one of the following: ‘plane-parallel’ ‘perspective’ ‘stereo-perspective’ ‘fisheye’ ‘spherical’ ‘stereo-spherical’
set_position(position, north_vector=None)[source]

Set the position of the camera.

Parameters:
  • width (number, YTQuantity, iterable, or 3 element YTArray) – If a scalar, assumes that the position is the same in all three coordinates. If an iterable, must contain only scalars or (length, unit) tuples.
  • north_vector (array_like, optional) – The ‘up’ direction for the plane of rays. If not specific, calculated automatically.
set_resolution(resolution)[source]

The resolution is the number of pixels in the image that will be produced. Must be a 2-tuple of integers or an integer.

set_width(width)[source]

Set the width of the image that will be produced by this camera.

Parameters:width (number, YTQuantity, iterable, or 3 element YTArray) – The width of the volume rendering in the horizontal, vertical, and depth directions. If a scalar, assumes that the width is the same in all three directions. If an iterable, must contain only scalars or (length, unit) tuples.
switch_orientation(normal_vector=None, north_vector=None)[source]

Change the view direction based on any of the orientation parameters.

This will recalculate all the necessary vectors and vector planes related to an orientable object.

Parameters:
  • normal_vector (array_like, optional) – The new looking vector from the camera to the focus.
  • north_vector (array_like, optional) – The ‘up’ direction for the plane of rays. If not specific, calculated automatically.
switch_view(normal_vector=None, north_vector=None)[source]

Change the view based on any of the view parameters.

This will recalculate the orientation and width based on any of normal_vector, width, center, and north_vector.

Parameters:
  • normal_vector (array_like, optional) – The new looking vector from the camera to the focus.
  • north_vector (array_like, optional) – The ‘up’ direction for the plane of rays. If not specific, calculated automatically.
width

The width of the region that will be seen in the image.

Parameters:width (number, YTQuantity, iterable, or 3 element YTArray) – The width of the volume rendering in the horizontal, vertical, and depth directions. If a scalar, assumes that the width is the same in all three directions. If an iterable, must contain only scalars or (length, unit) tuples.
yaw(theta, rot_center=None)[source]

Rotate by a given angle about the vertical axis

Yaw the view.

Parameters:
  • theta (float, in radians) – Angle (in radians) by which to yaw the view.
  • rot_center (array_like, optional) – Specify the center around which rotation will occur.

Examples

>>> import yt
>>> import numpy as np
>>> from yt.visualization.volume_rendering.api import Scene
>>> sc = Scene()
>>> cam = sc.add_camera()
>>> # yaw the camera by pi / 4 radians:
>>> cam.yaw(np.pi/4.0)
>>> # yaw the camera about the origin instead of its own position:
>>> cam.yaw(np.pi/4.0, rot_center=np.array([0.0, 0.0, 0.0]))
zoom(factor)[source]

Change the width of the FOV of the camera.

This will appear to zoom the camera in by some factor toward the focal point along the current view direction, but really it’s just changing the width of the field of view.

Parameters:factor (float) – The factor by which to divide the width

Examples

>>> import yt
>>> from yt.visualization.volume_rendering.api import Scene
>>> ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
>>> sc = Scene()
>>> cam = sc.add_camera(ds)
>>> cam.zoom(1.1)