# Run this cell to load the slideshow css. %run talktools def fizzbuzz(number): if number % 3 == 0 and number % 5 == 0: return 'FizzBuzz' elif number % 3 == 0: return 'Fizz' elif number % 5 == 0: return 'Buzz' else: return number fb = [] for number in range(1, 100): fb.append(fizzbuzz(number)) print fb website('yt-project.org', height=600) HTML('

Stellar Winds isodensity contour, rho=1e-24 g/ccby jnaimanon Sketchfab

') website('http://yt-project.org/gallery.html') # load yt, as simple as: import yt # yt.load() automagically figures out the output type ds = yt.load('HiresGalaxy/DD0100/DD0100') # Visualize a slice through the midplane of the galaxy slc = yt.SlicePlot(ds, 'z', 'density', width=20*yt.units.kiloparsec) # Customize the plot a bit slc.set_figure_size(4) import yt ds = yt.load('big_cosmo/DD0020/DD0020') print "Domain width is %s" % ds.domain_width.in_cgs() print "Current redshift is %s" % ds.current_redshift slc = yt.SlicePlot(ds, 0, 'density') slc.set_figure_size(5) # A data object that selects all of the data in the simulation, regardless of AMR level. ad = ds.all_data() # All of the gas density values, equivalent to ad['density'] dens = ad[('gas', 'density')] print dens print len(dens) print type(dens) %matplotlib inline from matplotlib import pyplot as plt # Each value corresponds to a single cell - this dataset includes a large amount of data on 4 AMR levels grid_level = ad['grid_level'].v plt.hist(grid_level, bins=[-0.5, 0.5, 1.5, 2.5, 3.5, 4.5], log=True, facecolor='green') plt.xlabel('AMR Level') plt.ylabel('Number of cells') max_val, max_loc = ds.find_max('matter_density') print max_val print max_loc from yt.units import Mpc sphere = ds.sphere(center=max_loc, radius=1*Mpc) prj = yt.ProjectionPlot(ds, 0, ('gas', 'density'), center=max_loc, width=2.2*Mpc, data_source=sphere) prj.set_zlim(('gas', 'density'), 1e-5, 1e-2) prj.set_figure_size(5) # Note: using a "deposit" field along with a weight field # ('deposit', 'all_cic') is the cloud-in-cell deposition of all of the particles in the simulatin prj = yt.ProjectionPlot(ds, 0, ('deposit', 'all_cic'), center=max_loc, width=2.2*Mpc, data_source=sphere, weight_field=('deposit', 'all_cic')) prj.set_figure_size(5) from pprint import pprint ds = yt.load("GalaxyClusterMerger/fiducial_1to3_b0.273d_hdf5_plt_cnt_0175") pprint(ds.field_list) ds.derived_field_list fi = ds.field_info[('gas', 'cell_mass')] print fi.get_source() print ds.field_info[('gas', 'specific_angular_momentum_x')].get_source() def three_times_density(field, data): return 3*data['density'] ds = yt.load('HiresGalaxy/DD0100/DD0100') ds.add_field(("gas", "three_times_density"), units="g/cm**3", function=three_times_density) ad = ds.all_data() print ad['density'] print ad['three_times_density'] from yt.units import cm, meter, kilogram, gram, second, joule print kilogram print type(kilogram) print kilogram*meter**2/second**2 print kilogram*meter**2/second**2 == joule print joule print kilogram + gram from yt.utilities.physical_constants import G, kboltz print "Newton's constant: ", G print "Newton's constant in MKS: ", G.in_mks(), "\n" print "Boltzmann constant: ", kboltz print "Boltzmann constant in MKS: ", kboltz.in_mks() import numpy as np rho = 1e-23*gram/cm**3 t_ff = np.sqrt(3*np.pi/(32*G*rho)) print t_ff print t_ff.in_units('Myr') ds = yt.load('big_cosmo/DD0020/DD0020') prj = yt.ProjectionPlot(ds, 0, 'matter_density', width=(32, 'Mpccm/h'), weight_field='matter_density') prj.set_figure_size(6) prj.set_unit('matter_density', 'Msun/pc**3') %matplotlib inline import yt import numpy as np from yt.data_objects.particle_filters import add_particle_filter from matplotlib import pyplot as plt from pprint import pprint ds = yt.load('HiresGalaxy/DD0100/DD0100') pprint(sorted(ds.field_list)) def formed_star(pfilter, data): filter = data["all", "creation_time"] > 0 return filter add_particle_filter("formed_star", function=formed_star, filtered_type='all', requires=["creation_time"]) # Load the data ds = yt.load("HiresGalaxy/DD0100/DD0100") ds.add_particle_filter('formed_star') # Create a selector to access the data ad = ds.all_data() # Access the creation time and particle mass datasets. masses = ad['formed_star', 'particle_mass'].in_units('Msun') formation_time = ad['formed_star', 'creation_time'].in_units('yr') # Create a plot of the star formation rate as a function of time time_range = [0, 1e8] # years n_bins = 1000 hist, bins = np.histogram(formation_time, bins=n_bins, range=time_range,) time = (bins[:-1] + bins[1:])/2 inds = np.digitize(formation_time, bins=bins) sfr = np.array([masses[inds == j].sum()/(bins[j+1]-bins[j]) for j in range(len(time))]) sfr[sfr == 0] = np.nan plt.plot(time/1e6, sfr) plt.xlabel('Time [Myr]') plt.ylabel('SFR [M$_\odot$ yr$^{-1}$]') # Can create deposition fields based on these new particle types yt.SlicePlot(ds, 2, ('deposit', 'formed_star_cic'), width=(20, 'kpc')) from IPython.display import YouTubeVideo YouTubeVideo('YWi4hO76Wss', width=1024, height=768) YouTubeVideo('cyzzxkX4gjw', width=1024, height=768) %%writefile parallel_test.py import yt yt.enable_parallelism() ds = yt.load('big_cosmo/DD0020/DD0020') ad = ds.all_data() tm = ad.quantities.total_mass() if yt.is_root(): print tm cat parallel_test.py %%time !python parallel_test.py %%time !mpirun -n 4 python parallel_test.py website('http://yt-project.org/docs/dev-3.0/analyzing/parallel_computation.html') import yt import glob from IPython.html.widgets import interact from IPython.display import display from yt.units import kpc fns = sorted(glob.glob('/trove/goldbaum/nofeedback/DD????/DD????')) time_series = yt.DatasetSeries(fns) ds = time_series[-1] prj = yt.ProjectionPlot(ds, 2, 'density') @interact(width=[1, 100]) def show_plot(width=100): prj.set_width(width*kpc) display(prj) @interact(index=[0, len(fns)-1]) def show_plot(index=57): ds = time_series[index] prj = yt.ProjectionPlot(ds, 2, 'density', width=(20, 'kpc')) prj.set_figure_size(5) prj.set_zlim('density', 1e-4, 1e-1) display(prj)