yt-project/yt

Only update camera state right before we need to

Open

#1,299 opened on Nov 23, 2016

View on GitHub
 (3 comments) (0 reactions) (0 assignees)Python (315 forks)auto 404
enhancementhelp wanted

Repository metrics

Stars
 (556 stars)
PR merge metrics
 (PR metrics pending)

Description

Originally reported by: Michael Zingale (Bitbucket: mzingale, GitHub: Unknown)


consider the following script:

import yt
import numpy as np
from yt.visualization.volume_rendering.api import \
    Scene, \
    VolumeSource

# fake test dataset
ds = yt.testing.fake_vr_orientation_test_ds(128)

# no log please
ds._get_field_info("density").take_log = False

sc = Scene()

vol = VolumeSource(ds, field=('gas', 'density'))
sc.add_source(vol)


cam = sc.add_camera(ds, lens_type="perspective")
cam.resolution = (1280, 720)

cam.north_vector = np.array([0., 0., 1.])

cam.focus = ds.arr(np.array([1., 0., 0.]), 'code_length')

cam.position = ds.arr(np.array([0., 0., 0.]), 'code_length')


#sc.annotate_domain(ds)
sc.render()

sc.save("test_{:03}.png".format(0), sigma_clip=6.0)

this runs as-is.

If you change the order of the properties to:

cam.north_vector = np.array([0., 0., 1.])
cam.position = ds.arr(np.array([0., 0., 0.]), 'code_length')
cam.focus = ds.arr(np.array([1., 0., 0.]), 'code_length')

it aborts with

RuntimeError: Cannot set the camera focus and position to the same value

it you change them to

cam.focus = ds.arr(np.array([1., 0., 0.]), 'code_length')                                          
cam.position = ds.arr(np.array([0., 0., 0.]), 'code_length')                                       
cam.north_vector = np.array([0., 0., 1.])          

it aborts with:

yt.utilities.exceptions.YTException: normal_vector and north_vector cannot be aligned.

these checks should wait until the user is done setting all the properties and the order of setting them should not matter.


Contributor guide