Commit 31dac622 authored by payno's avatar payno
Browse files

Merge branch 'improve_io_edfconverter' into 'master'

edfconverter: improve file closing management

Closes #80

See merge request !79
parents a91aa312 529bb888
Pipeline #60198 passed with stages
in 6 minutes and 25 seconds
......@@ -36,7 +36,6 @@ __date__ = "27/11/2020"
from collections import namedtuple
from typing import Optional
from nxtomomill.converter.hdf5.acquisition.baseacquisition import SourceType
from nxtomomill import utils
from nxtomomill.utils import ImageKey
......@@ -167,41 +166,51 @@ def edf_to_nx(
indexes = sorted(projections_urls.keys())
first_proj_file = projections_urls[indexes[0]]
fid = fabio.open(first_proj_file.file_path())
if hasattr(fid, "header"):
hd = fid.header
else:
hd = fid.getHeader()
try:
rotangle_index = (
hd[file_keys.motor_mne_key]
.split(" ")
.index(file_keys.rot_angle_key)
)
except:
rotangle_index = -1
try:
xtrans_index = (
hd[file_keys.motor_mne_key].split(" ").index(file_keys.x_trans_key)
)
except:
xtrans_index = -1
try:
ytrans_index = (
hd[file_keys.motor_mne_key].split(" ").index(file_keys.y_trans_key)
)
except:
ytrans_index = -1
try:
ztrans_index = (
hd[file_keys.motor_mne_key].split(" ").index(file_keys.z_trans_key)
)
except:
ztrans_index = -1
if hasattr(fid, "header"):
hd = fid.header
else:
hd = fid.getHeader()
try:
rotangle_index = (
hd[file_keys.motor_mne_key]
.split(" ")
.index(file_keys.rot_angle_key)
)
except:
rotangle_index = -1
try:
xtrans_index = (
hd[file_keys.motor_mne_key]
.split(" ")
.index(file_keys.x_trans_key)
)
except:
xtrans_index = -1
try:
ytrans_index = (
hd[file_keys.motor_mne_key]
.split(" ")
.index(file_keys.y_trans_key)
)
except:
ytrans_index = -1
try:
ztrans_index = (
hd[file_keys.motor_mne_key]
.split(" ")
.index(file_keys.z_trans_key)
)
except:
ztrans_index = -1
if hasattr(fid, "bytecode"):
frame_type = fid.bytecode
else:
frame_type = fid.getByteCode()
if hasattr(fid, "bytecode"):
frame_type = fid.bytecode
else:
frame_type = fid.getByteCode()
finally:
fid.close()
fid = None
return frame_type, rotangle_index, xtrans_index, ytrans_index, ztrans_index
(
......@@ -338,19 +347,24 @@ def edf_to_nx(
" for more information)" % url.path()
)
if fabio_file.nframes == 1:
if index != 0:
raise ValueError(
"Only a single frame available. Slice %s out of range" % index
)
data = fabio_file.data
header = fabio_file.header
else:
data = fabio_file.getframe(index).data
header = fabio_file.getframe(index).header
fabio_file.close()
fabio_file = None
try:
if fabio_file.nframes == 1:
if index != 0:
raise ValueError(
"Only a single frame available. Slice %s out of range"
% index
)
data = fabio_file.data
header = fabio_file.header
else:
data = fabio_file.getframe(index).data
header = fabio_file.getframe(index).header
except Exception as e:
data = None
header = None
finally:
fabio_file.close()
fabio_file = None
return data, header
if progress is not None:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment