Coverage for pySDC/projects/AllenCahn_Bayreuth/visualize.py: 0%

22 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-20 14:51 +0000

1import json 

2import glob 

3import numpy as np 

4import matplotlib 

5 

6matplotlib.use('TkAgg') 

7import matplotlib.pyplot as plt 

8 

9 

10def plot_data(name=''): 

11 """ 

12 Visualization using numpy arrays (written via MPI I/O) and json description 

13 

14 Produces one png file per time-step, combine as movie via e.g. 

15 > ffmpeg -i data/name_%08d.png name.mp4 

16 

17 Args: 

18 name (str): name of the simulation (expects data to be in data path) 

19 """ 

20 

21 json_files = sorted(glob.glob(f'./data/{name}_*.json')) 

22 data_files = sorted(glob.glob(f'./data/{name}_*.dat')) 

23 

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) 

27 

28 index = json_file.split('_')[1].split('.')[0] 

29 print(f'Working on step {index}...') 

30 

31 array = np.fromfile(data_file, dtype=obj['datatype']) 

32 array = array.reshape(obj['shape'], order='C') 

33 

34 plt.figure() 

35 

36 plt.imshow(array, vmin=0, vmax=1) 

37 

38 plt.colorbar() 

39 plt.title(f"Time: {obj['time']:6.4f}") 

40 

41 plt.savefig(f'data/{name}_{index}.png', bbox_inches='tight') 

42 plt.close() 

43 

44 

45if __name__ == "__main__": 

46 # name = 'AC-test' 

47 name = 'AC-test-noforce' 

48 # name = 'AC-2D-application' 

49 # name = 'AC-app-timeforce' 

50 

51 plot_data(name=name)