Skip to content

Commit b5bcfcc

Browse files
committed
Added postprocessing scripts to sundry
1 parent c62ef80 commit b5bcfcc

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

sundry/plot_exported_grids.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""Plot results of exported grids, e.g. in cross-section with matplotlib"""
2+
3+
import sys, os
4+
from matplotlib import use
5+
use("Agg")
6+
import matplotlib.pyplot as plt
7+
import numpy as np
8+
9+
"""Settings"""
10+
create_single_plots = True
11+
12+
# find all exported_grid*txt files in directory, and remove trailing commas
13+
14+
for filename in os.listdir("."):
15+
if "exported" in filename and "fixed" not in filename and "original" not in filename:
16+
lines = open(filename).readlines()
17+
new_name = os.path.splitext(filename)[0] + "_fixed.txt"
18+
file_new = open(new_name, "w")
19+
for line in lines:
20+
file_new.write(line[:-2] + "\n")
21+
if "delxyz" in filename:
22+
# determine nx, ny, nz
23+
lines = open(filename).readlines()
24+
nx = int(lines[0].split("*")[0])
25+
ny = int(lines[1].split("*")[0])
26+
nz = len(lines[2].split(","))-1
27+
28+
print nx, ny, nz
29+
30+
# now: open fixed files and store results in a list of numpy arrays
31+
32+
for filename in os.listdir("."):
33+
if "fixed" in filename:
34+
print filename
35+
try:
36+
grid = np.loadtxt(filename, delimiter = ',')
37+
except ValueError:
38+
print "Could not load exported grid " + filename
39+
continue
40+
# reshape to match propert nx, ny, nz structure
41+
print grid.shape
42+
grid = grid.reshape(nz, ny, nx)
43+
fig = plt.figure()
44+
ax = fig.add_subplot(111)
45+
ax.imshow(grid[:,ny/2,:], interpolation='nearest', origin='lower_left')
46+
ax.set_title(filename)
47+
plt.savefig(os.path.splitext(filename)[0] + ".png")
48+
49+
50+
51+
52+
53+

sundry/remove_trailing_comma.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""remove trailing comma from exported_grid files"""
2+
3+
import sys, os
4+
5+
filename = sys.argv[1]
6+
7+
lines = open(filename).readlines()
8+
9+
new_name = os.path.splitext(filename)[0] + "_fixed.csv"
10+
11+
file_new = open(new_name, "w")
12+
13+
for line in lines:
14+
file_new.write(line[:-2] + "\n")
15+
16+

0 commit comments

Comments
 (0)