Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
CaosDB Crawler
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
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
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
CaosDB Crawler
Commits
b94d7e5f
Commit
b94d7e5f
authored
2 years ago
by
Florian Spreckelsen
Browse files
Options
Downloads
Patches
Plain Diff
WIP: Begin converter classes
parent
6dc74b4a
No related branches found
No related tags found
2 merge requests
!160
STY: styling
,
!143
ENH: HDF5 Converter
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/caoscrawler/hdf5_converter.py
+62
-0
62 additions, 0 deletions
src/caoscrawler/hdf5_converter.py
with
62 additions
and
0 deletions
src/caoscrawler/hdf5_converter.py
+
62
−
0
View file @
b94d7e5f
...
@@ -25,3 +25,65 @@ except ModuleNotFoundError:
...
@@ -25,3 +25,65 @@ except ModuleNotFoundError:
"
Couldn
'
t find module h5py. Did you install the crawler package with
"
"
Couldn
'
t find module h5py. Did you install the crawler package with
"
"
its optional `h5-crawler` dependency?
"
"
its optional `h5-crawler` dependency?
"
)
)
from
typing
import
Union
from
.converters
import
convert_basic_element
,
DictElementConverter
,
SimpleFileConverter
from
.stores
import
GeneralStore
from
.structure_elements
import
StructureElement
def
__convert_attributes
(
elt
:
Union
[
h5py
.
File
,
h5py
.
Group
,
h5py
.
Dataset
]):
converted
=
[]
for
name
,
value
in
elt
.
attrs
.
items
():
converted
.
append
(
convert_basic_element
(
value
,
name
,
f
"
The value of attribute
{
name
}
has an unknown type:
{
type
(
value
)
}
.
"
))
return
converted
def
__convert_h5_elements
(
elt
:
Union
[
h5py
.
Group
,
h5py
.
Dataset
],
name
:
str
):
if
isinstance
(
elt
,
h5py
.
Group
):
return
H5GroupElement
(
name
,
elt
)
if
isinstance
(
elt
,
h5py
.
Dataset
):
return
H5DatasetElement
(
name
,
elt
)
raise
ValueError
(
"
The given element must be either a HDF5 Group or Dataset object.
"
)
class
H5GroupElement
(
StructureElement
):
def
__init__
(
self
,
name
:
str
,
value
:
h5py
.
Group
):
super
().
__init__
(
name
)
self
.
value
=
value
class
H5DatasetElement
(
StructureElement
):
def
__init__
(
self
,
name
:
str
,
value
:
h5py
.
Dataset
):
super
().
__init__
(
name
)
self
.
value
=
value
class
H5FileConverter
(
SimpleFileConverter
):
def
create_children
(
self
,
generalStore
:
GeneralStore
,
element
:
StructureElement
):
if
not
isinstance
(
element
,
File
):
raise
ValueError
(
"
create_children should have been called with a File object.
"
)
ff
=
h5py
.
File
(
element
.
path
,
'
r
'
)
children
=
[]
for
name
,
value
in
ff
.
items
():
children
.
append
(
__convert_h5_elements
(
value
,
name
))
children
.
extend
(
__convert_attributes
(
ff
))
return
children
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