本文整理汇总了Python中dxtbx.datablock.DataBlockFactory.from_json_file方法的典型用法代码示例。如果您正苦于以下问题:Python DataBlockFactory.from_json_file方法的具体用法?Python DataBlockFactory.from_json_file怎么用?Python DataBlockFactory.from_json_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dxtbx.datablock.DataBlockFactory
的用法示例。
在下文中一共展示了DataBlockFactory.from_json_file方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tst_with_external_lookup
# 需要导入模块: from dxtbx.datablock import DataBlockFactory [as 别名]
# 或者: from dxtbx.datablock.DataBlockFactory import from_json_file [as 别名]
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'
示例2: run
# 需要导入模块: from dxtbx.datablock import DataBlockFactory [as 别名]
# 或者: from dxtbx.datablock.DataBlockFactory import from_json_file [as 别名]
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'
示例3: from_string
# 需要导入模块: from dxtbx.datablock import DataBlockFactory [as 别名]
# 或者: from dxtbx.datablock.DataBlockFactory import from_json_file [as 别名]
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]
示例4: ini_datablock
# 需要导入模块: from dxtbx.datablock import DataBlockFactory [as 别名]
# 或者: from dxtbx.datablock.DataBlockFactory import from_json_file [as 别名]
def ini_datablock(self, json_file_path):
if json_file_path is not None:
try:
datablocks = DataBlockFactory.from_json_file(json_file_path)
# TODO check length of datablock for safety
datablock = datablocks[0]
self.my_sweep = datablock.extract_sweeps()[0]
self.img_select.clear()
except BaseException as e:
# We don't want to catch bare exceptions but don't know
# what this was supposed to catch. Log it.
logger.error(
"Caught unknown exception type %s: %s", type(e).__name__, e
)
logger.debug("Failed to load images from datablock.json")
try:
logger.debug(
"self.my_sweep.get_array_range() = %s",
self.my_sweep.get_array_range(),
)
n_of_imgs = len(self.my_sweep.indices())
logger.debug("n_of_imgs = %s", n_of_imgs)
self.img_select.setMaximum(n_of_imgs)
self.img_select.setMinimum(1)
self.img_step.setMaximum(n_of_imgs / 2)
self.img_step.setMinimum(1)
self.num_of_imgs_to_add.setMaximum(n_of_imgs)
self.num_of_imgs_to_add.setMinimum(1)
except BaseException as e:
# We don't want to catch bare exceptions but don't know
# what this was supposed to catch. Log it.
logger.error(
"Caught unknown exception type %s: %s", type(e).__name__, e
)
logger.debug("Failed to set up IMG control dialog")
self.btn_first_clicked()
self.ini_contrast()
self.set_img()
QTimer.singleShot(1000, self.scale2border)
示例5: load_reference_geometry
# 需要导入模块: from dxtbx.datablock import DataBlockFactory [as 别名]
# 或者: from dxtbx.datablock.DataBlockFactory import from_json_file [as 别名]
def load_reference_geometry(self):
if self.params.input.reference_geometry is None: return
try:
ref_datablocks = DataBlockFactory.from_json_file(self.params.input.reference_geometry, check_format=False)
except Exception:
ref_datablocks = None
if ref_datablocks is None:
from dxtbx.model.experiment.experiment_list import ExperimentListFactory
try:
ref_experiments = ExperimentListFactory.from_json_file(self.params.input.reference_geometry, check_format=False)
except Exception:
raise Sorry("Couldn't load geometry file %s"%self.params.input.reference_geometry)
assert len(ref_experiments.detectors()) == 1
self.reference_detector = ref_experiments.detectors()[0]
else:
assert len(ref_datablocks) == 1 and len(ref_datablocks[0].unique_detectors()) == 1
self.reference_detector = ref_datablocks[0].unique_detectors()[0]
示例6: do_import
# 需要导入模块: from dxtbx.datablock import DataBlockFactory [as 别名]
# 或者: from dxtbx.datablock.DataBlockFactory import from_json_file [as 别名]
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]
示例7: exercise_spotfinder
# 需要导入模块: from dxtbx.datablock import DataBlockFactory [as 别名]
# 或者: from dxtbx.datablock.DataBlockFactory import from_json_file [as 别名]
def exercise_spotfinder():
if not libtbx.env.has_module("dials_regression"):
print "Skipping exercise_spotfinder: dials_regression not present"
return
data_dir = libtbx.env.find_in_repositories(relative_path="dials_regression/centroid_test_data", test=os.path.isdir)
template = glob(os.path.join(data_dir, "centroid*.cbf"))
args = ["dials.find_spots", " ".join(template), "output.reflections=spotfinder.pickle", "output.shoeboxes=True"]
result = easy_run.fully_buffered(command=" ".join(args)).raise_if_errors()
assert os.path.exists("spotfinder.pickle")
with open("spotfinder.pickle", "rb") as f:
reflections = pickle.load(f)
assert len(reflections) == 653, len(reflections)
refl = reflections[0]
assert approx_equal(refl["intensity.sum.value"], 42)
assert approx_equal(refl["bbox"], (1398, 1400, 513, 515, 0, 1))
assert approx_equal(refl["xyzobs.px.value"], (1399.1190476190477, 514.2142857142857, 0.5))
assert "shoebox" in reflections
print "OK"
# now with a resolution filter
args = [
"dials.find_spots",
"filter.d_min=2",
"filter.d_max=15",
" ".join(template),
"output.reflections=spotfinder.pickle",
"output.shoeboxes=False",
]
result = easy_run.fully_buffered(command=" ".join(args)).raise_if_errors()
assert os.path.exists("spotfinder.pickle")
with open("spotfinder.pickle", "rb") as f:
reflections = pickle.load(f)
assert len(reflections) == 467, len(reflections)
assert "shoebox" not in reflections
print "OK"
# now with more generous parameters
args = [
"dials.find_spots",
"min_spot_size=3",
"max_separation=3",
" ".join(template),
"output.reflections=spotfinder.pickle",
]
result = easy_run.fully_buffered(command=" ".join(args)).raise_if_errors()
assert os.path.exists("spotfinder.pickle")
with open("spotfinder.pickle", "rb") as f:
reflections = pickle.load(f)
assert len(reflections) == 678, len(reflections)
print "OK"
# Now with a user defined mask
template = glob(os.path.join(data_dir, "centroid*.cbf"))
args = [
"dials.find_spots",
" ".join(template),
"output.reflections=spotfinder.pickle",
"output.shoeboxes=True",
"lookup.mask=%s" % os.path.join(data_dir, "mask.pickle"),
]
result = easy_run.fully_buffered(command=" ".join(args)).raise_if_errors()
assert os.path.exists("spotfinder.pickle")
with open("spotfinder.pickle", "rb") as f:
reflections = pickle.load(f)
from dxtbx.datablock import DataBlockFactory
datablocks = DataBlockFactory.from_json_file(os.path.join(data_dir, "datablock.json"))
assert len(datablocks) == 1
imageset = datablocks[0].extract_imagesets()[0]
detector = imageset.get_detector()
beam = imageset.get_beam()
for x, y, z in reflections["xyzobs.px.value"]:
d = detector[0].get_resolution_at_pixel(beam.get_s0(), (x, y))
assert d >= 3
# Now with a user defined mask
template = glob(os.path.join(data_dir, "centroid*.cbf"))
args = [
"dials.find_spots",
" ".join(template),
"output.reflections=spotfinder.pickle",
"output.shoeboxes=True",
"region_of_interest=800,1200,800,1200",
]
result = easy_run.fully_buffered(command=" ".join(args)).raise_if_errors()
assert os.path.exists("spotfinder.pickle")
with open("spotfinder.pickle", "rb") as f:
reflections = pickle.load(f)
x, y, z = reflections["xyzobs.px.value"].parts()
assert x.all_ge(800)
assert y.all_ge(800)
assert x.all_lt(1200)
assert y.all_lt(1200)
print "OK"
# now with XFEL stills
data_dir = libtbx.env.find_in_repositories(
relative_path="dials_regression/spotfinding_test_data", test=os.path.isdir
#.........这里部分代码省略.........