-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tool for converting gadget3 ICs to EAGLE ICs in HDF format #104
base: master
Are you sure you want to change the base?
Conversation
from scipy.io import FortranFile | ||
import h5py as h5 | ||
|
||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is common to put the docstring at the very beginning of the script file rather than after the imports.
tools/gadget3_to_eagleHDF.py
Outdated
parser = argparse.ArgumentParser(description=__doc__) | ||
parser.add_argument( | ||
'input_ICs', | ||
type=str, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is actually a special argument file type to handle files
type=str, | |
type=argparse.FileType(mode="br"), |
Note that you need to open it in binary format for FortranFile
to be happy.
tools/gadget3_to_eagleHDF.py
Outdated
def ics2hdf(ics_file): | ||
|
||
raw_ics = os.path.abspath(ics_file) | ||
|
||
# Do quick checks to make sure input is valid | ||
assert os.path.isfile(raw_ics),'Input ICs file does not exist.' | ||
assert raw_ics.split('.')[-1] == 'gadget3','Input ICs not valid. Please input GADGET3 binary ICs (.gadget3)' | ||
|
||
out_ics = raw_ics[:-7] + 'hdf5' | ||
|
||
print('Reading binary file '+raw_ics) | ||
|
||
# Open the FORTRAN unformatted binary ICs | ||
f = FortranFile(raw_ics, 'r') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming you use the trick bellow, this'll have to be changed into
def ics2hdf(ics_file): | |
raw_ics = os.path.abspath(ics_file) | |
# Do quick checks to make sure input is valid | |
assert os.path.isfile(raw_ics),'Input ICs file does not exist.' | |
assert raw_ics.split('.')[-1] == 'gadget3','Input ICs not valid. Please input GADGET3 binary ICs (.gadget3)' | |
out_ics = raw_ics[:-7] + 'hdf5' | |
print('Reading binary file '+raw_ics) | |
# Open the FORTRAN unformatted binary ICs | |
f = FortranFile(raw_ics, 'r') | |
def ics2hdf(ics_file): | |
assert ics_file.name.split('.')[-1] == 'gadget3', 'Input ICs not valid. Please input GADGET3 binary ICs (.gadget3)' | |
out_ics = raw_ics.name[:-7] + "hdf5" | |
print(f"Reading binary file {raw_ics}") | |
# Open the FORTRAN unformatted binary ICs | |
f = FortranFile(ics_file, 'r') |
I've been using this script to convert gadget3 ICs (as outputted by genetIC) to EAGLE-compatible HDF5 ICs for a long while now, and I thought it might be useful to include it in the tools here. I was spurred on to do this because Gandhali may need to write something similar, or adapt this script, to create ICs compatible with IllustrisTNG.