Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yt-project
GitHub Repository: yt-project/yt
Path: blob/main/doc/source/cookbook/offaxis_projection.py
928 views
1
import numpy as np
2
3
import yt
4
5
# Load the dataset.
6
ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
7
8
# Choose a center for the render.
9
c = [0.5, 0.5, 0.5]
10
11
# Our image plane will be normal to some vector. For things like collapsing
12
# objects, you could set it the way you would a cutting plane -- but for this
13
# dataset, we'll just choose an off-axis value at random. This gets normalized
14
# automatically.
15
L = [1.0, 0.0, 0.0]
16
17
# Our "width" is the width of the image plane as well as the depth.
18
# The first element is the left to right width, the second is the
19
# top-bottom width, and the last element is the back-to-front width
20
# (all in code units)
21
W = [0.04, 0.04, 0.4]
22
23
# The number of pixels along one side of the image.
24
# The final image will have Npixel^2 pixels.
25
Npixels = 512
26
27
# Create the off axis projection.
28
# Setting no_ghost to False speeds up the process, but makes a
29
# slightly lower quality image.
30
image = yt.off_axis_projection(ds, c, L, W, Npixels, ("gas", "density"), no_ghost=False)
31
32
# Write out the final image and give it a name
33
# relating to what our dataset is called.
34
# We save the log of the values so that the colors do not span
35
# many orders of magnitude. Try it without and see what happens.
36
yt.write_image(np.log10(image), f"{ds}_offaxis_projection.png")
37
38