Skip to content

Commit 97ac301

Browse files
author
davidcorteso
committed
Added docstrings for coordinate conversion functions and simplified compute_norms function from nebm_tools
1 parent e056c57 commit 97ac301

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

fidimag/common/nebm_tools.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,19 @@
55

66
def cartesian2spherical(y_cartesian):
77
"""
8-
y_cartesian :: [y_x0 y_y0 y_z0 y_x1 y_y1 ...]
8+
For a system of P+1 spins, this function takes an image of a NEBM energy
9+
band in Cartesian coordinates (3 * (P + 1) degrees of freedom):
10+
11+
y_cartesian :: [y_x0 y_y0 y_z0 y_x1 y_y1 ... y_zP]
12+
13+
and returns an array in spherical[1] coordinates (2 * (P + 1) degrees of
14+
freedom):
15+
16+
y_spherical :: [ y_theta0 y_phi0 y_theta1 y_phi1 ... y_phiP]
17+
18+
[1]:
19+
theta ranges from 0 to PI (polar angle)
20+
phi ranges from 0 to 2PI (azimuthal angle)
921
"""
1022
theta_phi = np.zeros((len(y_cartesian.reshape(-1, 3)), 2))
1123

@@ -24,6 +36,21 @@ def cartesian2spherical(y_cartesian):
2436

2537

2638
def spherical2cartesian(y_spherical):
39+
"""
40+
For a system of P+1 spins, this function takes an image of a NEBM energy
41+
band in spherical[1] coordinates (2 * (P + 1) degrees of freedom):
42+
43+
y_spherical :: [ y_theta0 y_phi0 y_theta1 y_phi1 ... y_phiP]
44+
45+
and returns and array in Cartesian coordinates (3 * (P + 1) degrees of
46+
freedom):
47+
48+
y_cartesian :: [y_x0 y_y0 y_z0 y_x1 y_y1 ... y_zP]
49+
50+
[1]:
51+
theta ranges from 0 to PI (polar angle)
52+
phi ranges from 0 to 2PI (azimuthal angle)
53+
"""
2754
y_cartesian = np.zeros((len(y_spherical.reshape(-1, 2)), 3))
2855

2956
theta, phi = y_spherical[::2], y_spherical[1::2]
@@ -46,12 +73,10 @@ def compute_norm(A, scale=None):
4673
4774
"""
4875

49-
y = np.copy(A)
76+
y = np.linalg.norm(A)
5077

5178
if scale:
52-
y = np.sqrt(np.sum(y ** 2.)) / len(y)
53-
else:
54-
y = np.sqrt(np.sum(y ** 2.))
79+
y = y / len(y)
5580

5681
return y
5782

0 commit comments

Comments
 (0)