-
Notifications
You must be signed in to change notification settings - Fork 0
/
XolotlPlot.py
158 lines (127 loc) · 5.65 KB
/
XolotlPlot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import glob
import os.path
import h5py
import numpy as np
import matplotlib.pyplot as plt
filename = '/home/guterlj/simulations/XOLOTL/onlyDtest/supertest/retentionOut.txt'
class classinstancemethod(classmethod):
def __get__(self, instance, type_):
descr_get = super().__get__ if instance is None else self.__func__.__get__
return descr_get(instance, type_)
class XolotlPlot():
def __init__(self, *args, **kwargs):
self.data_files={'retention':'retentionOut.txt', 'surface':'surface.txt'}
self.output = {}
super(XolotlPlot, self).__init__(*args, **kwargs)
@classinstancemethod
def plot_profiles(self, yscale='symlog',xscale='symlog'):
fig = plt.figure()
ax = plt.subplot(111)
data = self.output['profile']
print(self.output['profile']['He'][52])
print(data.keys())
List= [kk for kk in data.keys() if kk!='depth' and kk!='filename']
print(List)
for k in List:
print(k,data[k])
ax.plot(data['depth'], data[k], ls='-', lw=4, marker='.', markersize=10, alpha=0.5, label=k)
## Formatting
ax.set_xlabel("Depth [nm]",fontsize=12)
ax.set_ylabel("Concentration [atoms/nm3]",fontsize=12)
ax.set_yscale(yscale)
ax.set_xscale(xscale)
#plotDist.set_yscale('log')
#plotDist.set_xlim([0.0, 1000.0])
#plotDist.set_ylim([0.0, 0.15])
#plotDist.grid()
ax.legend()
ax.tick_params(axis='both', which='major', labelsize=12)
ax.tick_params(axis='both', which='minor', labelsize=12)
return ax
@classinstancemethod
def plot_retention(self,datatype=['bulk','burst','surface','content','fluxb','fluxs'],kw=None, **kwargs):
if type(datatype) == str: datatype = [datatype]
x,y=get_spdim(len(datatype))
fig ,axes = plt.subplots(x,y)
_axes = axes.flatten()
for i,k in enumerate(datatype):
getattr(self,'plot_{}'.format(k))(kw=kw,ax=_axes[i],**kwargs)
if self.case_path is not None:
fig.suptitle(self.case_path, fontsize=14)
@classinstancemethod
def _plot_vs_fluence(self, contents, ax,kw=None ):
if kw is None:
kw = contents
else:
if type(kw)== str:
kw = [kw]
assert type(kw) == list
assert all([k in contents for k in kw])
data = self.output['retention']
if data.get('time') is not None:
x = data.get('time')
xaxis_str= 'time [s]'
else:
x = data.get('fluence')
xaxis_str= 'fluence [nm^{-2}]'
for k in contents:
try:
ax.plot(x, data[k], ls='-', lw=4, marker='.', markersize=10, alpha=0.5, label=k)
except:
print('cannot plot retention:{}'.format(k))
ax.set_xlabel(xaxis_str)
@classinstancemethod
def _plot_retention_data(self, datatype, kw=None, ax=None, yscale='linear' ,xscale='linear',units='',species = ['Helium', 'Deuterium', 'Vacancy', 'Interstitial']):
contents =['{}_{}'.format(k,datatype) for k in species if not (k in ['Vacancy','Interstitial'] and datatype=='burst')]
if ax is None:
fig,_ax = plt.subplots(1)
else:
_ax = ax
self._plot_vs_fluence(contents, _ax, kw)
@classinstancemethod
def _plot_retention_data(self, datatype,kw=None, ax=None, yscale='linear' ,xscale='linear',units='', species = ['Helium', 'Deuterium', 'Vacancy', 'Interstitial'],):
contents =['{}_{}'.format(k,datatype) for k in species if not (k in ['Vacancy','Interstitial'] and datatype=='burst')]
if ax is None:
fig,_ax = plt.subplots(1)
else:
_ax = ax
self._plot_vs_fluence(contents, _ax, kw)
## Formatting
_ax.set_ylabel('{} [{}]'.format(datatype,units))
_ax.set_yscale(yscale)
_ax.set_xscale(xscale)
#plotDist.set_yscale('log')
#plotDist.set_xlim([0.0, 1000.0])
#plotDist.set_ylim([0.0, 0.15])
#plotDist.grid()
_ax.legend()
#ax.tick_params(axis='both', which='major', labelsize=25)
#ax.tick_params(axis='both', which='minor', labelsize=25)
setattr(self,'ax_{}'.format(datatype),_ax)
@classinstancemethod
def plot_bulk(self, kw=None, ax=None, **kwargs):
self._plot_retention_data('bulk', kw, ax, **kwargs)
@classinstancemethod
def plot_burst(self, kw=None, ax=None, **kwargs):
self._plot_retention_data('burst', kw, ax, **kwargs)
@classinstancemethod
def plot_surface(self, kw=None, ax=None, **kwargs):
self._plot_retention_data('surface', kw, ax, **kwargs)
@classinstancemethod
def plot_content(self, kw=None, ax=None, **kwargs):
self._plot_retention_data('content', kw, ax, **kwargs)
@classinstancemethod
def plot_fluxb(self, kw=None, ax=None, **kwargs):
self._plot_retention_data('fluxb', kw, ax, **kwargs)
@classinstancemethod
def plot_fluxs(self, kw=None, ax=None, **kwargs):
self._plot_retention_data('fluxs', kw, ax, **kwargs)
@classinstancemethod
def plot_influx(self, kw=None, ax=None, **kwargs):
if ax is None:
ax = plt.gca()
ax.plot(self.output['influx'][:,0],self.output['influx'][:,1], label='influx')
def get_spdim(nplots):
cols = int(np.ceil(np.sqrt(nplots)))
rows = int(np.ceil(nplots / cols))
return rows,cols