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
mimc
WindEnergyToolbox
Commits
8d9a02f2
Commit
8d9a02f2
authored
9 years ago
by
David Verelst
Browse files
Options
Downloads
Patches
Plain Diff
move prepost.windIO tests to test_windIO file
parent
18cb4d1f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
wetb/prepost/tests/test_windIO.py
+187
-0
187 additions, 0 deletions
wetb/prepost/tests/test_windIO.py
wetb/prepost/windIO.py
+1
-151
1 addition, 151 deletions
wetb/prepost/windIO.py
with
188 additions
and
151 deletions
wetb/prepost/tests/test_windIO.py
0 → 100644
+
187
−
0
View file @
8d9a02f2
'''
Created on 05/11/2015
@author: MMPE
'''
from
__future__
import
unicode_literals
from
__future__
import
print_function
from
__future__
import
division
from
__future__
import
absolute_import
from
future
import
standard_library
standard_library
.
install_aliases
()
import
unittest
import
os
import
struct
import
numpy
as
np
import
scipy.io
as
sio
from
wetb.prepost.windIO
import
Turbulence
,
LoadResults
# path for test data files
fpath
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'
data/
'
)
class
TestsLoadResults
(
unittest
.
TestCase
):
def
setUp
(
self
):
pass
def
test_load
(
self
):
respath
=
'
../../hawc2/tests/test_files/hawc2io/
'
resfile
=
'
Hawc2ascii
'
res
=
LoadResults
(
respath
,
resfile
)
class
TestsTurbulence
(
unittest
.
TestCase
):
def
setUp
(
self
):
pass
def
print_test_info
(
self
):
pass
def
test_reshaped
(
self
):
"""
Make sure we correctly reshape the array instead of the manual
index reassignments
"""
fpath
=
'
data/turb_s100_3.00w.bin
'
fid
=
open
(
fpath
,
'
rb
'
)
turb
=
np
.
fromfile
(
fid
,
'
float32
'
,
32
*
32
*
8192
)
turb
.
shape
fid
.
close
()
u
=
np
.
zeros
((
8192
,
32
,
32
))
for
i
in
range
(
8192
):
for
j
in
range
(
32
):
for
k
in
range
(
32
):
u
[
i
,
j
,
k
]
=
turb
[
i
*
1024
+
j
*
32
+
k
]
u2
=
np
.
reshape
(
turb
,
(
8192
,
32
,
32
))
self
.
assertTrue
(
np
.
alltrue
(
np
.
equal
(
u
,
u2
)))
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__
"
:
unittest
.
main
()
This diff is collapsed.
Click to expand it.
wetb/prepost/windIO.py
+
1
−
151
View file @
8d9a02f2
...
@@ -27,14 +27,12 @@ __version__ = '0.5'
...
@@ -27,14 +27,12 @@ __version__ = '0.5'
import
os
import
os
import
copy
import
copy
import
unittest
import
struct
import
struct
import
math
import
math
from
time
import
time
from
time
import
time
import
codecs
import
codecs
import
scipy
import
scipy
import
scipy.io
as
sio
import
scipy.integrate
as
integrate
import
scipy.integrate
as
integrate
import
array
import
array
import
numpy
as
np
import
numpy
as
np
...
@@ -1872,154 +1870,6 @@ class Bladed(object):
...
@@ -1872,154 +1870,6 @@ class Bladed(object):
return
df
return
df
class
Tests
(
unittest
.
TestCase
):
def
setUp
(
self
):
pass
def
print_test_info
(
self
):
pass
def
test_reshaped
(
self
):
"""
Make sure we correctly reshape the array instead of the manual
index reassignments
"""
fpath
=
'
data/turb_s100_3.00w.bin
'
fid
=
open
(
fpath
,
'
rb
'
)
turb
=
np
.
fromfile
(
fid
,
'
float32
'
,
32
*
32
*
8192
)
turb
.
shape
fid
.
close
()
u
=
np
.
zeros
((
8192
,
32
,
32
))
for
i
in
range
(
8192
):
for
j
in
range
(
32
):
for
k
in
range
(
32
):
u
[
i
,
j
,
k
]
=
turb
[
i
*
1024
+
j
*
32
+
k
]
u2
=
np
.
reshape
(
turb
,
(
8192
,
32
,
32
))
self
.
assertTrue
(
np
.
alltrue
(
np
.
equal
(
u
,
u2
)))
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__
'
:
unittest
.
main
()
pass
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