Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
plotMatrix.py
Go to the documentation of this file.
1#!/usr/bin/python3
2
3import sys
4import numpy
5import matplotlib.pyplot as pt
6
7def fibonacci_sphere(ax, num_points, values):
8 ga = (3 - numpy.sqrt(5)) * numpy.pi # golden angle
9
10 # Create a list of golden angle increments along tha range of number of points
11 theta = ga * numpy.arange(num_points)
12
13 # Z is a split into a range of -1 to 1 in order to create a unit circle
14 z = numpy.linspace(1/num_points-1, 1-1/num_points, num_points)
15
16 # a list of the radii at each height step of the unit circle
17 radius = numpy.sqrt(1 - z * z)
18
19 # Determine where xy fall on the sphere, given the azimuthal and polar angles
20 y = radius * numpy.sin(theta)
21 x = radius * numpy.cos(theta)
22
23 # Display points in a scatter plot
24 ax.scatter(x, y, z, s=100, c=values, vmin=-0.1, vmax=0.1, cmap="RdBu")
25 pt.show()
26
27
28
29
30filename = sys.argv[1]
31
32A = numpy.loadtxt(filename)
33
34# Plot matrix
35fig=pt.figure()
36pt.title("Ionosphere solver matrix")
37ax = fig.add_subplot(121)
38ax.matshow(A, cmap="RdBu", vmin=-5, vmax=5)
39for i in range(A.shape[1]):
40 for j in range(A.shape[0]):
41 c = A[j,i]
42 #ax.text(i, j, "%1.1f"%(c), va='center', ha='center', size="2")
43#pt.colorbar()
44
45# Plot inverse matrix
46ax = fig.add_subplot(122)
47try:
48 Ainv = numpy.linalg.inv(A)
49 ax.matshow(Ainv, cmap="RdBu")
50 for i in range(A.shape[1]):
51 for j in range(A.shape[0]):
52 c = Ainv[j,i]
53 #ax.text(i, j, "%1.1f"%(c), va='center', ha='center', size="2")
54except:
55 print("Inversion failed! Matrix singular?")
56
57# Calc eigenvalues
58λ,ev=numpy.linalg.eig(0.5*(A + numpy.transpose(A)))
59
60ev = ev[numpy.argsort(λ)]
61λ = numpy.sort(λ);
62
63print("Eigenvalues: " + str(λ))
64print("Smallest Eigenvector: " + str(ev[0]))
65
66#ax = fig.add_subplot(122, projection='3d')
67#fibonacci_sphere(ax, ev[0].shape[0],ev[0])
68
69#pt.show();
70pt.savefig("matrix.png", dpi=300)
fibonacci_sphere(ax, num_points, values)
Definition plotMatrix.py:7