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
Admin message
The Gitlab server is succesfully updated to version 17.9.2
Show more breadcrumbs
toolbox
WindEnergyToolbox
Commits
a4e47070
Commit
a4e47070
authored
8 years ago
by
David Verelst
Browse files
Options
Downloads
Patches
Plain Diff
prepost.windIO: add method to LogFile to convert csv format to df
parent
4ef58a75
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
wetb/prepost/windIO.py
+73
-0
73 additions, 0 deletions
wetb/prepost/windIO.py
with
73 additions
and
0 deletions
wetb/prepost/windIO.py
+
73
−
0
View file @
a4e47070
...
...
@@ -27,6 +27,7 @@ import struct
import
math
from
time
import
time
import
codecs
from
itertools
import
chain
import
scipy.integrate
as
integrate
import
numpy
as
np
...
...
@@ -136,6 +137,7 @@ class LogFile(object):
self
.
init_cols
=
len
(
self
.
err_init
)
self
.
sim_cols
=
len
(
self
.
err_sim
)
self
.
header
=
None
def
readlog
(
self
,
fname
,
case
=
None
,
save_iter
=
False
):
"""
...
...
@@ -354,6 +356,18 @@ class LogFile(object):
contents
=
contents
+
'
\n
'
return
contents
def
csv2df
(
self
,
fname
):
"""
Read a csv log file analysis and convert to a pandas.DataFrame
"""
colnames
,
min_itemsize
,
dtypes
=
self
.
headers4df
()
df
=
pd
.
read_csv
(
fname
,
header
=
0
,
names
=
colnames
,
sep
=
'
;
'
,
)
for
col
,
dtype
in
dtypes
.
items
():
df
[
col
]
=
df
[
col
].
astype
(
dtype
)
# replace nan with empty for str columns
if
dtype
==
str
:
df
[
col
]
=
df
[
col
].
str
.
replace
(
'
nan
'
,
''
)
return
df
def
_header
(
self
):
"""
Header for log analysis csv file
"""
...
...
@@ -371,6 +385,65 @@ class LogFile(object):
return
contents
def
headers4df
(
self
):
"""
Create header and a minimum itemsize for string columns when
converting a Log check analysis to a pandas.DataFrame
Returns
-------
header : list
List of column names as generated by WindIO.LogFile._header
min_itemsize : dict
Dictionary with column names as keys, and the minimum string lenght
as values.
dtypes : dict
Dictionary with column names as keys, and data types as values
"""
chain_iter
=
chain
.
from_iterable
colnames
=
[
'
file_name
'
]
colnames
.
extend
(
list
(
chain_iter
((
'
nr_%i
'
%
i
,
'
msg_%i
'
%
i
)
for
i
in
range
(
31
)))
)
gr
=
(
'
first_tstep_%i
'
,
'
last_step_%i
'
,
'
nr_%i
'
,
'
msg_%i
'
)
colnames
.
extend
(
list
(
chain_iter
(
(
k
%
i
for
k
in
gr
)
for
i
in
range
(
100
,
105
,
1
)))
)
colnames
.
extend
([
'
nr_extra
'
,
'
msg_extra
'
])
colnames
.
extend
([
'
elapsted_time
'
,
'
last_time_step
'
,
'
simulation_time
'
,
'
real_sim_time
'
,
'
sim_output_time
'
,
'
total_iterations
'
,
'
dt
'
,
'
nr_time_steps
'
,
'
seconds_p_iteration
'
,
'
mean_iters_p_time_step
'
,
'
max_iters_p_time_step
'
,
'
sim_id
'
])
dtypes
=
{}
# str and float datatypes for
msg_cols
=
[
'
msg_%i
'
%
i
for
i
in
range
(
30
)]
msg_cols
.
extend
([
'
msg_%i
'
%
i
for
i
in
range
(
100
,
105
,
1
)])
dtypes
.
update
({
k
:
str
for
k
in
msg_cols
})
# make the message/str columns long enough
min_itemsize
=
{
'
msg_%i
'
%
i
:
100
for
i
in
range
(
30
)}
# column names holding the number of occurances of messages
nr_cols
=
[
'
nr_%i
'
%
i
for
i
in
range
(
30
)]
nr_cols
.
extend
([
'
nr_%i
'
%
i
for
i
in
range
(
100
,
105
,
1
)])
# other float values
nr_cols
.
extend
([
'
elapsted_time
'
,
'
total_iterations
'
])
# NaN only exists in float arrays, not integers (NumPy limitation)
# so use float instead of int
dtypes
.
update
({
k
:
np
.
float64
for
k
in
nr_cols
})
return
colnames
,
min_itemsize
,
dtypes
class
LoadResults
(
ReadHawc2
):
"""
Read a HAWC2 result data 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