Bläddra i källkod

Kernel plotting routines

tags/1.6.1
Trevor Irons 5 år sedan
förälder
incheckning
d95f9758b0
2 ändrade filer med 120 tillägg och 0 borttagningar
  1. 62
    0
      akvo/terminal/plotKernel.py
  2. 58
    0
      akvo/terminal/plotKernelDiff.py

+ 62
- 0
akvo/terminal/plotKernel.py Visa fil

@@ -0,0 +1,62 @@
1
+import matplotlib.pyplot as plt
2
+import sys,os
3
+from pylab import meshgrid
4
+from matplotlib.colors import LightSource
5
+from matplotlib.ticker import ScalarFormatter
6
+from matplotlib.ticker import MaxNLocator
7
+from matplotlib.ticker import AutoMinorLocator
8
+from matplotlib.ticker import LogLocator
9
+from matplotlib.ticker import FormatStrFormatter
10
+import numpy as np
11
+import yaml
12
+from  lemma_yaml import *
13
+
14
+import cmocean 
15
+
16
+def catLayers(K0):
17
+    K = np.zeros( (len(K0.keys()), len(K0["layer-0"].data)) , dtype=complex )
18
+    for lay in range(len(K0.keys())):
19
+        #print(K0["layer-"+str(lay)].data) #    print (lay)
20
+        K[lay] = K0["layer-"+str(lay)].data #    print (lay)
21
+    return K
22
+if __name__ == "__main__":
23
+
24
+    with open(sys.argv[1]) as f:
25
+        # use safe_load instead load
26
+        K0 = yaml.load(f, Loader=yaml.Loader)
27
+
28
+    K = 1e9*catLayers(K0.K0)
29
+    q = np.array(K0.PulseI.data)* (float)(K0.Taup)
30
+
31
+    #plt.pcolor(K0.Interfaces.data, K0.PulseI.data, np.abs(K))
32
+    #plt.pcolor(q, K0.Interfaces.data, np.abs(K), cmap=cmocean.cm.gray_r)
33
+    #plt.contourf(q, K0.Interfaces.data[0:-1], np.abs(K), cmap=cmocean.cm.tempo)
34
+    plt.pcolor(q, K0.Interfaces.data, np.abs(K), cmap=cmocean.cm.tempo)
35
+    plt.colorbar()
36
+
37
+    ax1 = plt.gca()
38
+    ax1.set_ylim( ax1.get_ylim()[1], ax1.get_ylim()[0]  )
39
+    #ax1.set_xscale('log')
40
+    #ax1.set_yscale('log')
41
+    #ax1.xaxis.set_major_formatter(ScalarFormatter())
42
+    ax1.set_xticks([ax1.get_xlim()[0], 1, ax1.get_xlim()[1],])
43
+    ax1.xaxis.set_major_formatter(FormatStrFormatter('%.1f'))
44
+    #print(yaml.dump(K0.K0))
45
+    #print( K0.K0["layer-0"].data )
46
+    #print( type(  np.array(K0.K0["layer-0"].data) ) )
47
+    #plt.plot( np.real( K0.K0["layer-0"].data ) )
48
+    #plt.plot( K0.K0["layer-0"].data )
49
+    plt.gca().set_xlabel("q (A $\cdot$ s)")
50
+    plt.gca().set_ylabel("depth (m)")
51
+    plt.savefig("kernel.pdf")
52
+
53
+    sound = np.sum(K, axis=0)
54
+    plt.figure()
55
+    plt.plot(q, np.abs(sound))
56
+
57
+    
58
+
59
+    plt.savefig("sound.pdf")
60
+
61
+    plt.show()
62
+    #print(yaml.dump(K0))

+ 58
- 0
akvo/terminal/plotKernelDiff.py Visa fil

@@ -0,0 +1,58 @@
1
+import matplotlib.pyplot as plt
2
+import sys,os
3
+from pylab import meshgrid
4
+from matplotlib.colors import LightSource
5
+from matplotlib.ticker import ScalarFormatter
6
+from matplotlib.ticker import MaxNLocator
7
+from matplotlib.ticker import AutoMinorLocator
8
+from matplotlib.ticker import LogLocator
9
+from matplotlib.ticker import FormatStrFormatter
10
+import numpy as np
11
+import yaml
12
+from  lemma_yaml import *
13
+
14
+import cmocean 
15
+
16
+def catLayers(K0):
17
+    K = np.zeros( (len(K0.keys()), len(K0["layer-0"].data)) , dtype=complex )
18
+    for lay in range(len(K0.keys())):
19
+        #print(K0["layer-"+str(lay)].data) #    print (lay)
20
+        K[lay] = K0["layer-"+str(lay)].data #    print (lay)
21
+    return K
22
+
23
+if __name__ == "__main__":
24
+
25
+    with open(sys.argv[1]) as f:
26
+        # use safe_load instead load
27
+        K0 = yaml.load(f, Loader=yaml.Loader)
28
+    
29
+    with open(sys.argv[2]) as f2:
30
+        # use safe_load instead load
31
+        K02 = yaml.load(f2, Loader=yaml.Loader)
32
+
33
+    K = 1e9*catLayers(K0.K0)
34
+    K2 = 1e9*catLayers(K02.K0)
35
+    
36
+    q = np.array(K0.PulseI.data)* (float)(K0.Taup)
37
+
38
+    #plt.pcolor(K0.Interfaces.data, K0.PulseI.data, np.abs(K))
39
+    plt.pcolor(q, K0.Interfaces.data, np.abs(K), cmap=cmocean.cm.gray_r)
40
+    #plt.contourf(q, K0.Interfaces.data[0:-1], np.abs(K), cmap=cmocean.cm.tempo)
41
+    #plt.pcolor(q, K0.Interfaces.data, np.abs(K), cmap=cmocean.cm.tempo)
42
+    
43
+    plt.pcolor(q, K0.Interfaces.data, np.abs(K - K2), cmap=cmocean.cm.gray_r)
44
+    plt.colorbar()
45
+
46
+    ax1 = plt.gca()
47
+    ax1.set_ylim( ax1.get_ylim()[1], ax1.get_ylim()[0]  )
48
+    #ax1.set_xscale('log')
49
+    #ax1.xaxis.set_major_formatter(ScalarFormatter())
50
+    ax1.set_xticks([ax1.get_xlim()[0], 1, ax1.get_xlim()[1],])
51
+    ax1.xaxis.set_major_formatter(FormatStrFormatter('%.1f'))
52
+    #print(yaml.dump(K0.K0))
53
+    #print( K0.K0["layer-0"].data )
54
+    #print( type(  np.array(K0.K0["layer-0"].data) ) )
55
+    #plt.plot( np.real( K0.K0["layer-0"].data ) )
56
+    #plt.plot( K0.K0["layer-0"].data )
57
+    plt.show()
58
+    #print(yaml.dump(K0))

Laddar…
Avbryt
Spara