Data InspectionΒΆ

Notebook

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.

In [1]:
import yt

Now that we've loaded yt, we can load up some data. Let's load the IsolatedGalaxy dataset.

In [2]:
ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")

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:

In [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 = 1.39768066e+16 s = 4.42898275e+08 years

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:

In [4]:
ds.field_list
Out[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')]

And, all of the fields it thinks it knows how to generate:

In [5]:
ds.derived_field_list
Out[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_cylindrical_velocity_theta'),
 ('all', 'particle_cylindrical_velocity_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'),
 ('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_spherical_position_phi'),
 ('all', 'particle_spherical_position_radius'),
 ('all', 'particle_spherical_position_theta'),
 ('all', 'particle_spherical_velocity_phi'),
 ('all', 'particle_spherical_velocity_radius'),
 ('all', 'particle_spherical_velocity_theta'),
 ('all', 'particle_type'),
 ('all', 'particle_velocity'),
 ('all', 'particle_velocity_cylindrical_radius'),
 ('all', 'particle_velocity_cylindrical_theta'),
 ('all', 'particle_velocity_cylindrical_z'),
 ('all', 'particle_velocity_magnitude'),
 ('all', 'particle_velocity_relative'),
 ('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'),
 ('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'),
 ('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', 'vertex_x'),
 ('enzo', 'vertex_y'),
 ('enzo', 'vertex_z'),
 ('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', 'chandra_emissivity'),
 ('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', 'cylindrical_radial_velocity'),
 ('gas', 'cylindrical_radial_velocity_absolute'),
 ('gas', 'cylindrical_tangential_velocity'),
 ('gas', 'cylindrical_tangential_velocity_absolute'),
 ('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', 'jeans_mass'),
 ('gas', 'kT'),
 ('gas', 'kinetic_energy'),
 ('gas', 'mach_alfven'),
 ('gas', 'mach_number'),
 ('gas', 'magnetic_energy'),
 ('gas', 'magnetic_field_divergence'),
 ('gas', 'magnetic_field_divergence_absolute'),
 ('gas', 'magnetic_field_magnitude'),
 ('gas', 'magnetic_field_poloidal'),
 ('gas', 'magnetic_field_strength'),
 ('gas', 'magnetic_field_toroidal'),
 ('gas', 'magnetic_field_x'),
 ('gas', 'magnetic_field_y'),
 ('gas', 'magnetic_field_z'),
 ('gas', 'magnetic_pressure'),
 ('gas', 'matter_density'),
 ('gas', 'matter_mass'),
 ('gas', 'mazzotta_weighting'),
 ('gas', 'mean_molecular_weight'),
 ('gas', 'metal_density'),
 ('gas', 'metal_mass'),
 ('gas', 'metallicity'),
 ('gas', 'number_density'),
 ('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_velocity'),
 ('gas', 'radial_velocity_absolute'),
 ('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', 'sz_kinetic'),
 ('gas', 'szy'),
 ('gas', 'tangential_over_velocity_magnitude'),
 ('gas', 'tangential_velocity'),
 ('gas', 'temperature'),
 ('gas', 'thermal_energy'),
 ('gas', 'velocity_cylindrical_radius'),
 ('gas', 'velocity_cylindrical_theta'),
 ('gas', 'velocity_cylindrical_z'),
 ('gas', 'velocity_divergence'),
 ('gas', 'velocity_divergence_absolute'),
 ('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', 'vertex_x'),
 ('gas', 'vertex_y'),
 ('gas', 'vertex_z'),
 ('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', 'xray_emissivity'),
 ('gas', 'y'),
 ('gas', 'z'),
 ('index', 'cell_volume'),
 ('index', 'cylindrical_r'),
 ('index', 'cylindrical_radius'),
 ('index', 'cylindrical_theta'),
 ('index', 'cylindrical_z'),
 ('index', 'disk_angle'),
 ('index', 'dx'),
 ('index', 'dy'),
 ('index', 'dz'),
 ('index', 'grid_indices'),
 ('index', 'grid_level'),
 ('index', 'height'),
 ('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_r'),
 ('index', 'spherical_radius'),
 ('index', 'spherical_theta'),
 ('index', 'vertex_x'),
 ('index', 'vertex_y'),
 ('index', 'vertex_z'),
 ('index', 'virial_radius_fraction'),
 ('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_cylindrical_velocity_theta'),
 ('io', 'particle_cylindrical_velocity_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'),
 ('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_spherical_position_phi'),
 ('io', 'particle_spherical_position_radius'),
 ('io', 'particle_spherical_position_theta'),
 ('io', 'particle_spherical_velocity_phi'),
 ('io', 'particle_spherical_velocity_radius'),
 ('io', 'particle_spherical_velocity_theta'),
 ('io', 'particle_type'),
 ('io', 'particle_velocity'),
 ('io', 'particle_velocity_cylindrical_radius'),
 ('io', 'particle_velocity_cylindrical_theta'),
 ('io', 'particle_velocity_cylindrical_z'),
 ('io', 'particle_velocity_magnitude'),
 ('io', 'particle_velocity_relative'),
 ('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')]

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.

In [6]:
print(ds.field_info["gas", "vorticity_x"].get_source())
    def _vorticity_x(field, data):
        f  = (data[ftype, "velocity_z"][sl_center,sl_right,sl_center] -
              data[ftype, "velocity_z"][sl_center,sl_left,sl_center]) \
              / (div_fac*just_one(data["index", "dy"]))
        f -= (data[ftype, "velocity_y"][sl_center,sl_center,sl_right] -
              data[ftype, "velocity_y"][sl_center,sl_center,sl_left]) \
              / (div_fac*just_one(data["index", "dz"]))
        new_field = data.ds.arr(np.zeros_like(data[ftype, "velocity_z"],
                                              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:

In [7]:
ds.domain_width
Out[7]:
YTArray([ 1.,  1.,  1.]) code_length

yt can also convert this into various units:

In [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.91755627e+19   1.91755627e+19   1.91755627e+19] mile

Finally, we can get basic information about the particle types and number of particles in a simulation:

In [9]:
print (ds.particle_types)
print (ds.particle_types_raw)
print (ds.particle_type_counts)
['io', 'all']
['io']
{'io': 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 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.

In [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.

In [11]:
ds.index.grids[1]
Out[11]:
EnzoGrid_0002
In [12]:
g = ds.index.grids[1]
print(g)
EnzoGrid_0002

Grids have dimensions, extents, level, and even a list of Child grids.

In [13]:
g.ActiveDimensions
Out[13]:
array([16, 18, 16], dtype=int32)
In [14]:
g.LeftEdge, g.RightEdge
Out[14]:
(YTArray([ 0.25   ,  0.21875,  0.25   ]) code_length,
 YTArray([ 0.5,  0.5,  0.5]) code_length)
In [15]:
g.Level
Out[15]:
1
In [16]:
g.Children
Out[16]:
[EnzoGrid_0145]

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!

In [17]:
gs = ds.index.select_grids(ds.index.max_level)
In [18]:
g2 = gs[0]
print (g2)
print (g2.Parent)
print (g2.get_global_startindex())
EnzoGrid_0028
EnzoGrid_0023
[4096 4096 4096]
In [19]:
g2["density"][:,:,0]
Out[19]:
YTArray([[  1.01363690e-25,   3.45646382e-25,   6.41925898e-25, ...,
          5.96696509e-25,   5.10014698e-25,   4.21704727e-25],
       [  1.76641648e-25,   4.39171143e-25,   7.10127952e-25, ...,
          4.83368357e-25,   2.33865852e-25,   1.54410574e-25],
       [  2.03982852e-25,   5.07130376e-25,   8.93401738e-25, ...,
          1.58189599e-25,   6.55056907e-26,   4.26830665e-26],
       ..., 
       [  4.70574906e-25,   2.85658342e-25,   1.60217995e-25, ...,
          9.89565377e-27,   1.04609558e-26,   1.10698239e-26],
       [  2.17375380e-25,   1.26144714e-25,   8.58855917e-26, ...,
          9.51497754e-27,   9.96838536e-27,   1.05070102e-26],
       [  9.00905100e-26,   6.88664354e-26,   6.34225309e-26, ...,
          9.17543455e-27,   9.52855304e-27,   1.00110840e-26]], dtype=float32) g/cm**3
In [20]:
print ((g2.Parent.child_mask == 0).sum() * 8)
print (g2.ActiveDimensions.prod())
33592
33592
In [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 dimensionless 0.0 dimensionless
('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.012791603803634644 code_magnetic 0.012831846252083778 code_magnetic
('enzo', 'Cooling_Time') 39200162316288.0 s 1.1962319273319203e+19 s
('enzo', 'Dark_Matter_Density') 0.0 code_mass/code_length**3 1.0860615968704224 code_mass/code_length**3
('enzo', 'Density') 0.15646304190158844 code_mass/code_length**3 1204.91357421875 code_mass/code_length**3
('enzo', 'Electron_Density') 0.1374669373035431 code_mass/code_length**3 799.52587890625 code_mass/code_length**3
('enzo', 'Forming_Stellar_Mass_Density') 1.000000013351432e-10 dimensionless 1.000000013351432e-10 dimensionless
('enzo', 'Galaxy1Colour') 0.15646304190158844 dimensionless 1724.4417724609375 dimensionless
('enzo', 'Galaxy2Colour') 0.15646304190158844 dimensionless 1724.4417724609375 dimensionless
('enzo', 'HII_Density') 0.11890292912721634 code_mass/code_length**3 735.70068359375 code_mass/code_length**3
('enzo', 'HI_Density') 1.2184946740489977e-07 code_mass/code_length**3 178.8524627685547 code_mass/code_length**3
('enzo', 'HeIII_Density') 0.03670766204595566 code_mass/code_length**3 29.421302795410156 code_mass/code_length**3
('enzo', 'HeII_Density') 0.000840668857563287 code_mass/code_length**3 196.4578857421875 code_mass/code_length**3
('enzo', 'HeI_Density') 3.822050675950095e-09 code_mass/code_length**3 62.92707824707031 code_mass/code_length**3
('enzo', 'MBHColour') 2.322960573897248e-11 dimensionless 6.065337676552929e-10 dimensionless
('enzo', 'Metal_Density') 1.1651282875391189e-05 code_mass/code_length**3 1.5543633699417114 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') 1.000000013351432e-10 dimensionless 1.000000013351432e-10 dimensionless
('enzo', 'Star_Particle_Density') 1.000000013351432e-10 dimensionless 1.000000013351432e-10 dimensionless
('enzo', 'Temperature') 5423.7490234375 K 13363.3720703125 K
('enzo', 'TotalEnergy') 0.6497657299041748 code_velocity**2 1.4317575693130493 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.8689197897911072 code_velocity 10.238566398620605 code_velocity
('enzo', 'y-velocity') -1.5469202995300293 code_velocity 7.307499885559082 code_velocity
('enzo', 'z-velocity') -1.047468662261963 code_velocity 9.704765319824219 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

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.

In [22]:
sp = ds.sphere("max", (10, 'kpc'))
In [23]:
sp
Out[23]:
YTSphere (galaxy0030): , center=[  1.55561975e+24   1.54243494e+24   1.54356506e+24] cm, radius=3.0856775809623245e+22 cm

We can calculate a bunch of bulk quantities. Here's that list, but there's a list in the docs, too!

In [24]:
list(sp.quantities.keys())
Out[24]:
['CenterOfMass',
 'MinLocation',
 'WeightedAverageQuantity',
 'AngularMomentumVector',
 'SpinParameter',
 'MaxLocation',
 'SampleAtMaxFieldValues',
 'Extrema',
 'SampleAtMinFieldValues',
 'TotalQuantity',
 'BulkVelocity',
 'TotalMass',
 'WeightedVariance']

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.

In [25]:
sp.quantities.total_mass()
Out[25]:
YTArray([  3.27209035e+42,   8.58102338e+43]) g

(2)_Data_Inspection.ipynb; 2)_Data_Inspection_evaluated.ipynb; 2)_Data_Inspection.py)