Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cfel_fmt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dataAnalysis
cfel_fmt
Commits
d083025d
Commit
d083025d
authored
8 years ago
by
Valerio Mariani
Browse files
Options
Downloads
Patches
Plain Diff
Fixed namespace problems in cfelfabio modules
parent
3b858a1d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cfelfabio.py
+18
-44
18 additions, 44 deletions
cfelfabio.py
with
18 additions
and
44 deletions
cfelfabio.py
+
18
−
44
View file @
d083025d
# This file is part of cfelpyutils.
import
numpy
#
# cfelpyutils is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cfelpyutils is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cfelpyutils. If not, see <http://www.gnu.org/licenses/>.
"""
Utilities based on the fabio python module
This module contains utilities derived from the fabio python module.
This module allows python to understand and process several file format used in
x-ray crystallography. The utilites in this modules expand on what the fabio
module alread provides.
"""
import
fabio.cbfimage
import
fabio.cbfimage
def
read_cbf_from_stream
(
stream
):
def
read_cbf_from_stream
(
stream
):
"""
"
Reads a cbfimage object out of a data string buffer.
"""
Reads a cbfimage object out of a data string buffer.
Read a data string buffer received as a payload from the PETRAIII P11
Read a data string buffer received as a payload from the PETRAIII P11
sender,
sender,
and creates a cbfimage object from it (See the documentation of the
and creates a cbfimage object from it (See the documentation of the
fabio
fabio
python module).
python module).
Args:
Args:
stream (str): a data string buffer received from the PETRAIII P11 sender.
stream (str): a data string buffer received from the PETRAIII P11 sender.
Returns:
Returns:
cbf_obj (fabio.cbfimage): a cbfimage object containing the data
cbf_obj (fabio.cbfimage): a cbfimage object containing the data
extracted
extracted
from the string buffer.
from the string buffer.
"""
"""
cbf_obj
=
fabio
.
cbfimage
.
cbfimage
()
cbf_obj
=
fabio
.
cbfimage
.
cbfimage
()
...
@@ -51,26 +25,26 @@ def read_cbf_from_stream(stream):
...
@@ -51,26 +25,26 @@ def read_cbf_from_stream(stream):
infile
=
stream
infile
=
stream
cbf_obj
.
_readheader
(
infile
)
cbf_obj
.
_readheader
(
infile
)
if
fabio
.
cbfimage
.
CIF_BINARY_BLOCK_KEY
not
in
cbf_obj
.
fabio
.
cbfimage
.
CIF
:
if
fabio
.
cbfimage
.
CIF_BINARY_BLOCK_KEY
not
in
cbf_obj
.
cif
:
err
=
"
Not key %s in
fabio.cbfimage.
CIF, no CBF image in stream
"
%
(
fabio
.
cbfimage
.
CIF_BINARY_BLOCK_KEY
)
err
=
"
Not key %s in CIF, no CBF image in stream
"
%
(
fabio
.
cbfimage
.
CIF_BINARY_BLOCK_KEY
)
fabio
.
cbfimage
.
logger
.
error
(
err
)
logger
.
error
(
err
)
for
kv
in
cbf_obj
.
fabio
.
cbfimage
.
CIF
.
items
():
for
kv
in
cbf_obj
.
cif
.
items
():
print
(
"
%s: %s
"
%
kv
)
print
(
"
%s: %s
"
%
kv
)
raise
RuntimeError
(
err
)
raise
RuntimeError
(
err
)
if
cbf_obj
.
fabio
.
cbfimage
.
CIF
[
fabio
.
cbfimage
.
CIF_BINARY_BLOCK_KEY
]
==
"
fabio.cbfimage.
CIF Binary Section
"
:
if
cbf_obj
.
cif
[
fabio
.
cbfimage
.
CIF_BINARY_BLOCK_KEY
]
==
"
CIF Binary Section
"
:
cbf_obj
.
cbs
+=
infile
.
read
(
len
(
fabio
.
cbfimage
.
STARTER
)
+
int
(
cbf_obj
.
header
[
"
X-Binary-Size
"
])
-
len
(
cbf_obj
.
cbs
)
+
cbf_obj
.
start_binary
)
cbf_obj
.
cbs
+=
infile
.
read
(
len
(
fabio
.
cbfimage
.
STARTER
)
+
int
(
cbf_obj
.
header
[
"
X-Binary-Size
"
])
-
len
(
cbf_obj
.
cbs
)
+
cbf_obj
.
start_binary
)
else
:
else
:
if
len
(
cbf_obj
.
fabio
.
cbfimage
.
CIF
[
fabio
.
cbfimage
.
CIF_BINARY_BLOCK_KEY
])
>
int
(
cbf_obj
.
header
[
"
X-Binary-Size
"
])
+
cbf_obj
.
start_binary
+
len
(
fabio
.
cbfimage
.
STARTER
):
if
len
(
cbf_obj
.
cif
[
fabio
.
cbfimage
.
CIF_BINARY_BLOCK_KEY
])
>
int
(
cbf_obj
.
header
[
"
X-Binary-Size
"
])
+
cbf_obj
.
start_binary
+
len
(
fabio
.
cbfimage
.
STARTER
):
cbf_obj
.
cbs
=
cbf_obj
.
fabio
.
cbfimage
.
CIF
[
fabio
.
cbfimage
.
CIF_BINARY_BLOCK_KEY
][:
int
(
cbf_obj
.
header
[
"
X-Binary-Size
"
])
+
cbf_obj
.
start_binary
+
len
(
fabio
.
cbfimage
.
STARTER
)]
cbf_obj
.
cbs
=
cbf_obj
.
cif
[
fabio
.
cbfimage
.
CIF_BINARY_BLOCK_KEY
][:
int
(
cbf_obj
.
header
[
"
X-Binary-Size
"
])
+
cbf_obj
.
start_binary
+
len
(
fabio
.
cbfimage
.
STARTER
)]
else
:
else
:
cbf_obj
.
cbs
=
cbf_obj
.
fabio
.
cbfimage
.
CIF
[
fabio
.
cbfimage
.
CIF_BINARY_BLOCK_KEY
]
cbf_obj
.
cbs
=
cbf_obj
.
cif
[
fabio
.
cbfimage
.
CIF_BINARY_BLOCK_KEY
]
binary_data
=
cbf_obj
.
cbs
[
cbf_obj
.
start_binary
+
len
(
fabio
.
cbfimage
.
STARTER
):]
binary_data
=
cbf_obj
.
cbs
[
cbf_obj
.
start_binary
+
len
(
fabio
.
cbfimage
.
STARTER
):]
if
"
Content-MD5
"
in
cbf_obj
.
header
:
if
"
Content-MD5
"
in
cbf_obj
.
header
:
ref
=
fabio
.
cbfimage
.
numpy
.
string_
(
cbf_obj
.
header
[
"
Content-MD5
"
])
ref
=
numpy
.
string_
(
cbf_obj
.
header
[
"
Content-MD5
"
])
obt
=
fabio
.
cbfimage
.
md5sum
(
binary_data
)
obt
=
fabio
.
cbfimage
.
md5sum
(
binary_data
)
if
ref
!=
obt
:
if
ref
!=
obt
:
fabio
.
cbfimage
.
logger
.
error
(
"
Checksum of binary data mismatch: expected %s, got %s
"
%
(
ref
,
obt
))
logger
.
error
(
"
Checksum of binary data mismatch: expected %s, got %s
"
%
(
ref
,
obt
))
if
cbf_obj
.
header
[
"
conversions
"
]
==
"
x-CBF_BYTE_OFFSET
"
:
if
cbf_obj
.
header
[
"
conversions
"
]
==
"
x-CBF_BYTE_OFFSET
"
:
cbf_obj
.
data
=
cbf_obj
.
_readbinary_byte_offset
(
binary_data
).
astype
(
cbf_obj
.
bytecode
).
reshape
((
cbf_obj
.
dim2
,
cbf_obj
.
dim1
))
cbf_obj
.
data
=
cbf_obj
.
_readbinary_byte_offset
(
binary_data
).
astype
(
cbf_obj
.
bytecode
).
reshape
((
cbf_obj
.
dim2
,
cbf_obj
.
dim1
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment