From d373e0cdacde289c87fceb4cd94257a04afdd985 Mon Sep 17 00:00:00 2001 From: podlesny <podlesny@zedat.fu-berlin.de> Date: Thu, 25 Mar 2021 15:18:30 +0100 Subject: [PATCH] change units display in plots, add spatial slip event visualization --- data/tools/main.py | 6 ++-- data/tools/support/friction_stats.py | 4 +-- data/tools/support/iterations.py | 2 +- data/tools/support/slip_rates.py | 48 ++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 data/tools/support/slip_rates.py diff --git a/data/tools/main.py b/data/tools/main.py index a3f8c770..1ba1c049 100644 --- a/data/tools/main.py +++ b/data/tools/main.py @@ -21,6 +21,7 @@ from support.io import read_h5file from support.iterations import iterations from support.friction_stats import friction_stats +from support.slip_rates import slip_rates def build_patch(coords, percentage): x_coords = coords[:, 0] @@ -53,7 +54,7 @@ params = { h5file = read_h5file() print(list(h5file.keys())) -interval = [0.75*FINAL_TIME, FINAL_TIME] +interval = [10, 13] #[0.75*FINAL_TIME, FINAL_TIME] iterations(h5file, FINAL_TIME, interval) @@ -67,7 +68,8 @@ for body_ID in range(NBODIES): patch = build_patch(coords, 1.0) friction_stats(h5file, body_ID, FINAL_TIME, patch, interval) - + slip_rates(h5file, body_ID, FINAL_TIME, patch, interval, 0) + plt.show() h5file.close() \ No newline at end of file diff --git a/data/tools/support/friction_stats.py b/data/tools/support/friction_stats.py index 9651d299..8495a073 100644 --- a/data/tools/support/friction_stats.py +++ b/data/tools/support/friction_stats.py @@ -31,7 +31,7 @@ def friction_stats(h5file, body_ID, FINAL_TIME, patch=[], interval=[], TANGENTIA #ax_slip.plot(time, min_v, color='gray', linestyle='--') ax_slip.plot(time, avg_v, color='black', linestyle='-') #ax_slip.plot(time, max_v, color='gray', linestyle='--') - ax_slip.set_ylabel('slip rate V') + ax_slip.set_ylabel('slip rate V [m/s]') ax_slip.set_yscale('log') ax_slip.set_ylim([1e-6,1e-2]) #------------------------- @@ -54,7 +54,7 @@ def friction_stats(h5file, body_ID, FINAL_TIME, patch=[], interval=[], TANGENTIA ax_state.plot(time, avg_states, color='black', linestyle='-') #ax_state.plot(time, max_states, color='gray', linestyle='--') ax_state.set_ylabel('state') - ax_state.set_xlabel('time in s') + ax_state.set_xlabel('time [s]') #------------------------- # friction coefficient diff --git a/data/tools/support/iterations.py b/data/tools/support/iterations.py index 08279780..1e231bb9 100644 --- a/data/tools/support/iterations.py +++ b/data/tools/support/iterations.py @@ -35,7 +35,7 @@ def iterations(h5file, FINAL_TIME, interval = []): ax_mg = fig.add_subplot(2, 1, 2) ax_mg.plot(time, multigrid_final[t], color='black', linestyle='-') ax_mg.set_ylabel('multigrid iter.') - ax_mg.set_xlabel('time in s') + ax_mg.set_xlabel('time [s]') #------------------------- #ax_tau = fig.add_subplot(3, 1, 3) diff --git a/data/tools/support/slip_rates.py b/data/tools/support/slip_rates.py new file mode 100644 index 00000000..d122199d --- /dev/null +++ b/data/tools/support/slip_rates.py @@ -0,0 +1,48 @@ +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.cm as cm + +TANGENTIAL_COORDS = 1 + +def local_to_global(coords, SORT_COORD=0): + return coords[:, SORT_COORD].argsort() + +def slip_rates(h5file, body_ID, FINAL_TIME, patch=[], interval=[], SORT_COORD=0): + body = 'body' + str(body_ID) # 'frictionalBoundary' 'body' + str(body_ID) + + coords = np.array(h5file[body + '/coordinates']) + if len(patch) == 0: + patch = np.linspace(0, len(coords)-1, len(coords), endpoint=True, dtype='int8') + + # local to global + local_global = local_to_global(coords, SORT_COORD) + local_global = local_global[patch] + + patch_size = coords[local_global[-1], SORT_COORD] - coords[local_global[0], SORT_COORD] + + # read time + time = np.array(h5file['relativeTime']) * FINAL_TIME + time = np.delete(time, 0) + if len(interval) == 0: + interval = [0, FINAL_TIME] + t = [i for i in range(len(time)) if time[i]>=interval[0] and time[i]<=interval[1]] + time = time[t] + + fig = plt.figure() + + # velocity data + v = abs(np.array(h5file[body + '/velocity'])) + v_t = v[t,:,TANGENTIAL_COORDS] + v_tx = v_t[:,local_global] + + # plot + ax_slip = fig.add_subplot(1, 1, 1) + ax_slip.imshow(v_tx, interpolation='nearest', cmap=cm.Greys_r, aspect='auto', origin='lower', extent=[0, patch_size, time[0], time[-1]]) + #ax_slip.set_ylim([time[-1], time[0]]) + ax_slip.set_ylabel('time [s]') + ax_slip.set_xlabel('horizontal coordinate [m]') + #ax_slip.set_yscale('log') + # ax_slip.set_ylim([1e-6,1e-2]) + #------------------------- + + fig.canvas.draw() \ No newline at end of file -- GitLab