def read_snap(gal, snap, snapmin, bh, centerarray, rvirarray, centertype): if centertype == 'rockstar': padding = 95 - len(centerarray) center = centerarray[snap - padding] rvir = rvirarray[snap - padding] if centertype == 'gtrace': center = centerarray[snap - snapmin + 1] rvir = rvirarray[snap - snapmin + 1] s = pygad.Snap('/Volumes/Happy/Choi16_Fiducial/Fiducial_' + str(bh) + '/m0' + str(gal).zfill(3) + '/snap_m0' + str(gal).zfill(3) + '_sf_x_2x_' + str(snap).zfill(3), load_double_prec=True) s.to_physical_units() pygad.Translation(-center).apply(s) vel_center = pygad.analysis.mass_weighted_mean( s.stars[pygad.BallMask('1 kpc', center=pygad.UnitArr([0.0, 0.0, 0.0], 'kpc'))], 'vel') s['vel'] -= vel_center return s
center = centerarray[snap - snapmin + 1] #this is the pygad function to read in the snapshot s = pygad.Snap('/Volumes/G-RAID/Choi16_Fiducial/Fiducial_MrAGN/m0' + str(gal).zfill(3) + '/snap_m0' + str(gal).zfill(3) + '_sf_x_2x_' + str(snap).zfill(3), load_double_prec=True) #this converts all of the quantities with factors of the hubble constant and the scale factor to physical units s.to_physical_units() #Here we center the positions and velocities on the center that we established above pygad.Translation(-center).apply(s) vel_center = pygad.analysis.mass_weighted_mean( s.stars[pygad.BallMask('1 kpc', center=pygad.UnitArr([0.0, 0.0, 0.0], 'kpc'))], 'vel') s['vel'] -= vel_center #------------------------------------------------------------------------------ #the reason for the dotted lines (and the reason that I loaded in the virial radius and the centers separately), is because everything between the two dotted lines can be done just by using a function that I wrote called read_snap. I still wanted you to see how pygad natively reads snapshots, though. In order to use the function, just put read_snap.py in the same directory as your code #Everything between the dotted lines can be achieved by importing read_snap at the beginning of the file and then in place of the code within the dotted lines: s = read_snap.read_snap(gal, snap, snapmin, 'MrAGN', centerarray, rvirarray,