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
nxtomomill
Commits
01f1f1b6
Commit
01f1f1b6
authored
Nov 08, 2021
by
Henri Payno
Browse files
[edf2nx] add options to provide `sample_name`, `title`, `instrument_name` and `source_name`
parent
b91d3ab1
Pipeline
#59539
passed with stages
in 6 minutes and 20 seconds
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
nxtomomill/app/edf2nx.py
View file @
01f1f1b6
...
...
@@ -59,8 +59,6 @@ Application to convert a tomo dataset written in edf into and hdf5/nexus file.
y translation key in EDF HEADER
--z_trans_key Z_TRANS_KEY
z translation key in EDF HEADER
"""
__authors__
=
[
"C. Nemoz"
,
"H. Payno"
,
"A.Sole"
]
...
...
@@ -70,6 +68,8 @@ __date__ = "16/01/2020"
import
argparse
import
logging
from
nxtomomill.converter.hdf5.acquisition.baseacquisition
import
SourceType
from
nxtomomill
import
utils
from
nxtomomill
import
converter
from
nxtomomill.utils
import
Progress
...
...
@@ -143,6 +143,15 @@ def main(argv):
parser
.
add_argument
(
"--z_trans_key"
,
default
=
EDF_Z_TRANS
,
help
=
"z translation key in EDF HEADER"
)
parser
.
add_argument
(
"--sample_name"
,
default
=
None
,
help
=
"name of the sample"
)
parser
.
add_argument
(
"--title"
,
default
=
None
,
help
=
"title"
)
parser
.
add_argument
(
"--instrument_name"
,
default
=
None
,
help
=
"instrument name used"
)
parser
.
add_argument
(
"--source_name"
,
default
=
"ESRF"
,
help
=
"name of the source used"
)
parser
.
add_argument
(
"--source_type"
,
default
=
SourceType
.
SYNCHROTRON_X_RAY_SOURCE
,
help
=
"type of the source used"
,
)
options
=
parser
.
parse_args
(
argv
[
1
:])
...
...
@@ -167,6 +176,11 @@ def main(argv):
file_extension
=
options
.
file_extension
,
file_keys
=
file_keys
,
progress
=
Progress
(
""
),
sample_name
=
options
.
sample_name
,
title
=
options
.
title
,
instrument_name
=
options
.
instrument_name
,
source_name
=
options
.
source_name
,
source_type
=
options
.
source_type
,
)
...
...
nxtomomill/converter/edf/edfconverter.py
View file @
01f1f1b6
...
...
@@ -35,6 +35,9 @@ __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
from
nxtomomill.converter.version
import
version
as
converter_version
...
...
@@ -98,6 +101,11 @@ def edf_to_nx(
file_extension
:
str
,
file_keys
:
EDFFileKeys
=
DEFAULT_EDF_KEYS
,
progress
=
None
,
sample_name
:
Optional
[
str
]
=
None
,
title
:
Optional
[
str
]
=
None
,
instrument_name
:
Optional
[
str
]
=
None
,
source_name
:
Optional
[
str
]
=
None
,
source_type
:
Optional
[
SourceType
]
=
None
,
)
->
tuple
:
"""
Convert an edf file to a nexus file.
...
...
@@ -108,6 +116,11 @@ def edf_to_nx(
:param file_extension:
:param file_keys:
:param progress:
:param Optional[str] sample_name: name of the sample
:param Optional[str] title: dataset title
:param Optional[str] instrument_name: name of the instrument used
:param Optional[str] source_name: name of the source (most likely ESRF)
:param Optional[str] source_type: type of the source (most likely "Synchrotron X-ray Source")
:return: (nexus_file, entry)
:rtype:tuple
"""
...
...
@@ -121,6 +134,9 @@ def edf_to_nx(
)
_logger
.
info
(
"Output file will be "
+
fileout_h5
)
if
source_type
is
not
None
:
source_type
=
SourceType
.
from_value
(
source_type
)
DARK_ACCUM_FACT
=
True
with
HDF5File
(
fileout_h5
,
"w"
)
as
h5d
:
proj_urls
=
scan
.
get_proj_urls
(
scan
=
scan
.
path
)
...
...
@@ -212,7 +228,26 @@ def edf_to_nx(
dtype
=
numpy
.
int32
,
)
h5d
[
"/entry/sample/name"
]
=
os
.
path
.
basename
(
scan
.
path
)
h5d
[
"/entry/title"
]
=
(
title
if
title
is
not
None
else
os
.
path
.
basename
(
scan
.
path
)
)
if
sample_name
is
None
:
try
:
sample_name
=
os
.
path
.
abspath
(
scan
.
path
).
split
(
os
.
sep
)[
-
3
:]
except
:
sample_name
=
"unknow"
h5d
[
"/entry/sample/name"
]
=
sample_name
if
instrument_name
is
not
None
:
instrument_grp
=
h5d
[
"/entry"
].
require_group
(
"instrument"
)
instrument_grp
[
"name"
]
=
instrument_name
if
source_name
is
not
None
:
source_grp
=
h5d
[
"/entry/instrument"
].
require_group
(
"source"
)
source_grp
[
"name"
]
=
source_name
if
source_type
is
not
None
:
source_grp
=
h5d
[
"/entry/instrument"
].
require_group
(
"source"
)
source_grp
[
"type"
]
=
source_type
.
value
proj_angle
=
scan
.
scan_range
/
scan
.
tomo_n
...
...
@@ -551,6 +586,9 @@ def edf_to_nx(
h5d
[
"/entry/instrument/detector/data"
].
attrs
[
"interpretation"
]
=
u
"image"
h5d
[
"/entry/sample"
].
attrs
[
"NX_class"
]
=
u
"NXsample"
h5d
[
"/entry/definition"
]
=
"NXtomo"
source_grp
=
h5d
[
"/entry/instrument"
].
get
(
"source"
,
None
)
if
source_grp
is
not
None
and
"NX_class"
not
in
source_grp
.
attrs
:
source_grp
.
attrs
[
"NX_class"
]
=
"NXsource"
h5d
.
flush
()
...
...
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