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
deac1a93
Commit
deac1a93
authored
9 years ago
by
mads
Browse files
Options
Downloads
Patches
Plain Diff
documentation + ability to take 1d u,v,w vectors
parent
6e9d7855
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
wetb/hawc2/shear_file.py
+31
-1
31 additions, 1 deletion
wetb/hawc2/shear_file.py
wetb/hawc2/tests/test_shear_file.py
+35
-0
35 additions, 0 deletions
wetb/hawc2/tests/test_shear_file.py
with
66 additions
and
1 deletion
wetb/hawc2/shear_file.py
+
31
−
1
View file @
deac1a93
...
@@ -5,16 +5,46 @@ Created on 24/04/2014
...
@@ -5,16 +5,46 @@ Created on 24/04/2014
'''
'''
import
numpy
as
np
import
numpy
as
np
import
os
from
wetb.functions.make_dirs
import
make_dirs
def
save
(
filename
,
y_coordinates
,
z_coordinates
,
u
=
None
,
v
=
None
,
w
=
None
):
def
save
(
filename
,
y_coordinates
,
z_coordinates
,
u
=
None
,
v
=
None
,
w
=
None
):
"""
Parameters
----------
filename : str
filename
y_coordinates : array_like
lateral coordinates
z_coordinates : array_like
vertical coordinates
u : array_like, optional
shear_u component, normalized with U_mean
\n
shape must be (#z_coordinates, #y_coordinates) or (#z_coordinates,)
v : array_like, optional
shear_v component, normalized with U_mean
\n
shape must be (#z_coordinates, #y_coordinates) or (#z_coordinates,)
w : array_like, optional
shear_w component, normalized with U_mean
\n
shape must be (#z_coordinates, #y_coordinates) or (#z_coordinates,)
"""
shape
=
(
len
(
z_coordinates
),
len
(
y_coordinates
))
shape
=
(
len
(
z_coordinates
),
len
(
y_coordinates
))
vuw
=
[
v
,
u
,
w
]
vuw
=
[
v
,
u
,
w
]
for
i
in
range
(
3
):
for
i
in
range
(
3
):
if
vuw
[
i
]
is
None
:
if
vuw
[
i
]
is
None
:
vuw
[
i
]
=
np
.
zeros
((
shape
))
if
i
==
1
:
vuw
[
i
]
=
np
.
ones
((
shape
))
else
:
vuw
[
i
]
=
np
.
zeros
((
shape
))
else
:
else
:
vuw
[
i
]
=
np
.
array
(
vuw
[
i
])
if
len
(
vuw
[
i
].
shape
)
==
1
and
vuw
[
i
].
shape
[
0
]
==
shape
[
0
]:
vuw
[
i
]
=
np
.
repeat
(
np
.
atleast_2d
(
vuw
[
i
]).
T
,
shape
[
1
],
1
)
assert
vuw
[
i
].
shape
==
shape
,
(
i
,
vuw
[
i
].
shape
,
shape
)
assert
vuw
[
i
].
shape
==
shape
,
(
i
,
vuw
[
i
].
shape
,
shape
)
make_dirs
(
filename
)
with
open
(
filename
,
'
w
'
)
as
fid
:
with
open
(
filename
,
'
w
'
)
as
fid
:
fid
.
write
(
"
# autogenerated shear file
\n
"
)
fid
.
write
(
"
# autogenerated shear file
\n
"
)
fid
.
write
(
"
%d %d
\n
"
%
(
len
(
y_coordinates
),
len
(
z_coordinates
)))
fid
.
write
(
"
%d %d
\n
"
%
(
len
(
y_coordinates
),
len
(
z_coordinates
)))
...
...
This diff is collapsed.
Click to expand it.
wetb/hawc2/tests/test_shear_file.py
+
35
−
0
View file @
deac1a93
...
@@ -7,6 +7,7 @@ import unittest
...
@@ -7,6 +7,7 @@ import unittest
from
wetb.hawc2
import
shear_file
from
wetb.hawc2
import
shear_file
import
numpy
as
np
import
numpy
as
np
import
os
import
os
import
shutil
testfilepath
=
'
test_files/
'
testfilepath
=
'
test_files/
'
class
Test
(
unittest
.
TestCase
):
class
Test
(
unittest
.
TestCase
):
...
@@ -41,6 +42,40 @@ class Test(unittest.TestCase):
...
@@ -41,6 +42,40 @@ class Test(unittest.TestCase):
os
.
remove
(
f
)
os
.
remove
(
f
)
def
test_shearfile2
(
self
):
f
=
testfilepath
+
"
tmp_shearfile.dat
"
shear_file
.
save
(
f
,
[
-
55
,
55
],
[
30
,
100
,
160
]
,
u
=
np
.
array
([
0.7
,
1
,
1.3
]).
T
)
with
open
(
f
)
as
fid
:
self
.
assertEqual
(
fid
.
read
(),
"""
# autogenerated shear file
2 3
# shear v component
0.0000000000 0.0000000000
0.0000000000 0.0000000000
0.0000000000 0.0000000000
# shear u component
0.7000000000 0.7000000000
1.0000000000 1.0000000000
1.3000000000 1.3000000000
# shear w component
0.0000000000 0.0000000000
0.0000000000 0.0000000000
0.0000000000 0.0000000000
# y coordinates
-55.0000000000
55.0000000000
# z coordinates
30.0000000000
100.0000000000
160.0000000000
"""
)
os
.
remove
(
f
)
def
test_shear_makedirs
(
self
):
f
=
testfilepath
+
"
shear/tmp_shearfile2.dat
"
shear_file
.
save
(
f
,
[
-
55
,
55
],
[
30
,
100
,
160
]
,
u
=
np
.
array
([
0.7
,
1
,
1.3
]).
T
)
shutil
.
rmtree
(
testfilepath
+
"
shear
"
)
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
#import sys;sys.argv = ['', 'Test.test_shearfile']
#import sys;sys.argv = ['', 'Test.test_shearfile']
unittest
.
main
()
unittest
.
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