Coverage for pySDC/projects/AllenCahn_Bayreuth/visualize.py: 0%
22 statements
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-16 14:51 +0000
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-16 14:51 +0000
1import json
2import glob
3import numpy as np
4import matplotlib
6matplotlib.use('TkAgg')
7import matplotlib.pyplot as plt
10def plot_data(name=''):
11 """
12 Visualization using numpy arrays (written via MPI I/O) and json description
14 Produces one png file per time-step, combine as movie via e.g.
15 > ffmpeg -i data/name_%08d.png name.mp4
17 Args:
18 name (str): name of the simulation (expects data to be in data path)
19 """
21 json_files = sorted(glob.glob(f'./data/{name}_*.json'))
22 data_files = sorted(glob.glob(f'./data/{name}_*.dat'))
24 for json_file, data_file in zip(json_files, data_files):
25 with open(json_file, 'r') as fp:
26 obj = json.load(fp)
28 index = json_file.split('_')[1].split('.')[0]
29 print(f'Working on step {index}...')
31 array = np.fromfile(data_file, dtype=obj['datatype'])
32 array = array.reshape(obj['shape'], order='C')
34 plt.figure()
36 plt.imshow(array, vmin=0, vmax=1)
38 plt.colorbar()
39 plt.title(f"Time: {obj['time']:6.4f}")
41 plt.savefig(f'data/{name}_{index}.png', bbox_inches='tight')
42 plt.close()
45if __name__ == "__main__":
46 # name = 'AC-test'
47 name = 'AC-test-noforce'
48 # name = 'AC-2D-application'
49 # name = 'AC-app-timeforce'
51 plot_data(name=name)