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
def define_ds(snap, raw_sim_dir, raw_sim_name_prefix, caesar_dir, name_prefix, redshiftFile, verbose=False): """ """ import caesar import yt import numpy as np import os import pygad as pg _, zs_table, snaps_table = np.loadtxt(redshiftFile, unpack=True) infile = caesar_dir + name_prefix + '{:0>3}'.format(int(snap)) + \ '.hdf5' print("Loading Ceasar file: {}").format(infile) obj = caesar.load(infile) obj.galaxies.sort(key=lambda x: x.sfr, reverse=True) rawSim = raw_sim_dir + raw_sim_name_prefix + \ '{:>03}'.format(int(snap)) + '.hdf5' ds = yt.load(rawSim, over_refine_factor=1, index_ptype="all") s = pg.Snap(raw_sim_dir + raw_sim_name_prefix + '{:0>3}'.format(int(snap)) + '.hdf5') h = s.cosmology.h() # obj.simulation.hubble_constant if verbose: print_ds_info(h, obj, ds) zred = '{:.3f}'.format(zs_table[snaps_table == snap][0]) return s, h, obj, ds, float(zred)
ba = np.sqrt(eig_vals[0] / eig_vals[2]) ca = np.sqrt(eig_vals[1] / eig_vals[2]) print abs(ba - ba_0) / ba_0, abs(ca - ca_0) / ca_0 if abs(ba - ba_0) / ba_0 <= 1e-3 and abs(ca - ca_0) / ca_0 <= 1e-3: break return ba, ca filename = '../gamma-1.5-bh-6.hdf5' r_e = 10.722 s = pygad.Snap(filename) snap = s.stars com = find_com(snap['pos'][:, :], snap['mass'][:], max(snap['pos'][:, 0]) * 0.001) snap['pos'][:, :] = snap['pos'][:, :] - com snap = vm._orientsnap(snap, axisorientation=1, rangmom=0.5 * 20) snap.to_physical_units() print(np.sum(snap['mass'][:])) mask = snap['pos'][:, 0]**2 + snap['pos'][:, 1]**2 + snap['pos'][:, 2]**2 < r_e**2 coords = snap['pos'][mask, :]
pos = np.array([gp[k] for k in mygals[igal].glist]) if sum(mass) == 0: rhalf[0][igal] = rhalf[1][igal] = rhalf[2][igal] = 0 continue for idir0 in range(3): rhalf[idir0][igal], cent = compute_rfrac( idir0, mass, pos, frac) if igal % (len(mygals) / 20) == 0: print( '%d logM*= %.3f c= [%.3f,%.3f] rh2d= %.3f %.3f %.3f rh3d= %.3f' % (igal, np.log10(ms[igal]), cent[0], cent[1], rhalf[0][igal], rhalf[1][igal], rhalf[2][igal], mygals[igal].radii['stellar_half_mass'])) else: pgsnap = pg.Snap(snapfile, physical=True) print('Computing', plotvar, 'magnitudes for', len(pgsnap.stars), 'stars.') allL = pg.snapshot.get_luminosities(pgsnap.stars, band=plotvar) print(allL) for igal in range(len(mygals)): mass = np.array([sm[k] for k in mygals[igal].slist]) lum = np.array([allL[k] for k in mygals[igal].slist]) #if igal%(len(mygals)/20)==0: print igal,mags[:3],lum[:3],min(mags),max(mags),min(lum),max(lum) pos = np.array([sp[k] for k in mygals[igal].slist]) if not conc: for idir0 in range(3): rhalf[idir0][igal], cent = compute_rfrac( idir0, lum, pos) for idir0 in range(3): rhalfmass[idir0][igal], cent = compute_rfrac(
#---------------ignore this dotted line for now-------------------------------- #this finds the center for the given snapshot if centertype == 'rockstar': padding = 95 - len(centerarray) center = centerarray[snap - padding] if centertype == 'gtrace': 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')
plt.ylabel('Vrot los (km/s)') plt.savefig(filename) plt.clf() return np.max(vrot) if __name__ == '__main__': model = 'm50n512' wind = 's50j7k' snap = '151' results_dir = '/home/sapple/simba_sizes/sigma_rot/' data_dir = '/home/rad/data/' + model + '/' + wind + '/' s = pg.Snap(data_dir + 'snap_' + model + '_' + snap + '.hdf5') sim = caesar.load(data_dir + 'Groups/' + model + '_' + snap + '.hdf5') h = sim.simulation.hubble_constant redshift = sim.simulation.redshift G = sim.simulation.G.in_units('km**3/(Msun*s**2)') ssfr_min = 0. # look at literature for this range sm_min = 4.6e9 sfr_min = -1.5 factor = 2. # do profile up to twice half mass radius NR = 10 Npixels = 100 edge_vec = np.array([0, 1, 0]) # for edge-on projection
import pygad import matplotlib.pyplot as plt # snapname = "snap_m12.5n128_125.hdf5" snapname = "/scratch/shuiyao/data/m25n256/snap_m25n256_125.hdf5" s = pygad.Snap(snapname) print s.loadable_blocks() # snap, halo = pygad.tools.prepare_zoom(s) # R200, M200 = pygad.analysis.virial_info(snap) # fig, ax, cbar = pygad.plotting.image(snap.gas, extent='5 Mpc') # ax.add_artist(plot.Circle([0,0], R200, facecolor='none', edgecolor='w')) # plt.draw() s.cosmology s.redshift s.scale_factor s.parts s['ID'] s.gas['rho'] s.gas['temp'] # Will be derived automatically
bharray = np.loadtxt(path + 'BHSFactivity/bhlist10.txt', skiprows=1, dtype='uint', usecols=(2, )) swallowarray = np.loadtxt(path + 'blackhole_details/Swallow_shortlist.txt', dtype='uint', skiprows=1, usecols=(1, 2)) # This loops over all of the snapshots for i in snap: # This reads in the snapshot, converts it into physical units, and assigns a center to the galaxy s = pygad.Snap('/Volumes/Happy/Choi16_Fiducial/BH_trace/m0' + str(gal).zfill(3) + '/snap_m0' + str(gal).zfill(3) + '_sf_x_2x_' + str(i).zfill(3), load_double_prec=True) s.to_physical_units() center = pygad.analysis.shrinking_sphere(s.stars, center=[s.boxsize / 2] * 3, R=s.boxsize) pygad.Translation(-center).apply(s) dx = [] dy = [] dz = [] gas_id = s.gas['ID'] gasID = np.array(gas_id) gasid = [id.astype(np.uint64) for id in gasID] gasid = np.array(gasid)
# coding: utf-8 # Calculation of y parameter profile, through binning to mapping # load libraries import sys sys.path.append('/home/tazkera/pygad/') get_ipython().magic(u'pylab inline') pylab.rcParams['figure.figsize'] = (12, 8) import pygad as pg import pygad.binning # load data s = pg.Snap('./snap_p50n288gw_108.hdf5', load_double_prec=True) print s # create the pressure field s.gas['pressure'] = s.gas['temp'].in_units_of("K") * pg.physics.kB.in_units_of( 'keV/K') * ((s.gas['ne'] * s.gas['rho'].in_units_of("g/cm**3") * 0.76) / pg.physics.m_H.in_units_of("g")) # create the y-parameter field s.gas['y_param'] = (s.gas['pressure'].in_units_of("cm**-3 keV") * pg.physics.Th_cs.in_units_of('cm**2')) / ( pg.physics.m_e.in_units_of('g') * (pg.physics.c.in_units_of('cm/s')**2)) # create a mask to exclude the star formation >0 particles s.gas['sfr'] sfr_out = s.gas['sfr'] > 0 mask2 = np.array(sfr_out) * 1