def simple_previous_snap_read(Nsnap, use_multi='n'): if (int(Nsnap) < 10): Nsnapstring = '00'+str(Nsnap) elif (int(Nsnap) < 100): Nsnapstring = '0'+str(Nsnap) else: Nsnapstring = str(Nsnap) the_snapdir = './hdf5/' the_prefix ='snapshot' if (use_multi == 'y'): the_snapdir = './snapdir_'+Nsnapstring+'/' the_suffix = '.hdf5' print 'reading particle type 0 (gas?)' G = readsnap(the_snapdir, Nsnapstring, 0, snapshot_name=the_prefix, extension=the_suffix) if (len(G['p'][:,0]) < 1 ): print 'no previous snapshot detected! ',Nsnap sys.exit() x = G['p'][:,0] y = G['p'][:,1] z = G['p'][:,2] ID = G['id'] a = G['header'][2] Ttbl = (np.array([ID, x, y, z])).T return Ttbl, a
def importParticleData(self, ptype): """ Reads data in from whatever format you'd like. Input: ptype - The numerical index of the particle type you want Output: res - A dictionary that contains information for a *single* pointcloud! """ #we have a function of exactly this format, how convenient (/sarcasm)! return readsnap(self.snapdir, self.snapnum, ptype)
def importParticleData(self,ptype): """ Reads data in from whatever format you'd like. Input: ptype - The numerical index of the particle type you want Output: res - A dictionary that contains information for a *single* pointcloud! """ #we have a function of exactly this format, how convenient (/sarcasm)! return readsnap(self.snapdir,self.snapnum,ptype)
def loop_rdf_wr(sdir, snum, num_bins, box_size=[1, 1, 1]): """This computes the radial distribution function(g(r)) and radial velocities between grains of size bin i and those of size bin j, at separations given by vector 'radii'. The results are stored as 3 dimensional matrices; the first two axes are just spanning the possible i-j pairs, so it will be lower triangular; the third direction runs over the separations at which g and wr are computed""" Pd = readsnap(sdir, snum, 3) xd = Pd['p'][:, 0] yd = Pd['p'][:, 1] zd = Pd['p'][:, 2] vxd = Pd['v'][:, 0] vyd = Pd['v'][:, 1] vzd = Pd['v'][:, 2] # Shells # to be modified such that these numbers are not hard coded, but passed on # as a variable or something.. radii = np.array([0.0025, 0.005, 0.01, 0.025, 0.05]) dr = np.array([0.0025, 0.0025, 0.0075, 0.0225, 0.0275]) num_radii = radii.size # Construct the dust size bins and the vectors with their indices, ok_ds # The size bins are equally spaced in log-space # ok_ds is a list of vectors, each vector containing the indices of dust # particles in a certain size bin e_min = np.amin(Pd['R_d']) e_max = np.amax(Pd['R_d']) size_bins = np.linspace(np.log10(e_min * 0.99), np.log10(e_max * 1.01), num=num_bins + 1, endpoint=True) ok_ds = [] for i in np.arange(num_bins): dummy, = np.where((np.log10(Pd['R_d']) >= size_bins[i]) & (np.log10(Pd['R_d']) < size_bins[i + 1])) ok_ds.append(dummy) g_list = np.zeros((num_bins, num_bins, num_radii)) wr_list = np.zeros((num_bins, num_bins, num_radii)) for i in np.arange(num_bins): for j in np.arange(i + 1): print('Computing bins', i, j) # This is the call to the main routine to compute g(r) and wr(r) # between dust species i and dust species j g,wr = compute_rdf_wr(xd[ok_ds[i]],yd[ok_ds[i]],zd[ok_ds[i]],\ xd[ok_ds[j]],yd[ok_ds[j]],zd[ok_ds[j]],\ vxd[ok_ds[i]],vyd[ok_ds[i]],vzd[ok_ds[i]],\ vxd[ok_ds[j]],vyd[ok_ds[j]],vzd[ok_ds[j]],\ box_size, radii, dr, 0.1, Nt=10) g_list[i, j, :] = g wr_list[i, j, :] = wr return (g_list, wr_list, radii)
def readsnapToDF(snapdir, snapnum, parttype): res = readsnap(snapdir, snapnum, parttype, cosmological='m12i' in snapdir) ids = res.pop('id') vels = res.pop('v') coords = res.pop('p') res['xs'], res['vxs'] = coords[:, 0], vels[:, 0] res['ys'], res['vys'] = coords[:, 1], vels[:, 1] res['zs'], res['vzs'] = coords[:, 2], vels[:, 2] metallicity = res.pop('z') for i, zarray in enumerate(metallicity.T): res['met%d' % i] = zarray snap_df = pd.DataFrame(res, index=ids) return snap_df
def match_particles(PID_list, Nsnap, use_multi='n'): if (int(Nsnap) < 10): Nsnapstring = '00'+str(Nsnap) elif (int(Nsnap) < 100): Nsnapstring = '0'+str(Nsnap) else: Nsnapstring = str(Nsnap) the_snapdir = './hdf5/' the_prefix ='snapshot' if (use_multi == 'y'): the_snapdir = './snapdir_'+Nsnapstring+'/' the_suffix = '.hdf5' print 'reading particle type 0 (gas?)' G = readsnap(the_snapdir, Nsnapstring, 0, snapshot_name=the_prefix, extension=the_suffix) here = np.in1d(G['id'], PID_list) PID = G['id'][here] x = G['p'][:,0][here] y = G['p'][:,1][here] z = G['p'][:,2][here] vx = G['v'][:,0][here] vy = G['v'][:,1][here] vz = G['v'][:,2][here] h = G['header'][12] PhysTemp, PhysRho = convertTemp(G['u'][here], G['ne'][here], G['rho'][here], h) Metallicity = G['z'][:,0][here] a = G['header'][2] boxsize = G['header'][9] tbl = [] base = [PID, x,y,z, vx,vy,vz, PhysTemp, PhysRho, Metallicity] for part in base: tbl.append(part) tbl = np.array(tbl) Ttbl = tbl.T return (Ttbl, a, boxsize)
print "<nameout> == snapshot_184.hdf5" print "<nchunks> == 8" sys.exit(1337) namein0 = sys.argv[1] nameout = sys.argv[2] nchunks = sys.argv[3] fname_in = "%s/%s" % (dirpath, namein0) fname_out = "%s/%s" % (dirpath, nameout) print "Reading from input file" import readsnap as reads # For reading the properties # Gas print "Reading gas data" P0 = reads.readsnap(dirpath, nchunks, 0, cosmological=1, loud=1) # dark matter particles(high res.) print "Reading Dark Matter data: (only high res. particles)" P1 = reads.readsnap(dirpath, nchunks, 1, cosmological=1, loud=1) print "Reading Dark Matter data: (low res. particles: PartType2)" P2 = reads.readsnap(dirpath, nchunks, 2, cosmological=1, loud=1) print "Reading Dark Matter data: (low res. particles: PartType3)" P3 = reads.readsnap(dirpath, nchunks, 3, cosmological=1, loud=1) # Stellar particles print "Reading data for Stellar Particles" P4 = reads.readsnap(dirpath, nchunks, 4, cosmological=1, loud=1) # This is just for making a copy of the header file = h5py.File(fname_in, 'r') #fnew = h5py.File(fname_base+'.'+fname_ext, "w")
import h5py import numpy as np import readsnap as reads halo_list = ['/gdata/rouge/agraus/Alternative_physics_runs/SIDM_runs/h11707/','/gdata/rouge/agraus/Alternative_physics_runs/WDM_runs/h11707/'] for halo_number in halo_list: dirname = halo_number snap_start = 'snapshot_184' #For reading the properties P0=reads.readsnap(dirname,7,0,cosmological=1,loud=1,snapshot_name=snap_start,h0=1.0) P1=reads.readsnap(dirname,7,1,cosmological=1,loud=1,snapshot_name=snap_start,h0=1.0) P2=reads.readsnap(dirname,7,2,cosmological=1,loud=1,snapshot_name=snap_start,h0=1.0) P3=reads.readsnap(dirname,7,3,cosmological=1,loud=1,snapshot_name=snap_start,h0=1.0) P5=reads.readsnap(dirname,7,5,cosmological=1,loud=1,snapshot_name=snap_start,h0=1.0) P4=reads.readsnap(dirname,7,4,cosmological=1,loud=1,snapshot_name=snap_start,h0=1.0) #This is just for making a copy of the header print dirname+snap_start+'.0.hdf5' print 'whatever' file = h5py.File(dirname+snap_start+'.0.hdf5', 'r') stars=file['PartType4'] coord = stars['Coordinates'] Masses = stars['Masses'] Metallicity = stars['Metallicity'] ParticleIDs = stars['ParticleIDs'] SFT = stars['StellarFormationTime'] Vel = stars['Velocities'] fnew = h5py.File(dirname+snap_start+'_for_rock.'+'hdf5', "w") #Creating the header
import os, sys from readsnap import readsnap import np_tools import numpy as np global colormapMin,colormapMax ######################################################################## # Load the Data from the Data Files ######################################################################## # Load the snapshot data. datasetBase and snapshotNumber are defined in the config file! res = readsnap(datasetBase, snapshotNumber, 0) # Calculate what the radius and weight should be when shown, as an approximation to what it really is. radius = np.power(((res['m'] / res['rho'])/(2 * np.pi) ),(1.0/3.0)) weight = 2 * radius * res['rho'] ######################################################################## # Orient the Camera ######################################################################## if orientOnCoM: cameraPosition, pivotPoint, cameraOrientation = np_tools.setCenterOfMassView( res['p'], res['m'], 4. ) ######################################################################## # Put the Data in a Firefly-Recognizable Format ######################################################################## # Make a loader to keep the dataset around numpy_loader = NumpyLoader()
#dirname = './halo796_Y13/snapdir_184/' #dirname = './halo897_Y13/snapdir_184/' #dirname = './halo897_Y13_stampede/' #dirname = './halo848_Y13/snapdir_184/' #dirname = './halo11707_Y13/snapdir_184/' #dirname = './halo1016_Y13/snapdir_184/' #dirname = './halo12596_Y13/snapdir_184/' #dirname = './halo20910_Y13/snapdir_184/' #dirname = './halo32503_Y13/snapdir_184/' #dirname = './halo20192_Y13/snapdir_184/' #dirname = './halo897_Y13/snapdir_184/' dirname = './snapdir_184/' import readsnap as reads # For reading the properties # Gas P0=reads.readsnap(dirname,7,0,cosmological=1,loud=1) # dark matter particles(high res.) P1=reads.readsnap(dirname,7,1,cosmological=1,loud=1) # dark matter particles(low res.) P2=reads.readsnap(dirname,7,2,cosmological=1,loud=1) P3=reads.readsnap(dirname,7,3,cosmological=1,loud=1) P5=reads.readsnap(dirname,7,5,cosmological=1,loud=1) # Stellar particles P4=reads.readsnap(dirname,7,4,cosmological=1,loud=1) # This is just for making a copy of the header file = h5py.File(dirname+'snapshot_184.0.hdf5', 'r') #stars=file['PartType4'] #coord = stars['Coordinates'] #Masses = stars['Masses'] #Metallicity = stars['Metallicity']
theN = Ns[count] print 'reading particle type 4 for ', theN if (theN < 10): Nsnapstring = '00' + str(theN) elif (theN < 100): Nsnapstring = '0' + str(theN) else: Nsnapstring = str(theN) the_snapdir = './hdf5/' if (multifile): the_snapdir = './snapdir_' + Nsnapstring + '/' the_prefix = 'snapshot' the_suffix = '.hdf5' S = readsnap(the_snapdir, Nsnapstring, 4, snapshot_name=the_prefix, extension=the_suffix) thetime = S['header'][2] redshift = S['header'][3] boxsize = S['header'][9] omega_matter = S['header'][10] omega_L = S['header'][11] h = S['header'][12] AHF_haloX = x[count] AHF_haloY = y[count] AHF_haloZ = z[count] AHF_Rvir = Rvir[count] AHF_a = 1.0 / (1.0 + Zs[count]) if (adaptive_Rstar):
while (count < TheLen and not fake): theN = Ns[count] print 'reading particle type 4 for ',theN if (theN < 10): Nsnapstring = '00'+str(theN) elif (theN < 100): Nsnapstring = '0'+str(theN) else: Nsnapstring = str(theN) the_snapdir = './hdf5/' if (multifile): the_snapdir = './snapdir_'+Nsnapstring+'/' the_prefix ='snapshot' the_suffix = '.hdf5' S = readsnap(the_snapdir, Nsnapstring, 4, snapshot_name=the_prefix, extension=the_suffix) thetime = S['header'][2] redshift = S['header'][3] boxsize = S['header'][9] omega_matter = S['header'][10] omega_L = S['header'][11] h = S['header'][12] AHF_haloX = x[count] AHF_haloY = y[count] AHF_haloZ = z[count] AHF_Rvir = Rvir[count] AHF_a = 1.0 / (1.0 + Zs[count]) if (adaptive_Rstar): Rstars = Inner_SF_thresh*Rvir[count]
Nsnapstring = str(Nsnap) the_snapdir = './hdf5/' the_prefix = 'snapshot' if (multifile == 'y'): the_snapdir = './snapdir_' + Nsnapstring + '/' the_suffix = '.hdf5' #get the first 20 DM particles and see where they came from the_ptype = 1 gthe_ptype = 0 sthe_ptype = 4 S = readsnap(the_snapdir, Nsnapstring, the_ptype, snapshot_name=the_prefix, extension=the_suffix) gS = readsnap(the_snapdir, Nsnapstring, gthe_ptype, snapshot_name=the_prefix, extension=the_suffix) sS = readsnap(the_snapdir, Nsnapstring, sthe_ptype, snapshot_name=the_prefix, extension=the_suffix) PID_list = S['id'][:] DMpos = S['p'][:, :]
print "<nchunks> == 8" sys.exit(1337) dirpath=sys.argv[1] namein0=sys.argv[2] nameout=sys.argv[3] nchunks=sys.argv[4] fname_in = "%s/%s"%(dirpath,namein0) fname_out = "%s/%s"%(dirpath,nameout) print "Reading from input file" import readsnap as reads # For reading the properties # Gas print "Reading gas data" P0=reads.readsnap(dirpath,nchunks,0,cosmological=0,loud=1,snapshot_name='snapshot_184') # dark matter particles(high res.) print "Reading Dark Matter data: (only high res. particles)" P1=reads.readsnap(dirpath,nchunks,1,cosmological=0,loud=1,snapshot_name='snapshot_184') print "Reading Dark Matter data: (low res. particles: PartType2)" P2=reads.readsnap(dirpath,nchunks,2,cosmological=0,loud=1,snapshot_name='snapshot_184') print "Reading Dark Matter data: (low res. particles: PartType3)" P3=reads.readsnap(dirpath,nchunks,3,cosmological=0,loud=1,snapshot_name='snapshot_184') # Stellar particles print "Reading data for Stellar Particles" P4=reads.readsnap(dirpath,nchunks,4,cosmological=0,loud=1,snapshot_name='snapshot_184') # This is just for making a copy of the header print 'copying header from: '+str(fname_in) file_copy = h5py.File(fname_in+'0.hdf5', 'r')
Nsnapstring = '00'+str(sys.argv[1]) elif (int(sys.argv[1]) < 100): Nsnapstring = '0'+str(sys.argv[1]) else: Nsnapstring = str(sys.argv[1]) Nsnap = int(sys.argv[1]) the_snapdir = './hdf5/' if (multifile): the_snapdir = './snapdir_'+Nsnapstring+'/' the_prefix ='snapshot' the_suffix = '.hdf5' #read the snapshot print 'reading particle type 0 (gas?)' G = readsnap(the_snapdir, Nsnapstring, 0, snapshot_name=the_prefix, extension=the_suffix) print 'reading particle type 4' S = readsnap(the_snapdir, Nsnapstring, 4, snapshot_name=the_prefix, extension=the_suffix) if (readDM): print 'reading particle type 5 (black holes? I hope not)' P5 = readsnap(the_snapdir, Nsnapstring, 5, snapshot_name=the_prefix, extension=the_suffix,skip_bh=1) print 'reading particle type 1 (fine DM?)' DM = readsnap(the_snapdir, Nsnapstring, 1, snapshot_name=the_prefix, extension=the_suffix) print 'reading particle type 2' P2 = readsnap(the_snapdir, Nsnapstring, 2, snapshot_name=the_prefix, extension=the_suffix) print 'reading particle type 3'
Nsnapstring = '0' + str(sys.argv[1]) else: Nsnapstring = str(sys.argv[1]) Nsnap = int(sys.argv[1]) the_snapdir = './hdf5/' if (multifile): the_snapdir = './snapdir_' + Nsnapstring + '/' the_prefix = 'snapshot' the_suffix = '.hdf5' #read the snapshot print 'reading particle type 0 (gas?)' G = readsnap(the_snapdir, Nsnapstring, 0, snapshot_name=the_prefix, extension=the_suffix) a = G['header'][2] z = 1.0 / a - 1.0 redshift = G['header'][3] boxsize = G['header'][9] omega_matter = G['header'][10] omega_L = G['header'][11] h = G['header'][12] redshiftstring = "{0:.3f}".format(redshift) Hubble = hubble_param(a, omega_matter, h) PhysTemp, PhysRho = SF.convertTemp(G['u'], G['ne'], G['rho'], h) halostats = SF.find_halo_now(halo_to_do, a, therod=use_fixed_halos)
snum_max = snum_min zmin = 0.510 zmax = 0.525 dt = 0.025 # don't forget to adjust colorbar min/max scale below vmin = -0.5 vmax = 0.5 x_subtract = 0 y_subtract = 0 z_subtract = 0 xg, yg = np.mgrid[0:1:512j, 0:1:512j] for snum in np.arange(snum_min, snum_max + 1): print(snum) H = readsnap(sdir, snum, 0, header_only=1) time = H['time'] print('time', time) P = readsnap(sdir, snum, 0) Pd = readsnap(sdir, snum, 3) x = P['p'][:, 0] y = P['p'][:, 1] z = P['p'][:, 2] vx = P['v'][:, 0] vy = P['v'][:, 1] vz = P['v'][:, 2] rho = P['rho'] xd = Pd['p'][:, 0] yd = Pd['p'][:, 1] zd = Pd['p'][:, 2]
def snapdata(path, snap): data = rs.readsnap(path, snap, 0) dataBH = rs.readsnap(path, snap, 5, skip_bh=1) dataSTAR = rs.readsnap(path, snap, 4) return data, dataBH, dataSTAR