Starting Out and Loading Data¶
We’re going to get started by loading up yt. This next command brings all of the libraries into memory and sets up our environment.
[1]:
import yt
Now that we’ve loaded yt, we can load up some data. Let’s load the IsolatedGalaxy
dataset.
[2]:
ds = yt.load_sample("IsolatedGalaxy")
Fields and Facts¶
When you call the load
function, yt tries to do very little – this is designed to be a fast operation, just setting up some information about the simulation. Now, the first time you access the “index” it will read and load the mesh and then determine where data is placed in the physical domain and on disk. Once it knows that, yt can tell you some statistics about the simulation:
[3]:
ds.print_stats()
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 code_time = 1.39768066e+16 s = 4.42898275e+08 yr
Smallest Cell:
Width: 1.221e-04 Mpc
Width: 1.221e+02 pc
Width: 2.518e+07 AU
Width: 3.767e+20 cm
yt can also tell you the fields it found on disk:
[4]:
ds.field_list
[4]:
[('all', 'creation_time'),
('all', 'dynamical_time'),
('all', 'metallicity_fraction'),
('all', 'particle_index'),
('all', 'particle_mass'),
('all', 'particle_position_x'),
('all', 'particle_position_y'),
('all', 'particle_position_z'),
('all', 'particle_type'),
('all', 'particle_velocity_x'),
('all', 'particle_velocity_y'),
('all', 'particle_velocity_z'),
('enzo', 'Average_creation_time'),
('enzo', 'Bx'),
('enzo', 'By'),
('enzo', 'Bz'),
('enzo', 'Cooling_Time'),
('enzo', 'Dark_Matter_Density'),
('enzo', 'Density'),
('enzo', 'Electron_Density'),
('enzo', 'Forming_Stellar_Mass_Density'),
('enzo', 'Galaxy1Colour'),
('enzo', 'Galaxy2Colour'),
('enzo', 'HII_Density'),
('enzo', 'HI_Density'),
('enzo', 'HeIII_Density'),
('enzo', 'HeII_Density'),
('enzo', 'HeI_Density'),
('enzo', 'MBHColour'),
('enzo', 'Metal_Density'),
('enzo', 'PhiField'),
('enzo', 'Phi_pField'),
('enzo', 'SFR_Density'),
('enzo', 'Star_Particle_Density'),
('enzo', 'Temperature'),
('enzo', 'TotalEnergy'),
('enzo', 'gammaHI'),
('enzo', 'kphHI'),
('enzo', 'kphHeI'),
('enzo', 'kphHeII'),
('enzo', 'x-velocity'),
('enzo', 'y-velocity'),
('enzo', 'z-velocity'),
('io', 'creation_time'),
('io', 'dynamical_time'),
('io', 'metallicity_fraction'),
('io', 'particle_index'),
('io', 'particle_mass'),
('io', 'particle_position_x'),
('io', 'particle_position_y'),
('io', 'particle_position_z'),
('io', 'particle_type'),
('io', 'particle_velocity_x'),
('io', 'particle_velocity_y'),
('io', 'particle_velocity_z'),
('nbody', 'creation_time'),
('nbody', 'dynamical_time'),
('nbody', 'metallicity_fraction'),
('nbody', 'particle_index'),
('nbody', 'particle_mass'),
('nbody', 'particle_position_x'),
('nbody', 'particle_position_y'),
('nbody', 'particle_position_z'),
('nbody', 'particle_type'),
('nbody', 'particle_velocity_x'),
('nbody', 'particle_velocity_y'),
('nbody', 'particle_velocity_z')]
And, all of the fields it thinks it knows how to generate:
[5]:
ds.derived_field_list
[5]:
[('all', 'age'),
('all', 'creation_time'),
('all', 'dynamical_time'),
('all', 'mesh_id'),
('all', 'metallicity_fraction'),
('all', 'particle_angular_momentum'),
('all', 'particle_angular_momentum_magnitude'),
('all', 'particle_angular_momentum_x'),
('all', 'particle_angular_momentum_y'),
('all', 'particle_angular_momentum_z'),
('all', 'particle_index'),
('all', 'particle_mass'),
('all', 'particle_ones'),
('all', 'particle_position'),
('all', 'particle_position_cylindrical_radius'),
('all', 'particle_position_cylindrical_theta'),
('all', 'particle_position_cylindrical_z'),
('all', 'particle_position_relative_x'),
('all', 'particle_position_relative_y'),
('all', 'particle_position_relative_z'),
('all', 'particle_position_spherical_phi'),
('all', 'particle_position_spherical_radius'),
('all', 'particle_position_spherical_theta'),
('all', 'particle_position_x'),
('all', 'particle_position_y'),
('all', 'particle_position_z'),
('all', 'particle_radial_velocity'),
('all', 'particle_radius'),
('all', 'particle_specific_angular_momentum'),
('all', 'particle_specific_angular_momentum_x'),
('all', 'particle_specific_angular_momentum_y'),
('all', 'particle_specific_angular_momentum_z'),
('all', 'particle_type'),
('all', 'particle_velocity'),
('all', 'particle_velocity_cylindrical_radius'),
('all', 'particle_velocity_cylindrical_theta'),
('all', 'particle_velocity_cylindrical_z'),
('all', 'particle_velocity_los'),
('all', 'particle_velocity_magnitude'),
('all', 'particle_velocity_relative_x'),
('all', 'particle_velocity_relative_y'),
('all', 'particle_velocity_relative_z'),
('all', 'particle_velocity_spherical_phi'),
('all', 'particle_velocity_spherical_radius'),
('all', 'particle_velocity_spherical_theta'),
('all', 'particle_velocity_x'),
('all', 'particle_velocity_y'),
('all', 'particle_velocity_z'),
('all', 'relative_particle_position'),
('all', 'relative_particle_position_x'),
('all', 'relative_particle_position_y'),
('all', 'relative_particle_position_z'),
('all', 'relative_particle_velocity'),
('all', 'relative_particle_velocity_x'),
('all', 'relative_particle_velocity_y'),
('all', 'relative_particle_velocity_z'),
('deposit', 'all_cic'),
('deposit', 'all_cic_age'),
('deposit', 'all_cic_velocity_x'),
('deposit', 'all_cic_velocity_y'),
('deposit', 'all_cic_velocity_z'),
('deposit', 'all_count'),
('deposit', 'all_density'),
('deposit', 'all_mass'),
('deposit', 'all_nn_age'),
('deposit', 'all_nn_velocity_x'),
('deposit', 'all_nn_velocity_y'),
('deposit', 'all_nn_velocity_z'),
('deposit', 'io_cic'),
('deposit', 'io_cic_age'),
('deposit', 'io_cic_velocity_x'),
('deposit', 'io_cic_velocity_y'),
('deposit', 'io_cic_velocity_z'),
('deposit', 'io_count'),
('deposit', 'io_density'),
('deposit', 'io_mass'),
('deposit', 'io_nn_age'),
('deposit', 'io_nn_velocity_x'),
('deposit', 'io_nn_velocity_y'),
('deposit', 'io_nn_velocity_z'),
('deposit', 'nbody_cic'),
('deposit', 'nbody_cic_age'),
('deposit', 'nbody_cic_velocity_x'),
('deposit', 'nbody_cic_velocity_y'),
('deposit', 'nbody_cic_velocity_z'),
('deposit', 'nbody_count'),
('deposit', 'nbody_density'),
('deposit', 'nbody_mass'),
('deposit', 'nbody_nn_age'),
('deposit', 'nbody_nn_velocity_x'),
('deposit', 'nbody_nn_velocity_y'),
('deposit', 'nbody_nn_velocity_z'),
('enzo', 'Average_creation_time'),
('enzo', 'Bx'),
('enzo', 'By'),
('enzo', 'Bz'),
('enzo', 'Cooling_Time'),
('enzo', 'Dark_Matter_Density'),
('enzo', 'Density'),
('enzo', 'Electron_Density'),
('enzo', 'Forming_Stellar_Mass_Density'),
('enzo', 'Galaxy1Colour'),
('enzo', 'Galaxy2Colour'),
('enzo', 'HII_Density'),
('enzo', 'HI_Density'),
('enzo', 'HeIII_Density'),
('enzo', 'HeII_Density'),
('enzo', 'HeI_Density'),
('enzo', 'MBHColour'),
('enzo', 'Metal_Density'),
('enzo', 'PhiField'),
('enzo', 'Phi_pField'),
('enzo', 'SFR_Density'),
('enzo', 'Star_Particle_Density'),
('enzo', 'Temperature'),
('enzo', 'TotalEnergy'),
('enzo', 'cell_volume'),
('enzo', 'dx'),
('enzo', 'dy'),
('enzo', 'dz'),
('enzo', 'gammaHI'),
('enzo', 'kphHI'),
('enzo', 'kphHeI'),
('enzo', 'kphHeII'),
('enzo', 'path_element_x'),
('enzo', 'path_element_y'),
('enzo', 'path_element_z'),
('enzo', 'volume'),
('enzo', 'x'),
('enzo', 'x-velocity'),
('enzo', 'y'),
('enzo', 'y-velocity'),
('enzo', 'z'),
('enzo', 'z-velocity'),
('gas', 'El_density'),
('gas', 'El_fraction'),
('gas', 'El_mass'),
('gas', 'El_number_density'),
('gas', 'H_density'),
('gas', 'H_fraction'),
('gas', 'H_mass'),
('gas', 'H_nuclei_density'),
('gas', 'H_number_density'),
('gas', 'H_p0_density'),
('gas', 'H_p0_fraction'),
('gas', 'H_p0_mass'),
('gas', 'H_p0_number_density'),
('gas', 'H_p1_density'),
('gas', 'H_p1_fraction'),
('gas', 'H_p1_mass'),
('gas', 'H_p1_number_density'),
('gas', 'He_density'),
('gas', 'He_fraction'),
('gas', 'He_mass'),
('gas', 'He_nuclei_density'),
('gas', 'He_number_density'),
('gas', 'He_p0_density'),
('gas', 'He_p0_fraction'),
('gas', 'He_p0_mass'),
('gas', 'He_p0_number_density'),
('gas', 'He_p1_density'),
('gas', 'He_p1_fraction'),
('gas', 'He_p1_mass'),
('gas', 'He_p1_number_density'),
('gas', 'He_p2_density'),
('gas', 'He_p2_fraction'),
('gas', 'He_p2_mass'),
('gas', 'He_p2_number_density'),
('gas', 'alfven_speed'),
('gas', 'angular_momentum_magnitude'),
('gas', 'angular_momentum_x'),
('gas', 'angular_momentum_y'),
('gas', 'angular_momentum_z'),
('gas', 'averaged_density'),
('gas', 'baroclinic_vorticity_magnitude'),
('gas', 'baroclinic_vorticity_x'),
('gas', 'baroclinic_vorticity_y'),
('gas', 'baroclinic_vorticity_z'),
('gas', 'cell_mass'),
('gas', 'cell_volume'),
('gas', 'cooling_time'),
('gas', 'courant_time_step'),
('gas', 'cutting_plane_magnetic_field_x'),
('gas', 'cutting_plane_magnetic_field_y'),
('gas', 'cutting_plane_magnetic_field_z'),
('gas', 'cutting_plane_velocity_x'),
('gas', 'cutting_plane_velocity_y'),
('gas', 'cutting_plane_velocity_z'),
('gas', 'dark_matter_density'),
('gas', 'density'),
('gas', 'density_gradient_magnitude'),
('gas', 'density_gradient_x'),
('gas', 'density_gradient_y'),
('gas', 'density_gradient_z'),
('gas', 'dx'),
('gas', 'dy'),
('gas', 'dynamical_time'),
('gas', 'dz'),
('gas', 'emission_measure'),
('gas', 'entropy'),
('gas', 'four_velocity_magnitude'),
('gas', 'four_velocity_t'),
('gas', 'four_velocity_x'),
('gas', 'four_velocity_y'),
('gas', 'four_velocity_z'),
('gas', 'jeans_mass'),
('gas', 'kT'),
('gas', 'kinetic_energy_density'),
('gas', 'lorentz_factor'),
('gas', 'mach_alfven'),
('gas', 'mach_number'),
('gas', 'magnetic_energy_density'),
('gas', 'magnetic_field_cylindrical_radius'),
('gas', 'magnetic_field_cylindrical_theta'),
('gas', 'magnetic_field_cylindrical_z'),
('gas', 'magnetic_field_divergence'),
('gas', 'magnetic_field_divergence_absolute'),
('gas', 'magnetic_field_los'),
('gas', 'magnetic_field_magnitude'),
('gas', 'magnetic_field_poloidal'),
('gas', 'magnetic_field_poloidal_magnitude'),
('gas', 'magnetic_field_spherical_phi'),
('gas', 'magnetic_field_spherical_radius'),
('gas', 'magnetic_field_spherical_theta'),
('gas', 'magnetic_field_strength'),
('gas', 'magnetic_field_toroidal'),
('gas', 'magnetic_field_toroidal_magnitude'),
('gas', 'magnetic_field_x'),
('gas', 'magnetic_field_y'),
('gas', 'magnetic_field_z'),
('gas', 'magnetic_pressure'),
('gas', 'mass'),
('gas', 'matter_density'),
('gas', 'matter_mass'),
('gas', 'mazzotta_weighting'),
('gas', 'mean_molecular_weight'),
('gas', 'metal_density'),
('gas', 'metal_mass'),
('gas', 'metallicity'),
('gas', 'momentum_density_x'),
('gas', 'momentum_density_y'),
('gas', 'momentum_density_z'),
('gas', 'momentum_x'),
('gas', 'momentum_y'),
('gas', 'momentum_z'),
('gas', 'number_density'),
('gas', 'optical_depth'),
('gas', 'path_element_x'),
('gas', 'path_element_y'),
('gas', 'path_element_z'),
('gas', 'plasma_beta'),
('gas', 'pressure'),
('gas', 'pressure_gradient_magnitude'),
('gas', 'pressure_gradient_x'),
('gas', 'pressure_gradient_y'),
('gas', 'pressure_gradient_z'),
('gas', 'radial_mach_number'),
('gas', 'radial_magnetic_field'),
('gas', 'radial_magnetic_field_absolute'),
('gas', 'radial_velocity'),
('gas', 'radial_velocity_absolute'),
('gas', 'relative_magnetic_field_x'),
('gas', 'relative_magnetic_field_y'),
('gas', 'relative_magnetic_field_z'),
('gas', 'relative_velocity_x'),
('gas', 'relative_velocity_y'),
('gas', 'relative_velocity_z'),
('gas', 'rotation_measure'),
('gas', 'shear'),
('gas', 'shear_criterion'),
('gas', 'shear_mach'),
('gas', 'sound_speed'),
('gas', 'specific_angular_momentum_magnitude'),
('gas', 'specific_angular_momentum_x'),
('gas', 'specific_angular_momentum_y'),
('gas', 'specific_angular_momentum_z'),
('gas', 'specific_thermal_energy'),
('gas', 'specific_total_energy'),
('gas', 'sz_kinetic'),
('gas', 'szy'),
('gas', 'tangential_magnetic_field'),
('gas', 'tangential_over_magnetic_field_magnitude'),
('gas', 'tangential_over_velocity_magnitude'),
('gas', 'tangential_velocity'),
('gas', 'temperature'),
('gas', 'velocity_cylindrical_radius'),
('gas', 'velocity_cylindrical_theta'),
('gas', 'velocity_cylindrical_z'),
('gas', 'velocity_divergence'),
('gas', 'velocity_divergence_absolute'),
('gas', 'velocity_los'),
('gas', 'velocity_magnitude'),
('gas', 'velocity_spherical_phi'),
('gas', 'velocity_spherical_radius'),
('gas', 'velocity_spherical_theta'),
('gas', 'velocity_x'),
('gas', 'velocity_y'),
('gas', 'velocity_z'),
('gas', 'volume'),
('gas', 'vorticity_growth_magnitude'),
('gas', 'vorticity_growth_magnitude_absolute'),
('gas', 'vorticity_growth_timescale'),
('gas', 'vorticity_growth_x'),
('gas', 'vorticity_growth_y'),
('gas', 'vorticity_growth_z'),
('gas', 'vorticity_magnitude'),
('gas', 'vorticity_squared'),
('gas', 'vorticity_stretching_magnitude'),
('gas', 'vorticity_stretching_x'),
('gas', 'vorticity_stretching_y'),
('gas', 'vorticity_stretching_z'),
('gas', 'vorticity_x'),
('gas', 'vorticity_y'),
('gas', 'vorticity_z'),
('gas', 'x'),
('gas', 'y'),
('gas', 'z'),
('index', 'cell_volume'),
('index', 'cylindrical_radius'),
('index', 'cylindrical_theta'),
('index', 'cylindrical_z'),
('index', 'dx'),
('index', 'dy'),
('index', 'dz'),
('index', 'grid_indices'),
('index', 'grid_level'),
('index', 'morton_index'),
('index', 'ones'),
('index', 'ones_over_dx'),
('index', 'path_element_x'),
('index', 'path_element_y'),
('index', 'path_element_z'),
('index', 'radius'),
('index', 'spherical_phi'),
('index', 'spherical_radius'),
('index', 'spherical_theta'),
('index', 'virial_radius_fraction'),
('index', 'volume'),
('index', 'x'),
('index', 'y'),
('index', 'z'),
('index', 'zeros'),
('io', 'age'),
('io', 'creation_time'),
('io', 'dynamical_time'),
('io', 'mesh_id'),
('io', 'metallicity_fraction'),
('io', 'particle_angular_momentum'),
('io', 'particle_angular_momentum_magnitude'),
('io', 'particle_angular_momentum_x'),
('io', 'particle_angular_momentum_y'),
('io', 'particle_angular_momentum_z'),
('io', 'particle_index'),
('io', 'particle_mass'),
('io', 'particle_ones'),
('io', 'particle_position'),
('io', 'particle_position_cylindrical_radius'),
('io', 'particle_position_cylindrical_theta'),
('io', 'particle_position_cylindrical_z'),
('io', 'particle_position_relative_x'),
('io', 'particle_position_relative_y'),
('io', 'particle_position_relative_z'),
('io', 'particle_position_spherical_phi'),
('io', 'particle_position_spherical_radius'),
('io', 'particle_position_spherical_theta'),
('io', 'particle_position_x'),
('io', 'particle_position_y'),
('io', 'particle_position_z'),
('io', 'particle_radial_velocity'),
('io', 'particle_radius'),
('io', 'particle_specific_angular_momentum'),
('io', 'particle_specific_angular_momentum_x'),
('io', 'particle_specific_angular_momentum_y'),
('io', 'particle_specific_angular_momentum_z'),
('io', 'particle_type'),
('io', 'particle_velocity'),
('io', 'particle_velocity_cylindrical_radius'),
('io', 'particle_velocity_cylindrical_theta'),
('io', 'particle_velocity_cylindrical_z'),
('io', 'particle_velocity_los'),
('io', 'particle_velocity_magnitude'),
('io', 'particle_velocity_relative_x'),
('io', 'particle_velocity_relative_y'),
('io', 'particle_velocity_relative_z'),
('io', 'particle_velocity_spherical_phi'),
('io', 'particle_velocity_spherical_radius'),
('io', 'particle_velocity_spherical_theta'),
('io', 'particle_velocity_x'),
('io', 'particle_velocity_y'),
('io', 'particle_velocity_z'),
('io', 'relative_particle_position'),
('io', 'relative_particle_position_x'),
('io', 'relative_particle_position_y'),
('io', 'relative_particle_position_z'),
('io', 'relative_particle_velocity'),
('io', 'relative_particle_velocity_x'),
('io', 'relative_particle_velocity_y'),
('io', 'relative_particle_velocity_z'),
('nbody', 'age'),
('nbody', 'creation_time'),
('nbody', 'dynamical_time'),
('nbody', 'mesh_id'),
('nbody', 'metallicity_fraction'),
('nbody', 'particle_angular_momentum'),
('nbody', 'particle_angular_momentum_magnitude'),
('nbody', 'particle_angular_momentum_x'),
('nbody', 'particle_angular_momentum_y'),
('nbody', 'particle_angular_momentum_z'),
('nbody', 'particle_index'),
('nbody', 'particle_mass'),
('nbody', 'particle_ones'),
('nbody', 'particle_position'),
('nbody', 'particle_position_cylindrical_radius'),
('nbody', 'particle_position_cylindrical_theta'),
('nbody', 'particle_position_cylindrical_z'),
('nbody', 'particle_position_relative_x'),
('nbody', 'particle_position_relative_y'),
('nbody', 'particle_position_relative_z'),
('nbody', 'particle_position_spherical_phi'),
('nbody', 'particle_position_spherical_radius'),
('nbody', 'particle_position_spherical_theta'),
('nbody', 'particle_position_x'),
('nbody', 'particle_position_y'),
('nbody', 'particle_position_z'),
('nbody', 'particle_radial_velocity'),
('nbody', 'particle_radius'),
('nbody', 'particle_specific_angular_momentum'),
('nbody', 'particle_specific_angular_momentum_x'),
('nbody', 'particle_specific_angular_momentum_y'),
('nbody', 'particle_specific_angular_momentum_z'),
('nbody', 'particle_type'),
('nbody', 'particle_velocity'),
('nbody', 'particle_velocity_cylindrical_radius'),
('nbody', 'particle_velocity_cylindrical_theta'),
('nbody', 'particle_velocity_cylindrical_z'),
('nbody', 'particle_velocity_los'),
('nbody', 'particle_velocity_magnitude'),
('nbody', 'particle_velocity_relative_x'),
('nbody', 'particle_velocity_relative_y'),
('nbody', 'particle_velocity_relative_z'),
('nbody', 'particle_velocity_spherical_phi'),
('nbody', 'particle_velocity_spherical_radius'),
('nbody', 'particle_velocity_spherical_theta'),
('nbody', 'particle_velocity_x'),
('nbody', 'particle_velocity_y'),
('nbody', 'particle_velocity_z'),
('nbody', 'relative_particle_position'),
('nbody', 'relative_particle_position_x'),
('nbody', 'relative_particle_position_y'),
('nbody', 'relative_particle_position_z'),
('nbody', 'relative_particle_velocity'),
('nbody', 'relative_particle_velocity_x'),
('nbody', 'relative_particle_velocity_y'),
('nbody', 'relative_particle_velocity_z')]
yt can also transparently generate fields. However, we encourage you to examine exactly what yt is doing when it generates those fields. To see, you can ask for the source of a given field.
[6]:
print(ds.field_info["gas", "vorticity_x"].get_source())
def _vorticity_x(field, data):
vz = data[ftype, "relative_velocity_z"]
vy = data[ftype, "relative_velocity_y"]
f = (vz[sl_center, sl_right, sl_center] - vz[sl_center, sl_left, sl_center]) / (
div_fac * just_one(data["index", "dy"])
)
f -= (
vy[sl_center, sl_center, sl_right] - vy[sl_center, sl_center, sl_left]
) / (div_fac * just_one(data["index", "dz"]))
new_field = data.ds.arr(np.zeros_like(vz, dtype=np.float64), f.units)
new_field[sl_center, sl_center, sl_center] = f
return new_field
yt stores information about the domain of the simulation:
[7]:
ds.domain_width
yt can also convert this into various units:
[8]:
print(ds.domain_width.in_units("kpc"))
print(ds.domain_width.in_units("au"))
print(ds.domain_width.in_units("mile"))
[1000.10448889 1000.10448889 1000.10448889] kpc
[2.06286359e+11 2.06286359e+11 2.06286359e+11] AU
[1.9175515e+19 1.9175515e+19 1.9175515e+19] mile
Finally, we can get basic information about the particle types and number of particles in a simulation:
[9]:
print(ds.particle_types)
print(ds.particle_types_raw)
print(ds.particle_type_counts)
['io', 'all', 'nbody']
['io']
{'io': np.int64(1124453)}
For this dataset, we see that there are two particle types defined, (io
and all
), but that only one of these particle types in ds.particle_types_raw
. The ds.particle_types
list contains all particle types in the simulation, including ones that are dynamically defined like particle unions. The ds.particle_types_raw
list includes only particle types that are in the output file we loaded the dataset from.
We can also see that there are a bit more than 1.1 million particles in this simulation. Only particle types in ds.particle_types_raw
will appear in the ds.particle_type_counts
dictionary.
Mesh Structure¶
If you’re using a simulation type that has grids (for instance, here we’re using an Enzo simulation) you can examine the structure of the mesh. For the most part, you probably won’t have to use this unless you’re debugging a simulation or examining in detail what is going on.
[10]:
print(ds.index.grid_left_edge)
[[0. 0. 0. ]
[0.25 0.21875 0.25 ]
[0.5 0.21875 0.25 ]
[0.21875 0.5 0.25 ]
[0.5 0.5 0.25 ]
[0.25 0.25 0.5 ]
[0.5 0.25 0.5 ]
[0.25 0.5 0.5 ]
[0.5 0.5 0.5 ]
[0.5 0.5 0.5 ]
[0.5 0.5 0.5 ]
[0.5 0.5 0.5 ]
[0.5 0.5 0.5 ]
[0.50976562 0.5 0.5 ]
[0.50976562 0.5 0.50585938]
[0.50976562 0.53515625 0.50585938]
[0.52148438 0.53515625 0.50585938]
[0.52148438 0.54101562 0.52539062]
[0.52734375 0.53515625 0.50585938]
[0.50976562 0.5 0.50585938]
[0.50976562 0.5 0.5 ]
[0.5 0.5 0.5 ]
[0.5 0.5 0.5 ]
[0.5 0.5 0.50585938]
[0.50634766 0.50244141 0.50585938]
[0.50488281 0.5 0.50585938]
[0.5 0.50390625 0.50585938]
[0.5 0.5 0.5 ]
[0.28125 0.5 0.5 ]
[0.3359375 0.5 0.5 ]
[0.40625 0.5 0.5 ]
[0.4453125 0.5 0.5 ]
[0.44921875 0.52539062 0.50390625]
[0.46289062 0.52734375 0.5 ]
[0.48242188 0.52539062 0.5 ]
[0.46875 0.54492188 0.5078125 ]
[0.45703125 0.52539062 0.51953125]
[0.47851562 0.52539062 0.5 ]
[0.46484375 0.52539062 0.5 ]
[0.45898438 0.52539062 0.50585938]
[0.48242188 0.52539062 0.52539062]
[0.47070312 0.52539062 0.51953125]
[0.47851562 0.52539062 0.52539062]
[0.47851562 0.5 0.5 ]
[0.49023438 0.5 0.5 ]
[0.49658203 0.51025391 0.50048828]
[0.49462891 0.5 0.5 ]
[0.49584961 0.5 0.5 ]
[0.49584961 0.50048828 0.5 ]
[0.49584961 0.5012207 0.5 ]
[0.49804688 0.5012207 0.5 ]
[0.49633789 0.50341797 0.5 ]
[0.49658203 0.5012207 0.50073242]
[0.49658203 0.50244141 0.50073242]
[0.49780273 0.5012207 0.50146484]
[0.5 0.28125 0.5 ]
[0.5 0.3359375 0.5 ]
[0.5 0.40625 0.5 ]
[0.50195312 0.44140625 0.50585938]
[0.5 0.45117188 0.5 ]
[0.515625 0.44335938 0.5 ]
[0.53125 0.46289062 0.5 ]
[0.53125 0.49023438 0.5 ]
[0.53125 0.4609375 0.515625 ]
[0.53125 0.47265625 0.515625 ]
[0.53125 0.48046875 0.515625 ]
[0.53125 0.48632812 0.53125 ]
[0.54101562 0.484375 0.515625 ]
[0.53710938 0.48046875 0.53320312]
[0.5 0.47460938 0.50195312]
[0.5 0.47949219 0.5 ]
[0.50292969 0.4765625 0.50195312]
[0.50195312 0.48779297 0.50048828]
[0.5 0.48974609 0.5 ]
[0.5 0.49609375 0.50976562]
[0.5 0.49414062 0.5 ]
[0.5 0.49707031 0.5 ]
[0.28125 0.28125 0.5 ]
[0.3359375 0.3359375 0.5 ]
[0.46484375 0.37890625 0.50390625]
[0.40625 0.40625 0.5 ]
[0.49609375 0.44335938 0.50585938]
[0.44921875 0.453125 0.5 ]
[0.4765625 0.47753906 0.5 ]
[0.49755859 0.48925781 0.50097656]
[0.49023438 0.49121094 0.5 ]
[0.49609375 0.48828125 0.50341797]
[0.49633789 0.49389648 0.5 ]
[0.49487305 0.49926758 0.5 ]
[0.49731445 0.49609375 0.5 ]
[0.49755859 0.49609375 0.5 ]
[0.49487305 0.49707031 0.5 ]
[0.49682617 0.49682617 0.5 ]
[0.5 0.5 0.28125 ]
[0.5 0.5 0.3359375 ]
[0.5 0.5 0.40234375]
[0.5 0.5 0.453125 ]
[0.5 0.5 0.4765625 ]
[0.5 0.5 0.49121094]
[0.5 0.5 0.49682617]
[0.50170898 0.5 0.49804688]
[0.50170898 0.50219727 0.49853516]
[0.50219727 0.50219727 0.4987793 ]
[0.50170898 0.50219727 0.49951172]
[0.50292969 0.50219727 0.49951172]
[0.265625 0.5 0.28125 ]
[0.3359375 0.5 0.328125 ]
[0.40234375 0.5 0.40625 ]
[0.45117188 0.5 0.45117188]
[0.49804688 0.5 0.47265625]
[0.47460938 0.5 0.4765625 ]
[0.49316406 0.50195312 0.48730469]
[0.48925781 0.50244141 0.49658203]
[0.49072266 0.5 0.49072266]
[0.49926758 0.50048828 0.49560547]
[0.49487305 0.5 0.49926758]
[0.49707031 0.5 0.49707031]
[0.49609375 0.50219727 0.49951172]
[0.49658203 0.5 0.49853516]
[0.5 0.265625 0.28125 ]
[0.5 0.3203125 0.328125 ]
[0.5 0.3984375 0.40625 ]
[0.546875 0.41796875 0.4453125 ]
[0.546875 0.453125 0.41796875]
[0.546875 0.4375 0.4375 ]
[0.546875 0.4921875 0.41796875]
[0.546875 0.48046875 0.41796875]
[0.55859375 0.46875 0.43359375]
[0.5 0.4609375 0.4453125 ]
[0.5 0.44921875 0.47460938]
[0.51367188 0.47265625 0.46289062]
[0.51367188 0.47460938 0.45703125]
[0.52734375 0.47070312 0.46679688]
[0.51367188 0.46679688 0.46875 ]
[0.5 0.47460938 0.47753906]
[0.5 0.49023438 0.49072266]
[0.50488281 0.49560547 0.48974609]
[0.50488281 0.49169922 0.49365234]
[0.50488281 0.49511719 0.49365234]
[0.50488281 0.49511719 0.49462891]
[0.50488281 0.49707031 0.49267578]
[0.50488281 0.49853516 0.49316406]
[0.5 0.49560547 0.49707031]
[0.50317383 0.4987793 0.49902344]
[0.265625 0.28125 0.28125 ]
[0.328125 0.3359375 0.328125 ]
[0.4140625 0.40625 0.40625 ]
[0.49414062 0.43945312 0.48632812]
[0.45703125 0.4765625 0.46875 ]
[0.48632812 0.44921875 0.453125 ]
[0.45117188 0.4921875 0.453125 ]
[0.44921875 0.453125 0.47851562]
[0.46289062 0.484375 0.45507812]
[0.484375 0.46484375 0.45703125]
[0.47265625 0.47851562 0.46484375]
[0.47265625 0.45898438 0.47070312]
[0.4765625 0.47265625 0.46289062]
[0.4765625 0.47070312 0.46679688]
[0.47363281 0.48535156 0.49414062]
[0.47363281 0.48339844 0.49707031]
[0.48242188 0.48535156 0.48632812]
[0.48144531 0.48339844 0.49121094]
[0.47753906 0.4921875 0.48632812]
[0.48632812 0.47558594 0.47753906]
[0.49511719 0.49707031 0.48632812]
[0.49755859 0.49560547 0.48828125]
[0.49169922 0.48974609 0.49414062]
[0.49023438 0.49169922 0.49072266]
[0.49560547 0.49853516 0.49951172]
[0.49707031 0.49707031 0.49853516]
[0.49658203 0.49755859 0.49707031]
[0.49902344 0.49560547 0.49755859]
[0.49804688 0.49609375 0.49853516]] code_length
But, you may have to access information about individual grid objects! Each grid object mediates accessing data from the disk and has a number of attributes that tell you about it. The index (ds.index
here) has an attribute grids
which is all of the grid objects.
[11]:
ds.index.grids[1]
[11]:
EnzoGrid_0002 ([16 18 16])
[12]:
g = ds.index.grids[1]
print(g)
EnzoGrid_0002 ([16 18 16])
Grids have dimensions, extents, level, and even a list of Child grids.
[13]:
g.ActiveDimensions
[13]:
array([16, 18, 16], dtype=int32)
[14]:
g.LeftEdge, g.RightEdge
[14]:
(unyt_array([0.25 , 0.21875, 0.25 ], 'code_length'),
unyt_array([0.5, 0.5, 0.5], 'code_length'))
[15]:
g.Level
[15]:
1
[16]:
g.Children
[16]:
[EnzoGrid_0145 ([30 28 28])]
Advanced Grid Inspection¶
If we want to examine grids only at a given level, we can! Not only that, but we can load data and take a look at various fields.
This section can be skipped!
[17]:
gs = ds.index.select_grids(ds.index.max_level)
[18]:
g2 = gs[0]
print(g2)
print(g2.Parent)
print(g2.get_global_startindex())
EnzoGrid_0028 ([38 34 26])
EnzoGrid_0023 ([40 42 24])
[4096 4096 4096]
[19]:
g2["density"][:, :, 0]
[19]:
unyt_array([[1.0136369e-25, 3.4564638e-25, 6.4192590e-25, ..., 5.9669651e-25,
5.1001470e-25, 4.2170473e-25],
[1.7664165e-25, 4.3917114e-25, 7.1012795e-25, ..., 4.8336836e-25,
2.3386585e-25, 1.5441057e-25],
[2.0398285e-25, 5.0713038e-25, 8.9340174e-25, ..., 1.5818960e-25,
6.5505691e-26, 4.2683066e-26],
...,
[4.7057491e-25, 2.8565834e-25, 1.6021799e-25, ..., 9.8956538e-27,
1.0460956e-26, 1.1069824e-26],
[2.1737538e-25, 1.2614471e-25, 8.5885592e-26, ..., 9.5149775e-27,
9.9683854e-27, 1.0507010e-26],
[9.0090510e-26, 6.8866435e-26, 6.3422531e-26, ..., 9.1754346e-27,
9.5285530e-27, 1.0011084e-26]], dtype='>f4', units='g/cm**3')
[20]:
print((g2.Parent.child_mask == 0).sum() * 8)
print(g2.ActiveDimensions.prod())
33592
33592
[21]:
for f in ds.field_list:
fv = g[f]
if fv.size == 0:
continue
print(f, fv.min(), fv.max())
('all', 'creation_time') 0.0 s 0.0 s
('all', 'dynamical_time') 0.0 s 0.0 s
('all', 'metallicity_fraction') 0.0 code_metallicity 0.0 code_metallicity
('all', 'particle_index') 495510.0 dimensionless 999626.0 dimensionless
('all', 'particle_mass') 4.2555414545269184e+38 g 4.2555414545269184e+38 g
('all', 'particle_position_x') 0.41541787345992065 code_length 0.4978604680250108 code_length
('all', 'particle_position_y') 0.262784210985574 code_length 0.4940284595802798 code_length
('all', 'particle_position_z') 0.262642536622731 code_length 0.4951038390260019 code_length
('all', 'particle_type') 1.0 dimensionless 1.0 dimensionless
('all', 'particle_velocity_x') -3771602.328267241 cm/s 6406800.047442201 cm/s
('all', 'particle_velocity_y') -9214187.767832078 cm/s 1247333.940700183 cm/s
('all', 'particle_velocity_z') -9018941.986469014 cm/s -186059.66175555275 cm/s
('enzo', 'Average_creation_time') 0.0 dimensionless 0.0 dimensionless
('enzo', 'Bx') 0.0 code_magnetic 0.0 code_magnetic
('enzo', 'By') 0.0 code_magnetic 0.0 code_magnetic
('enzo', 'Bz') 0.012791604 code_magnetic 0.012831846 code_magnetic
('enzo', 'Cooling_Time') 39200162000000.0 s 1.1962319e+19 s
('enzo', 'Dark_Matter_Density') 0.0 code_mass/code_length**3 1.0860616 code_mass/code_length**3
('enzo', 'Density') 0.15646304 code_mass/code_length**3 1204.9136 code_mass/code_length**3
('enzo', 'Electron_Density') 0.13746694 code_mass/code_length**3 799.5259 code_mass/code_length**3
('enzo', 'Forming_Stellar_Mass_Density') 1e-10 dimensionless 1e-10 dimensionless
('enzo', 'Galaxy1Colour') 0.15646304 dimensionless 1724.4418 dimensionless
('enzo', 'Galaxy2Colour') 0.15646304 dimensionless 1724.4418 dimensionless
('enzo', 'HII_Density') 0.11890293 code_mass/code_length**3 735.7007 code_mass/code_length**3
('enzo', 'HI_Density') 1.2184947e-07 code_mass/code_length**3 178.85246 code_mass/code_length**3
('enzo', 'HeIII_Density') 0.036707662 code_mass/code_length**3 29.421303 code_mass/code_length**3
('enzo', 'HeII_Density') 0.00084066886 code_mass/code_length**3 196.45789 code_mass/code_length**3
('enzo', 'HeI_Density') 3.8220507e-09 code_mass/code_length**3 62.92708 code_mass/code_length**3
('enzo', 'MBHColour') 2.3229606e-11 dimensionless 6.0653377e-10 dimensionless
('enzo', 'Metal_Density') 1.1651283e-05 code_mass/code_length**3 1.5543634 code_mass/code_length**3
('enzo', 'PhiField') 0.0 dimensionless 0.0 dimensionless
('enzo', 'Phi_pField') 0.0 dimensionless 0.0 dimensionless
('enzo', 'SFR_Density') 1e-10 dimensionless 1e-10 dimensionless
('enzo', 'Star_Particle_Density') 1e-10 dimensionless 1e-10 dimensionless
('enzo', 'Temperature') 5423.749 K 13363.372 K
('enzo', 'TotalEnergy') 0.64976573 code_velocity**2 1.4317576 code_velocity**2
('enzo', 'gammaHI') 0.0 dimensionless 0.0 dimensionless
('enzo', 'kphHI') 0.0 dimensionless 0.0 dimensionless
('enzo', 'kphHeI') 0.0 dimensionless 0.0 dimensionless
('enzo', 'kphHeII') 0.0 dimensionless 0.0 dimensionless
('enzo', 'x-velocity') -0.8689198 code_velocity 10.238566 code_velocity
('enzo', 'y-velocity') -1.5469203 code_velocity 7.3075 code_velocity
('enzo', 'z-velocity') -1.0474687 code_velocity 9.704765 code_velocity
('io', 'creation_time') 0.0 code_time 0.0 code_time
('io', 'dynamical_time') 0.0 code_time 0.0 code_time
('io', 'metallicity_fraction') 0.0 code_metallicity 0.0 code_metallicity
('io', 'particle_index') 495510.0 dimensionless 999626.0 dimensionless
('io', 'particle_mass') 5.244230578682618e-06 code_mass 5.244230578682618e-06 code_mass
('io', 'particle_position_x') 0.41541787345992065 code_length 0.4978604680250108 code_length
('io', 'particle_position_y') 0.262784210985574 code_length 0.4940284595802798 code_length
('io', 'particle_position_z') 0.262642536622731 code_length 0.4951038390260019 code_length
('io', 'particle_type') 1.0 dimensionless 1.0 dimensionless
('io', 'particle_velocity_x') -2.846985340118408 code_velocity 4.836158275604248 code_velocity
('io', 'particle_velocity_y') -6.955308437347412 code_velocity 0.941547155380249 code_velocity
('io', 'particle_velocity_z') -6.80792760848999 code_velocity -0.1404467076063156 code_velocity
('nbody', 'creation_time') 0.0 s 0.0 s
('nbody', 'dynamical_time') 0.0 s 0.0 s
('nbody', 'metallicity_fraction') 0.0 code_metallicity 0.0 code_metallicity
('nbody', 'particle_index') 495510.0 dimensionless 999626.0 dimensionless
('nbody', 'particle_mass') 4.2555414545269184e+38 g 4.2555414545269184e+38 g
('nbody', 'particle_position_x') 0.41541787345992065 code_length 0.4978604680250108 code_length
('nbody', 'particle_position_y') 0.262784210985574 code_length 0.4940284595802798 code_length
('nbody', 'particle_position_z') 0.262642536622731 code_length 0.4951038390260019 code_length
('nbody', 'particle_type') 1.0 dimensionless 1.0 dimensionless
('nbody', 'particle_velocity_x') -3771602.328267241 cm/s 6406800.047442201 cm/s
('nbody', 'particle_velocity_y') -9214187.767832078 cm/s 1247333.940700183 cm/s
('nbody', 'particle_velocity_z') -9018941.986469014 cm/s -186059.66175555275 cm/s
Examining Data in Regions¶
yt provides data object selectors. In subsequent notebooks we’ll examine these in more detail, but we can select a sphere of data and perform a number of operations on it. yt makes it easy to operate on fluid fields in an object in bulk, but you can also examine individual field values.
This creates a sphere selector positioned at the most dense point in the simulation that has a radius of 10 kpc.
[22]:
sp = ds.sphere("max", (10, "kpc"))
[23]:
sp
[23]:
YTSphere (galaxy0030): , center=[1.55561975e+24 1.54243494e+24 1.54356506e+24] cm, radius=3.085677580962325e+22 cm
We can calculate a bunch of bulk quantities. Here’s that list, but there’s a list in the docs, too!
[24]:
list(sp.quantities.keys())
[24]:
['WeightedAverageQuantity',
'TotalQuantity',
'TotalMass',
'CenterOfMass',
'BulkVelocity',
'WeightedStandardDeviation',
'AngularMomentumVector',
'Extrema',
'SampleAtMaxFieldValues',
'MaxLocation',
'SampleAtMinFieldValues',
'MinLocation',
'SpinParameter']
Let’s look at the total mass. This is how you call a given quantity. yt calls these “Derived Quantities”. We’ll talk about a few in a later notebook.
[25]:
sp.quantities.total_mass()
[25]:
unyt_array([3.27209035e+42, 8.58102338e+43], 'g')