Skip to content

Commit

Permalink
copied from athenak, so we can tinker with it here
Browse files Browse the repository at this point in the history
  • Loading branch information
teuben committed Aug 23, 2023
1 parent 24a9f3d commit 573d03c
Show file tree
Hide file tree
Showing 4 changed files with 1,389 additions and 0 deletions.
59 changes: 59 additions & 0 deletions plot_hst.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#! /usr/bin/env python

# Script for plotting 1D data from Athena++ .hst files.

# Run "plot_hst.py -h" for help.

# Python modules
import argparse

# Athena++ modules
import athena_read


# Main function
def main(**kwargs):

# get input file and read data
input_file = kwargs['input']
data = athena_read.hst(input_file)

# get variable names, check they are valid, and set x/y data
variables = kwargs['variables']
if variables not in data:
print('Invalid input variable name, valid names are:')
for key in data:
print(key)
raise RuntimeError

y_vals = data[variables]
x_vals = data["time"]

print(data)

# Load Python plotting modules
output_file = kwargs['output']
if output_file != 'show':
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt

# Plot data
plt.figure()
plt.plot(x_vals, y_vals)
plt.show()


# Execute main function
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--input',
help='name of input (hst) file')
parser.add_argument('-o', '--output',
default='show',
help='image filename; omit to display to screen')
parser.add_argument('-v', '--variables',
help='comma-separated list of variables to be plotted')

args = parser.parse_args()
main(**vars(args))
70 changes: 70 additions & 0 deletions plot_mesh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#! /usr/bin/env python

# Script for plotting mesh structure in mesh_structure.dat (default name) file
# produced by running Athena++ with "-m" argument.

# Can optionally specify "-i <input_file>" and/or "-o <output_file>". If -o
# argument is omitted, output defaults to display on screen rather than
# saving to file.

# Run "plot_mesh.py -h" for help.

# Python modules
import argparse


# Main function
def main(**kwargs):

# Extract inputs
input_file = kwargs['input']
output_file = kwargs['output']

# Load Python plotting modules
if output_file != 'show':
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
# not used explicitly, but required for 3D projections
from mpl_toolkits.mplot3d import Axes3D # noqa

# Read and plot block edges
fig = plt.figure()
ax = fig.gca(projection='3d')
x = []
y = []
z = []
with open(input_file) as f:
for line in f:
if line[0] != '\n' and line[0] != '#':
numbers_str = line.split()
x.append(float(numbers_str[0]))
y.append(float(numbers_str[1]))
# append zero if 2D
if (len(numbers_str) > 2):
z.append(float(numbers_str[2]))
else:
z.append(0.0)
if line[0] == '\n' and len(x) != 0:
ax.plot(x, y, z, 'k-')
x = []
y = []
z = []
if output_file == 'show':
plt.show()
else:
plt.savefig(output_file, bbox_inches='tight')


# Execute main function
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--input',
default='mesh_structure.dat',
help='name of input (mesh structure) file')
parser.add_argument('-o',
'--output',
default='show',
help='image filename; omit to display to screen')
args = parser.parse_args()
main(**vars(args))
Loading

0 comments on commit 573d03c

Please sign in to comment.