-
Notifications
You must be signed in to change notification settings - Fork 2
/
visualize.py
executable file
·284 lines (237 loc) · 7.19 KB
/
visualize.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#!/usr/bin/env python
import argparse
import logging
from src.observable import Observable
from src.visualization.animate import Animate
from src.visualization.ic_dist import IcDist
from src.visualization.ic_vs_b import IcVsB
from src.visualization.interactive_plot import InteractivePlot
from src.visualization.iv_plot import IvPlot
class Visualize:
def __init__(self):
# Set the current frame and field
self.frame = 0
self.observable = Observable.COMPLEX_FIELD
# Parse command line args
parser = argparse.ArgumentParser(
description='visualize TDGL simulation data'
)
parser.add_argument(
'input',
metavar='INPUT',
type=str, help='data file to visualize'
)
parser.add_argument(
'-v',
'--verbose',
action='store_true',
default=False,
help='run in verbose mode'
)
parser.add_argument(
'-s',
'--silent',
action='store_true',
default=False,
help='run in silent mode'
)
parser.add_argument(
'-a',
'--allow-save',
action='store_true',
default=False,
help='allow saving file'
)
parser.set_defaults(func=self.visualize_tdgl)
subparsers = parser.add_subparsers()
animate_parser = subparsers.add_parser(
'animate',
help='create an animation of '
'the TDGL data'
)
animate_parser.add_argument(
'output',
metavar='OUTPUT',
type=str,
help='output file for animation'
)
animate_parser.add_argument(
'-o',
'--observable',
type=str,
choices=Observable.get_keys(),
default='COMPLEX_FIELD',
help='specify the observable to '
'display in the animation'
)
animate_parser.add_argument(
'-f',
'--fps',
type=int,
default=10,
help='frame rate of the animation'
)
animate_parser.add_argument(
'-d',
'--dpi',
type=float,
default=200,
help='resolution in dots per inch'
)
animate_parser.add_argument(
'-g',
'--gpu',
action='store_true',
default=False,
help='enable NVIDIA GPU acceleration'
)
animate_parser.set_defaults(func=self.animate_tdgl)
iv_parser = subparsers.add_parser('iv', help='plot an IV curve')
iv_parser.add_argument(
'-o',
'--output',
type=str,
default=None,
help='save the IV curve to file'
)
iv_parser.add_argument(
'-m',
'--marker-size',
type=int,
default=None,
help='size 1of the markers in the curve'
)
iv_parser.add_argument(
'-S',
'--save',
type=str,
default=None,
help='specify outfile for saving the data'
)
iv_parser.set_defaults(func=self.iv)
ic_vs_b_parser = subparsers.add_parser(
'ic-vs-b',
help='plot the critical current as a function of the magnetic field'
)
ic_vs_b_parser.add_argument(
'-t',
'--threshold',
type=float,
default=0.01,
help='voltage level to measure the '
'critical current'
)
ic_vs_b_parser.add_argument(
'-o',
'--output',
type=str,
default=None,
help='save the Ic vs B curve to file'
)
ic_vs_b_parser.add_argument(
'-d',
'--data-output',
type=str,
default=None,
help='save Ic vs B data to file'
)
ic_vs_b_parser.set_defaults(func=self.ic_vs_b)
iv_parser.set_defaults(func=self.iv)
ic_dist = subparsers.add_parser(
'ic-dist',
help='plot the critical current distribution'
)
ic_dist.add_argument(
'-t',
'--threshold',
type=float,
default=0.01,
help='voltage level to measure the '
'critical current'
)
ic_dist.add_argument(
'-o',
'--output',
type=str,
default=None,
help='save the Ic vs B curve to file'
)
ic_dist.add_argument(
'-b',
'--bins',
type=int,
default=10,
help='number of bins'
)
ic_dist.add_argument(
'-n',
'--normalized',
action='store_true',
default=False,
help='if the histogram should be normalized to a '
'probability distribution'
)
ic_dist.add_argument(
'-d',
'--data-output',
type=str,
default=None,
help='save Ic vs B data to file'
)
ic_dist.set_defaults(func=self.ic_dist)
# Get arguments
self.args = parser.parse_args()
# Create a logger
self.logger = logging.getLogger('visualize')
console_stream = logging.StreamHandler()
console_stream.setFormatter(
logging.Formatter('%(levelname)s: %(message)s'))
self.logger.addHandler(console_stream)
# Set log level to DEBUG in verbose mode and INFO in non-verbose mode
self.logger.setLevel(
logging.DEBUG if self.args.verbose else logging.INFO)
# Disable logging if silent mode is enabled
self.logger.disabled = self.args.silent
self.args.func()
def visualize_tdgl(self):
InteractivePlot(
input_file=self.args.input,
enable_save=self.args.allow_save,
logger=self.logger
).show()
def animate_tdgl(self):
Animate(
input_file=self.args.input,
output_file=self.args.output,
logger=self.logger,
silent=self.args.silent,
observable=Observable.from_key(self.args.observable),
dpi=self.args.dpi,
fps=self.args.fps,
gpu=self.args.gpu
).build()
def iv(self):
IvPlot(
input_path=self.args.input,
output_file=self.args.output,
save=self.args.save,
logger=self.logger
).show()
def ic_vs_b(self):
IcVsB(
input_path=self.args.input,
output_file=self.args.output,
threshold=self.args.threshold,
data_file=self.args.data_output
).show()
def ic_dist(self):
IcDist(
input_path=self.args.input,
output_file=self.args.output,
threshold=self.args.threshold,
data_file=self.args.data_output,
bins=self.args.bins,
normalized=self.args.normalized
).show()
if __name__ == '__main__':
Visualize()