-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplots.py
65 lines (54 loc) · 1.05 KB
/
plots.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
"""
Lazy Python interface to make plots of JONSWAP spectrum and timeserie.
"""
import numpy
import subprocess
import matplotlib.pyplot as plt
Hs = 4.5
Tp = 10
duration = 300
# Timeserie
result = subprocess.run(
[
'./jonswap',
str(Hs),
str(Tp),
'-d', str(duration),
'-h'
],
stdout=subprocess.PIPE
)
data = numpy.loadtxt(
result.stdout.decode('utf-8').split('\n'),
skiprows=4
)
time, elev = data.transpose()
plt.close()
plt.plot(time, elev)
plt.grid()
plt.title(f'JONSWAP Hs {Hs} Tp {Tp}')
plt.xlabel('Time [s]')
plt.ylabel('Elevation [m]')
plt.savefig('timeserie.png')
plt.close()
# Spectrum
result = subprocess.run(
[
'./jonswap',
str(Hs),
str(Tp)
],
stdout=subprocess.PIPE
)
data = numpy.loadtxt(
result.stdout.decode('utf-8').split('\n'),
skiprows=5
)
T, w, PM, JS, amp, phi = data.transpose()
plt.plot(T, JS)
plt.grid()
plt.title(f'JONSWAP Hs {Hs} Tp {Tp}')
plt.xlabel('Period [s]')
plt.ylabel('Energy [m2s/rd]')
plt.savefig('spectrum.png')
plt.close()