|
|
```python
|
|
|
# coding: utf-8
|
|
|
import h5py as h5
|
|
|
import numpy as np
|
|
|
old = h5.File("EAGLE_ICs_25.hdf5", "r")
|
|
|
snap = h5.File("eagle_000.hdf5", "r")
|
|
|
new = h5.File("new.hdf5", "w")
|
|
|
old.copy(old["/Header"], new)
|
|
|
old.copy(old["/PartType1"], new)
|
|
|
old.copy(old["/PartType4"], new)
|
|
|
old.copy(old["/PartType5"], new)
|
|
|
old.copy(old["/Units"], new)
|
|
|
old.copy(old["/RuntimePars"], new)
|
|
|
old_h = old["/PartType0/SmoothingLength"][:]
|
|
|
snap_h = snap["/PartType0/SmoothingLength"][:]
|
|
|
old_ids = old["/PartType0/ParticleIDs"][:]
|
|
|
snap_ids = snap["/PartType0/ParticleIDs"][:]
|
|
|
old_m = old["/PartType0/Masses"][:]
|
|
|
snap_m = snap["/PartType0/Masses"][:]
|
|
|
snap_u = snap["/PartType0/InternalEnergy"][:]
|
|
|
old_u = old["/PartType0/InternalEnergy"][:]
|
|
|
old_pos = old["/PartType0/Coordinates"][:,:]
|
|
|
snap_pos = snap["/PartType0/Coordinates"][:,:]
|
|
|
snap_vel = snap["/PartType0/Velocities"][:,:]
|
|
|
old_vel = old["/PartType0/Velocities"][:,:]
|
|
|
new.create_group("PartType0")
|
|
|
old_index = np.argsort(old_ids)
|
|
|
snap_index = np.argsort(snap_ids)
|
|
|
old_u = old_u[old_index]
|
|
|
old_h = old_h[old_index]
|
|
|
old_m = old_m[old_index]
|
|
|
old_ids = old_ids[old_index]
|
|
|
old_pos = old_pos[old_index,:]
|
|
|
old_vel = old_vel[old_index,:]
|
|
|
snap_u = snap_u[snap_index]
|
|
|
snap_h = snap_h[snap_index]
|
|
|
snap_m = snap_m[snap_index]
|
|
|
snap_ids = snap_ids[snap_index]
|
|
|
snap_pos = snap_pos[snap_index,:]
|
|
|
snap_vel = snap_vel[snap_index,:]
|
|
|
new.create_dataset("/PartType0/Masses", np.shape(old_m), fletcher32=True, chunks=True, dtype='f4', data=old_m, shuffle=True, compression="gzip", compression_opts=8)
|
|
|
new.create_dataset("/PartType0/InternalEnergy", np.shape(old_u), fletcher32=True, chunks=True, dtype='f4', data=old_u, shuffle=True, compression="gzip", compression_opts=8)
|
|
|
new.create_dataset("/PartType0/SmoothingLength", np.shape(snap_h), fletcher32=True, chunks=True, dtype='f4', data=snap_h, shuffle=True, compression="gzip", compression_opts=8)
|
|
|
new.create_dataset("/PartType0/ParticleIDs", np.shape(old_ids), fletcher32=True, chunks=True, dtype='i8', data=old_ids, shuffle=True, compression="gzip", compression_opts=8)
|
|
|
new.create_dataset("/PartType0/Coordinates", np.shape(old_pos), fletcher32=True, chunks=True, dtype='f8', data=old_pos, shuffle=True, compression="gzip", compression_opts=8)
|
|
|
new.create_dataset("/PartType0/Velocities", np.shape(old_vel), fletcher32=True, chunks=True, dtype='f4', data=old_vel, shuffle=True, compression="gzip", compression_opts=8)
|
|
|
new.close()
|
|
|
old.close()
|
|
|
snap.close()
|
|
|
``` |
|
|
\ No newline at end of file |