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
6d74119a
Commit
6d74119a
authored
9 years ago
by
mads
Browse files
Options
Downloads
Patches
Plain Diff
added at_time_file + test
parent
34ce42ad
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
wetb/hawc2/at_time_file.py
+68
-0
68 additions, 0 deletions
wetb/hawc2/at_time_file.py
wetb/hawc2/tests/test_AtTimeFile.py
+51
-0
51 additions, 0 deletions
wetb/hawc2/tests/test_AtTimeFile.py
wetb/hawc2/tests/test_files/at_time.dat
+28
-0
28 additions, 0 deletions
wetb/hawc2/tests/test_files/at_time.dat
with
147 additions
and
0 deletions
wetb/hawc2/at_time_file.py
0 → 100644
+
68
−
0
View file @
6d74119a
'''
Created on 24/04/2014
@author: MMPE
'''
import
numpy
as
np
class
AtTimeFile
(
object
):
"""
Loads an at time file generated by HAWC2
>>>
atfile
=
AtTimeFile
(
"
at_time.dat
"
)
# load file
>>>
atfile
.
attribute_names
# Attribute names
[
'
radius_s
'
,
'
twist
'
,
'
chord
'
]
>>>
atfile
[:
3
,
1
])
# first 3 twist rows
[
0.
-
0.775186
-
2.91652
]
>>>
atfile
.
twist
()[:
3
])
# first 3 twist rows
[
0.
-
0.775186
-
2.91652
]
>>>
atfile
.
twist
(
10
)
# Twist at radius = 10 (interpolated)
-
5.34743208242399
"""
def
__init__
(
self
,
filename
):
with
open
(
filename
)
as
fid
:
lines
=
fid
.
readlines
()
self
.
attribute_names
=
lines
[
2
].
lower
().
replace
(
"
#
"
,
""
).
split
()
data
=
np
.
array
([[
float
(
l
)
for
l
in
lines
[
i
].
split
()
]
for
i
in
range
(
3
,
len
(
lines
))])
self
.
data
=
data
def
func_factory
(
column
):
def
values
(
radius
=
None
):
if
radius
is
None
:
return
self
.
data
[:,
column
]
else
:
return
np
.
interp
(
radius
,
self
.
data
[:,
0
],
self
.
data
[:,
column
])
return
values
for
column
,
att_name
in
enumerate
(
self
.
attribute_names
):
setattr
(
self
,
att_name
,
func_factory
(
column
))
def
radius
(
self
,
radius
=
None
):
"""
Radius of calculation point(s)
Parameters
----------
radius : int or float, optional
- if None (default): Radius of calculation points
\n
- if int or float: Radius of calculation point nearest radius
Returns
-------
radius : float or array_like
Radius of calculation points or radius of calculation point nearest radius
"""
if
radius
is
None
:
return
self
.
radius_s
(
radius
)
else
:
return
self
.
radius_s
()[
np
.
argmin
(
np
.
abs
(
self
.
radius_s
()
-
radius
))]
def
value
(
self
,
radius
,
column
):
return
np
.
interp
(
radius
,
self
.
data
[:,
0
],
self
.
data
[:,
column
])
def
__getitem__
(
self
,
subset
):
return
self
.
data
[
subset
]
if
__name__
==
"
__main__
"
:
at
=
AtTimeFile
(
r
"
tests/test_files/at_time.dat
"
)
print
(
at
.
attribute_names
)
print
(
at
.
twist
(
36
))
print
(
at
.
chord
(
36
))
This diff is collapsed.
Click to expand it.
wetb/hawc2/tests/test_AtTimeFile.py
0 → 100644
+
51
−
0
View file @
6d74119a
'''
Created on 17/07/2014
@author: MMPE
'''
import
unittest
from
wetb.hawc2.at_time_file
import
AtTimeFile
import
numpy
as
np
class
Test
(
unittest
.
TestCase
):
def
setUp
(
self
):
unittest
.
TestCase
.
setUp
(
self
)
self
.
testfilepath
=
"
test_files/
"
def
test_doc_examples
(
self
):
atfile
=
AtTimeFile
(
self
.
testfilepath
+
"
at_time.dat
"
)
# load file
self
.
assertEqual
(
atfile
.
attribute_names
,
[
'
radius_s
'
,
'
twist
'
,
'
chord
'
])
np
.
testing
.
assert_array_equal
(
atfile
[:
3
,
1
],
[
0.
,
-
0.775186
,
-
2.91652
])
np
.
testing
.
assert_array_equal
(
atfile
.
twist
()[:
3
],
[
0.
,
-
0.775186
,
-
2.91652
])
self
.
assertEqual
(
atfile
.
twist
(
10
),
-
5.34743208242399
)
# Twist at radius = 10 (interpolated)
def
test_at_time_file
(
self
):
atfile
=
AtTimeFile
(
self
.
testfilepath
+
"
at_time.dat
"
)
self
.
assertEqual
(
atfile
.
attribute_names
,
[
'
radius_s
'
,
'
twist
'
,
'
chord
'
])
self
.
assertEqual
(
atfile
.
radius_s
()[
9
],
6.32780
)
self
.
assertEqual
(
atfile
.
twist
()[
9
],
-
13.5373
)
self
.
assertEqual
(
atfile
.
chord
()[
9
],
1.54999
)
def
test_at_time_file_at_radius
(
self
):
atfile
=
AtTimeFile
(
self
.
testfilepath
+
"
at_time.dat
"
)
self
.
assertEqual
(
atfile
.
radius_s
(
9
),
9
)
self
.
assertEqual
(
atfile
.
twist
(
9
),
-
6.635983309665461
)
self
.
assertEqual
(
atfile
.
chord
(
9
),
1.3888996578373045
)
def
test_at_time_file_radius
(
self
):
atfile
=
AtTimeFile
(
self
.
testfilepath
+
"
at_time.dat
"
)
self
.
assertEqual
(
atfile
.
radius
()[
12
],
10.2505
)
self
.
assertEqual
(
atfile
.
radius
(
10
),
10.2505
)
self
.
assertEqual
(
atfile
.
radius
(
10.5
),
10.2505
)
if
__name__
==
"
__main__
"
:
#import sys;sys.argv = ['', 'Test.testName']
unittest
.
main
()
This diff is collapsed.
Click to expand it.
wetb/hawc2/tests/test_files/at_time.dat
0 → 100644
+
28
−
0
View file @
6d74119a
# Version ID : HAWC2AERO 2.4w
# Radial output at time: 1.00000000000000
# Radius_s # twist # Chord
0.00000E+00 0.00000E+00 1.00000E-03
8.76944E-02 -7.75186E-01 1.00000E-03
3.49277E-01 -2.91652E+00 1.00000E-03
7.80273E-01 -5.85792E+00 1.00000E-03
1.37331E+00 -8.61678E+00 1.00000E-03
2.11823E+00 -8.54428E+00 8.30976E-01
3.00230E+00 -1.25115E+01 1.25260E+00
4.01039E+00 -1.75520E+01 1.51878E+00
5.12525E+00 -1.76464E+01 1.61724E+00
6.32780E+00 -1.35373E+01 1.54999E+00
7.59748E+00 -9.71721E+00 1.45905E+00
8.91254E+00 -6.74868E+00 1.39442E+00
1.02505E+01 -5.02465E+00 1.30997E+00
1.15885E+01 -3.92039E+00 1.22316E+00
1.29035E+01 -2.82899E+00 1.13556E+00
1.41732E+01 -2.04828E+00 1.04888E+00
1.53758E+01 -1.39988E+00 9.63946E-01
1.64906E+01 -9.33385E-01 8.80714E-01
1.74987E+01 -5.70469E-01 7.94120E-01
1.83828E+01 -2.98853E-01 6.90240E-01
1.91277E+01 -1.22955E-01 5.56800E-01
1.97207E+01 -3.28925E-02 3.86719E-01
2.01517E+01 -2.73822E-03 2.11422E-01
2.04133E+01 1.14111E-03 8.17689E-02
2.05010E+01 0.00000E+00 3.60000E-02
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