本文整理汇总了Python中pycbf.cbf_handle_struct函数的典型用法代码示例。如果您正苦于以下问题:Python cbf_handle_struct函数的具体用法?Python cbf_handle_struct怎么用?Python cbf_handle_struct使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cbf_handle_struct函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_image_volume
def get_image_volume(cbf_paths):
"""Load the image volume from the list of cbf_paths. The list of paths is
assumed to be is order from 1->n.
:param cbf_paths: The list of cbf files
:param width The width (xsize) of the volume
:param height The height (ysize) of the volume
:returns: The 3D volume array
"""
# Read the first image and get the size
cbf_handle = pycbf.cbf_handle_struct()
cbf_handle.read_file(cbf_paths[0], pycbf.MSG_DIGEST)
image = get_image(cbf_handle)
height, width = image.shape
# Initialise the image volume
num_slices = len(cbf_paths)
volume = numpy.zeros(shape=(num_slices, height, width), dtype=numpy.int32)
volume[0,:,:] = image
# For each CBF file, read the image and put into the image volume
for i, filename in enumerate(cbf_paths[1:]):
cbf_handle = pycbf.cbf_handle_struct()
cbf_handle.read_file(filename, pycbf.MSG_DIGEST)
volume[i+1,:,:] = get_image(cbf_handle)
# Return the image volume
return volume
开发者ID:biochem-fan,项目名称:dials,代码行数:29,代码来源:pycbf_extra.py
示例2: save_numpy_data_as_cbf
def save_numpy_data_as_cbf(data, size1, size2, title, cbfout, pilatus_header=None):
h = pycbf.cbf_handle_struct()
h.new_datablock(title)
h.require_category('array_data')
if pilatus_header is not None:
h.require_column('header_convention')
h.set_value('"PILATUS_1.2"')
h.require_column('header_contents')
h.set_value(pilatus_header)
h.require_category('array_data')
h.require_column('data')
elsigned = 1
if data.dtype in (numpy.uint8, numpy.uint16, numpy.uint32, numpy.uint64):
elsigned = 0
h.set_integerarray_wdims_fs(pycbf.CBF_BYTE_OFFSET, 1, data.tostring(), data.dtype.itemsize,
elsigned, len(data), "little_endian",
size1, size2, 1, 0)
h.write_file(cbfout, pycbf.CBF,
pycbf.MIME_HEADERS|pycbf.MSG_DIGEST|pycbf.PAD_4K, pycbf.ENC_NONE)
开发者ID:harumome,项目名称:kamo,代码行数:25,代码来源:cbf.py
示例3: read_image
def read_image(filename):
if os.path.splitext(filename)[1] == '.cbf':
try:
import pycbf
except ImportError:
raise NeXusError('Reading CBF files requires the pycbf module')
cbf = pycbf.cbf_handle_struct()
cbf.read_file(filename, pycbf.MSG_DIGEST)
cbf.select_datablock(0)
cbf.select_category(0)
cbf.select_column(2)
imsize = cbf.get_image_size(0)
return np.fromstring(cbf.get_integerarray_as_string(),
np.int32).reshape(imsize)
else:
try:
from nexpy.readers.tifffile import tifffile as TIFF
except ImportError:
raise NeXusError('Reading TIFF files requires the TIFF reader installed with NeXpy')
if filename.endswith('.bz2'):
import bz2
tiff_file = TIFF.TiffFile(bz2.BZ2File(filename))
else:
tiff_file = TIFF.TiffFile(filename)
return tiff_file.asarray()
开发者ID:janezd,项目名称:nexusformat,代码行数:25,代码来源:nxstack.py
示例4: open_file_return_array
def open_file_return_array(filename):
import pycbf
import numpy
# open file
cbf_handle = pycbf.cbf_handle_struct()
cbf_handle.read_file(filename, pycbf.MSG_DIGEST)
cbf_handle.rewind_datablock()
# find right datablock
cbf_handle.select_datablock(0)
cbf_handle.select_category(0)
cbf_handle.select_column(2)
cbf_handle.select_row(0)
type = cbf_handle.get_typeofvalue()
assert (type.find('bnry') > -1)
# read and reshape
image = numpy.fromstring(cbf_handle.get_integerarray_as_string(),
numpy.int32)
parameters = cbf_handle.get_integerarrayparameters_wdims()
image.shape = (parameters[10], parameters[9])
return image
开发者ID:dials,项目名称:dials_scratch,代码行数:25,代码来源:biostruct-25.py
示例5: read_metadata
def read_metadata(filename):
if filename.endswith('bz2'):
fname = os.path.splitext(filename)[0]
else:
fname = filename
if os.path.splitext(fname)[1] == '.cbf':
try:
import pycbf
except ImportError:
raise NeXusError('Reading CBF files requires the pycbf module')
cbf = pycbf.cbf_handle_struct()
cbf.read_file(fname, pycbf.MSG_DIGEST)
cbf.select_datablock(0)
cbf.select_category(0)
cbf.select_column(1)
meta_text = cbf.get_value().splitlines()
date_string = meta_text[2][2:]
time_stamp = epoch(date_string)
exposure = float(meta_text[5].split()[2])
summed_exposures = 1
return time_stamp, exposure, summed_exposures
elif os.path.exists(fname+'.metadata'):
parser = ConfigParser()
parser.read(fname+'.metadata')
return (parser.getfloat('metadata', 'timeStamp'),
parser.getfloat('metadata', 'exposureTime'),
parser.getint('metadata', 'summedExposures'))
else:
return time.time(), 1.0, 1
开发者ID:janezd,项目名称:nexusformat,代码行数:29,代码来源:nxstack.py
示例6: imgCIF
def imgCIF(cif_file):
'''Initialize a scan model from an imgCIF file.'''
cbf_handle = pycbf.cbf_handle_struct()
cbf_handle.read_file(cif_file, pycbf.MSG_DIGEST)
return scan_factory.imgCIF_H(cif_file, cbf_handle)
开发者ID:cctbx,项目名称:cctbx-playground,代码行数:7,代码来源:scan.py
示例7: _get_cbf_handle
def _get_cbf_handle(self):
try:
return self._cbf_handle
except AttributeError:
self._cbf_handle = pycbf.cbf_handle_struct()
self._cbf_handle.read_widefile(self._image_file, pycbf.MSG_DIGEST)
return self._cbf_handle
开发者ID:cctbx,项目名称:cctbx-playground,代码行数:7,代码来源:FormatCBFFull.py
示例8: load_cbf_as_numpy
def load_cbf_as_numpy(filein, quiet=True):
assert os.path.isfile(filein)
if not quiet:
print "reading", filein, "as cbf"
h = pycbf.cbf_handle_struct()
h.read_file(filein, pycbf.MSG_DIGEST)
ndimfast, ndimslow = h.get_image_size_fs(0)
arr = numpy.fromstring(h.get_image_fs_as_string(0, 4, 1, ndimfast, ndimslow), dtype=numpy.int32)
return arr, ndimfast, ndimslow
开发者ID:harumome,项目名称:kamo,代码行数:9,代码来源:cbf.py
示例9: understand
def understand(image_file):
'''Check to see if this looks like an CBF format image, i.e. we can
make sense of it.'''
cbf_handle = pycbf.cbf_handle_struct()
cbf_handle.read_widefile(image_file, pycbf.MSG_DIGEST)
#check if multiple arrays
return cbf_handle.count_elements() > 1
开发者ID:keitaroyam,项目名称:cctbx_fork,代码行数:9,代码来源:FormatCBFMultiTile.py
示例10: imgCIF
def imgCIF(cif_file):
'''Initialize a goniometer model from an imgCIF file.'''
# FIXME in here work out how to get the proper setting matrix if != 1
cbf_handle = pycbf.cbf_handle_struct()
cbf_handle.read_file(cif_file, pycbf.MSG_DIGEST)
return goniometer_factory.imgCIF_H(cbf_handle)
开发者ID:cctbx,项目名称:cctbx-playground,代码行数:9,代码来源:goniometer.py
示例11: understand
def understand(image_file):
'''Check to see if this looks like an CBF format image, i.e. we can
make sense of it.'''
try:
cbf_handle = pycbf.cbf_handle_struct()
cbf_handle.read_widefile(image_file, pycbf.MSG_DIGEST)
except Exception, e:
if 'CBFlib Error' in str(e):
return False
开发者ID:dalekreitler,项目名称:cctbx-playground,代码行数:10,代码来源:FormatCBFMultiTile.py
示例12: load_xds_special
def load_xds_special(cbfin):
h = pycbf.cbf_handle_struct()
h.read_file(cbfin, pycbf.MSG_DIGEST)
h.require_category("array_data")
h.find_column("header_contents")
header = h.get_value()
M = cbf_binary_adaptor(cbfin)
data = M.uncompress_implementation("buffer_based").uncompress_data()
#print "slow, fast=", M.dim_slow(), M.dim_fast() # can be obtained after getting data
return header, data, M.dim_slow(), M.dim_fast()
开发者ID:harumome,项目名称:kamo,代码行数:11,代码来源:cbf.py
示例13: imgCIF
def imgCIF(cif_file, sensor):
'''Initialize a detector model from an imgCIF file.'''
cbf_handle = pycbf.cbf_handle_struct()
cbf_handle.read_file(cif_file, pycbf.MSG_DIGEST)
cbf_detector = cbf_handle.construct_detector(0)
pixel = (cbf_detector.get_inferred_pixel_size(1),
cbf_detector.get_inferred_pixel_size(2))
# FIXME can probably simplify the code which follows below by
# making proper use of cctbx vector calls - should not be as
# complex as it appears to be...
origin = tuple(cbf_detector.get_pixel_coordinates(0, 0))
fast = cbf_detector.get_pixel_coordinates(0, 1)
slow = cbf_detector.get_pixel_coordinates(1, 0)
dfast = [fast[j] - origin[j] for j in range(3)]
dslow = [slow[j] - origin[j] for j in range(3)]
lfast = math.sqrt(sum([dfast[j] * dfast[j] for j in range(3)]))
lslow = math.sqrt(sum([dslow[j] * dslow[j] for j in range(3)]))
fast = tuple([dfast[j] / lfast for j in range(3)])
slow = tuple([dslow[j] / lslow for j in range(3)])
size = tuple(reversed(cbf_handle.get_image_size(0)))
try:
underload = find_undefined_value(cbf_handle)
overload = cbf_handle.get_overload(0) * dxtbx_overload_scale
trusted_range = (underload, overload)
except: # intentional
trusted_range = (0.0, 0.0)
cbf_detector.__swig_destroy__(cbf_detector)
del(cbf_detector)
# Get the sensor type
dtype = detector_factory.sensor(sensor)
# If the sensor type is PAD then create the detector with a
# parallax corrected pixel to millimeter function
#if dtype == detector_helper_sensors.SENSOR_PAD:
#px_mm = ParallaxCorrectedPxMmStrategy(0.252500934883)
#else:
px_mm = SimplePxMmStrategy()
return detector_factory.make_detector(
dtype, fast, slow, origin, pixel, size,
trusted_range, px_mm)
开发者ID:cctbx,项目名称:cctbx-playground,代码行数:53,代码来源:detector.py
示例14: read_image
def read_image(self, filename):
if self.get_image_type() == 'CBF':
import pycbf
cbf = pycbf.cbf_handle_struct()
cbf.read_file(str(filename), pycbf.MSG_DIGEST)
cbf.select_datablock(0)
cbf.select_category(0)
cbf.select_column(2)
imsize = cbf.get_image_size(0)
return np.fromstring(cbf.get_integerarray_as_string(),np.int32).reshape(imsize)
else:
return TIFF.imread(filename)
开发者ID:rayosborn,项目名称:nxpeaks,代码行数:12,代码来源:stack_images.py
示例15: imgCIF
def imgCIF(cif_file):
'''Initialize a goniometer model from an imgCIF file.'''
cbf_handle = pycbf.cbf_handle_struct()
cbf_handle.read_file(cif_file, pycbf.MSG_DIGEST)
cbf_gonio = cbf_handle.construct_goniometer()
axis, fixed = cbf_gonio_to_effective_axis_fixed(cbf_gonio)
cbf_gonio.__swig_destroy__(cbf_gonio)
del(cbf_gonio)
return goniometer_factory.make_goniometer(axis, fixed)
开发者ID:keitaroyam,项目名称:cctbx_fork,代码行数:14,代码来源:goniometer.py
示例16: load_minicbf_as_numpy
def load_minicbf_as_numpy(filein, quiet=True): # This can also read XDS special cbf
assert os.path.isfile(filein)
if not quiet:
print "reading", filein, "as minicbf"
h = pycbf.cbf_handle_struct()
h.read_file(filein, pycbf.MSG_DIGEST)
h.require_category("array_data")
h.find_column("data")
compression, binary_id, elsize, elsigned, elunsigned, elements, minelement, maxelement, bo, ndimfast, ndimmid, ndimslow, padding = h.get_integerarrayparameters_wdims()
assert elsize == 4 or elsize == 8
assert elsigned == 1
assert ndimslow <= 1
arr = numpy.fromstring(h.get_integerarray_as_string(), dtype=numpy.int32 if elsize==4 else numpy.int64)
return arr, ndimfast, ndimmid
开发者ID:harumome,项目名称:kamo,代码行数:14,代码来源:cbf.py
示例17: understand
def understand(image_file):
'''Check to see if this looks like an CSPD CBF format image, i.e. we can
make sense of it.'''
cbf_handle = pycbf.cbf_handle_struct()
cbf_handle.read_widefile(image_file, pycbf.MSG_DIGEST)
cbf_handle.find_category("diffrn_detector")
if cbf_handle.count_rows() > 1:
return False # support 1 detector per file for now
cbf_handle.find_column("type")
return cbf_handle.get_value() == "CS PAD"
开发者ID:dalekreitler,项目名称:cctbx-playground,代码行数:14,代码来源:FormatCBFCspad.py
示例18: get_pilatus_header
def get_pilatus_header(cbfin):
h = pycbf.cbf_handle_struct()
if cbfin.endswith(".bz2"):
# TODO to speed up, better only bunzip2 the first part of file..
import tempfile
import bz2
junk, tmpf = tempfile.mkstemp()
open(tmpf, "wb").write(bz2.BZ2File(cbfin).read())
h.read_file(tmpf, pycbf.MSG_DIGEST)
os.remove(tmpf)
else:
h.read_file(cbfin, pycbf.MSG_DIGEST)
h.require_category("array_data")
h.find_column("header_contents")
header = h.get_value()
return header
开发者ID:harumome,项目名称:kamo,代码行数:16,代码来源:cbf.py
示例19: get_data
def get_data(self):
self.import_file = self.get_filename()
cbf = pycbf.cbf_handle_struct()
cbf.read_file(str(self.import_file), pycbf.MSG_DIGEST)
cbf.select_datablock(0)
cbf.select_category(0)
cbf.select_column(2)
imsize = cbf.get_image_size(0)
z = NXfield(np.fromstring(cbf.get_integerarray_as_string(),np.int32).reshape(imsize), name='z')
y = NXfield(range(z.shape[0]), name='y')
x = NXfield(range(z.shape[1]), name='x')
cbf.select_column(1)
notes = NXnote(type='text/plain', description='CBF Header',
data=cbf.get_value().replace('\n','\r\n'))
return NXentry(NXdata(z,(y,x)), CBF_header=notes)
开发者ID:JPHammonds,项目名称:nexpy,代码行数:17,代码来源:readcbf.py
示例20: imgCIF
def imgCIF(cif_file):
'''Initialize a detector model from an imgCIF file. N.B. the
definition of the polarization plane is not completely helpful
in this - it is the angle between the polarization plane and the
+Y laboratory frame vector.'''
d2r = math.pi / 180.0
cbf_handle = pycbf.cbf_handle_struct()
cbf_handle.read_file(cif_file, pycbf.MSG_DIGEST)
cbf_handle.find_category('axis')
# find record with equipment = source
cbf_handle.find_column('equipment')
cbf_handle.find_row('source')
# then get the vector and offset from this
direction = []
for j in range(3):
cbf_handle.find_column('vector[%d]' % (j + 1))
direction.append(cbf_handle.get_doublevalue())
# and the wavelength
wavelength = cbf_handle.get_wavelength()
# and information about the polarization - FIXME this should probably
# be a rotation about the beam not about the Z axis.
try:
polar_fraction, polar_angle = cbf_handle.get_polarization()
except: # intentional
polar_fraction = 0.999
polar_angle = 0.0
polar_plane_normal = (
math.sin(polar_angle * d2r), math.cos(polar_angle * d2r), 0.0)
return beam_factory.make_polarized_beam(
sample_to_source=direction,
wavelength=wavelength,
polarization=polar_plane_normal,
polarization_fraction=polar_fraction)
开发者ID:cctbx,项目名称:cctbx-playground,代码行数:44,代码来源:beam.py
注:本文中的pycbf.cbf_handle_struct函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论