Skip to content
Snippets Groups Projects
Commit d083025d authored by Valerio Mariani's avatar Valerio Mariani
Browse files

Fixed namespace problems in cfelfabio modules

parent 3b858a1d
No related branches found
No related tags found
No related merge requests found
# 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))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment