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
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
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
toolbox
WindEnergyToolbox
Commits
8a21e29b
There was a problem fetching the pipeline summary.
Commit
8a21e29b
authored
8 years ago
by
David Verelst
Browse files
Options
Downloads
Patches
Plain Diff
prepost test_windIO: remove turbulence file tests
parent
283d7b43
No related branches found
No related tags found
No related merge requests found
Pipeline
#
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
wetb/prepost/tests/test_windIO.py
+39
-162
39 additions, 162 deletions
wetb/prepost/tests/test_windIO.py
with
39 additions
and
162 deletions
wetb/prepost/tests/test_windIO.py
+
39
−
162
View file @
8a21e29b
...
@@ -11,176 +11,53 @@ from future import standard_library
...
@@ -11,176 +11,53 @@ from future import standard_library
standard_library
.
install_aliases
()
standard_library
.
install_aliases
()
import
unittest
import
unittest
import
os
import
struct
import
numpy
as
np
import
numpy
as
np
import
scipy.io
as
sio
from
wetb.prepost.windIO
import
Turbulence
,
LoadResults
from
wetb.prepost.windIO
import
LoadResults
# path for test data files
fpath
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'
data/
'
)
class
TestsLoadResults
(
unittest
.
TestCase
):
class
TestsLoadResults
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
pass
self
.
respath
=
'
../../hawc2/tests/test_files/hawc2io/
'
self
.
fascii
=
'
Hawc2ascii
'
def
test_load
(
self
):
self
.
fbin
=
'
Hawc2bin
'
respath
=
'
../../hawc2/tests/test_files/hawc2io/
'
def
loadresfile
(
self
,
resfile
):
resfile
=
'
Hawc2ascii
'
res
=
LoadResults
(
self
.
respath
,
resfile
)
res
=
LoadResults
(
respath
,
resfile
)
self
.
assertTrue
(
hasattr
(
res
,
'
sig
'
))
self
.
assertEqual
(
res
.
Freq
,
40.0
)
self
.
assertEqual
(
res
.
N
,
800
)
self
.
assertEqual
(
res
.
Nch
,
28
)
class
TestsTurbulence
(
unittest
.
TestCase
):
self
.
assertEqual
(
res
.
Time
,
20.0
)
self
.
assertEqual
(
res
.
sig
.
shape
,
(
800
,
28
))
def
setUp
(
self
):
return
res
pass
def
test_load_ascii
(
self
):
def
print_test_info
(
self
):
res
=
self
.
loadresfile
(
self
.
fascii
)
pass
self
.
assertEqual
(
res
.
FileType
,
'
ASCII
'
)
def
test_reshaped
(
self
):
def
test_load_binary
(
self
):
"""
res
=
self
.
loadresfile
(
self
.
fbin
)
Make sure we correctly reshape the array instead of the manual
self
.
assertEqual
(
res
.
FileType
,
'
BINARY
'
)
index reassignments
"""
def
test_compare_ascii_bin
(
self
):
fpath
=
'
data/turb_s100_3.00w.bin
'
res_ascii
=
LoadResults
(
self
.
respath
,
self
.
fascii
)
fid
=
open
(
fpath
,
'
rb
'
)
res_bin
=
LoadResults
(
self
.
respath
,
self
.
fbin
)
turb
=
np
.
fromfile
(
fid
,
'
float32
'
,
32
*
32
*
8192
)
turb
.
shape
for
k
in
range
(
res_ascii
.
sig
.
shape
[
1
]):
fid
.
close
()
np
.
testing
.
assert_allclose
(
res_ascii
.
sig
[:,
k
],
res_bin
.
sig
[:,
k
],
u
=
np
.
zeros
((
8192
,
32
,
32
))
rtol
=
1e-02
,
atol
=
0.001
)
for
i
in
range
(
8192
):
def
test_unified_chan_names
(
self
):
for
j
in
range
(
32
):
res
=
LoadResults
(
self
.
respath
,
self
.
fascii
,
readdata
=
False
)
for
k
in
range
(
32
):
self
.
assertFalse
(
hasattr
(
res
,
'
sig
'
))
u
[
i
,
j
,
k
]
=
turb
[
i
*
1024
+
j
*
32
+
k
]
np
.
testing
.
assert_array_equal
(
res
.
ch_df
.
index
.
values
,
np
.
arange
(
0
,
28
))
u2
=
np
.
reshape
(
turb
,
(
8192
,
32
,
32
))
self
.
assertEqual
(
res
.
ch_df
.
ch_name
.
values
[
0
],
'
Time
'
)
self
.
assertEqual
(
res
.
ch_df
.
ch_name
.
values
[
27
],
self
.
assertTrue
(
np
.
alltrue
(
np
.
equal
(
u
,
u2
)))
'
windspeed-global-Vy--2.50-1.00--52.50
'
)
def
test_headers
(
self
):
fpath
=
'
data/
'
basename
=
'
turb_s100_3.00_refoctave_header
'
fid
=
open
(
fpath
+
basename
+
'
.wnd
'
,
'
rb
'
)
R1
=
struct
.
unpack
(
"
h
"
,
fid
.
read
(
2
))[
0
]
R2
=
struct
.
unpack
(
"
h
"
,
fid
.
read
(
2
))[
0
]
turb
=
struct
.
unpack
(
"
i
"
,
fid
.
read
(
4
))[
0
]
lat
=
struct
.
unpack
(
"
f
"
,
fid
.
read
(
4
))[
0
]
# last line
fid
.
seek
(
100
)
LongVertComp
=
struct
.
unpack
(
"
f
"
,
fid
.
read
(
4
))[
0
]
fid
.
close
()
basename
=
'
turb_s100_3.00_python_header
'
fid
=
open
(
fpath
+
basename
+
'
.wnd
'
,
'
rb
'
)
R1_p
=
struct
.
unpack
(
"
h
"
,
fid
.
read
(
2
))[
0
]
R2_p
=
struct
.
unpack
(
"
h
"
,
fid
.
read
(
2
))[
0
]
turb_p
=
struct
.
unpack
(
"
i
"
,
fid
.
read
(
4
))[
0
]
lat_p
=
struct
.
unpack
(
"
f
"
,
fid
.
read
(
4
))[
0
]
# last line
fid
.
seek
(
100
)
LongVertComp_p
=
struct
.
unpack
(
"
f
"
,
fid
.
read
(
4
))[
0
]
fid
.
close
()
self
.
assertEqual
(
R1
,
R1_p
)
self
.
assertEqual
(
R2
,
R2_p
)
self
.
assertEqual
(
turb
,
turb_p
)
self
.
assertEqual
(
lat
,
lat_p
)
self
.
assertEqual
(
LongVertComp
,
LongVertComp_p
)
def
test_write_bladed
(
self
):
fpath
=
'
data/
'
turb
=
Turbulence
()
# write with Python
basename
=
'
turb_s100_3.00
'
turb
.
write_bladed
(
fpath
,
basename
,
shape
=
(
8192
,
32
,
32
))
python
=
turb
.
read_bladed
(
fpath
,
basename
)
# load octave
basename
=
'
turb_s100_3.00_refoctave
'
octave
=
turb
.
read_bladed
(
fpath
,
basename
)
# float versions of octave
basename
=
'
turb_s100_3.00_refoctave_float
'
fid
=
open
(
fpath
+
basename
+
'
.wnd
'
,
'
rb
'
)
octave32
=
np
.
fromfile
(
fid
,
'
float32
'
,
8192
*
32
*
32
*
3
)
# find the differences
nr_diff
=
(
python
-
octave
).
__ne__
(
0
).
sum
()
print
(
nr_diff
)
print
(
nr_diff
/
len
(
python
))
self
.
assertTrue
(
np
.
alltrue
(
python
==
octave
))
def
test_turbdata
(
self
):
shape
=
(
8192
,
32
,
32
)
fpath
=
'
data/
'
basename
=
'
turb_s100_3.00_refoctave
'
fid
=
open
(
fpath
+
basename
+
'
.wnd
'
,
'
rb
'
)
# check the last element of the header
fid
.
seek
(
100
)
print
(
struct
.
unpack
(
"
f
"
,
fid
.
read
(
4
))[
0
])
# save in a list using struct
items
=
(
os
.
path
.
getsize
(
fpath
+
basename
+
'
.wnd
'
)
-
104
)
/
2
data_list
=
[
struct
.
unpack
(
"
h
"
,
fid
.
read
(
2
))[
0
]
for
k
in
range
(
items
)]
fid
.
seek
(
104
)
data_16
=
np
.
fromfile
(
fid
,
'
int16
'
,
shape
[
0
]
*
shape
[
1
]
*
shape
[
2
]
*
3
)
fid
.
seek
(
104
)
data_8
=
np
.
fromfile
(
fid
,
'
int8
'
,
shape
[
0
]
*
shape
[
1
]
*
shape
[
2
]
*
3
)
self
.
assertTrue
(
np
.
alltrue
(
data_16
==
data_list
))
self
.
assertFalse
(
np
.
alltrue
(
data_8
==
data_list
))
def
test_compare_octave
(
self
):
"""
Compare the results from the original script run via octave
"""
turb
=
Turbulence
()
iu
,
iv
,
iw
=
turb
.
convert2bladed
(
'
data/
'
,
'
turb_s100_3.00
'
,
shape
=
(
8192
,
32
,
32
))
res
=
sio
.
loadmat
(
'
data/workspace.mat
'
)
# increase tolerances, values have a range up to 5000-10000
# and these values will be written to an int16 format for BLADED!
self
.
assertTrue
(
np
.
allclose
(
res
[
'
iu
'
],
iu
,
rtol
=
1e-03
,
atol
=
1e-2
))
self
.
assertTrue
(
np
.
allclose
(
res
[
'
iv
'
],
iv
,
rtol
=
1e-03
,
atol
=
1e-2
))
self
.
assertTrue
(
np
.
allclose
(
res
[
'
iw
'
],
iw
,
rtol
=
1e-03
,
atol
=
1e-2
))
def
test_allindices
(
self
):
"""
Verify that all indices are called
"""
fpath
=
'
data/turb_s100_3.00w.bin
'
fid
=
open
(
fpath
,
'
rb
'
)
turb
=
np
.
fromfile
(
fid
,
'
float32
'
,
32
*
32
*
8192
)
turb
.
shape
fid
.
close
()
check
=
[]
for
i
in
range
(
8192
):
for
j
in
range
(
32
):
for
k
in
range
(
32
):
check
.
append
(
i
*
1024
+
j
*
32
+
k
)
qq
=
np
.
array
(
check
)
qdiff
=
np
.
diff
(
qq
)
self
.
assertTrue
(
np
.
alltrue
(
np
.
equal
(
qdiff
,
np
.
ones
(
qdiff
.
shape
))))
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
...
...
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