|
| 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 | + |
0 commit comments