-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #217 from lanl/mesa-input
a short script for taking mesa input and preparing it for the grsolver
- Loading branch information
Showing
1 changed file
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
This script retrieves raw MESA profile data variables, reverses them to be center to surface, and outputs them in the format needed for GRSOLVER for use in Phoebus. | ||
Usage: | ||
python read_MESA_for_grsolver.py 20m_cc.dat | ||
Arguments: | ||
input_file: filename of MESA profile | ||
""" | ||
|
||
import numpy as np | ||
import pandas as pd | ||
from argparse import ArgumentParser | ||
|
||
|
||
def load(file): | ||
df = pd.read_csv(file, sep=r"\s+", header=4) | ||
df = df.iloc[::-1].reset_index(drop=True) | ||
nzones = len(df) | ||
if nzones > 0: | ||
print("loaded file:", file, " with ", nzones, " zones.") | ||
else: | ||
print("failed to load file", file) | ||
exit() | ||
return df | ||
|
||
|
||
def retrieve_and_save(df, file): | ||
radius = df["radius_cm"] | ||
velocity = df["velocity"] | ||
# if model non-rotating, pass array of zeros | ||
try: | ||
angular_velocity = df["omega"] | ||
except KeyError: | ||
print("angular velocity not found, setting to zero.") | ||
angular_velocity = np.zeros_like((radius)) | ||
density = df["density"] # g/cm^3 | ||
pressure = df["pressure"] # g/cm^3 | ||
ye = df["ye"] | ||
temperature = df["temperature"] # K | ||
sie = df["energy"] # ! internal energy (ergs/g) | ||
|
||
np.savetxt( | ||
file.split(".")[0] + str("_raw_data.txt"), | ||
np.column_stack( | ||
[ | ||
radius, | ||
velocity, | ||
angular_velocity, | ||
density, | ||
pressure, | ||
ye, | ||
temperature, | ||
sie, | ||
] | ||
), | ||
header="MESA output from model `" + str(file.split(".")[0]) + "` | \ " | ||
"radius (cm) velocity (cm/s) angular_velocity (rad/s) density (g/cm^3) pressure (dyne/cm^2) ye temperature (K) specific internal energy (erg/g)", | ||
) | ||
return | ||
|
||
|
||
def main(): | ||
parser = ArgumentParser( | ||
description="Retrieve raw MESA profile data variables and output to format needed for GRSOLVER for use in Phoebus." | ||
) | ||
parser.add_argument( | ||
"file", | ||
type=str, | ||
default="file", | ||
help="name of the input MESA file", | ||
) | ||
args = parser.parse_args() | ||
|
||
df = load(args.file) | ||
retrieve_and_save(df, args.file) | ||
|
||
return | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |