summaryrefslogtreecommitdiff
path: root/silx/app/convert.py
diff options
context:
space:
mode:
Diffstat (limited to 'silx/app/convert.py')
-rw-r--r--silx/app/convert.py48
1 files changed, 14 insertions, 34 deletions
diff --git a/silx/app/convert.py b/silx/app/convert.py
index a8c2783..7e601ce 100644
--- a/silx/app/convert.py
+++ b/silx/app/convert.py
@@ -23,29 +23,23 @@
# ############################################################################*/
"""Convert silx supported data files into HDF5 files"""
+__authors__ = ["P. Knobel"]
+__license__ = "MIT"
+__date__ = "05/02/2019"
+
import ast
import os
import argparse
from glob import glob
import logging
-import numpy
import re
import time
+import numpy
+import six
import silx.io
from silx.io.specfile import is_specfile
-from silx.third_party import six
-
-try:
- from silx.io import fabioh5
-except ImportError:
- fabioh5 = None
-
-
-__authors__ = ["P. Knobel"]
-__license__ = "MIT"
-__date__ = "12/09/2017"
-
+from silx.io import fabioh5
_logger = logging.getLogger(__name__)
"""Module logger"""
@@ -306,20 +300,14 @@ def main(argv):
_logger.debug("Backtrace", exc_info=True)
hdf5plugin = None
+ import h5py
+
try:
- import h5py
from silx.io.convert import write_to_h5
except ImportError:
_logger.debug("Backtrace", exc_info=True)
- h5py = None
write_to_h5 = None
- if h5py is None:
- message = "Module 'h5py' is not installed but is mandatory."\
- + " You can install it using \"pip install h5py\"."
- _logger.error(message)
- return -1
-
if hdf5plugin is None:
message = "Module 'hdf5plugin' is not installed. It supports additional hdf5"\
+ " compressions. You can install it using \"pip install hdf5plugin\"."
@@ -455,7 +443,11 @@ def main(argv):
create_dataset_args["chunks"] = chunks
if options.compression is not None:
- create_dataset_args["compression"] = options.compression
+ try:
+ compression = int(options.compression)
+ except ValueError:
+ compression = options.compression
+ create_dataset_args["compression"] = compression
if options.compression_opts is not None:
create_dataset_args["compression_opts"] = options.compression_opts
@@ -470,18 +462,6 @@ def main(argv):
not contains_specfile(options.input_files) and
not options.add_root_group) or options.file_pattern is not None:
# File series -> stack of images
- if fabioh5 is None:
- # return a helpful error message if fabio is missing
- try:
- import fabio
- except ImportError:
- _logger.error("The fabio library is required to convert"
- " edf files. Please install it with 'pip "
- "install fabio` and try again.")
- else:
- # unexpected problem in silx.io.fabioh5
- raise
- return -1
input_group = fabioh5.File(file_series=options.input_files)
if hdf5_path != "/":
# we want to append only data and headers to an existing file