Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
WindEnergyToolbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wtlib
WindEnergyToolbox
Commits
6cae8857
Commit
6cae8857
authored
7 years ago
by
Mads M. Pedersen
Browse files
Options
Downloads
Patches
Plain Diff
Revert "updates in wetb.wind.turbulence"
This reverts commit
43fc8cd9
.
parent
43fc8cd9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+0
-1
0 additions, 1 deletion
.gitignore
wetb/wind/turbulence/mann_parameters.py
+13
-27
13 additions, 27 deletions
wetb/wind/turbulence/mann_parameters.py
wetb/wind/turbulence/spectra.py
+84
-25
84 additions, 25 deletions
wetb/wind/turbulence/spectra.py
with
97 additions
and
53 deletions
.gitignore
+
0
−
1
View file @
6cae8857
...
@@ -22,4 +22,3 @@ wetb/prepost/tests/data/demo_dlc/remote*
...
@@ -22,4 +22,3 @@ wetb/prepost/tests/data/demo_dlc/remote*
/wetb/fatigue_tools/rainflowcounting/compile.py
/wetb/fatigue_tools/rainflowcounting/compile.py
/docs/api
/docs/api
/htmlcov
/htmlcov
/wetb/wind/tests/test_mann_parameters.py
This diff is collapsed.
Click to expand it.
wetb/wind/turbulence/mann_parameters.py
+
13
−
27
View file @
6cae8857
...
@@ -11,7 +11,8 @@ from scipy.interpolate import RectBivariateSpline
...
@@ -11,7 +11,8 @@ from scipy.interpolate import RectBivariateSpline
import
numpy
as
np
import
numpy
as
np
from
wetb.wind.turbulence.spectra
import
spectra
,
logbin_spectra
,
\
from
wetb.wind.turbulence.spectra
import
spectra
,
logbin_spectra
,
\
plot_spectrum
plot_spectrum
,
plot_spectra
from
wetb.utils.test_files
import
move2test_files
...
@@ -24,12 +25,7 @@ RBS2 = RectBivariateSpline(xp, yp, sp2)
...
@@ -24,12 +25,7 @@ RBS2 = RectBivariateSpline(xp, yp, sp2)
RBS3
=
RectBivariateSpline
(
xp
,
yp
,
sp3
)
RBS3
=
RectBivariateSpline
(
xp
,
yp
,
sp3
)
RBS4
=
RectBivariateSpline
(
xp
,
yp
,
sp4
)
RBS4
=
RectBivariateSpline
(
xp
,
yp
,
sp4
)
def
estimate_mann_parameters
(
sf
,
u
,
v
,
w
=
None
):
if
isinstance
(
u
,
(
list
,
tuple
)):
#return fit_mann_model_spectra(*mean_spectra(sf, u, v, w))
raise
NotImplementedError
else
:
return
fit_mann_model_spectra
(
*
spectra
(
sf
,
u
,
v
,
w
))
#def mean_spectra(fs, u_ref_lst, u_lst, v_lst=None, w_lst=None):
#def mean_spectra(fs, u_ref_lst, u_lst, v_lst=None, w_lst=None):
# if isinstance(fs, (int, float)):
# if isinstance(fs, (int, float)):
...
@@ -145,11 +141,13 @@ def fit_mann_model_spectra(k1, uu, vv=None, ww=None, uw=None, log10_bin_size=.2,
...
@@ -145,11 +141,13 @@ def fit_mann_model_spectra(k1, uu, vv=None, ww=None, uw=None, log10_bin_size=.2,
from
scipy.optimize
import
fmin
from
scipy.optimize
import
fmin
x
=
fmin
(
_local_error
,
start_vals_for_optimisation
,
logbin_spectra
(
k1
,
uu
,
vv
,
ww
,
uw
,
log10_bin_size
,
min_bin_count
),
disp
=
False
)
x
=
fmin
(
_local_error
,
start_vals_for_optimisation
,
logbin_spectra
(
k1
,
uu
,
vv
,
ww
,
uw
,
log10_bin_size
,
min_bin_count
),
disp
=
False
)
if
plt
is
not
False
:
if
plt
:
if
not
hasattr
(
plt
,
'
plot
'
):
if
not
hasattr
(
plt
,
'
plot
'
):
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
plt
_plot_spectra
(
k1
,
uu
,
vv
,
ww
,
uw
,
plt
=
plt
)
# plot_spectra(k1, uu, vv, ww, uw, plt=plt)
plot_mann_spectra
(
*
x
,
plt
=
plt
)
# plot_mann_spectra(*x, plt=plt)
ae
,
L
,
G
=
x
plot_fit
(
ae
,
L
,
G
,
k1
,
uu
,
vv
,
ww
,
uw
,
log10_bin_size
=
log10_bin_size
,
plt
=
plt
)
plt
.
title
(
'
ae:%.3f, L:%.1f, G:%.2f
'
%
tuple
(
x
))
plt
.
title
(
'
ae:%.3f, L:%.1f, G:%.2f
'
%
tuple
(
x
))
plt
.
xlabel
(
'
Wavenumber $k_{1}$ [$m^{-1}$]
'
)
plt
.
xlabel
(
'
Wavenumber $k_{1}$ [$m^{-1}$]
'
)
plt
.
ylabel
(
r
'
Spectral density $k_{1} F(k_{1})/U^{2} [m^2/s^2]$
'
)
plt
.
ylabel
(
r
'
Spectral density $k_{1} F(k_{1})/U^{2} [m^2/s^2]$
'
)
...
@@ -254,26 +252,13 @@ def fit_ae(sf, u, L, G, min_bin_count=None, plt=False):
...
@@ -254,26 +252,13 @@ def fit_ae(sf, u, L, G, min_bin_count=None, plt=False):
return
ae
return
ae
def
plot_
spectra
(
ae
,
L
,
G
,
k1
,
uu
,
vv
=
None
,
ww
=
None
,
uw
=
None
,
mean_u
=
1
,
log10_bin_size
=
.
2
,
plt
=
None
):
def
plot_
fit
(
ae
,
L
,
G
,
k1
,
uu
,
vv
=
None
,
ww
=
None
,
uw
=
None
,
mean_u
=
1
,
log10_bin_size
=
.
2
,
plt
=
None
):
# if plt is None:
# if plt is None:
# import matplotlib.pyplot as plt
# import matplotlib.pyplot as plt
_
plot_spectra
(
k1
,
uu
,
vv
,
ww
,
uw
,
mean_u
,
log10_bin_size
,
plt
)
plot_spectra
(
k1
,
uu
,
vv
,
ww
,
uw
,
mean_u
,
log10_bin_size
,
plt
)
plot_mann_spectra
(
ae
,
L
,
G
,
"
-
"
,
mean_u
,
plt
)
plot_mann_spectra
(
ae
,
L
,
G
,
"
-
"
,
mean_u
,
plt
)
def
_plot_spectra
(
k1
,
uu
,
vv
=
None
,
ww
=
None
,
uw
=
None
,
mean_u
=
1
,
log10_bin_size
=
.
2
,
plt
=
None
):
if
plt
is
None
:
import
matplotlib.pyplot
as
plt
bk1
,
buu
,
bvv
,
bww
,
buw
=
logbin_spectra
(
k1
,
uu
,
vv
,
ww
,
uw
,
log10_bin_size
)
def
plot
(
xx
,
label
,
color
,
plt
):
plt
.
semilogx
(
bk1
,
bk1
*
xx
*
10
**
0
/
mean_u
**
2
,
'
.
'
+
color
,
label
=
label
)
plot
(
buu
,
'
uu
'
,
'
r
'
,
plt
)
plt
.
xlabel
(
'
Wavenumber $k_{1}$ [$m^{-1}$]
'
)
plt
.
ylabel
(
r
'
Spectral density $k_{1} F(k_{1})/U^{2} [m^2/s^2]$
'
)
if
(
bvv
)
is
not
None
:
plot
(
bvv
,
'
vv
'
,
'
g
'
,
plt
)
if
bww
is
not
None
:
plot
(
bww
,
'
ww
'
,
'
b
'
,
plt
)
plot
(
buw
,
'
uw
'
,
'
m
'
,
plt
)
def
plot_mann_spectra
(
ae
,
L
,
G
,
style
=
'
-
'
,
u_ref
=
1
,
plt
=
None
,
spectra
=
[
'
uu
'
,
'
vv
'
,
'
ww
'
,
'
uw
'
]):
def
plot_mann_spectra
(
ae
,
L
,
G
,
style
=
'
-
'
,
u_ref
=
1
,
plt
=
None
,
spectra
=
[
'
uu
'
,
'
vv
'
,
'
ww
'
,
'
uw
'
]):
if
plt
is
None
:
if
plt
is
None
:
...
@@ -312,7 +297,8 @@ if __name__ == "__main__":
...
@@ -312,7 +297,8 @@ if __name__ == "__main__":
nx
=
8192
nx
=
8192
ny
,
nz
=
8
,
8
ny
,
nz
=
8
,
8
sf
=
(
nx
/
l
)
sf
=
(
nx
/
l
)
fn
=
os
.
path
.
dirname
(
wind
.
__file__
)
+
"
/tests/test_files/turb/h2a8192_8_8_16384_32_32_0.15_10_3.3%s.dat
"
#fn = os.path.dirname(wind.__file__)+"/tests/test_files/turb/h2a8192_8_8_16384_32_32_0.15_10_3.3%s.dat"
#fn = os.path.dirname(wind.__file__)+"/tests/test_files/turb/h2a8192_8_8_16384_32_32_0.15_10_3.3%s.dat"
u
,
v
,
w
=
[
np
.
fromfile
(
fn
%
uvw
,
np
.
dtype
(
'
<f
'
),
-
1
).
reshape
(
nx
,
ny
*
nz
)
for
uvw
in
[
'
u
'
,
'
v
'
,
'
w
'
]]
u
,
v
,
w
=
[
np
.
fromfile
(
fn
%
uvw
,
np
.
dtype
(
'
<f
'
),
-
1
).
reshape
(
nx
,
ny
*
nz
)
for
uvw
in
[
'
u
'
,
'
v
'
,
'
w
'
]]
ae
,
L
,
G
=
fit_mann_model_spectra
(
*
spectra
(
sf
,
u
,
v
,
w
),
plt
=
plt
)
ae
,
L
,
G
=
fit_mann_model_spectra
(
*
spectra
(
sf
,
u
,
v
,
w
),
plt
=
plt
)
print
(
ae
,
L
,
G
)
print
(
ae
,
L
,
G
)
This diff is collapsed.
Click to expand it.
wetb/wind/turbulence/spectra.py
+
84
−
25
View file @
6cae8857
...
@@ -35,20 +35,21 @@ def spectrum(x, y=None, k=1):
...
@@ -35,20 +35,21 @@ def spectrum(x, y=None, k=1):
fftx
=
fftx
[:
len
(
fftx
)
//
2
]
*
2
# positive half * 2
fftx
=
fftx
[:
len
(
fftx
)
//
2
]
*
2
# positive half * 2
if
len
(
fftx
.
shape
)
==
2
:
#
if len(fftx.shape) == 2:
fftx
=
np
.
mean
(
fftx
,
1
)
#
fftx = np.mean(fftx, 1)
return
np
.
real
(
fftx
*
len
(
x
)
/
(
2
*
k
))[
1
:]
return
np
.
real
(
fftx
*
len
(
x
)
/
(
2
*
k
))[
1
:]
def
spectra
(
spa
c
ial_
frq
,
u
,
v
=
None
,
w
=
None
,
detrend
=
True
):
def
spectra
(
spa
t
ial_
resolution
,
u
,
v
=
None
,
w
=
None
,
detrend
=
True
):
"""
Return the wave number, the uu, vv, ww autospectra and the uw cross spectra
"""
Return the wave number, the uu, vv, ww autospectra and the uw cross spectra
Parameters
Parameters
----------
----------
spacial_frq : inf or float
spatial_resolution : int, float or array_like
- For time series: Sample frequency, see Notes
\n
Distance between samples in meters
- For turbulence boxes: 1/dx where
- For turbulence boxes: 1/dx = Lx/Nx where dx is distance between points,
dx is nx/Lx (number of grid points in length direction / box length in meters)
Nx is number of points and Lx is box length in meters
- For time series: Sample frequency / U
u : array_like
u : array_like
The u-wind component
\n
The u-wind component
\n
- if shape is (r,): One time series with *r* observations
\n
- if shape is (r,): One time series with *r* observations
\n
...
@@ -74,36 +75,75 @@ def spectra(spacial_frq, u, v=None, w=None, detrend=True):
...
@@ -74,36 +75,75 @@ def spectra(spacial_frq, u, v=None, w=None, detrend=True):
- uw: The uw cross spectrum, only if w is provided
\n
- uw: The uw cross spectrum, only if w is provided
\n
For two dimensional input, the mean spectra are returned
For two dimensional input, the mean spectra are returned
Notes
-----
If the
'
mean wind speed
'
or
'
shear compensated reference wind speed
'
are subtracted from u in advance,
then the spacial_frq must be divided by the subtracted wind speed
"""
"""
assert
isinstance
(
spacial_frq
,
(
int
,
float
))
assert
isinstance
(
spatial_resolution
,
(
int
,
float
))
k
=
2
*
np
.
pi
*
spacial_frq
k
=
2
*
np
.
pi
*
spatial_resolution
if
v
is
not
None
:
assert
u
.
shape
==
v
.
shape
if
np
.
mean
(
u
)
>
1
:
if
w
is
not
None
:
assert
u
.
shape
==
w
.
shape
k
/=
np
.
mean
(
u
)
u
=
u
-
np
.
mean
(
u
,
0
)
if
1
and
len
(
u
.
shape
)
==
2
:
if
v
is
not
None
:
assert
np
.
abs
(
np
.
mean
(
u
,
0
)).
max
()
<
1
v
=
v
-
np
.
mean
(
v
,
0
)
if
v
is
not
None
:
assert
np
.
abs
(
np
.
mean
(
v
,
0
)).
max
()
<
1
if
w
is
not
None
:
if
w
is
not
None
:
assert
np
.
abs
(
np
.
mean
(
w
,
0
)).
max
()
<
1
w
=
w
-
np
.
mean
(
w
,
0
)
if
isinstance
(
k
,
float
):
k
=
np
.
repeat
(
k
,
u
.
shape
[
1
])
else
:
assert
u
.
shape
[
1
]
==
k
.
shape
[
0
]
k1_vec
=
np
.
array
([
np
.
linspace
(
0
,
k_
/
2
,
len
(
u
)
/
2
)[
1
:]
for
k_
in
k
]).
T
else
:
assert
np
.
abs
(
np
.
mean
(
u
))
<
1
if
v
is
not
None
:
assert
np
.
abs
(
np
.
mean
(
v
))
<
1
if
w
is
not
None
:
assert
np
.
abs
(
np
.
mean
(
w
))
<
1
assert
isinstance
(
k
,
float
)
k1_vec
=
np
.
linspace
(
0
,
k
/
2
,
len
(
u
)
/
2
)[
1
:]
if
detrend
:
if
detrend
:
u
,
v
,
w
=
detrend_wsp
(
u
,
v
,
w
)
u
,
v
,
w
=
detrend_wsp
(
u
,
v
,
w
)
k1_vec
=
np
.
linspace
(
0
,
k
/
2
,
len
(
u
)
/
2
)[
1
:]
return
[
k1_vec
]
+
[
spectrum
(
x1
,
x2
,
k
=
k
)
for
x1
,
x2
in
[(
u
,
u
),
(
v
,
v
),
(
w
,
w
),
(
w
,
u
)]]
return
[
k1_vec
]
+
[
spectrum
(
x1
,
x2
,
k
=
k
)
for
x1
,
x2
in
[(
u
,
u
),
(
v
,
v
),
(
w
,
w
),
(
w
,
u
)]]
def
spectra_from_time_series
(
sample_frq
,
Uvw_lst
):
"""
Return the wave number, the uu, vv, ww autospectra and the uw cross spectra
Parameters
----------
sample_frq : int, float or array_like
Sample frequency
Uvw_lst : array_like
list of U, v and w, [(U1,v1,w1),(U2,v2,w2)...]
Returns
-------
k1, uu[, vv[, ww, uw]] : 2-5 x array_like
- k1: wave number
- uu: The uu auto spectrum
\n
- vv: The vv auto spectrum, only if v is provided
\n
- ww: The ww auto spectrum, only if w is provided
\n
- uw: The uw cross spectrum, only if w is provided
\n
For two dimensional input, the mean spectra are returned
"""
assert
isinstance
(
sample_frq
,
(
int
,
float
))
U
,
v
,
w
=
[
np
.
array
(
Uvw_lst
)[:,
i
,:].
T
for
i
in
range
(
3
)]
k
=
2
*
np
.
pi
*
sample_frq
/
U
.
mean
(
0
)
if
v
is
not
None
:
assert
np
.
abs
(
np
.
nanmean
(
v
,
0
)).
max
()
<
1
,
"
Max absolute mean of v is %f
"
%
np
.
abs
(
np
.
nanmean
(
v
,
0
)).
max
()
if
w
is
not
None
:
assert
np
.
abs
(
np
.
nanmean
(
w
,
0
)).
max
()
<
1
k1_vec
=
np
.
array
([
np
.
linspace
(
0
,
k_
/
2
,
U
.
shape
[
0
]
/
2
)[
1
:]
for
k_
in
k
]).
T
u
=
U
-
np
.
nanmean
(
U
,
0
)
u
,
v
,
w
=
detrend_wsp
(
u
,
v
,
w
)
return
[
k1_vec
]
+
[
spectrum
(
x1
,
x2
,
k
=
k
)
for
x1
,
x2
in
[(
u
,
u
),
(
v
,
v
),
(
w
,
w
),
(
w
,
u
)]]
def
bin_spectrum
(
x
,
y
,
bin_size
,
min_bin_count
=
2
):
def
bin_spectrum
(
x
,
y
,
bin_size
,
min_bin_count
=
2
):
assert
min_bin_count
>
0
assert
min_bin_count
>
0
x
=
x
/
bin_size
x
=
x
/
bin_size
low
,
high
=
np
.
floor
(
np
.
min
(
x
)),
np
.
ceil
(
np
.
max
(
x
))
low
,
high
=
np
.
floor
(
np
.
nan
min
(
x
)),
np
.
ceil
(
np
.
nan
max
(
x
))
bins
=
int
(
high
-
low
)
bins
=
int
(
high
-
low
)
nbr_in_bins
=
np
.
histogram
(
x
,
bins
,
range
=
(
low
,
high
))[
0
]
nbr_in_bins
=
np
.
histogram
(
x
,
bins
,
range
=
(
low
,
high
))[
0
]
if
len
(
x
.
shape
)
==
2
:
min_bin_count
*=
x
.
shape
[
1
]
mask
=
nbr_in_bins
>=
min_bin_count
mask
=
nbr_in_bins
>=
min_bin_count
return
np
.
histogram
(
x
,
bins
,
range
=
(
low
,
high
),
weights
=
y
)[
0
][
mask
]
/
nbr_in_bins
[
mask
],
nbr_in_bins
return
np
.
histogram
(
x
,
bins
,
range
=
(
low
,
high
),
weights
=
y
)[
0
][
mask
]
/
nbr_in_bins
[
mask
],
nbr_in_bins
...
@@ -138,3 +178,22 @@ def detrend_wsp(u, v=None, w=None):
...
@@ -138,3 +178,22 @@ def detrend_wsp(u, v=None, w=None):
dwsp
[:,
i
]
=
dwsp
[:,
i
]
-
t
*
trend
+
t
[
-
1
]
/
2
*
trend
dwsp
[:,
i
]
=
dwsp
[:,
i
]
-
t
*
trend
+
t
[
-
1
]
/
2
*
trend
return
dwsp
.
reshape
(
wsp
.
shape
)
return
dwsp
.
reshape
(
wsp
.
shape
)
return
[
_detrend
(
wsp
)
for
wsp
in
[
u
,
v
,
w
]]
return
[
_detrend
(
wsp
)
for
wsp
in
[
u
,
v
,
w
]]
def
plot_spectra
(
k1
,
uu
,
vv
=
None
,
ww
=
None
,
uw
=
None
,
mean_u
=
1
,
log10_bin_size
=
.
2
,
plt
=
None
,
marker_style
=
'
.
'
):
if
plt
is
None
:
import
matplotlib.pyplot
as
plt
bk1
,
buu
,
bvv
,
bww
,
buw
=
logbin_spectra
(
k1
,
uu
,
vv
,
ww
,
uw
,
log10_bin_size
)
def
plot
(
xx
,
label
,
color
,
plt
):
plt
.
semilogx
(
bk1
,
bk1
*
xx
*
10
**
0
/
mean_u
**
2
,
marker_style
+
color
,
label
=
label
)
plot
(
buu
,
'
uu
'
,
'
r
'
,
plt
)
plt
.
xlabel
(
'
Wavenumber $k_{1}$ [$m^{-1}$]
'
)
if
mean_u
==
1
:
plt
.
ylabel
(
r
'
Spectral density $k_{1} F(k_{1}) [m^2/s^2]$
'
)
else
:
plt
.
ylabel
(
r
'
Spectral density $k_{1} F(k_{1})/U^{2} [-]$
'
)
if
(
bvv
)
is
not
None
:
plot
(
bvv
,
'
vv
'
,
'
g
'
,
plt
)
if
bww
is
not
None
:
plot
(
bww
,
'
ww
'
,
'
b
'
,
plt
)
plot
(
buw
,
'
uw
'
,
'
m
'
,
plt
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment