forked from caiostringari/swantools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
102 lines (71 loc) · 2.68 KB
/
test.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import swantools.io
import swantools.utils
import swantools.plot
import datetime
import matplotlib.pyplot as plt
import numpy as np
def readtable():
R = swantools.io.SwanIO()
P = swantools.plot.SwanPlot()
# Reading TABLE dada with headers:
df = R.read_swantable('data/table.txt')
y = df["Hsig"]
x = df.index.values
P.timeseries(x,y,"Significant Wave Heights")
def readspc():
# Reading spectral data
R = swantools.io.SwanIO()
lat,lon,freqs,dirs,times,factors,spectrum = R.read_swanspc('data/spectrum.spc')
P = swantools.plot.SwanPlot()
P.spcplot(freqs,dirs,times[15],spectrum[15,:,:]*factors[15])
# for t, time in enumerate(times):
# P.spcplot(freqs,dirs,times[t],spectrum[t,:,:])
def readblock(mode):
R = swantools.io.SwanIO()
P = swantools.plot.SwanPlot()
if mode == "non-stat":
# Reading a block file - Non stationary example
lon,lat,times,hs = R.read_swanblock('data/block.mat','Hsig')
P.blockplot(lon,lat,hs[0,:,:],"Non-stationary Results")
# for t, time in enumerate(times):
# P.blockplot(lon,lat,hs[t,:,:],time.strftime("%Y%m%d %H:%M"))
elif mode == "stat":
# Reading a block file - Non stationary example
lon,lat,times,hs = R.read_swanblock('data/stat_block.mat','Hsig',stat=True)
P.blockplot(lon,lat,hs,"Stationary Results")
def writescp():
# Getting some data to play with
R = swantools.io.SwanIO()
lat,lon,freqs,dirs,times,factors,spectrum = R.read_swanspc('data/spectrum.spc')
# Re-writing the data
R.write_spectrum("spcout.spc",lat,lon,times,freqs,dirs,factors,spectrum)
# Plot to confirm
lat,lon,freqs,dirs,times,factors,spectrum = R.read_swanspc('spcout.spc')
P = swantools.plot.SwanPlot()
for t, time in enumerate(times):
P.spcplot(freqs,dirs,times[t],spectrum[t,:,:])
def netcdf_output():
R = swantools.io.SwanIO()
W = swantools.io.Converters()
lon,lat,times,hs = R.read_swanblock('data/block.mat','Hsig')
W.np2nc("Hsig.nc",lat,lon,times,hs,"Significant Wave Height")
def spectral_output():
R = swantools.io.SwanIO()
W = swantools.io.Converters()
lon,lat,freqs,dirs,times,factors,spectrum = R.read_swanspc('data/spectrum.spc')
W.spc2nc("spectrum.nc",lat,lon,freqs,dirs,times,factors,spectrum)
if __name__ == "__main__":
# # Table data
# import seaborn as sns
# with sns.axes_style("darkgrid"):
# readtable()
# Spectral data
readspc()
# Field data
readblock("non-stat")
# Convertung block to netCDF4
netcdf_output()
# Converting spctral file to netCDF4
spectral_output()
# Wrinting spctral data
writescp()