Skip to content

Commit

Permalink
full particles info reader
Browse files Browse the repository at this point in the history
  • Loading branch information
sambit-giri committed Jan 15, 2024
1 parent 11d7a3c commit 37a7413
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/tools21cm/nbody_pkdgrav.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,33 @@ def dLightSpeedSim(self,dMpcUnit):
"""
return 8677.2079486362706 / dMpcUnit

def read_particles(self, filename):
tipsy = open(filename,'rb')
header_type = np.dtype([('time', '>f8'),('N', '>i4'), ('Dims', '>i4'), ('Ngas', '>i4'), ('Ndark', '>i4'), ('Nstar', '>i4'), ('pad', '>i4')])
gas_type = np.dtype([('mass','>f4'), ('x', '>f4'),('y', '>f4'),('z', '>f4'), ('vx', '>f4'),('vy', '>f4'),('vz', '>f4'),
('rho','>f4'), ('temp','>f4'), ('hsmooth','>f4'), ('metals','>f4'), ('phi','>f4')])
dark_type = np.dtype([('mass','>f4'), ('x', '>f4'),('y', '>f4'),('z', '>f4'), ('vx', '>f4'),('vy', '>f4'),('vz', '>f4'),
('eps','>f4'), ('phi','>f4')])
star_type = np.dtype([('mass','>f4'), ('x', '>f4'),('y', '>f4'),('z', '>f4'), ('vx', '>f4'),('vy', '>f4'),('vz', '>f4'),
('metals','>f4'), ('tform','>f4'), ('eps','>f4'), ('phi','>f4')])

header = np.fromfile(tipsy,dtype=header_type,count=1)
header = dict(zip(header_type.names,header[0]))
gas = np.fromfile(tipsy,dtype=gas_type,count=header['Ngas'])
gas = pd.DataFrame(gas,columns=gas.dtype.names)
dark = np.fromfile(tipsy,dtype=dark_type,count=header['Ndark'])
dark = pd.DataFrame(dark,columns=dark.dtype.names)
star = np.fromfile(tipsy,dtype=star_type,count=header['Nstar'])
star = pd.DataFrame(star,columns=star.dtype.names)
tipsy.close()

data = {}
data['header'] = header
data['gas'] = gas
data['dark'] = dark
data['star'] = star
return data

class HaloCataloguePkdgrav3(ReaderPkdgrav3):

def __init__(self, box_len, nGrid,
Expand Down

0 comments on commit 37a7413

Please sign in to comment.