本文整理汇总了Python中dxtbx.datablock.DataBlockFactory类的典型用法代码示例。如果您正苦于以下问题:Python DataBlockFactory类的具体用法?Python DataBlockFactory怎么用?Python DataBlockFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DataBlockFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tst_json
def tst_json(self):
from dxtbx.datablock import DataBlockFactory
from dxtbx.imageset import ImageSweep
filenames = self.multiple_block_filenames()
blocks1 = DataBlockFactory.from_filenames(filenames)
blocks2 = self.encode_json_then_decode(blocks1)
assert(len(blocks2) == len(blocks1))
for b1, b2 in zip(blocks1, blocks2):
assert(b1.format_class() == b2.format_class())
assert(b1 == b2)
assert(blocks1 == blocks2)
filenames = self.multiple_block_filenames()
blocks1 = DataBlockFactory.from_filenames(filenames)
blocks2 = self.encode_json_then_decode(blocks1, check_format=False)
assert(len(blocks2) == len(blocks1))
for b1, b2 in zip(blocks1, blocks2):
for im1, im2 in zip(b1.extract_imagesets(), b2.extract_imagesets()):
assert(len(im1) == len(im2))
if isinstance(im1, ImageSweep):
assert(isinstance(im2, ImageSweep))
assert(im1.get_beam() == im2.get_beam())
assert(im1.get_detector() == im2.get_detector())
assert(im1.get_goniometer() == im2.get_goniometer())
assert(im1.get_scan() == im2.get_scan())
else:
assert(not isinstance(im2, ImageSweep))
for i in xrange(len(im1)):
assert(im1.get_beam(i) == im2.get_beam(i))
assert(im1.get_detector(i) == im2.get_detector(i))
print 'OK'
示例2: to_datablocks
def to_datablocks(self):
''' Return the experiment list as a datablock list.
This assumes that the experiment contains 1 datablock.'''
from dxtbx.datablock import DataBlockFactory
# Convert the experiment list to dict
obj = self.to_dict()
# Convert the dictionary to a datablock dictionary
obj['__id__'] = 'DataBlock'
for e in obj['experiment']:
iid = e['imageset']
imageset = obj['imageset'][iid]
if 'beam' in e:
imageset['beam'] = e['beam']
if 'detector' in e:
imageset['detector'] = e['detector']
if 'goniometer' in e:
imageset['goniometer'] = e['goniometer']
if 'scan' in e:
imageset['scan'] = e['scan']
# Remove the experiments
del obj['experiment']
# Create the datablock
return DataBlockFactory.from_dict([obj])
示例3: run
def run(self):
params, options = self.parser.parse_args(show_diff_phil=True)
assert params.input.single_img is not None
filebase = os.path.splitext(params.input.single_img)[0]
for item in dir(params.output):
value = getattr(params.output, item)
try:
if "%s" in value:
setattr(params.output, item, value % filebase)
except Exception:
pass
self.params = params
self.options = options
# load the image
img = dxtbx.load(params.input.single_img)
imgset = MemImageSet([img])
datablock = DataBlockFactory.from_imageset(imgset)[0]
# Cannot export MemImageSets
# if self.params.output.datablock_filename:
# from dxtbx.datablock import DataBlockDumper
# dump = DataBlockDumper(datablock)
# dump.as_json(self.params.output.datablock_filename)
observed = self.find_spots(datablock)
experiments, indexed = self.index(datablock, observed)
experiments = self.refine(experiments, indexed)
integrated = self.integrate(experiments, indexed)
示例4: tst_from_datablock
def tst_from_datablock(self):
from dxtbx.imageset import ImageSweep, NullReader, SweepFileList
from dxtbx.model import Beam, Detector, Goniometer, Scan
from dxtbx.datablock import DataBlockFactory
from dxtbx.model.crystal import crystal_model
imageset = ImageSweep(NullReader(SweepFileList("filename%01d.cbf", (0, 2))))
imageset.set_beam(Beam())
imageset.set_detector(Detector())
imageset.set_goniometer(Goniometer())
imageset.set_scan(Scan((1, 2), (0, 1)))
crystal = crystal_model((1, 0, 0), (0, 1, 0), (0, 0, 1), space_group_symbol=0)
datablock = DataBlockFactory.from_imageset(imageset)
experiments = ExperimentListFactory.from_datablock_and_crystal(
datablock, crystal)
assert(len(experiments) == 1)
assert(experiments[0].imageset is not None)
assert(experiments[0].beam is not None)
assert(experiments[0].detector is not None)
assert(experiments[0].goniometer is not None)
assert(experiments[0].scan is not None)
assert(experiments[0].crystal is not None)
print 'OK'
pass
示例5: run
def run(self):
from os.path import join, exists
from libtbx import easy_run
import os
input_filename = join(self.path, "datablock.json")
output_filename = "output_datablock.json"
mask_filename = join(self.path, "lookup_mask.pickle")
easy_run.fully_buffered(
['dials.apply_mask',
'input.datablock=%s' % input_filename,
'input.mask=%s' % mask_filename,
'output.datablock=%s' % output_filename]).raise_if_errors()
from dxtbx.datablock import DataBlockFactory
datablocks = DataBlockFactory.from_json_file(output_filename)
assert len(datablocks) == 1
imagesets = datablocks[0].extract_imagesets()
assert len(imagesets) == 1
imageset = imagesets[0]
assert imageset.external_lookup.mask.filename == mask_filename
print 'OK'
示例6: tst_with_external_lookup
def tst_with_external_lookup(self):
from dxtbx.datablock import DataBlockFactory
from dxtbx.imageset import ImageSweep
from os.path import join
filename = join(self.dials_regression, "centroid_test_data",
"datablock_with_lookup.json")
blocks = DataBlockFactory.from_json_file(filename)
assert(len(blocks) == 1)
imageset = blocks[0].extract_imagesets()[0]
assert imageset.external_lookup.mask.data is not None
assert imageset.external_lookup.gain.data is not None
assert imageset.external_lookup.pedestal.data is not None
assert imageset.external_lookup.mask.filename is not None
assert imageset.external_lookup.gain.filename is not None
assert imageset.external_lookup.pedestal.filename is not None
assert imageset.external_lookup.mask.data.all_eq(True)
assert imageset.external_lookup.gain.data.all_eq(1)
assert imageset.external_lookup.pedestal.data.all_eq(0)
blocks = self.encode_json_then_decode(blocks)
assert(len(blocks) == 1)
imageset = blocks[0].extract_imagesets()[0]
assert imageset.external_lookup.mask.data is not None
assert imageset.external_lookup.gain.data is not None
assert imageset.external_lookup.pedestal.data is not None
assert imageset.external_lookup.mask.filename is not None
assert imageset.external_lookup.gain.filename is not None
assert imageset.external_lookup.pedestal.filename is not None
assert imageset.external_lookup.mask.data.all_eq(True)
assert imageset.external_lookup.gain.data.all_eq(1)
assert imageset.external_lookup.pedestal.data.all_eq(0)
print 'OK'
示例7: do_import
def do_import(filename):
info("Loading %s"%os.path.basename(filename))
datablocks = DataBlockFactory.from_filenames([filename])
if len(datablocks) == 0:
raise Abort("Could not load %s"%filename)
if len(datablocks) > 1:
raise Abort("Got multiple datablocks from file %s"%filename)
return datablocks[0]
示例8: __init__
def __init__(self,
source_image=None,
object_folder=None,
gain = 0.32,
params=None):
'''Initialise the script.'''
from dials.util.options import OptionParser
from dxtbx.datablock import DataBlockFactory
from dials.array_family import flex
from iotbx.phil import parse
from xfel.command_line.xfel_process import phil_scope
phil_scope = parse('''
include scope xfel.command_line.xtc_process.phil_scope
''', process_includes=True)
sub_phil_scope = parse('''
output {
cxi_merge_picklefile = None
.type = str
.help = Output integration results for each color data to separate cctbx.xfel-style pickle files
}
indexing {
stills {
ewald_proximity_resolution_cutoff = 2.0
.type = float
.help = For calculating the area under the green curve, or the acceptable
.help = volume of reciprocal space for spot prediction, use this high-resolution cutoff
}
}
cxi_merge {
include scope xfel.command_line.cxi_merge.master_phil
}
''', process_includes=True)
phil_scope.adopt_scope(sub_phil_scope)
# Create the parser
self.parser = OptionParser(
phil=phil_scope,
read_datablocks=True,
read_datablocks_from_images=True)
self.params = params
self.img = [source_image]
self.obj_base = object_folder
self.phil = phil_scope.extract()
with misc.Capturing() as junk_output:
self.datablock = DataBlockFactory.from_filenames(self.img)[0]
self.obj_filename = "int_{}".format(os.path.basename(self.img[0]))
self.phil.output.cxi_merge_picklefile = os.path.join(self.obj_base, self.img[0])
示例9: from_string
def from_string(self, s):
from dxtbx.datablock import DataBlockFactory
from os.path import exists
from libtbx.utils import Sorry
if s is None:
return None
if s not in self.cache:
if not exists(s):
raise Sorry('File %s does not exist' % s)
self.cache[s] = FilenameDataWrapper(s,
DataBlockFactory.from_json_file(s,
check_format=self._check_format))
return self.cache[s]
示例10: work
def work(filename, cl=[]):
from dials.command_line.find_spots import phil_scope as params
from dxtbx.datablock import DataBlockFactory
from dials.array_family import flex
interp = params.command_line_argument_interpreter()
for cla in cl:
params = params.fetch(interp.process(cla))
datablock = DataBlockFactory.from_filenames([filename])[0]
reflections = flex.reflection_table.from_observations(
datablock, params.extract())
detector = datablock.unique_detectors()[0]
beam = datablock.unique_beams()[0]
return analyse(reflections, detector, beam)
示例11: datablock
def datablock(filename, check_format=True):
''' Load a given JSON or pickle file.
Params:
filename The input filename
Returns:
The datablock
'''
from dxtbx.datablock import DataBlockFactory
return DataBlockFactory.from_serialized_format(
filename, check_format=check_format)
示例12: do_import
def do_import(filename):
logger.info("Loading %s"%os.path.basename(filename))
try:
datablocks = DataBlockFactory.from_json_file(filename)
except ValueError:
datablocks = DataBlockFactory.from_filenames([filename])
if len(datablocks) == 0:
raise Abort("Could not load %s"%filename)
if len(datablocks) > 1:
raise Abort("Got multiple datablocks from file %s"%filename)
# Ensure the indexer and downstream applications treat this as set of stills
from dxtbx.imageset import ImageSet
reset_sets = []
for imageset in datablocks[0].extract_imagesets():
imageset = ImageSet(imageset.reader(), imageset.indices())
imageset._models = imageset._models
imageset.set_scan(None)
imageset.set_goniometer(None)
reset_sets.append(imageset)
return DataBlockFactory.from_imageset(reset_sets)[0]
示例13: tst_pickling
def tst_pickling(self):
from dxtbx.datablock import DataBlockFactory
filenames = self.multiple_block_filenames()
blocks1 = DataBlockFactory.from_filenames(filenames)
blocks2 = self.pickle_then_unpickle(blocks1)
assert(len(blocks2) == len(blocks1))
for b1, b2 in zip(blocks1, blocks2):
assert(b1.format_class() == b2.format_class())
assert(b1 == b2)
assert(blocks1 == blocks2)
print 'OK'
示例14: tst_create_multiple_sweeps
def tst_create_multiple_sweeps(self):
from dxtbx.datablock import DataBlockFactory
filenames = self.multiple_sweep_filenames()
blocks = DataBlockFactory.from_filenames(filenames)
assert(len(blocks) == 1)
assert(blocks[0].num_images() == 6)
imageset = blocks[0].extract_imagesets()
assert(len(imageset) == 2)
sweeps = blocks[0].extract_sweeps()
assert(len(sweeps) == 2)
assert(len(sweeps[0]) == 3)
assert(len(sweeps[1]) == 3)
print 'OK'
示例15: OnChooseDirectory
def OnChooseDirectory (self, event) :
dir_name = self.dir_ctrl.GetPhilValue()
if (dir_name is not None) :
from dxtbx.datablock import DataBlockFactory
datablocks = DataBlockFactory.from_filenames([dir_name])
imagesets = datablocks[0].extract_imagesets()
self._imagesets = imagesets
#from iotbx.detectors import identify_dataset
#self._datasets = identify_dataset(dir_name)
#choices = [ d.format() for d in self._datasets ]
choices = [imgset.get_template() for imgset in self._imagesets]
self.stack_ctrl.SetItems(choices)
for i in range(len(choices)):
self.stack_ctrl.SetSelection(i)