def generate_dials_corrections(image_filename, sensor_thickness_mm, energy_ev=None, method=compute_absolute_offset): """Generate equivalent correction tables equivalent to those from XDS, but using the equations above.""" from dxtbx import load from scitbx import matrix from scitbx.array_family import flex import math import random import os image = load(image_filename) beam = matrix.col(image.get_beam().get_s0()).normalize() if energy_ev: energy_kev = energy_ev * 0.001 else: wavelength = image.get_beam().get_wavelength() energy_kev = 12.3985 / wavelength mu = derive_absorption_coefficient_Si(energy_kev) d = image.get_detector()[0] fast = matrix.col(d.get_fast_axis()) slow = matrix.col(d.get_slow_axis()) normal = matrix.col(d.get_normal()) origin = matrix.col(d.get_origin()) distance = origin.dot(normal) offset = distance * normal - origin offset_fast = offset.dot(fast) offset_slow = offset.dot(slow) pixel_size = d.get_pixel_size() # this is in order slow, fast i.e. C order image_size = image.get_raw_data().focus() F = fast * pixel_size[0] S = slow * pixel_size[1] fast_parallax = flex.double(flex.grid(image_size)) slow_parallax = flex.double(flex.grid(image_size)) for i in range(image_size[0]): for j in range(image_size[1]): p = (origin + i * S + j * F).normalize() theta = p.angle(normal) dot_f = -p.dot(fast) dot_s = -p.dot(slow) offset = method(sensor_thickness_mm, theta, mu) fast_parallax[i, j] = dot_f * offset slow_parallax[i, j] = dot_s * offset return fast_parallax, slow_parallax
def generate_dials_corrections(image_filename, sensor_thickness_mm, energy_ev = None, method=compute_absolute_offset): '''Generate equivalent correction tables equivalent to those from XDS, but using the equations above.''' from dxtbx import load from scitbx import matrix from scitbx.array_family import flex import math import random import os image = load(image_filename) beam = matrix.col(image.get_beam().get_s0()).normalize() if energy_ev: energy_kev = energy_ev * 0.001 else: wavelength = image.get_beam().get_wavelength() energy_kev = 12.3985 / wavelength mu = derive_absorption_coefficient_Si(energy_kev) d = image.get_detector()[0] fast = matrix.col(d.get_fast_axis()) slow = matrix.col(d.get_slow_axis()) normal = matrix.col(d.get_normal()) origin = matrix.col(d.get_origin()) distance = origin.dot(normal) offset = distance * normal - origin offset_fast = offset.dot(fast) offset_slow = offset.dot(slow) pixel_size = d.get_pixel_size() # this is in order slow, fast i.e. C order image_size = image.get_raw_data().focus() F = fast * pixel_size[0] S = slow * pixel_size[1] fast_parallax = flex.double(flex.grid(image_size)) slow_parallax = flex.double(flex.grid(image_size)) for i in range(image_size[0]): for j in range(image_size[1]): p = (origin + i * S + j * F).normalize() theta = p.angle(normal) dot_f = - p.dot(fast) dot_s = - p.dot(slow) offset = method(sensor_thickness_mm, theta, mu) fast_parallax[i, j] = dot_f * offset slow_parallax[i, j] = dot_s * offset return fast_parallax, slow_parallax
def generate_xds_corrections(image_filename, sensor_thickness_mm, energy_ev=None): '''Generate an XYCORR input file from an image header via dxtbx, noting well that this will *tell lies* as the image is rescaled to give a 1:1 correction table in 0.025 rather than 0.1 (original) pixel increments.''' from dxtbx import load from scitbx import matrix image = load(image_filename) beam = matrix.col(image.get_beam().get_s0()).normalize() if energy_ev: wavelength = 12398.5 / energy_ev else: wavelength = image.get_beam().get_wavelength() energy_ev = 12398.5 / wavelength from mu_Si import derive_absorption_coefficient_Si silicon = derive_absorption_coefficient_Si(0.001 * energy_ev) d = image.get_detector()[0] fast = matrix.col(d.get_fast_axis()) slow = matrix.col(d.get_slow_axis()) normal = matrix.col(d.get_normal()) origin = matrix.col(d.get_origin()) distance = origin.dot(normal) offset = distance * normal - origin offset_fast = offset.dot(fast) offset_slow = offset.dot(slow) trusted = d.get_trusted_range() pixel_size = d.get_pixel_size() # this is in order slow, fast i.e. C order image_size = image.get_raw_data().focus() open('XDS.INP', 'w').write(xds_template % { 'overload':trusted[1], 'fast_x':fast.elems[0], 'fast_y':fast.elems[1], 'fast_z':fast.elems[2], 'slow_x':slow.elems[0], 'slow_y':slow.elems[1], 'slow_z':slow.elems[2], 'n_fast':image_size[1] * 4, 'n_slow':image_size[0] * 4, 'pixel_fast':pixel_size[0] / 4.0, 'pixel_slow':pixel_size[1] / 4.0, 'distance':distance, 'wavelength':wavelength, 'beam_x':beam.elems[0], 'beam_y':beam.elems[1], 'beam_z':beam.elems[2], 'silicon':silicon, 'thickness':sensor_thickness_mm, 'origin_fast':offset_fast / (pixel_size[0] / 4.0), 'origin_slow':offset_slow / (pixel_size[1] / 4.0) }) output = run_job('xds_par') # now read the correction tables in and scale to mm - recall pixel size / 4 # above.. x_corrections_parallax = read_xds_calibration_file( 'X-CORRECTIONS.cbf').as_double() * (pixel_size[1] / 40.0) y_corrections_parallax = read_xds_calibration_file( 'Y-CORRECTIONS.cbf').as_double() * (pixel_size[0] / 40.0) return x_corrections_parallax, y_corrections_parallax
def generate_xds_corrections(image_filename, sensor_thickness_mm, energy_ev=None): """Generate an XYCORR input file from an image header via dxtbx, noting well that this will *tell lies* as the image is rescaled to give a 1:1 correction table in 0.025 rather than 0.1 (original) pixel increments.""" from dxtbx import load from scitbx import matrix image = load(image_filename) beam = matrix.col(image.get_beam().get_s0()).normalize() if energy_ev: wavelength = 12398.5 / energy_ev else: wavelength = image.get_beam().get_wavelength() energy_ev = 12398.5 / wavelength from mu_Si import derive_absorption_coefficient_Si silicon = derive_absorption_coefficient_Si(0.001 * energy_ev) d = image.get_detector()[0] fast = matrix.col(d.get_fast_axis()) slow = matrix.col(d.get_slow_axis()) normal = matrix.col(d.get_normal()) origin = matrix.col(d.get_origin()) distance = origin.dot(normal) offset = distance * normal - origin offset_fast = offset.dot(fast) offset_slow = offset.dot(slow) trusted = d.get_trusted_range() pixel_size = d.get_pixel_size() # this is in order slow, fast i.e. C order image_size = image.get_raw_data().focus() open("XDS.INP", "w").write( xds_template % { "overload": trusted[1], "fast_x": fast.elems[0], "fast_y": fast.elems[1], "fast_z": fast.elems[2], "slow_x": slow.elems[0], "slow_y": slow.elems[1], "slow_z": slow.elems[2], "n_fast": image_size[1] * 4, "n_slow": image_size[0] * 4, "pixel_fast": pixel_size[0] / 4.0, "pixel_slow": pixel_size[1] / 4.0, "distance": distance, "wavelength": wavelength, "beam_x": beam.elems[0], "beam_y": beam.elems[1], "beam_z": beam.elems[2], "silicon": silicon, "thickness": sensor_thickness_mm, "origin_fast": offset_fast / (pixel_size[0] / 4.0), "origin_slow": offset_slow / (pixel_size[1] / 4.0), }) output = run_job("xds_par") # now read the correction tables in and scale to mm - recall pixel size / 4 # above.. x_corrections_parallax = read_xds_calibration_file( "X-CORRECTIONS.cbf").as_double() * (pixel_size[1] / 40.0) y_corrections_parallax = read_xds_calibration_file( "Y-CORRECTIONS.cbf").as_double() * (pixel_size[0] / 40.0) return x_corrections_parallax, y_corrections_parallax