Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
VirtualFluids
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
iRMB
VirtualFluids
Commits
4875370d
Commit
4875370d
authored
1 year ago
by
Hkorb
Browse files
Options
Downloads
Patches
Plain Diff
add reader for timeseries files
parent
4a6ab0c3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!245
Add new probe, Refactor File Writer
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pythonbindings/pyfluids/timeseries_probe_reader.py
+47
-0
47 additions, 0 deletions
pythonbindings/pyfluids/timeseries_probe_reader.py
with
47 additions
and
0 deletions
pythonbindings/pyfluids/timeseries_probe_reader.py
0 → 100644
+
47
−
0
View file @
4875370d
import
numpy
as
np
from
pathlib
import
Path
import
pandas
as
pd
#%%
class
TimeseriesProbeReader
:
def
__init__
(
self
,
file
:
Path
):
self
.
file
=
file
self
.
quants
,
self
.
positions
,
self
.
data
=
\
self
.
read_file
()
def
read_file
(
self
):
with
open
(
self
.
file
,
"
rb
"
)
as
f
:
header_length
=
0
header_length
+=
len
(
f
.
readline
())
# first line
quant_line
=
f
.
readline
()
header_length
+=
len
(
f
.
readline
())
# number of points
number_of_points_line
=
f
.
readline
()
header_length
+=
len
(
f
.
readline
())
# positions
n_points
=
int
(
number_of_points_line
)
positions
=
np
.
zeros
((
n_points
,
3
))
for
i
in
range
(
n_points
):
pos_line
=
f
.
readline
()
header_length
+=
len
(
pos_line
)
positions
[
i
]
=
[
float
(
pos
)
for
pos
in
pos_line
.
split
(
b
"
,
"
)]
header_length
+=
len
(
quant_line
)
header_length
+=
len
(
number_of_points_line
)
quants
=
quant_line
.
decode
().
split
(
"
"
)[
1
:
-
1
]
n_quants
=
len
(
quants
)
data
=
np
.
fromfile
(
self
.
file
,
dtype
=
np
.
float32
,
offset
=
header_length
)
n_timesteps
=
len
(
data
)
//
(
n_quants
*
n_points
+
1
)
return
quants
,
positions
,
data
.
reshape
(
n_timesteps
,
n_points
*
n_quants
+
1
)
def
get_data
(
self
):
return
self
.
data
def
get_positions
(
self
):
return
self
.
positions
def
get_quantities
(
self
):
return
self
.
quants
def
to_dataframe
(
self
):
return
pd
.
DataFrame
(
self
.
data
[:,
1
:],
columns
=
self
.
quants
,
index
=
self
.
data
[:,
0
])
\ No newline at end of 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