Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tomotools
tomoscan
Commits
2e339977
Commit
2e339977
authored
Mar 25, 2021
by
Pierre Paleo
Browse files
Add check_virtual_sources_exist
parent
bf3ea398
Pipeline
#43744
failed with stages
in 2 minutes and 31 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
tomoscan/io.py
View file @
2e339977
...
...
@@ -127,3 +127,36 @@ def isErrno(e, errno):
"""
# Because e.__cause__ is None for chained exceptions
return
"errno = {}"
.
format
(
errno
)
in
""
.
join
(
traceback
.
format_exc
())
def
check_virtual_sources_exist
(
fname
,
data_path
):
"""
Check that a virtual dataset points to actual data.
Parameters
----------
fname: str
HDF5 file path
data_path: str
Path within the HDF5 file
Returns
--------
res: bool
Whether the virtual dataset points to actual data.
"""
with
HDF5File
(
fname
,
"r"
)
as
f
:
if
data_path
not
in
f
:
print
(
"No dataset %s in file %s"
%
(
data_path
,
fname
))
return
False
dptr
=
f
[
data_path
]
if
not
dptr
.
is_virtual
:
return
True
for
vsource
in
dptr
.
virtual_sources
():
vsource_fname
=
os
.
path
.
join
(
os
.
path
.
dirname
(
dptr
.
file
.
filename
),
vsource
.
file_name
)
if
not
os
.
path
.
isfile
(
vsource_fname
):
print
(
"No such file: %s"
%
vsource_fname
)
return
False
elif
not
check_virtual_sources_exist
(
vsource_fname
,
vsource
.
dset_name
):
print
(
"Error with virtual source %s"
%
vsource_fname
)
return
False
return
True
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment