Newer
Older
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
# -*- coding: utf-8 -*-
"""Load magnetization data from LLG files."""
import numpy as np
class MagData:
'''An object storing magnetization data loaded from a LLG-file.'''
def __init__(self, x_mag, y_mag, z_mag, res): # TODO: electrostatic component!
'''Load magnetization in LLG-file format.
Arguments:
filename - the name of the file where the data are stored
Returns:
None
'''
assert np.shape(x_mag) == np.shape(y_mag) == np.shape(z_mag), 'Dimensions do not match!'
self.res = res
self.dim = np.shape(x_mag)
scale = 1.0E-9 / 1.0E-2 #from cm to nm
data = np.genfromtxt(filename, skip_header=2)
x_dim, y_dim, z_dim = np.genfromtxt(filename, dtype=int,
skip_header=1,
skip_footer=len(data[:, 0]))
res = (data[1, 0] - data[0, 0]) / scale
x_len, y_len, z_len = [data[-1, i]/scale+res/2 for i in range(3)]
x_mag, y_mag, z_mag = [data[:, i].reshape(z_dim, y_dim, x_dim)
for i in range(3,6)]
#Reshape in Python and Igor is different,
#Python fills rows first, Igor columns!
self.filename = filename
self.res = res
self.dim = (z_dim, y_dim, x_dim)
self.length = (z_len, y_len, x_len)
self.magnitude = (z_mag, y_mag, x_mag)
def __str__(self):
'''Return the filename of the loaded file.
Arguments:
None
Returns:
the name of the loaded file as a string
'''
return self.filename