Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tomotools
Nabu
Commits
10ce947c
Commit
10ce947c
authored
Dec 17, 2020
by
Pierre Paleo
Browse files
Merge branch 'edf' into 'master'
Support for output EDF format Closes
#211
See merge request
!101
parents
c7277a15
ab93eeca
Pipeline
#40513
failed with stages
in 4 minutes and 24 seconds
Changes
3
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
nabu/io/writer.py
View file @
10ce947c
...
...
@@ -11,6 +11,10 @@ from ..misc.utils import rescale_data
from
.config
import
export_dict_to_h5
from
.utils
import
check_h5py_version
# won't be necessary once h5py >= 3.0 required
try
:
from
silx.third_party.EdfFile
import
EdfFile
except
ImportError
:
EdfFile
=
None
try
:
from
glymur
import
Jp2k
__have_jp2k__
=
True
...
...
@@ -282,6 +286,57 @@ class TIFFWriter(Writer):
return
path
.
dirname
(
self
.
fname
)
class
EDFWriter
(
Writer
):
def
__init__
(
self
,
fname
,
start_index
=
0
,
filemode
=
"w"
):
"""
EDF (ESRF Data Format) writer.
Parameters
-----------
fname: str
Path to the output file name
start_index: int, optional
When writing a stack of images, each image is written in a dedicated file
In this case, the output is a series of files `filename_0000.tif`,
`filename_0001.edf`, etc. This parameter is the starting index for
file names.
"""
super
().
__init__
(
fname
)
self
.
filemode
=
filemode
self
.
start_index
=
start_index
def
_write_edf
(
self
,
data
,
config
=
None
,
filename
=
None
,
filemode
=
None
):
if
filename
is
None
:
filename
=
self
.
fname
edf
=
EdfFile
(
filename
)
config
=
config
or
{}
config
[
"software"
]
=
str
(
"nabu %s"
%
version
)
config
[
"date"
]
=
get_datetime
()
edf
.
WriteImage
(
config
,
data
)
edf
=
None
def
write
(
self
,
data
,
*
args
,
config
=
None
,
**
kwargs
):
if
data
.
ndim
<
3
:
self
.
_write_edf
(
data
,
config
=
config
)
return
if
(
data
.
ndim
==
3
)
and
(
data
.
shape
[
0
]
==
1
):
self
.
_write_edf
(
data
[
0
],
config
=
config
)
return
dirname
,
rel_filename
=
path
.
split
(
self
.
fname
)
prefix
,
ext
=
path
.
splitext
(
rel_filename
)
for
i
in
range
(
data
.
shape
[
0
]):
curr_rel_filename
=
prefix
+
str
(
"_%04d"
%
(
self
.
start_index
+
i
))
+
ext
fname
=
path
.
join
(
dirname
,
curr_rel_filename
)
self
.
_write_edf
(
data
[
i
],
filename
=
fname
,
config
=
config
)
def
get_filename
(
self
):
return
path
.
dirname
(
self
.
fname
)
class
JP2Writer
(
Writer
):
def
__init__
(
self
,
fname
,
start_index
=
0
,
filemode
=
"wb"
,
psnr
=
None
,
auto_convert
=
True
):
"""
...
...
@@ -379,5 +434,6 @@ Writers = {
"j2k"
:
JP2Writer
,
"jp2"
:
JP2Writer
,
"jp2k"
:
JP2Writer
,
"edf"
:
EDFWriter
,
}
nabu/resources/nabu_config.py
View file @
10ce947c
...
...
@@ -309,7 +309,7 @@ nabu_config = {
},
"file_format"
:
{
"default"
:
"hdf5"
,
"help"
:
"Output file format. Available are: hdf5, tiff, jp2"
,
"help"
:
"Output file format. Available are: hdf5, tiff, jp2
, edf
"
,
"validator"
:
output_file_format_validator
,
"type"
:
"optional"
,
},
...
...
nabu/resources/params.py
View file @
10ce947c
...
...
@@ -92,6 +92,7 @@ files_formats = {
"jp2k"
:
"jp2"
,
"j2k"
:
"jp2"
,
"jpeg2000"
:
"jp2"
,
"edf"
:
"edf"
,
}
class
FileFormat
(
Enum
):
EDF
=
"edf"
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment