示例#1
0
def spot_resolution_shells(imagesets, reflections, params):
    from dials.array_family import flex

    mapped_reflections = flex.reflection_table()
    for i, imageset in enumerate(imagesets):
        if "imageset_id" in reflections:
            sel = reflections["imageset_id"] == i
        else:
            sel = reflections["id"] == i
        if isinstance(reflections["id"], flex.size_t):
            reflections["id"] = reflections["id"].as_int()
        refl = reflections.select(sel)
        refl.centroid_px_to_mm(imageset.get_detector(), imageset.get_scan())
        refl.map_centroids_to_reciprocal_space(imageset.get_detector(),
                                               imageset.get_beam(),
                                               imageset.get_goniometer())
        mapped_reflections.extend(refl)
    reflections = mapped_reflections
    two_theta_array = reflections["rlp"].norms()
    h0 = flex.weighted_histogram(two_theta_array**2, n_slots=params.shells)
    n = h0.slots()
    d = 1.0 / flex.sqrt(h0.slot_centers())

    for j in range(params.shells):
        print("%d %f %d" % (j, d[j], n[j]))
示例#2
0
def spot_resolution_shells(imagesets, reflections, params):
  goniometer = imagesets[0].get_goniometer()
  from dials.algorithms.indexing import indexer
  from dials.array_family import flex
  mapped_reflections = flex.reflection_table()
  for i, imageset in enumerate(imagesets):
    if 'imageset_id' in reflections:
      sel = (reflections['imageset_id'] == i)
    else:
      sel = (reflections['id'] == i)
    if isinstance(reflections['id'], flex.size_t):
      reflections['id'] = reflections['id'].as_int()
    refl = indexer.indexer_base.map_spots_pixel_to_mm_rad(
      reflections.select(sel),
      imageset.get_detector(), imageset.get_scan())

    indexer.indexer_base.map_centroids_to_reciprocal_space(
      refl, imageset.get_detector(), imageset.get_beam(),
      imageset.get_goniometer())
    mapped_reflections.extend(refl)
  reflections = mapped_reflections
  two_theta_array = reflections['rlp'].norms()
  h0 = flex.weighted_histogram(two_theta_array ** 2, n_slots=params.shells)
  n = h0.slots()
  d = 1.0 / flex.sqrt(h0.slot_centers())

  for j in range(params.shells):
    print('%d %f %d' % (j, d[j], n[j]))
示例#3
0
def spot_resolution_shells(imagesets, reflections, params):
  goniometer = imagesets[0].get_goniometer()
  from dials.algorithms.indexing import indexer
  from dials.array_family import flex
  mapped_reflections = flex.reflection_table()
  for i, imageset in enumerate(imagesets):
    if 'imageset_id' in reflections:
      sel = (reflections['imageset_id'] == i)
    else:
      sel = (reflections['id'] == i)
    if isinstance(reflections['id'], flex.size_t):
      reflections['id'] = reflections['id'].as_int()
    refl = indexer.indexer_base.map_spots_pixel_to_mm_rad(
      reflections.select(sel),
      imageset.get_detector(), imageset.get_scan())

    indexer.indexer_base.map_centroids_to_reciprocal_space(
      refl, imageset.get_detector(), imageset.get_beam(),
      imageset.get_goniometer())
    mapped_reflections.extend(refl)
  reflections = mapped_reflections
  two_theta_array = reflections['rlp'].norms()
  h0 = flex.weighted_histogram(two_theta_array ** 2, n_slots=params.shells)
  n = h0.slots()
  d = 1.0 / flex.sqrt(h0.slot_centers())

  for j in range(params.shells):
    print '%d %f %d' % (j, d[j], n[j])
示例#4
0
def spot_resolution_shells(experiments, reflections, params):
    from dials.array_family import flex

    reflections.centroid_px_to_mm(experiments)
    reflections.map_centroids_to_reciprocal_space(experiments)
    two_theta_array = reflections["rlp"].norms()
    h0 = flex.weighted_histogram(flex.pow2(two_theta_array), n_slots=params.shells)
    n = h0.slots()
    d = 1.0 / flex.sqrt(h0.slot_centers())

    for j in range(params.shells):
        print("%d %f %d" % (j, d[j], n[j]))
示例#5
0
def background(imageset, indx, n_bins, corrected=False, mask_params=None):
    if mask_params is None:
        # Default mask params for trusted range
        mask_params = phil_scope.fetch(parse("")).extract().masking

    detector = imageset.get_detector()
    beam = imageset.get_beam()

    # Only working with single panel detector for now
    assert len(detector) == 1
    panel = detector[0]
    imageset_mask = imageset.get_mask(indx)[0]
    mask = dials.util.masking.generate_mask(imageset, mask_params)[0]
    mask = imageset_mask & mask

    n = matrix.col(panel.get_normal()).normalize()
    b = matrix.col(beam.get_s0()).normalize()
    wavelength = beam.get_wavelength()

    if math.fabs(b.dot(n)) < 0.95:
        raise Sorry("Detector not perpendicular to beam")

    # Use corrected data to determine signal and background regions
    corrected_data = imageset.get_corrected_data(indx)
    assert len(corrected_data) == 1
    corrected_data = corrected_data[0].as_double()

    # Use choice of raw or corrected data to evaluate the background values
    if corrected:
        data = corrected_data
    else:
        data = imageset.get_raw_data(indx)[0].as_double()

    spot_params = spot_phil.fetch(source=parse("")).extract()
    threshold_function = SpotFinderFactory.configure_threshold(spot_params)
    peak_pixels = threshold_function.compute_threshold(corrected_data, mask)
    signal = data.select(peak_pixels.iselection())
    background_pixels = mask & ~peak_pixels
    background = data.select(background_pixels.iselection())

    # print some summary information
    print(f"Mean background: {flex.sum(background) / background.size():.3f}")
    if len(signal) > 0:
        print(
            f"Max/total signal pixels: {flex.max(signal):.0f} / {flex.sum(signal):.0f}"
        )
    else:
        print("No signal pixels on this image")
    print("Peak/background/masked pixels: %d / %d / %d" %
          (peak_pixels.count(True), background.size(), mask.count(False)))

    # compute histogram of two-theta values, then same weighted
    # by pixel values, finally divide latter by former to get
    # the radial profile out, need to set the number of bins
    # sensibly; inspired by method in PyFAI

    two_theta_array = panel.get_two_theta_array(beam.get_s0())
    two_theta_array = two_theta_array.as_1d().select(
        background_pixels.iselection())

    # Use flex.weighted_histogram
    h0 = flex.weighted_histogram(two_theta_array, n_slots=n_bins)
    h1 = flex.weighted_histogram(two_theta_array, background, n_slots=n_bins)
    h2 = flex.weighted_histogram(two_theta_array,
                                 background * background,
                                 n_slots=n_bins)

    d0 = h0.slots()
    d1 = h1.slots()
    d2 = h2.slots()

    I = d1 / d0
    I2 = d2 / d0
    sig = flex.sqrt(I2 - flex.pow2(I))

    tt = h0.slot_centers()
    d_spacings = wavelength / (2.0 * flex.sin(0.5 * tt))

    return d_spacings, I, sig