|
1 |
| -import numpy as np |
2 |
| -import argparse |
3 |
| - |
4 |
| -import matplotlib.pyplot as plt |
5 |
| -import itertools |
6 |
| -import json, glob |
7 |
| -from numpy import nan as NAN |
8 |
| - |
9 |
| -parser = argparse.ArgumentParser(description='Postprocessing') |
10 |
| -parser.add_argument('foldername', type=str, help='enter folder with experimental data here') |
11 |
| - |
12 |
| -plt.rc('font', **{'family': 'sans-serif', 'sans-serif': ['lmodern'], 'size' : 15}) |
13 |
| -plt.rc('text', usetex=True) |
14 |
| - |
15 |
| -legends = [] |
16 |
| -lines = [] |
17 |
| -name = parser.parse_args().foldername |
18 |
| -plottingdir = r'./' + name |
19 |
| -filenames = glob.glob(plottingdir+"/*.json") |
20 |
| -print("reading from") |
21 |
| -print(filenames) |
22 |
| - |
23 |
| -marker_collection = ('o','x','d','s','^','<','>','v','.') |
24 |
| - |
25 |
| -marker_left = itertools.cycle(marker_collection) |
26 |
| - |
27 |
| -plot_right = True |
28 |
| -if plot_right: |
29 |
| - marker_right = itertools.cycle(marker_collection) |
30 |
| - |
31 |
| -if plot_right: |
32 |
| - f, (ax1, ax2) = plt.subplots(1, 2, sharey=True, figsize=(12,9)) |
33 |
| -else: |
34 |
| - f, (ax1) = plt.subplots(1, 1, sharey=True, figsize=(12,9)) |
35 |
| - |
36 |
| -data_left = np.empty(shape=(0,0)) |
37 |
| -data_right = np.empty(shape=(0,0)) |
38 |
| -data_header = [] |
39 |
| - |
40 |
| - |
41 |
| -def concat_w_zero_padding(a,b): |
42 |
| - if len(a.shape) > 1 and a.shape[1] == 0: # a has no entries |
43 |
| - return b |
44 |
| - elif len(b.shape) > 1 and b.shape[1] == 0: # b has no entries |
45 |
| - return a |
46 |
| - else: # both arrays have entries |
47 |
| - la = a.shape[0] |
48 |
| - lb = b.shape[0] |
49 |
| - if la < lb: # padding a |
50 |
| - a = np.pad(a, (0, lb-la), 'constant') |
51 |
| - elif la > lb: # padding b |
52 |
| - b = np.pad(b, (0, la-lb), 'constant') |
53 |
| - else: # no padding needed if la = lb |
54 |
| - pass |
55 |
| - return np.c_[a,b] |
56 |
| - |
57 |
| - |
58 |
| -for filename in filenames: |
59 |
| - print("---") |
60 |
| - print(filename) |
61 |
| - with open(filename) as data_file: |
62 |
| - |
63 |
| - data = json.load(data_file) |
64 |
| - taus = np.array(data['temporal_resolution']) |
65 |
| - |
66 |
| - if data.has_key('errors_left'): |
67 |
| - errors_left = np.array(data['errors_left']) |
68 |
| - errors_left[errors_left > 10.0] = NAN |
69 |
| - ax1.dataLim._set_x1(taus.max()) |
70 |
| - line = ax1.loglog(taus, errors_left, ':',marker=marker_left.next(),markerfacecolor="none",markersize=10,markeredgewidth=2) |
71 |
| - data_left = concat_w_zero_padding(data_left, errors_left) |
72 |
| - elif data.has_key('errors'): |
73 |
| - errors = np.array(data['errors']) |
74 |
| - errors[errors > 10.0] = NAN |
75 |
| - line = ax1.loglog(taus, errors, marker=marker_left.next(),markerfacecolor="none") |
76 |
| - data_left = concat_w_zero_padding(data_left, errors) |
77 |
| - |
78 |
| - if plot_right and data.has_key('errors_right'): |
79 |
| - errors_right = np.array(data['errors_right']) |
80 |
| - errors_right[errors_right > 10.0] = NAN |
81 |
| - ax2.loglog(taus, errors_right, ':',marker=marker_right.next(),markerfacecolor="none",markersize=10,markeredgewidth=2) |
82 |
| - data_right = concat_w_zero_padding(data_right, errors_right) |
83 |
| - elif plot_right and data.has_key('errors'): |
84 |
| - errors = np.array(data['errors']) |
85 |
| - errors[errors > 10.0] = NAN |
86 |
| - ax2.loglog(taus, errors, marker=marker_right.next()) |
87 |
| - data_right = concat_w_zero_padding(data_right, errors) |
88 |
| - |
89 |
| - if data['numerical_parameters'].has_key('neumann coupling scheme'): |
90 |
| - legends.append(data['experiment_name']) |
91 |
| - elif data['numerical_parameters'].has_key('neumann coupling order'): |
92 |
| - legends.append(data['experiment_name']+" - FD order: "+ str(data['numerical_parameters']['neumann coupling order'])) |
93 |
| - else: |
94 |
| - legends.append(data['experiment_name']) |
95 |
| - |
96 |
| - data_header.append(data['experiment_name']) |
97 |
| - |
98 |
| - lines.append(line[0]) |
99 |
| - |
100 |
| -data_left = concat_w_zero_padding(data_left, taus) |
101 |
| -data_right = concat_w_zero_padding(data_right, taus) |
102 |
| -data_header.append('taus') |
103 |
| - |
104 |
| -def plot_order_line(order, ax, x_min, x_max, y_min, y_max): |
105 |
| - x = np.zeros(2) |
106 |
| - y = np.zeros(2) |
107 |
| - |
108 |
| - size = 10.0 |
109 |
| - x[0], y[0] = x_max, y_min * size**order * .1 |
110 |
| - x[1], y[1] = 1.0/size*x_max, y_min * .1 |
111 |
| - x *= .5 |
112 |
| - legend = r" $\mathcal{O}(\tau^{"+str(order)+"})$" |
113 |
| - ax.loglog(x,y,'k') |
114 |
| - ax.annotate(legend, xy=(x[0]*1.1, y[0]), horizontalalignment='left', verticalalignment='center') |
115 |
| - return |
116 |
| - |
117 |
| -ax1.grid() |
118 |
| -ax1.set_title(r"error in left domain $\Omega_L$") |
119 |
| -ax1.set_xlabel(r"time step $\tau$") |
120 |
| -ax1.set_ylabel(r"error $\epsilon$") |
121 |
| -x_min, y_min = ax1.dataLim._get_min() |
122 |
| -x_max, y_max = ax1.dataLim._get_max() |
123 |
| -plot_order_line(1, ax1, x_min, x_max, y_min, y_max) |
124 |
| -plot_order_line(2, ax1, x_min, x_max, y_min, y_max) |
125 |
| -plot_order_line(4, ax1, x_min, x_max, y_min, y_max) |
126 |
| - |
127 |
| -if plot_right: |
128 |
| - x_min, y_min = ax2.dataLim._get_min() |
129 |
| - x_max, y_max = ax2.dataLim._get_max() |
130 |
| - plot_order_line(1, ax2, x_min, x_max, y_min, y_max) |
131 |
| - plot_order_line(2, ax2, x_min, x_max, y_min, y_max) |
132 |
| - plot_order_line(4, ax2, x_min, x_max, y_min, y_max) |
133 |
| - |
134 |
| -box = ax1.get_position() |
135 |
| -ax1.set_position([box.x0, box.y0 + box.height * 0.2, |
136 |
| - box.width, box.height * 0.8]) |
137 |
| - |
138 |
| -if plot_right: |
139 |
| - ax2.grid() |
140 |
| - ax2.set_title(r"error in right domain $\Omega_R$") |
141 |
| - ax2.set_xlabel(r"time step $\tau$") |
142 |
| - box = ax2.get_position() |
143 |
| - ax2.set_position([box.x0, box.y0 + box.height * 0.2, |
144 |
| - box.width, box.height * 0.8]) |
145 |
| - |
146 |
| -f.legend(lines, legends, 'lower center',bbox_to_anchor=(0.5, 0.05),prop={'size': 15}) |
147 |
| -f.set_size_inches(6,6) |
148 |
| -plt.subplots_adjust(left=0.15, bottom=0.4, right=0.90, top=0.93, wspace=None, hspace=None) |
149 |
| -plt.savefig(plottingdir + '//' + name+'.pdf') |
150 |
| -np.savetxt(plottingdir + '//data_left.csv', data_left, header=', '.join(data_header),delimiter=',') |
151 |
| -np.savetxt(plottingdir + '//data_right.csv', data_right, header=', '.join(data_header),delimiter=',') |
152 |
| -plt.show() |
| 1 | +import numpy as np |
| 2 | +import argparse |
| 3 | + |
| 4 | +import matplotlib.pyplot as plt |
| 5 | +import itertools |
| 6 | +import json, glob |
| 7 | +from numpy import nan as NAN |
| 8 | + |
| 9 | +parser = argparse.ArgumentParser(description='Postprocessing') |
| 10 | +parser.add_argument('foldername', type=str, help='enter folder with experimental data here') |
| 11 | + |
| 12 | +plt.rc('font', **{'family': 'sans-serif', 'sans-serif': ['lmodern'], 'size' : 15}) |
| 13 | +plt.rc('text', usetex=True) |
| 14 | + |
| 15 | +legends = [] |
| 16 | +lines = [] |
| 17 | +name = parser.parse_args().foldername |
| 18 | +plottingdir = r'./' + name |
| 19 | +filenames = glob.glob(plottingdir+"/*.json") |
| 20 | +print("reading from") |
| 21 | +print(filenames) |
| 22 | + |
| 23 | +marker_collection = ('o','x','d','s','^','<','>','v','.') |
| 24 | + |
| 25 | +marker_left = itertools.cycle(marker_collection) |
| 26 | + |
| 27 | +plot_right = True |
| 28 | +if plot_right: |
| 29 | + marker_right = itertools.cycle(marker_collection) |
| 30 | + |
| 31 | +if plot_right: |
| 32 | + f, (ax1, ax2) = plt.subplots(1, 2, sharey=True, figsize=(12,9)) |
| 33 | +else: |
| 34 | + f, (ax1) = plt.subplots(1, 1, sharey=True, figsize=(12,9)) |
| 35 | + |
| 36 | +data_left = np.empty(shape=(0,0)) |
| 37 | +data_right = np.empty(shape=(0,0)) |
| 38 | +data_header = [] |
| 39 | + |
| 40 | + |
| 41 | +def concat_w_zero_padding(a,b): |
| 42 | + if len(a.shape) > 1 and a.shape[1] == 0: # a has no entries |
| 43 | + return b |
| 44 | + elif len(b.shape) > 1 and b.shape[1] == 0: # b has no entries |
| 45 | + return a |
| 46 | + else: # both arrays have entries |
| 47 | + la = a.shape[0] |
| 48 | + lb = b.shape[0] |
| 49 | + if la < lb: # padding a |
| 50 | + a = np.pad(a, (0, lb-la), 'constant') |
| 51 | + elif la > lb: # padding b |
| 52 | + b = np.pad(b, (0, la-lb), 'constant') |
| 53 | + else: # no padding needed if la = lb |
| 54 | + pass |
| 55 | + return np.c_[a,b] |
| 56 | + |
| 57 | + |
| 58 | +for filename in filenames: |
| 59 | + print("---") |
| 60 | + print(filename) |
| 61 | + with open(filename) as data_file: |
| 62 | + |
| 63 | + data = json.load(data_file) |
| 64 | + taus = np.array(data['temporal_resolution']) |
| 65 | + |
| 66 | + if 'errors_left' in data: |
| 67 | + errors_left = np.array(data['errors_left']) |
| 68 | + errors_left[errors_left > 10.0] = NAN |
| 69 | + #ax1.dataLim._set_x1(taus.max()) |
| 70 | + line = ax1.loglog(taus, errors_left, ':',marker=next(marker_left),markerfacecolor="none",markersize=10,markeredgewidth=2) |
| 71 | + data_left = concat_w_zero_padding(data_left, errors_left) |
| 72 | + elif 'errors' in data: |
| 73 | + errors = np.array(data['errors']) |
| 74 | + errors[errors > 10.0] = NAN |
| 75 | + line = ax1.loglog(taus, errors, marker=next(marker_left),markerfacecolor="none") |
| 76 | + data_left = concat_w_zero_padding(data_left, errors) |
| 77 | + |
| 78 | + if plot_right and 'errors_right' in data: |
| 79 | + errors_right = np.array(data['errors_right']) |
| 80 | + errors_right[errors_right > 10.0] = NAN |
| 81 | + ax2.loglog(taus, errors_right, ':',marker=next(marker_right),markerfacecolor="none",markersize=10,markeredgewidth=2) |
| 82 | + data_right = concat_w_zero_padding(data_right, errors_right) |
| 83 | + elif plot_right and 'errors' in data: |
| 84 | + errors = np.array(data['errors']) |
| 85 | + errors[errors > 10.0] = NAN |
| 86 | + ax2.loglog(taus, errors, marker=next(marker_right)) |
| 87 | + data_right = concat_w_zero_padding(data_right, errors) |
| 88 | + |
| 89 | + if 'neumann coupling scheme' in data['numerical_parameters']: |
| 90 | + legends.append(data['experiment_name']) |
| 91 | + elif 'neumann coupling order' in data['numerical_parameters']: |
| 92 | + legends.append(data['experiment_name']+" - FD order: "+ str(data['numerical_parameters']['neumann coupling order'])) |
| 93 | + else: |
| 94 | + legends.append(data['experiment_name']) |
| 95 | + |
| 96 | + data_header.append(data['experiment_name']) |
| 97 | + |
| 98 | + lines.append(line[0]) |
| 99 | + |
| 100 | +data_left = concat_w_zero_padding(data_left, taus) |
| 101 | +data_right = concat_w_zero_padding(data_right, taus) |
| 102 | +data_header.append('taus') |
| 103 | + |
| 104 | +def plot_order_line(order, ax, x_min, x_max, y_min, y_max): |
| 105 | + x = np.zeros(2) |
| 106 | + y = np.zeros(2) |
| 107 | + |
| 108 | + size = 2.0 |
| 109 | + x[0], y[0] = x_max, y_min * size**order * .1 |
| 110 | + x[1], y[1] = 1.0/size*x_max, y_min * .1 |
| 111 | + x *= .5 |
| 112 | + legend = r" $\mathcal{O}(\tau^{"+str(order)+"})$" |
| 113 | + ax.loglog(x,y,'k') |
| 114 | + ax.annotate(legend, xy=(x[0]*1.1, y[0]), horizontalalignment='left', verticalalignment='center') |
| 115 | + return |
| 116 | + |
| 117 | +ax1.grid() |
| 118 | +ax1.set_title(r"error in left domain $\Omega_L$") |
| 119 | +ax1.set_xlabel(r"time step $\tau$") |
| 120 | +ax1.set_ylabel(r"error $\epsilon$") |
| 121 | +x_min, x_max = ax1.get_xlim() |
| 122 | +y_min, y_max = ax1.get_ylim() |
| 123 | +plot_order_line(1, ax1, x_min, x_max, y_min, y_max) |
| 124 | +plot_order_line(2, ax1, x_min, x_max, y_min, y_max) |
| 125 | +plot_order_line(4, ax1, x_min, x_max, y_min, y_max) |
| 126 | + |
| 127 | +if plot_right: |
| 128 | + x_min, x_max = ax2.get_xlim() |
| 129 | + y_min, y_max = ax2.get_ylim() |
| 130 | + plot_order_line(1, ax2, x_min, x_max, y_min, y_max) |
| 131 | + plot_order_line(2, ax2, x_min, x_max, y_min, y_max) |
| 132 | + plot_order_line(4, ax2, x_min, x_max, y_min, y_max) |
| 133 | + |
| 134 | +box = ax1.get_position() |
| 135 | +ax1.set_position([box.x0, box.y0 + box.height * 0.2, |
| 136 | + box.width, box.height * 0.8]) |
| 137 | + |
| 138 | +if plot_right: |
| 139 | + ax2.grid() |
| 140 | + ax2.set_title(r"error in right domain $\Omega_R$") |
| 141 | + ax2.set_xlabel(r"time step $\tau$") |
| 142 | + box = ax2.get_position() |
| 143 | + ax2.set_position([box.x0, box.y0 + box.height * 0.2, |
| 144 | + box.width, box.height * 0.8]) |
| 145 | + |
| 146 | +f.legend(lines, legends, 'lower center',bbox_to_anchor=(0.5, 0.05),prop={'size': 15}) |
| 147 | +f.set_size_inches(6,6) |
| 148 | +plt.subplots_adjust(left=0.15, bottom=0.4, right=0.90, top=0.93, wspace=None, hspace=None) |
| 149 | +plt.savefig(plottingdir + '//' + name+'.pdf') |
| 150 | +np.savetxt(plottingdir + '//data_left.csv', data_left, header=', '.join(data_header),delimiter=',') |
| 151 | +np.savetxt(plottingdir + '//data_right.csv', data_right, header=', '.join(data_header),delimiter=',') |
| 152 | +plt.show() |
0 commit comments