Exemplo n.º 1
0
def exercise():
  g = graphics_utils.make_rainbow_gradient(nbins=21)
  assert approx_equal(g[0], (0.0, 0.0, 1.0))
  assert approx_equal(g[10], (0.0, 1.0, 0.0))
  assert approx_equal(g[-1], (1.0, 0.0, 0.0))
  sel = flex.bool([True] * 10)
  sel[5] = False
  r = graphics_utils.color_rainbow(
    selection=sel,
    color_all=False)
  assert approx_equal(r[0], (0.0,0.0,1.0))
  assert approx_equal(r[-1], (1.0,0.0,0.0))
  assert approx_equal(r[4], (0.0,1.0,0.0))
  r2 = graphics_utils.color_rainbow(
    selection=sel,
    color_all=True)
  assert approx_equal(r2[0], (0.0,0.0,1.0))
  assert approx_equal(r2[-1], (1.0,0.0,0.0))
  assert approx_equal(r2[6], (2/3.,1.0,0.0))
  b = flex.double([4.0,5.2,1.7,6.9,9.5,24.3])
  c = graphics_utils.color_by_property(
    properties=b,
    selection=flex.bool(b.size(), True))
  assert approx_equal(c[2], (0.0,0.0,1.0))
  c2 = graphics_utils.scale_selected_colors(
    input_colors=c,
    selection=flex.bool(c.size(), True),
    scale=0.9)
  assert approx_equal(c2[2], (0.0,0.0,0.9))
  c3 = graphics_utils.grayscale_by_property(
    properties=b,
    selection=flex.bool(b.size(), True))
  assert approx_equal(c3[2], (0.95,0.95,0.95))
Exemplo n.º 2
0
def exercise () :
  g = graphics_utils.make_rainbow_gradient(nbins=21)
  assert approx_equal(g[0], (0.0, 0.0, 1.0))
  assert approx_equal(g[10], (0.0, 1.0, 0.0))
  assert approx_equal(g[-1], (1.0, 0.0, 0.0))
  sel = flex.bool([True] * 10)
  sel[5] = False
  r = graphics_utils.color_rainbow(
    selection=sel,
    color_all=False)
  assert approx_equal(r[0], (0.0,0.0,1.0))
  assert approx_equal(r[-1], (1.0,0.0,0.0))
  assert approx_equal(r[4], (0.0,1.0,0.0))
  r2 = graphics_utils.color_rainbow(
    selection=sel,
    color_all=True)
  assert approx_equal(r2[0], (0.0,0.0,1.0))
  assert approx_equal(r2[-1], (1.0,0.0,0.0))
  assert approx_equal(r2[6], (2/3.,1.0,0.0))
  b = flex.double([4.0,5.2,1.7,6.9,9.5,24.3])
  c = graphics_utils.color_by_property(
    properties=b,
    selection=flex.bool(b.size(), True))
  assert approx_equal(c[2], (0.0,0.0,1.0))
  c2 = graphics_utils.scale_selected_colors(
    input_colors=c,
    selection=flex.bool(c.size(), True),
    scale=0.9)
  assert approx_equal(c2[2], (0.0,0.0,0.9))
  c3 = graphics_utils.grayscale_by_property(
    properties=b,
    selection=flex.bool(b.size(), True))
  assert approx_equal(c3[2], (0.95,0.95,0.95))
Exemplo n.º 3
0
    def generate_view_data(self):
        from scitbx.array_family import flex
        from scitbx import graphics_utils
        settings = self.settings
        data_for_colors = data_for_radii = None
        data = self.data  #self.work_array.data()
        sigmas = self.sigmas
        if (isinstance(data, flex.double) and data.all_eq(0)):
            data = flex.double(data.size(), 1)
        if ((self.multiplicities is not None)
                and (settings.scale_colors_multiplicity)):
            data_for_colors = self.multiplicities.data().as_double()
            assert data_for_colors.size() == data.size()
        elif (settings.sqrt_scale_colors) and (isinstance(data, flex.double)):
            data_for_colors = flex.sqrt(flex.abs(data))
        elif isinstance(data, flex.complex_double):
            data_for_colors = self.radians
            # when using map coefficients the sigmas are filled with foms if provided
            #if self.sigmas:
            #  self.foms = self.sigmas
            foms_for_colours = self.foms
        elif (settings.sigma_color) and sigmas is not None:
            data_for_colors = sigmas.as_double()
        else:
            data_for_colors = flex.abs(data.deep_copy())

        uc = self.work_array.unit_cell()
        #abc = uc.parameters()[0:3]
        min_dist = min(uc.reciprocal_space_vector((1, 1, 1)))
        min_radius = 0.20 * min_dist
        max_radius = 40 * min_dist
        if ((self.multiplicities is not None)
                and (settings.scale_radii_multiplicity)):
            #data_for_radii = data.deep_copy()
            data_for_radii = self.multiplicities.data().as_double()

            if (settings.sigma_radius) and sigmas is not None:
                data_for_radii = sigmas * self.multiplicities.as_double()
                #print "sigmas: " + self.miller_array.info().label_string()
            assert data_for_radii.size() == data.size()
        #elif (settings.sqrt_scale_radii) and (isinstance(data, flex.double)):
        #  data_for_radii = flex.sqrt(flex.abs(data))
        elif (settings.sigma_radius) and sigmas is not None:
            data_for_radii = sigmas.as_double()
            #print "sigmas: " + self.miller_array.info().label_string()
        else:
            #data_for_radii = flex.abs(data.deep_copy())
            data_for_radii = nth_power_scale(data.deep_copy(),
                                             settings.nth_power_scale_radii)
        if (settings.slice_mode):
            data = data.select(self.slice_selection)
            if (not settings.keep_constant_scale):
                data_for_radii = data_for_radii.select(self.slice_selection)
                data_for_colors = data_for_colors.select(self.slice_selection)
                foms_for_colours = foms_for_colours.select(
                    self.slice_selection)
        if isinstance(data, flex.complex_double):
            if len([e for e in foms_for_colours if math.isnan(e)]) > 0:
                colors = graphics_utils.colour_by_phi_FOM(
                    data_for_colors, None)
            else:
                colors = graphics_utils.colour_by_phi_FOM(
                    data_for_colors, foms_for_colours)
        elif (settings.color_scheme in ["rainbow", "heatmap", "redblue"]):
            colors = graphics_utils.color_by_property(
                properties=data_for_colors,
                selection=flex.bool(data_for_colors.size(), True),
                color_all=False,
                gradient_type=settings.color_scheme)
        elif (settings.color_scheme == "grayscale"):
            colors = graphics_utils.grayscale_by_property(
                properties=data_for_colors,
                selection=flex.bool(data_for_colors.size(), True),
                shade_all=False,
                invert=settings.black_background)
        else:
            if (settings.black_background):
                base_color = (1.0, 1.0, 1.0)
            else:
                base_color = (0.0, 0.0, 0.0)
            colors = flex.vec3_double(data_for_colors.size(), base_color)
        if (settings.slice_mode) and (settings.keep_constant_scale):
            colors = colors.select(self.slice_selection)
            data_for_radii = data_for_radii.select(self.slice_selection)

        #if (settings.sqrt_scale_radii) and (not settings.scale_radii_multiplicity):
        #  data_for_radii = flex.sqrt(flex.abs(data_for_radii))
        if len(data_for_radii):
            max_value = flex.max(data_for_radii)
            scale = max_radius / max_value
            radii = data_for_radii * (scale * self.settings.scale)
            too_small = radii < min_radius
            if (too_small.count(True) > 0):
                radii.set_selected(too_small,
                                   flex.double(radii.size(), min_radius))
            assert radii.size() == colors.size()
        else:
            radii = flex.double()
            max_radius = 0
        self.radii = radii
        self.max_radius = max_radius
        self.colors = colors
        if isinstance(data, flex.complex_double):
            self.foms = foms_for_colours
Exemplo n.º 4
0
 def generate_view_data(self):
     from scitbx.array_family import flex
     #from scitbx import graphics_utils
     settings = self.settings
     data_for_colors = data_for_radii = None
     if not self.fullprocessarray:
         return
     data = self.data  #self.work_array.data()
     sigmas = self.sigmas
     if (isinstance(data, flex.double) and data.all_eq(0)):
         data = flex.double(data.size(), 1)
     if ((self.multiplicities is not None)
             and (settings.scale_colors_multiplicity)):
         data_for_colors = self.multiplicities.data().as_double()
         assert data_for_colors.size() == data.size()
     elif (settings.sqrt_scale_colors) and (isinstance(data, flex.double)):
         data_for_colors = flex.sqrt(flex.abs(data))
     elif isinstance(data, flex.complex_double):
         data_for_colors = self.radians
         foms_for_colours = self.foms
         # assuming last part of the labels indicates the phase label as in ["FCALC","PHICALC"]
         self.colourlabel = self.miller_array.info().labels[-1]
     elif (settings.sigma_color) and sigmas is not None:
         data_for_colors = sigmas.as_double()
         self.colourlabel = self.miller_array.info().labels[-1]
     else:
         data_for_colors = flex.abs(data.deep_copy())
     uc = self.work_array.unit_cell()
     self.min_dist = min(uc.reciprocal_space_vector(
         (1, 1, 1))) * self.renderscale
     min_radius = 0.05 * self.min_dist
     max_radius = 0.5 * self.min_dist
     if ((self.multiplicities is not None)
             and (settings.scale_radii_multiplicity)):
         data_for_radii = self.multiplicities.data().as_double()
         if (settings.sigma_radius) and sigmas is not None:
             data_for_radii = sigmas * self.multiplicities.as_double()
         assert data_for_radii.size() == data.size()
     elif (settings.sigma_radius) and sigmas is not None:
         data_for_radii = sigmas.as_double()
     else:
         data_for_radii, self.nth_power_scale_radii = nth_power_scale(
             flex.abs(data.deep_copy()), settings.nth_power_scale_radii)
     if (settings.slice_mode):
         data = data.select(self.slice_selection)
         if (not settings.keep_constant_scale):
             data_for_radii = data_for_radii.select(self.slice_selection)
             data_for_colors = data_for_colors.select(self.slice_selection)
             foms_for_colours = foms_for_colours.select(
                 self.slice_selection)
     if isinstance(data, flex.complex_double):
         if self.isUsingFOMs():
             colors = graphics_utils.colour_by_phi_FOM(
                 data_for_colors, foms_for_colours)
         else:
             colors = graphics_utils.colour_by_phi_FOM(
                 data_for_colors, None)
     elif (settings.color_scheme in ["rainbow", "heatmap", "redblue"]):
         colors = graphics_utils.color_by_property(
             properties=data_for_colors,
             selection=flex.bool(data_for_colors.size(), True),
             color_all=False,
             gradient_type=settings.color_scheme)
     elif (settings.color_scheme == "grayscale"):
         colors = graphics_utils.grayscale_by_property(
             properties=data_for_colors,
             selection=flex.bool(data_for_colors.size(), True),
             shade_all=False,
             invert=settings.black_background)
     else:
         if (settings.black_background):
             base_color = (1.0, 1.0, 1.0)
         else:
             base_color = (0.0, 0.0, 0.0)
         colors = flex.vec3_double(data_for_colors.size(), base_color)
     if (settings.slice_mode) and (settings.keep_constant_scale):
         colors = colors.select(self.slice_selection)
         data_for_radii = data_for_radii.select(self.slice_selection)
     #if (settings.sqrt_scale_radii) and (not settings.scale_radii_multiplicity):
     #  data_for_radii = flex.sqrt(flex.abs(data_for_radii))
     if len(data_for_radii):
         #dat2 = flex.abs(flex.double([e for e in data_for_radii if not math.isnan(e)]))
         dat2 = flex.abs(
             flex.double(graphics_utils.NoNansArray(data_for_radii, 0.1)))
         # don't divide by 0 if dealing with selection of Rfree array where all values happen to be zero
         scale = max_radius / (flex.max(dat2) + 0.001)
         radii = data_for_radii * (self.settings.scale * scale)
         assert radii.size() == colors.size()
     else:
         radii = flex.double()
         max_radius = 0
     self.radii = radii
     self.max_radius = max_radius
     self.min_radius = min_radius
     self.colors = colors
     if isinstance(data, flex.complex_double):
         self.foms = foms_for_colours
Exemplo n.º 5
0
    def render(self, canvas):
        from scitbx.array_family import flex
        from libtbx.utils import frange
        import math
        size = self.GetSize()
        border = 10
        i_rows = flex.double_range(border, size[1] - border)
        scene = self.scene
        if self.scene.settings.scale_colors_multiplicity:
            data = self.scene.multiplicities.data()
        else:
            data = self.scene.data
            if self.settings.sqrt_scale_colors:
                data = flex.sqrt(data)
        min_data = flex.min(data)
        max_data = flex.max(data)
        data_for_colors = flex.double(
            frange(max_data, min_data, -(max_data - min_data) / len(i_rows)))
        tick_step = int(math.ceil((max_data - min_data) / 10))
        i_row_ticks = []
        tick_text = []
        start_tick = math.floor(max_data)
        i_tick = 0
        for i in range(len(data_for_colors) - 1):
            tick_d = start_tick - tick_step * i_tick
            if abs(data_for_colors[i] - tick_d) < abs(data_for_colors[i + 1] -
                                                      tick_d):
                i_row_ticks.append(i_rows[i])
                tick_text.append(str(int(tick_d)))
                i_tick += 1
        tick_d = start_tick - tick_step * i_tick
        if tick_d == min_data:
            i_row_ticks.append(i_rows[-1])
            tick_text.append(str(int(tick_d)))

        from scitbx import graphics_utils
        if (self.settings.color_scheme in ["rainbow", "heatmap", "redblue"]):
            colors = graphics_utils.color_by_property(
                properties=data_for_colors,
                selection=flex.bool(data_for_colors.size(), True),
                color_all=False,
                gradient_type=self.settings.color_scheme)
        elif (self.settings.color_scheme == "grayscale"):
            colors = graphics_utils.grayscale_by_property(
                properties=data_for_colors,
                selection=flex.bool(data_for_colors.size(), True),
                shade_all=False,
                invert=self.settings.black_background)
        else:
            if (self.settings.black_background):
                base_color = (1.0, 1.0, 1.0)
            else:
                base_color = (0.0, 0.0, 0.0)
            colors = flex.vec3_double(data_for_colors.size(), base_color)

        l_padding = border
        r_padding = 4 * border

        for i_row, color in zip(i_rows, colors):
            self.draw_line(canvas,
                           l_padding,
                           i_row,
                           size[0] - r_padding,
                           i_row,
                           color=color)

        for i_row, text in zip(i_row_ticks, tick_text):
            self.draw_text(canvas, text, size[0] - 0.8 * r_padding, i_row - 5)
            self.draw_line(canvas, size[0] - r_padding - 10, i_row,
                           size[0] - r_padding, i_row)
Exemplo n.º 6
0
 def generate_view_data(self):
     from scitbx.array_family import flex
     from scitbx import graphics_utils
     settings = self.settings
     data_for_colors = data_for_radii = None
     data = self.data  #self.work_array.data()
     if (isinstance(data, flex.double) and data.all_eq(0)):
         data = flex.double(data.size(), 1)
     if ((self.multiplicities is not None)
             and (settings.scale_colors_multiplicity)):
         data_for_colors = self.multiplicities.data().as_double()
         assert data_for_colors.size() == data.size()
     elif (settings.sqrt_scale_colors) and (isinstance(data, flex.double)):
         data_for_colors = flex.sqrt(data)
     else:
         data_for_colors = data.deep_copy()
     if ((self.multiplicities is not None)
             and (settings.scale_radii_multiplicity)):
         #data_for_radii = data.deep_copy()
         data_for_radii = self.multiplicities.data().as_double()
         assert data_for_radii.size() == data.size()
     elif (settings.sqrt_scale_radii) and (isinstance(data, flex.double)):
         data_for_radii = flex.sqrt(data)
     else:
         data_for_radii = data.deep_copy()
     if (settings.slice_mode):
         data = data.select(self.slice_selection)
         if (not settings.keep_constant_scale):
             data_for_radii = data_for_radii.select(self.slice_selection)
             data_for_colors = data_for_colors.select(self.slice_selection)
     if (settings.color_scheme in ["rainbow", "heatmap", "redblue"]):
         colors = graphics_utils.color_by_property(
             properties=data_for_colors,
             selection=flex.bool(data_for_colors.size(), True),
             color_all=False,
             gradient_type=settings.color_scheme)
     elif (settings.color_scheme == "grayscale"):
         colors = graphics_utils.grayscale_by_property(
             properties=data_for_colors,
             selection=flex.bool(data_for_colors.size(), True),
             shade_all=False,
             invert=settings.black_background)
     else:
         if (settings.black_background):
             base_color = (1.0, 1.0, 1.0)
         else:
             base_color = (0.0, 0.0, 0.0)
         colors = flex.vec3_double(data_for_colors.size(), base_color)
     if (settings.slice_mode) and (settings.keep_constant_scale):
         colors = colors.select(self.slice_selection)
         data_for_radii = data_for_radii.select(self.slice_selection)
     uc = self.work_array.unit_cell()
     abc = uc.parameters()[0:3]
     min_dist = min(uc.reciprocal_space_vector((1, 1, 1)))
     min_radius = 0.20 * min_dist
     max_radius = 40 * min_dist
     if (settings.sqrt_scale_radii) and (
             not settings.scale_radii_multiplicity):
         data_for_radii = flex.sqrt(data_for_radii)
     if len(data_for_radii):
         max_value = flex.max(data_for_radii)
         scale = max_radius / max_value
         radii = data_for_radii * scale
         too_small = radii < min_radius
         if (too_small.count(True) > 0):
             radii.set_selected(too_small,
                                flex.double(radii.size(), min_radius))
         assert radii.size() == colors.size()
     else:
         radii = flex.double()
         max_radius = 0
     self.radii = radii
     self.max_radius = max_radius
     self.colors = colors
