Open In Colab

Spiral Galaxy (Enzo)#

Prerequisites (Run Once)#

[1]:
%%capture
#@title Installing Libraries
!pip install vivid3d==0.3.7
!pip install yt
[3]:
#@title Loading Data with YT
import yt
import numpy as np

ds = yt.load_sample("IsolatedGalaxy")                # Load example data from yt
sphere = ds.sphere(center="c", radius=(17, "kpc")) # Create sphere object
ds.print_stats()
/usr/local/lib/python3.7/dist-packages/yt/sample_data/api.py:145: UserWarning: Storage directory from yt config doesn't exist (currently set to '/does/not/exist'). Current working directory will be used instead.
  "Storage directory from yt config doesn't exist "
yt : [INFO     ] 2022-11-06 04:00:27,120 'IsolatedGalaxy' is not available locally. Looking up online.
yt : [INFO     ] 2022-11-06 04:00:27,125 Downloading from https://yt-project.org/data/IsolatedGalaxy.tar.gz
100%|████████████████████████████████████████| 305M/305M [00:00<00:00, 134GB/s]
yt : [INFO     ] 2022-11-06 04:06:00,474 Untaring downloaded file to '/content'
yt : [INFO     ] 2022-11-06 04:06:06,904 Parameters: current_time              = 0.0060000200028298
yt : [INFO     ] 2022-11-06 04:06:06,908 Parameters: domain_dimensions         = [32 32 32]
yt : [INFO     ] 2022-11-06 04:06:06,912 Parameters: domain_left_edge          = [0. 0. 0.]
yt : [INFO     ] 2022-11-06 04:06:06,917 Parameters: domain_right_edge         = [1. 1. 1.]
yt : [INFO     ] 2022-11-06 04:06:06,922 Parameters: cosmological_simulation   = 0
Parsing Hierarchy : 100%|██████████| 173/173 [00:00<00:00, 8476.61it/s]
yt : [INFO     ] 2022-11-06 04:06:06,978 Gathering a field list (this may take a moment.)
level   # grids        # cells       # cells^3
----------------------------------------------
  0          1           32768              32
  1          8           34304              33
  2          8          181888              57
  3          8          646968              87
  4         15          947856              99
  5         51          874128              96
  6         18          786328              93
  7         28          446776              77
  8         36          209400              60
----------------------------------------------
           173         4160416


t = 6.00002000e-03 = 1.39768066e+16 s = 4.42898275e+08 years

Smallest Cell:
        Width: 1.221e-04 Mpc Mpc
        Width: 1.221e+02 pc pc
        Width: 2.518e+07 AU AU
        Width: 3.767e+20 cm cm

Creating Model#

[4]:
# Pre-vizualization of the dataset
plot = yt.ParticleProjectionPlot(ds, "z", ("all", "creation_time"), width=(17, "kpc")).set_cmap('creation_time', 'inferno')
plot.set_unit(("all", "creation_time"), "Myr")
plot.annotate_title("Particle Creation Time")
yt : [INFO     ] 2022-11-06 04:06:09,083 xlim = 0.491501 0.508499
yt : [INFO     ] 2022-11-06 04:06:09,086 ylim = 0.491501 0.508499
yt : [INFO     ] 2022-11-06 04:06:09,089 xlim = 0.491501 0.508499
yt : [INFO     ] 2022-11-06 04:06:09,092 ylim = 0.491501 0.508499
yt : [INFO     ] 2022-11-06 04:06:09,127 Splatting (('all', 'creation_time')) onto a 800 by 800 mesh using method 'ngp'
[4]:

[15]:
import vivid3d

creation_time = np.array(sphere[("all", "creation_time")].in_units('Myr'))
stars_mask = creation_time > 0 # Mask for selecting only cells with stars

x = sphere[("all", "particle_position_x")].in_units('kpc') # Create list of x grid values
y = sphere[("all", "particle_position_y")].in_units('kpc') # Create list of y grid values
z = sphere[("all", "particle_position_z")].in_units('kpc') # Create list of z grid values

stars = np.array(list(zip(x, y, z)))[stars_mask]           # Transform XYZ to Point3DArray and mask by creation_time
color_field = creation_time[stars_mask]                    # Selected particles color_field
print(color_field.min(), color_field.max())
print(len(color_field))

star_field = vivid3d.PointCloud(stars, color_field, 100, 300) # Create PointCloud object
0.08391844693191003 442.88480579829684
124447
[19]:
# Making the stars glowy!
star_field.material = vivid3d.Material(emission_strength = 1.0)
star_field.colormap = "RdBu" # Old stars are red, young stars are blue

star_field.show()
[19]:
[ ]: