def radius_cut(halo, idx): try: RVIR = pynbody.array.SimArray(np.max(halo['r'].in_units('kpc')),'kpc') except Exception as e: print("No RVIR. Trying AHF method.") print(e) try: RVIR = halo_properties[idx].properties['Rvir'] except: print("No RVIR.") return halo diskf = filt.Sphere(str(RVIR*0.2) +' kpc') #20% Virial Radius return halo[diskf]
def sideon(h, vec_to_xform=calc_sideon_matrix, cen_size="1 kpc", disk_size="5 kpc", cen=None, vcen=None, move_all=True, **kwargs): global config if move_all: top = h.ancestor else: top = h if cen is None: logger.info("Finding halo center...") # or h['pos'][h['phi'].argmin()] cen = halo.center(h, retcen=True, **kwargs) logger.info("... cen=%s" % cen) tx = transformation.inverse_translate(top, cen) if vcen is None: vcen = halo.vel_center(h, retcen=True, cen_size=cen_size) tx = transformation.inverse_v_translate(tx, vcen) cen = h[filt.Sphere(disk_size)] logger.info("Calculating angular momentum vector...") trans = vec_to_xform(ang_mom_vec(cen)) logger.info("Transforming simulation...") tx = transformation.transform(tx, trans) logger.info("...done!") return tx
def half_stellar_radius(halo): half_sm = np.sum(halo.star['mass'].in_units('Msol'))* 0.5 max_high_r = np.max(halo.star['r'].in_units('kpc')) #print(max_high_r) test_r = 0.5 * max_high_r testrf = filt.LowPass('r', test_r) min_low_r = 0.0 test_sm = np.sum(halo[testrf].star['mass'].in_units('Msol')) it = 0 while ((np.abs(test_sm - half_sm) / half_sm) > 0.01): it = it + 1 if (it > 20): break if (test_sm > half_sm): test_r = 0.5 * (min_low_r + test_r) else: test_r = (test_r + max_high_r) * 0.5 testrf = filt.LowPass('r', test_r) test_sm = np.sum(halo[testrf].star['mass'].in_units('Msol')) if (test_sm > half_sm): max_high_r = test_r else: min_low_r = test_r #print("Half stellar radius found as: {}".format(test_r)) diskf = filt.Sphere(str(test_r) +' kpc') return halo[diskf] # Clean sample: put a cut on 100 stellar particles and hallo mass max based on Moster # Add more observations # Stick with the clean sample 10^9 and make plots for isolated galaxies and whole population # Select all galaxies that do not have any halo similar or larger within 3 virial - flag galaxies as isolated or non-isolated. There should be no other galaxy # Salam isolated - still plot them as single plots
def write(s,filename='dumbfile.out'): f = pynbody.util.open_(filename,'wb') f.write(struct.pack(">i", len(s))) s.tofile(f) f.close() simname = sys.argv[1] #pp.plt.ion() s = pynbody.load(simname) h = s.halos() diskf = filt.Disc('40 kpc','3 kpc') fifmyrf = filt.LowPass('age','15 Myr') fhmyrf = filt.LowPass('age','500 Myr') twokpcf = filt.Sphere('2 kpc') i=1 if (len(sys.argv) > 2): photiords = np.genfromtxt(sys.argv[2],dtype='i8') frac = np.float(len(np.where(np.in1d(photiords,h[i]['iord']))[0]))/len(photiords) print 'i: %d frac: %.2f'%(i,frac) while(((frac) < 0.5) & (i<100)): i=i+1 frac = np.float(len(np.where(np.in1d(photiords,h[i]['iord']))[0]))/len(photiords) print 'i: %d frac: %.2f'%(i,frac) else: while len(h[i].star) <2: i=i+1 if (i==100): sys.exit() pynbody.analysis.angmom.faceon(h[i]) try: