Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vibrationlib
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
FS-PETRA-UPM
vibrationlib
Commits
a293a103
Commit
a293a103
authored
11 months ago
by
Stephan Botta
Browse files
Options
Downloads
Patches
Plain Diff
bugfixes
parent
23f99a20
No related branches found
No related tags found
No related merge requests found
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pyproject.toml
+1
-1
1 addition, 1 deletion
pyproject.toml
vibrationlib.sublime-workspace
+776
-675
776 additions, 675 deletions
vibrationlib.sublime-workspace
vibrationlib/rawinfo.py
+78
-52
78 additions, 52 deletions
vibrationlib/rawinfo.py
with
855 additions
and
728 deletions
pyproject.toml
+
1
−
1
View file @
a293a103
...
...
@@ -18,7 +18,7 @@ dmypy = true
[project]
name
=
"vibrationlib"
version
=
"0.7.
1
"
version
=
"0.7.
2
"
description
=
"pip"
authors
=
[
{
name
=
"Stephan Botta"
,
email
=
"stephan.botta@desy.de"
}
,
...
...
This diff is collapsed.
Click to expand it.
vibrationlib.sublime-workspace
+
776
−
675
View file @
a293a103
This diff is collapsed.
Click to expand it.
vibrationlib/rawinfo.py
+
78
−
52
View file @
a293a103
"""
Summary.
"""
import
datetime
as
dt
from
abc
import
ABC
,
abstractmethod
import
pandas
as
pd
# type: ignore[import]
import
h5py
# type: ignore[import]
from
pathlib
import
Path
import
h5py
# type: ignore[import]
import
pandas
as
pd
# type: ignore[import]
class
__RawInfo__
(
ABC
):
"""
...
...
@@ -17,26 +18,33 @@ class __RawInfo__(ABC):
self
.
metadata
:
dict
self
.
groups_and_datasets
:
pd
.
DataFrame
@abstractmethod
def
to_dict
(
self
):
pass
class
__QdisInfo__
(
__RawInfo__
):
def
__init__
(
self
,
datafile
:
str
)
->
None
:
self
.
datafile
=
datafile
self
.
metadata
=
self
.
get_metadata
()
def
get_metadata
(
self
)
->
dict
:
def
get_metadata
(
self
)
->
dict
:
with
h5py
.
File
(
self
.
datafile
,
"
r
"
)
as
file
:
starttime
=
file
[
'
entry/instrument/detector/scan_start
'
]
stoptime
=
file
[
'
entry/instrument/detector/scan_stop
'
]
SampleRate
=
file
[
'
entry/instrument/detector/sampling_frequency
'
]
starttime
=
file
[
"
entry/instrument/detector/scan_start
"
]
stoptime
=
file
[
"
entry/instrument/detector/scan_stop
"
]
SampleRate
=
file
[
"
entry/instrument/detector/sampling_frequency
"
]
assert
isinstance
(
SampleRate
,
h5py
.
Dataset
)
assert
isinstance
(
starttime
,
h5py
.
Dataset
)
assert
isinstance
(
stoptime
,
h5py
.
Dataset
)
starttime
=
starttime
[()]
stoptime
=
stoptime
[()]
SampleRate
=
SampleRate
[()][
0
]
starttime
=
dt
.
datetime
.
strptime
(
starttime
.
decode
(),
"
%a %b %d %H:%M:%S %Y
\n
"
).
astimezone
()
stoptime
=
dt
.
datetime
.
strptime
(
stoptime
.
decode
(),
"
%a %b %d %H:%M:%S %Y
\n
"
).
astimezone
()
starttime
=
dt
.
datetime
.
strptime
(
starttime
.
decode
(),
"
%a %b %d %H:%M:%S %Y
\n
"
).
astimezone
()
stoptime
=
dt
.
datetime
.
strptime
(
stoptime
.
decode
(),
"
%a %b %d %H:%M:%S %Y
\n
"
).
astimezone
()
return
{
"
StartTime
"
:
starttime
,
"
SampleRate
"
:
SampleRate
,
...
...
@@ -63,29 +71,33 @@ class __QdisInfo__(__RawInfo__):
stop_str
=
str
(
f
'
Measurement End:
{
self
.
metadata
[
"
StopTime
"
]
}
\n
'
)
samplerate_str
=
str
(
f
'
Sample Rate:
{
self
.
metadata
[
"
SampleRate
"
]
}
\n
'
)
groups_str
=
str
(
f
'
Groups:
{
self
.
groups_and_datasets
[
"
Group
"
][
0
]
}
\n
'
)
datasets_str
=
str
(
f
'
Datasets:
{
self
.
groups_and_datasets
[
"
Dataset
"
][
0
]
}
\n
'
)
return
(
"
Information:
\n
"
+
samplerate_str
+
start_str
+
stop_str
+
groups_str
+
datasets_str
)
datasets_str
=
str
(
f
'
Datasets:
{
self
.
groups_and_datasets
[
"
Dataset
"
][
0
]
}
\n
'
)
return
(
"
Information:
\n
"
+
samplerate_str
+
start_str
+
stop_str
+
groups_str
+
datasets_str
)
def
to_dict
(
self
)
->
dict
:
metadata
=
self
.
metadata
groups_and_datasets
=
self
.
groups_and_datasets
.
to_dict
()
temp_df
=
self
.
groups_and_datasets
.
drop
([
'
StopTime
'
,
'
Group
'
],
axis
=
1
)
temp_df
[
'
StartTime
'
]
=
temp_df
[
'
StartTime
'
].
dt
.
strftime
(
"
%X
"
)
values
=
list
(
temp_df
[[
'
Dataset
'
,
'
StartTime
'
]].
agg
(
'
at
'
.
join
,
axis
=
1
))
labels
=
temp_df
[
"
Dataset
"
]
res
=
dict
(
map
(
lambda
i
,
j
:
(
i
,
j
)
,
labels
,
values
))
temp_df
=
self
.
groups_and_datasets
.
drop
([
"
StopTime
"
,
"
Group
"
],
axis
=
1
)
temp_df
[
"
StartTime
"
]
=
temp_df
[
"
StartTime
"
].
dt
.
strftime
(
"
%X
"
)
values
=
list
(
temp_df
[[
"
Dataset
"
,
"
StartTime
"
]].
agg
(
"
at
"
.
join
,
axis
=
1
))
labels
=
temp_df
[
"
Dataset
"
]
res
=
dict
(
map
(
lambda
i
,
j
:
(
i
,
j
),
labels
,
values
))
return
{
"
metadata
"
:
metadata
,
"
groups_and_datasets
"
:
groups_and_datasets
,
"
datafile
"
:
self
.
datafile
,
"
datasets_str
"
:
res
"
datasets_str
"
:
res
,
}
class
__CsvInfo__
(
__RawInfo__
):
def
__init__
(
self
,
datafile
:
str
)
->
None
:
self
.
datafile
=
datafile
self
.
metadata
=
self
.
get_metadata
()
...
...
@@ -111,18 +123,16 @@ class __CsvInfo__(__RawInfo__):
starttime
=
dt
.
datetime
.
now
()
SampleRate
=
1
/
(
df
[
"
# t
"
][
2
]
-
df
[
"
# t
"
][
1
])
duration
=
float
(
list
(
pd
.
read_csv
(
self
.
datafile
,
skiprows
=
row_count
+
4
,
nrows
=
1
,
sep
=
"
;
"
))[
0
])
list
(
pd
.
read_csv
(
self
.
datafile
,
skiprows
=
row_count
+
4
,
nrows
=
1
,
sep
=
"
;
"
))[
0
]
)
with
open
(
self
.
datafile
)
as
get_start
:
for
line
,
content
in
enumerate
(
get_start
):
if
line
<
1
:
pass
elif
line
==
1
:
starttime
=
dt
.
datetime
.
strptime
(
content
,
"
# %Y-%m-%d %H:%M:%S
\n
"
)
starttime
=
dt
.
datetime
.
strptime
(
content
,
"
# %Y-%m-%d %H:%M:%S
\n
"
)
else
:
break
stoptime
=
starttime
+
dt
.
timedelta
(
seconds
=
duration
)
...
...
@@ -138,10 +148,15 @@ class __CsvInfo__(__RawInfo__):
stop_str
=
str
(
f
'
Measurement End:
{
self
.
metadata
[
"
StopTime
"
]
}
\n
'
)
samplerate_str
=
str
(
f
'
Sample Rate:
{
self
.
metadata
[
"
SampleRate
"
]
}
\n
'
)
groups_str
=
str
(
f
'
Groups:
{
self
.
groups_and_datasets
[
"
Group
"
][
0
]
}
\n
'
)
datasets_str
=
str
(
f
'
Datasets:
{
self
.
groups_and_datasets
[
"
Dataset
"
][
0
]
}
\n
'
)
return
(
"
Information:
\n
"
+
samplerate_str
+
start_str
+
stop_str
+
groups_str
+
datasets_str
)
datasets_str
=
str
(
f
'
Datasets:
{
self
.
groups_and_datasets
[
"
Dataset
"
][
0
]
}
\n
'
)
return
(
"
Information:
\n
"
+
samplerate_str
+
start_str
+
stop_str
+
groups_str
+
datasets_str
)
def
to_dict
(
self
)
->
dict
:
metadata
=
self
.
metadata
...
...
@@ -151,7 +166,7 @@ class __CsvInfo__(__RawInfo__):
"
metadata
"
:
metadata
,
"
groups_and_datasets
"
:
groups_and_datasets
,
"
datafile
"
:
self
.
datafile
,
"
datasets_str
"
:
datasets_str
"
datasets_str
"
:
datasets_str
,
}
...
...
@@ -166,7 +181,7 @@ class __HDF5Info__(__RawInfo__):
"
SampleRate
"
:
0
,
"
AcqTime
"
:
0
,
"
StartTime
"
:
dt
.
datetime
.
now
().
astimezone
(),
"
StopTime
"
:
dt
.
datetime
(
1970
,
1
,
2
,
1
,
1
,
1
).
astimezone
(),
"
StopTime
"
:
dt
.
datetime
(
1970
,
1
,
2
,
1
,
1
,
1
).
astimezone
(),
}
self
.
datafile
=
datafile
self
.
tmp
=
pd
.
DataFrame
()
...
...
@@ -176,29 +191,34 @@ class __HDF5Info__(__RawInfo__):
def
__get_metadata__
(
self
)
->
None
:
with
h5py
.
File
(
self
.
datafile
,
"
r
"
)
as
file
:
file
.
visititems
(
self
.
visitor_function
)
self
.
gpds
=
pd
.
DataFrame
(
self
.
gpds
,
columns
=
[
"
grna
"
,
"
StartTime
"
,
"
StopTime
"
])
self
.
tmp
[[
"
Group
"
,
"
Dataset
"
]]
=
self
.
gpds
.
grna
.
str
.
split
(
"
/
"
,
expand
=
True
)
self
.
gpds
=
pd
.
DataFrame
(
self
.
gpds
,
columns
=
[
"
grna
"
,
"
StartTime
"
,
"
StopTime
"
])
self
.
tmp
[[
"
Group
"
,
"
Dataset
"
]]
=
self
.
gpds
.
grna
.
str
.
split
(
"
/
"
,
expand
=
True
)
self
.
tmp
[
"
StartTime
"
]
=
self
.
gpds
[
"
StartTime
"
]
self
.
tmp
[
"
StopTime
"
]
=
self
.
gpds
[
"
StopTime
"
]
self
.
tmp
=
self
.
tmp
[[
"
StartTime
"
,
"
StopTime
"
,
"
Group
"
,
"
Dataset
"
]]
def
__str__
(
self
)
->
str
:
samplerate_str
=
str
(
f
'
Sample Rate:
{
self
.
metadata
[
"
SampleRate
"
]
}
Hz
\n
'
)
samplerate_str
=
str
(
f
'
Sample Rate:
{
self
.
metadata
[
"
SampleRate
"
]
}
Hz
\n
'
)
acq_time_str
=
str
(
f
'
Acquisition Time per Dataset:
{
self
.
metadata
[
"
AcqTime
"
]
}
s
\n
'
)
f
'
Acquisition Time per Dataset:
{
self
.
metadata
[
"
AcqTime
"
]
}
s
\n
'
)
start_str
=
str
(
f
'
Measurement Start:
{
self
.
metadata
[
"
StartTime
"
]
}
\n
'
)
stop_str
=
str
(
f
'
Measurement End:
{
self
.
metadata
[
"
StopTime
"
]
}
\n
'
)
groups_str
=
"
,
"
.
join
(
str
(
x
)
for
x
in
self
.
groups_and_datasets
.
Group
.
unique
())
groups_str
=
"
,
"
.
join
(
str
(
x
)
for
x
in
self
.
groups_and_datasets
.
Group
.
unique
())
groups_str
=
str
(
f
"
Groups:
{
groups_str
}
\n
"
)
datasets_str
=
"
,
"
.
join
(
str
(
x
)
for
x
in
self
.
groups_and_datasets
.
Dataset
.
unique
())
str
(
x
)
for
x
in
self
.
groups_and_datasets
.
Dataset
.
unique
()
)
datasets_str
=
str
(
f
"
Datasets:
{
datasets_str
}
\n
"
)
return
(
"
Information:
\n
"
+
samplerate_str
+
acq_time_str
+
start_str
+
stop_str
+
groups_str
+
datasets_str
)
return
(
"
Information:
\n
"
+
samplerate_str
+
acq_time_str
+
start_str
+
stop_str
+
groups_str
+
datasets_str
)
def
visitor_function
(
self
,
h5name
,
h5obj
)
->
None
:
"""
Summary.
"""
...
...
@@ -221,24 +241,29 @@ class __HDF5Info__(__RawInfo__):
metadata
=
self
.
metadata
groups_and_datasets
=
self
.
groups_and_datasets
.
to_dict
()
filename
=
self
.
datafile
temp_df
=
self
.
groups_and_datasets
.
drop
([
'
StopTime
'
,
'
Group
'
],
axis
=
1
)
temp_df
[
'
StartTime
'
]
=
temp_df
[
'
StartTime
'
].
dt
.
strftime
(
"
%X
"
)
values
=
list
(
temp_df
[[
'
Dataset
'
,
'
StartTime
'
]].
agg
(
'
at
'
.
join
,
axis
=
1
))
temp_df
=
self
.
groups_and_datasets
.
drop
([
"
StopTime
"
,
"
Group
"
],
axis
=
1
)
temp_df
[
"
StartTime
"
]
=
temp_df
[
"
StartTime
"
].
dt
.
strftime
(
"
%X
"
)
values
=
list
(
temp_df
[[
"
Dataset
"
,
"
StartTime
"
]].
agg
(
"
at
"
.
join
,
axis
=
1
))
labels
=
temp_df
[
"
Dataset
"
]
res
=
dict
(
map
(
lambda
i
,
j
:
(
i
,
j
)
,
labels
,
values
))
res
=
dict
(
map
(
lambda
i
,
j
:
(
i
,
j
),
labels
,
values
))
return
{
"
metadata
"
:
metadata
,
"
groups_and_datasets
"
:
groups_and_datasets
,
"
datafile
"
:
filename
,
"
datasets_str
"
:
res
"
datasets_str
"
:
res
,
}
class
__FromDictInfo__
(
__RawInfo__
):
def
__init__
(
self
,
dictionary
:
dict
)
->
None
:
self
.
dictionary
=
dictionary
self
.
metadata
=
dictionary
[
"
metadata
"
]
self
.
groups_and_datasets
=
pd
.
DataFrame
(
dictionary
[
"
groups_and_datasets
"
])
self
.
datafile
=
dictionary
[
"
datafile
"
]
def
to_dict
(
self
)
->
dict
:
return
self
.
dictonary
def
get_info
(
datafile
:
str
=
""
)
->
__RawInfo__
:
if
datafile
==
""
:
...
...
@@ -252,5 +277,6 @@ def get_info(datafile: str = "") -> __RawInfo__:
else
:
return
__HDF5Info__
()
def
import_info_dict
(
rawinfo_dic
:
dict
)
->
__RawInfo__
:
return
__FromDictInfo__
(
rawinfo_dic
)
\ No newline at end of file
def
import_info_dict
(
rawinfo_dic
:
str
)
->
__RawInfo__
:
return
__FromDictInfo__
(
rawinfo_dic
)
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