Exemplo n.º 7
0
 def generate_view_data (self) :
   from scitbx.array_family import flex
   from scitbx import graphics_utils
   settings = self.settings
   data_for_colors = data_for_radii = None
   data = self.data #self.work_array.data()
   if (isinstance(data, flex.double) and data.all_eq(0)):
     data = flex.double(data.size(), 1)
   if ((self.multiplicities is not None) and
       (settings.scale_colors_multiplicity)) :
     data_for_colors = self.multiplicities.data().as_double()
     assert data_for_colors.size() == data.size()
   elif (settings.sqrt_scale_colors) and (isinstance(data, flex.double)) :
     data_for_colors = flex.sqrt(data)
   else :
     data_for_colors = data.deep_copy()
   if ((self.multiplicities is not None) and
       (settings.scale_radii_multiplicity)) :
     #data_for_radii = data.deep_copy()
     data_for_radii = self.multiplicities.data().as_double()
     assert data_for_radii.size() == data.size()
   elif (settings.sqrt_scale_radii) and (isinstance(data, flex.double)) :
     data_for_radii = flex.sqrt(data)
   else :
     data_for_radii = data.deep_copy()
   if (settings.slice_mode) :
     data = data.select(self.slice_selection)
     if (not settings.keep_constant_scale) :
       data_for_radii = data_for_radii.select(self.slice_selection)
       data_for_colors = data_for_colors.select(self.slice_selection)
   if (settings.color_scheme in ["rainbow", "heatmap", "redblue"]) :
     colors = graphics_utils.color_by_property(
       properties=data_for_colors,
       selection=flex.bool(data_for_colors.size(), True),
       color_all=False,
       gradient_type=settings.color_scheme)
   elif (settings.color_scheme == "grayscale") :
     colors = graphics_utils.grayscale_by_property(
       properties=data_for_colors,
       selection=flex.bool(data_for_colors.size(), True),
       shade_all=False,
       invert=settings.black_background)
   else :
     if (settings.black_background) :
       base_color = (1.0,1.0,1.0)
     else :
       base_color = (0.0,0.0,0.0)
     colors = flex.vec3_double(data_for_colors.size(), base_color)
   if (settings.slice_mode) and (settings.keep_constant_scale) :
     colors = colors.select(self.slice_selection)
     data_for_radii = data_for_radii.select(self.slice_selection)
   uc = self.work_array.unit_cell()
   abc = uc.parameters()[0:3]
   min_dist = min(uc.reciprocal_space_vector((1,1,1)))
   min_radius = 0.20 * min_dist
   max_radius = 40 * min_dist
   if (settings.sqrt_scale_radii) and (not settings.scale_radii_multiplicity):
     data_for_radii = flex.sqrt(data_for_radii)
   if len(data_for_radii):
     max_value = flex.max(data_for_radii)
     scale = max_radius / max_value
     radii = data_for_radii * scale
     too_small = radii < min_radius
     if (too_small.count(True) > 0) :
       radii.set_selected(too_small, flex.double(radii.size(), min_radius))
     assert radii.size() == colors.size()
   else:
     radii = flex.double()
     max_radius = 0
   self.radii = radii
   self.max_radius = max_radius
   self.colors = colors