How to use the yt.load function in yt

To help you get started, we’ve selected a few yt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gamer-project / gamer / example / test_problem / Hydro / Plummer / plot_script / plot_gas.py View on Github external
print( '-------------------------------------------------------------------\n' )


idx_start   = args.idx_start
idx_end     = args.idx_end
didx        = args.didx
prefix      = args.prefix

field       = 'density'
#field       = [ 'density', 'Cloud0', 'Cloud1' ]
dpi         = 150


yt.enable_parallelism()

ts = yt.load( [ prefix+'/Data_%06d'%idx for idx in range(idx_start, idx_end+1, didx) ] )

for ds in ts.piter():

   pz_dens = yt.ProjectionPlot( ds, 'z', field )
   pz_dens.set_zlim( field, 1.0e-5, 5.0e-2 )
   pz_dens.set_font( {'size':16} )
   pz_dens.set_axes_unit( 'code_length' )
   pz_dens.set_unit( field, 'code_mass/code_length**2' )
   pz_dens.annotate_timestamp( time_unit='code_time', corner='upper_right' )
   pz_dens.save( mpl_kwargs={"dpi":dpi} )
github gamer-project / gamer / example / test_problem / Hydro / AGORA_IsolatedGalaxy / yt_script / plot_gas_slice.py View on Github external
idx_start   = args.idx_start
idx_end     = args.idx_end
didx        = args.didx
prefix      = '../'

colormap    = 'algae'
width_kpc   = 30
center_mode = 'c'
dpi         = 150


yt.enable_parallelism()

ts = yt.load( [ prefix+'/Data_%06d'%idx for idx in range(idx_start, idx_end+1, didx) ] )
#ts = yt.load( 'Data_??????' )

for ds in ts.piter():

#  define density^2 for calculating the weighted temperature
   def _density_square( field, data ):
      return data["density"]**2

   ds.add_field( ("gas", "density_square"), function=_density_square, sampling_type="cell", units="g**2/cm**6" )


#  density slice -- face-on
   sz_dens = yt.SlicePlot( ds, 'z', 'density', center=center_mode, width=(width_kpc,'kpc') )
   sz_dens.set_zlim( 'density', 1.0e-26, 3.0e-23 )
   sz_dens.set_cmap( 'density', colormap )
   sz_dens.annotate_timestamp( time_unit='Myr', corner='upper_right' )
github ECP-WarpX / WarpX / Examples / Tests / radiation_reaction / test_const_B_analytical / analysis_classicalRR.py View on Github external
def check():
    filename = sys.argv[1]
    data_set_end = yt.load(filename)

    sim_time = data_set_end.current_time.to_value()

    #simulation results
    all_data =  data_set_end.all_data()
    spec_names = [cc.name for cc in cases]

    #All momenta
    res_mom = np.array([np.array([
        all_data[sp, 'particle_momentum_x'].v[0],
        all_data[sp, 'particle_momentum_y'].v[0],
        all_data[sp, 'particle_momentum_z'].v[0]])
        for sp in spec_names])

    for cc in zip(cases, res_mom):
        init_gamma = gamma(cc[0].init_mom)
github yt-project / yt / yt / utilities / amr_kdtree / amr_kdtree.py View on Github external
if splitdims[i] != -1:
                n.create_split(splitdims[i], splitposs[i])

        mylog.info('AMRKDTree rebuilt, Final Volume: %e' % self.tree.trunk.kd_sum_volume())
        return self.tree.trunk

    def count_volume(self):
        return self.tree.trunk.kd_sum_volume()

    def count_cells(self):
        return self.tree.sum_cells()

if __name__ == "__main__":
    import yt
    from time import time
    ds = yt.load('/Users/skillman/simulations/DD1717/DD1717')
    ds.index

    t1 = time()
    hv = AMRKDTree(ds)
    t2 = time()

    print(hv.tree.trunk.kd_sum_volume())
    print(hv.tree.trunk.kd_node_check())
    print('Time: %e seconds' % (t2-t1))
github yt-project / yt / doc / source / cookbook / particle_filter.py View on Github external
def stars_old(pfilter, data):
    age = data.ds.current_time - data["Stars", "creation_time"]
    filter = np.logical_or(age < 0, age.in_units('Myr') >= 100)
    return filter

# Create the particle filters
add_particle_filter("stars_young", function=stars_10Myr, filtered_type='Stars',
                    requires=["creation_time"])
add_particle_filter("stars_medium", function=stars_100Myr, filtered_type='Stars',
                    requires=["creation_time"])
add_particle_filter("stars_old", function=stars_old, filtered_type='Stars',
                    requires=["creation_time"])

# Load a dataset and apply the particle filters
filename = "TipsyGalaxy/galaxy.00300"
ds = yt.load(filename)
ds.add_particle_filter('stars_young')
ds.add_particle_filter('stars_medium')
ds.add_particle_filter('stars_old')

# What are the total masses of different ages of star in the whole simulation 
# volume?
ad = ds.all_data()
mass_young = ad['stars_young', 'particle_mass'].in_units('Msun').sum()
mass_medium = ad['stars_medium', 'particle_mass'].in_units('Msun').sum()
mass_old = ad['stars_old', 'particle_mass'].in_units('Msun').sum()
print("Mass of young stars = %g Msun" % mass_young)
print("Mass of medium stars = %g Msun" % mass_medium)
print("Mass of old stars = %g Msun" % mass_old)

