def run(args): cmd_line = command_line.argument_interpreter( master_params=master_phil_scope) working_phil = cmd_line.process_and_fetch(args=args) working_phil.show() params = working_phil.extract() if params.find_spots_phil is not None: params.find_spots_phil = os.path.abspath(params.find_spots_phil) assert os.path.isfile(params.find_spots_phil) if params.index_phil is not None: params.index_phil = os.path.abspath(params.index_phil) assert os.path.isfile(params.index_phil) templates = params.template print(templates) args = [] filenames = [] for t in templates: print(t) filenames.extend(glob.glob(t)) print(filenames) from dxtbx.imageset import ImageSetFactory, ImageSweep from dxtbx.datablock import DataBlockFactory datablocks = DataBlockFactory.from_args(filenames, verbose=True) i = 0 for i, datablock in enumerate(datablocks): sweeps = datablock.extract_sweeps() for imageset in sweeps: if (isinstance(imageset, ImageSweep) and len(imageset) >= params.min_sweep_length): i += 1 print(imageset) print(imageset.get_template()) args.append((imageset.paths(), i, params)) # sort based on the first filename of each imageset args.sort(key=lambda x: x[0][0]) nproc = params.nproc results = easy_mp.parallel_map( func=run_once, iterable=args, processes=nproc, method=params.technology, qsub_command=params.qsub_command, preserve_order=True, asynchronous=False, preserve_exception_message=True, )
def run(args=None): dxtbx.util.encode_output_as_utf8() datablocks = DataBlockFactory.from_args(args or sys.argv[1:]) assert len(datablocks) == 1 detectors = datablocks[0].unique_detectors() assert len(detectors) == 1 detector = detectors[0] assert len(detector) == 1 px_mm = detector[0].get_px_mm_strategy() assert isinstance(px_mm, ParallaxCorrectedPxMmStrategy) print("Mu: %f mm^-1 " % px_mm.mu()) print("t0: %f mm" % px_mm.t0()) image_size = detector[0].get_image_size()[::-1] xcorr = flex.double(flex.grid(image_size)) ycorr = flex.double(flex.grid(image_size)) pixel_size = detector[0].get_pixel_size() for j in range(xcorr.all()[0]): for i in range(xcorr.all()[1]): x1, y1 = detector[0].pixel_to_millimeter((i, j)) x0, y0 = i * pixel_size[0], j * pixel_size[1] xcorr[j, i] = x1 - x0 ycorr[j, i] = y1 - y0 vmin = min([flex.min(xcorr), flex.min(ycorr)]) vmax = max([flex.max(xcorr), flex.max(ycorr)]) fig, ax = pylab.subplots() pylab.subplot(121) pylab.imshow(xcorr.as_numpy_array(), interpolation="none", vmin=vmin, vmax=vmax) pylab.subplot(122) im = pylab.imshow(ycorr.as_numpy_array(), interpolation="none", vmin=vmin, vmax=vmax) fig.subplots_adjust(right=0.8) cax = fig.add_axes([0.9, 0.1, 0.03, 0.8]) fig.colorbar(im, cax=cax) pylab.show()
from __future__ import division if __name__ == '__main__': import sys from dxtbx.datablock import DataBlockFactory from dxtbx.model import ParallaxCorrectedPxMmStrategy datablocks = DataBlockFactory.from_args(sys.argv[1:]) assert(len(datablocks) == 1) detectors = datablocks[0].unique_detectors() assert(len(detectors) == 1) detector = detectors[0] assert(len(detector) == 1) px_mm = detector[0].get_px_mm_strategy() assert(isinstance(px_mm, ParallaxCorrectedPxMmStrategy)) print "Mu: %f mm^-1 " % px_mm.mu() print "t0: %f mm" % px_mm.t0() from matplotlib import pylab from scitbx.array_family import flex image_size = detector[0].get_image_size()[::-1] xcorr = flex.double(flex.grid(image_size)) ycorr = flex.double(flex.grid(image_size)) pixel_size = detector[0].get_pixel_size() for j in range(xcorr.all()[0]): for i in range(xcorr.all()[1]): x1, y1 = detector[0].pixel_to_millimeter((i,j)) x0, y0 = i * pixel_size[0], j * pixel_size[1] xcorr[j,i] = x1 - x0 ycorr[j,i] = y1 - y0 vmin = min([flex.min(xcorr), flex.min(ycorr)])
help="Don't sort input files (default is True)") # Parse the command line arguments (options, args) = parser.parse_args() if len(args) == 0: parser.print_help() # Sort arguments if options.sort: args = sorted(args) # Get the data blocks from the input files # We've set verbose to print out files as they're tested. unhandled = [] datablocks = DataBlockFactory.from_args(args, verbose=options.verbose, unhandled=unhandled) # Print out any unhandled files if len(unhandled) > 0: print '-' * 80 print 'The following command line arguments were not handled:' for filename in unhandled: print ' %s' % filename # Loop through the data blocks for i, datablock in enumerate(datablocks): # Extract any sweeps sweeps = datablock.extract_sweeps()
def run(args): import os from libtbx.phil import command_line from libtbx.utils import Sorry, Usage if len(args) == 0: from cStringIO import StringIO s = StringIO() master_phil_scope.show(out=s) raise Usage("""\ dxtbx.export_bitmaps image_files [options] % s """ % s.getvalue()) from dxtbx.datablock import DataBlockFactory unhandled = [] datablocks = DataBlockFactory.from_args(args, verbose=False, unhandled=unhandled) assert len(datablocks) > 0 imagesets = datablocks[0].extract_imagesets() cmd_line = command_line.argument_interpreter( master_params=master_phil_scope) working_phil = cmd_line.process_and_fetch(args=unhandled) working_phil.show() params = working_phil.extract() brightness = params.brightness / 100 vendortype = "made up" # check that binning is a power of 2 binning = params.binning if not (binning > 0 and ((binning & (binning - 1)) == 0)): raise Sorry("binning must be a power of 2") output_dir = params.output_dir if output_dir is None: output_dir = "." elif not os.path.exists(output_dir): os.makedirs(output_dir) from rstbx.slip_viewer.tile_generation \ import _get_flex_image, _get_flex_image_multipanel for imageset in imagesets: detector = imageset.get_detector() panel = detector[0] # XXX is this inclusive or exclusive? saturation = panel.get_trusted_range()[1] for i_image, image in enumerate(imageset): if len(detector) > 1: # FIXME This doesn't work properly, as flex_image.size2() is incorrect # also binning doesn't work assert binning == 1 flex_image = _get_flex_image_multipanel( brightness=brightness, panels=detector, raw_data=image, beam=imageset.get_beam()) else: flex_image = _get_flex_image(brightness=brightness, data=image, binning=binning, saturation=saturation, vendortype=vendortype) flex_image.setWindow(0, 0, 1) flex_image.adjust( color_scheme=colour_schemes.get(params.colour_scheme)) # now export as a bitmap flex_image.prep_string() try: import PIL.Image as Image except ImportError: import Image # XXX is size//binning safe here? try: pil_img = Image.fromstring('RGB', (flex_image.size2() // binning, flex_image.size1() // binning), flex_image.export_string) except NotImplementedError: pil_img = Image.frombytes('RGB', (flex_image.size2() // binning, flex_image.size1() // binning), flex_image.export_string) basename = os.path.basename( os.path.splitext(imageset.paths()[i_image])[0]) path = os.path.join(output_dir, basename + '.' + params.format) print "Exporting %s" % path tmp_stream = open(path, 'wb') pil_img.save(tmp_stream, format=params.format) tmp_stream.close()
action = "store_false", default = True, help = "Don't sort input files (default is True)") # Parse the command line arguments (options, args) = parser.parse_args() if len(args) == 0: parser.print_help() # Sort arguments if options.sort: args = sorted(args) # Get the data blocks from the input files # We've set verbose to print out files as they're tested. unhandled = [] datablocks = DataBlockFactory.from_args(args, verbose=options.verbose, unhandled=unhandled) # Print out any unhandled files if len(unhandled) > 0: print '-' * 80 print 'The following command line arguments were not handled:' for filename in unhandled: print ' %s' % filename # Loop through the data blocks for i, datablock in enumerate(datablocks): # Extract any sweeps sweeps = datablock.extract_sweeps() # Extract any stills
def run(args): import os from libtbx.phil import command_line from libtbx.utils import Sorry, Usage if len(args) == 0: from cStringIO import StringIO s = StringIO() master_phil_scope.show(out=s) raise Usage("""\ dxtbx.export_bitmaps image_files [options] % s """ %s.getvalue()) from dxtbx.datablock import DataBlockFactory unhandled = [] datablocks = DataBlockFactory.from_args( args, verbose=False, unhandled=unhandled) assert len(datablocks) > 0 imagesets = datablocks[0].extract_imagesets() cmd_line = command_line.argument_interpreter(master_params=master_phil_scope) working_phil = cmd_line.process_and_fetch(args=unhandled) working_phil.show() params = working_phil.extract() brightness = params.brightness / 100 vendortype = "made up" # check that binning is a power of 2 binning = params.binning if not (binning > 0 and ((binning & (binning - 1)) == 0)): raise Sorry("binning must be a power of 2") output_dir = params.output_dir if output_dir is None: output_dir = "." elif not os.path.exists(output_dir): os.makedirs(output_dir) from rstbx.slip_viewer.tile_generation \ import _get_flex_image, _get_flex_image_multipanel for imageset in imagesets: detector = imageset.get_detector() panel = detector[0] # XXX is this inclusive or exclusive? saturation = panel.get_trusted_range()[1] for i_image, image in enumerate(imageset): if len(detector) > 1: # FIXME This doesn't work properly, as flex_image.size2() is incorrect # also binning doesn't work assert binning == 1 flex_image = _get_flex_image_multipanel( brightness=brightness, panels=detector, raw_data=image) else: flex_image = _get_flex_image( brightness=brightness, data=image, binning=binning, saturation=saturation, vendortype=vendortype) flex_image.setWindow(0, 0, 1) flex_image.adjust(color_scheme=colour_schemes.get(params.colour_scheme)) # now export as a bitmap flex_image.prep_string() import Image # XXX is size//binning safe here? pil_img = Image.fromstring( 'RGB', (flex_image.size2()//binning, flex_image.size1()//binning), flex_image.export_string) basename = os.path.basename(os.path.splitext(imageset.paths()[i_image])[0]) path = os.path.join( output_dir, basename + '.' + params.format) print "Exporting %s" %path tmp_stream = open(path, 'wb') pil_img.save(tmp_stream, format=params.format) tmp_stream.close()