# Generate 4 projections: gas density, young stars, medium stars, old stars
fields = [('gas', 'density'), ('deposit', 'stars_young_cic'),
github yt-project / yt / doc / source / cookbook / camera_movement.py View on Github external
import yt
import numpy as np

# Follow the simple_volume_rendering cookbook for the first part of this.
ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")  # load data
im, sc = yt.volume_render(ds)
cam = sc.camera
cam.resolution = (512, 512)
cam.set_width(ds.domain_width/20.0)

# Find the maximum density location, store it in max_c
v, max_c = ds.find_max('density')

frame = 0
# Move to the maximum density location over 5 frames
for _ in cam.iter_move(max_c, 5):
    sc.render('camera_movement_%04i.png' % frame, clip_ratio=8.0)
    frame += 1

# Zoom in by a factor of 10 over 5 frames
for _ in cam.iter_zoom(10.0, 5):
github ECP-WarpX / WarpX / Tools / yt3d_mpi.py View on Github external
def img_onestep(filename):
    ds = yt.load( filename )
    ad = ds.all_data()
    iteration=int(filename[-5:])
    sc = yt.create_scene(ds, field='Ez')
    if use_moving_window:
        z_shift = jitter_shift( ds, ad, cfl, iteration )
    array_shift = z_shift * np.array([0., 0., 1.])
    if plot_mr_patch:
        box_patch = yt.visualization.volume_rendering.render_source.BoxSource(
            left_edge =ds.index.grids[1].LeftEdge +array_shift,
            right_edge=ds.index.grids[1].RightEdge+array_shift,
            color=[1.,0.1,0.1,.01] )
        sc.add_source(box_patch)
    ########################
    ### volume rendering ###
    ########################
    source = sc[0]
github ECP-WarpX / WarpX / Examples / Modules / RigidInjection / analysis_rigid_injection_LabFrame.py View on Github external
# needed.
def remove_rigid_lines(plotfile, nlines_if_rigid):
    header_name = plotfile + '/WarpXHeader'
    f = open(header_name, 'r')
    file_lines = f.readlines()
    nlines = len(file_lines)
    f.close()
    if nlines == nlines_if_rigid:
        f = open(header_name, 'w')        
        f.writelines(file_lines[:-3])
        f.close()

# Remove rigid injection header lines
remove_rigid_lines(filename, 18)
# Read beam parameters
ds = yt.load( filename )
ad = ds.all_data()
# Beam longitudinal position
z = np.mean(ad['beam', 'particle_position_y'].v)
# Beam width
w = np.std(ad['beam', 'particle_position_x'].v)

# initial parameters
z0 = 20.e-6
z0_no_rigid = -5.e-6
w0 = 1.e-6
theta0 = np.arcsin(0.1)

# Theoretical beam width after propagation if rigid OFF
# Inform the user if rigid injection simply off (just to be kind)
wth_no_rigid = np.sqrt( w0**2 + (z-z0_no_rigid)**2*theta0**2 )
error_no_rigid = np.abs((w-wth_no_rigid)/wth_no_rigid)
github dnarayanan / powderday / powderday / front_ends / front_end_controller.py View on Github external
print ('[front_end_controller:] enzo data set detected')
        return field_add


    def arepo():
        from powderday.front_ends.arepo2pd import arepo_field_add as field_add
        print('[front_end_controller:] arepo data set detected')
        return field_add


    bbox = [[-2.*cfg.par.bbox_lim,2.*cfg.par.bbox_lim],
            [-2.*cfg.par.bbox_lim,2.*cfg.par.bbox_lim],
            [-2.*cfg.par.bbox_lim,2.*cfg.par.bbox_lim]]
    
    try: 
        ds = yt.load(fname,bounding_box = bbox)
        ds.index
        print ('[front_end_controller:] bounding_box being used')
    except:
        ds = yt.load(fname)
        ds.index
        print ('[front_end_controller:] NO bounding_box being used')

    ds_type = ds.dataset_type 
    
  
    #define the options dictionary
    options = {'gadget_hdf5':gadget,
               'tipsy':tipsy,
               'ramses':ramses,
               'enzo_packed_3d':enzo,
               'arepo_hdf5':arepo}
github yt-project / yt / doc / source / cookbook / annotations.py View on Github external
import yt

ds = yt.load("enzo_tiny_cosmology/DD0046/DD0046")
p = yt.ProjectionPlot(ds, "z", "density")
p.annotate_sphere([0.54,0.72], radius=(1, 'Mpc'), coord_system='axis', text='Halo #7')
p.annotate_sphere([0.65,0.38,0.3], radius=(1.5, 'Mpc'), coord_system='data', circle_args={'color':'green', 'linewidth':4, 'linestyle':'dashed'})
p.annotate_arrow([0.87,0.59,0.2], coord_system='data', plot_args={'color':'red'})
p.annotate_text([10,20], 'Some halos', coord_system='plot')
p.annotate_marker([0.45,0.1,0.4], coord_system='data',
                  plot_args={'color':'yellow', 's':500})
p.annotate_line([0.2,0.4], [0.3,0.9], coord_system='axis')
p.annotate_timestamp(redshift=True)
p.annotate_scale()
p.save()