Exemple #1
0
    def OnCompute(self, event):

        global tex_data
        global tex2
        global omega
        global kappa
        global offset_matrix
        global shadowsetting
        global tex_shadow
        global tex_noshad
        global noshad_data
        global tex

        omega = self.widget[0].GetValue()
        kappa = self.widget[1].GetValue()
        offset_matrix = [
            self.widget[2].GetValue(),
            self.widget[3].GetValue(),
            self.widget[4].GetValue(),
        ]

        newshadow = shadowmapper.Shadow(
            shadowmapper.day2_coords,
            filename,
            DET_ANGLE,
            d,
            detector_origin,
            fast_axis,
            slow_axis,
        )

        [
            tex_data,
            tex,
            tex2,
            tex_shadow,
            tex_noshad,
            noshad_data,
        ] = newshadow.shadow_texture(kappa=kappa,
                                     omega=omega,
                                     blank=blanksetting)

        pixels = newshadow.affected_pixels(kappa=kappa,
                                           omega=omega,
                                           blank=blanksetting)[1]

        shadowsetting = self.shadowcheck.GetValue()

        if shadowsetting is True:
            print("At these goniometer angles, the shadow affects", pixels,
                  "pixels.")

        self.Destroy()
        app.MainLoop()
Exemple #2
0
 def OnPlot(self, event):
     myshadow = shadowmapper.Shadow(
         shadowmapper.day2_coords,
         filename,
         DET_ANGLE,
         d,
         detector_origin,
         fast_axis,
         slow_axis,
     )
     myshadow.pixel_plotter(num_points=self.points.GetValue())
     self.Destroy()
Exemple #3
0
    def __init__(self, filename):
        self.newimage = analyser.Image(filename)

        (
            origin,
            fast,
            slow,
            dimensions,
            pix,
            dist,
            res,
        ) = self.newimage.detector_parameters()

        self.newshadow = shadowmapper.Shadow(shadowmapper.day2_coords,
                                             filename, det_angle, dist, origin,
                                             fast, slow)
Exemple #4
0
def view_experiment(
    filename, sample_x_length=4.0, sample_y_length=0.5, sample_z_length=8.0
):

    """
    Read a cbf image and display a 3D model of the experiment.

    This function is intended to be used by the block of code at the
    end of the module. This will start the program with a dialog box
    allowing the user to select a file.

    Arguments:
    filename -- the name of the cbf image to be read. Must include the
    .cbf extension.
    sample_x,y,z_length -- the dimensions of the sample in mm.

    The model can be rotated by clicking and dragging the mouse, and
    zoomed with the mousewheel. The model is displayed in a wxPython
    based OpenGLCanvas.

    Note that the default sample dimensions are much larger than the
    true dimensions; however for the purposes of the program it is best
    to have a crystal large enough to be visible.
    """

    myimage = analyser.Image(filename)

    viewer.B = myimage.find_beam_direction()

    (
        viewer.detector_origin,
        viewer.fast_axis,
        viewer.slow_axis,
        viewer.dimensions,
        viewer.pix,
        viewer.d,
        res,
    ) = myimage.detector_parameters()

    ((i, j, k), (alpha, beta, gamma), viewer.R) = myimage.get_sample_orientation()

    viewer.sample_angles = (alpha, beta, gamma)

    viewer.img_array = myimage.image_to_array()

    mysample = modeller.Sample(sample_x_length, sample_y_length, sample_z_length)

    viewer.r_f = mysample.rotate(i, j, k)

    for i in range(viewer.num_panels):
        det.append(modeller.Panel(viewer.dimensions[i, 0], viewer.dimensions[i, 1]))

        viewer.d_r_f[i] = det[i].get_coords(
            viewer.detector_origin[i], viewer.fast_axis[i], viewer.slow_axis[i]
        )

    myshadow = shadowmapper.Shadow(
        shadowmapper.day2_coords,
        filename,
        viewer.DET_ANGLE,
        viewer.d,
        viewer.detector_origin,
        viewer.fast_axis,
        viewer.slow_axis,
    )

    viewer.filename, viewer.shadowsetting, viewer.blanksetting = (
        filename,
        False,
        False,
    )

    (viewer.kappa, viewer.omega, viewer.offset_matrix, viewer.sample_x) = (
        -180.0,
        90.0,
        np.zeros(3),
        0.0,
    )

    (
        viewer.tex_data,
        viewer.tex,
        viewer.tex2,
        viewer.tex_shadow,
        viewer.tex_noshad,
        viewer.noshad_data,
    ) = myshadow.shadow_texture()

    viewer.app = wx.App()
    viewer.frame = viewer.MainWindow()
    viewer.app.MainLoop()
Exemple #5
0
    def OnCompute(self, event):

        alpha = -np.deg2rad(self.angle[0].GetValue())
        beta = np.deg2rad(self.angle[1].GetValue())
        gamma = np.deg2rad(self.angle[2].GetValue())

        # rotation matrices for each axis
        r_x = np.array(
            [
                [1.0, 0.0, 0.0],
                [0.0, np.cos(alpha), -np.sin(alpha)],
                [0.0, np.sin(alpha), np.cos(alpha)],
            ],
            float,
        )
        r_y = np.array(
            [
                [np.cos(beta), 0.0, np.sin(beta)],
                [0.0, 1.0, 0.0],
                [-np.sin(beta), 0.0, np.cos(beta)],
            ],
            float,
        )
        r_z = np.array(
            [
                [np.cos(gamma), -np.sin(gamma), 0.0],
                [np.sin(gamma), np.cos(gamma), 0.0],
                [0.0, 0.0, 1.0],
            ],
            float,
        )
        # r_tot = matrix representing the total rotation
        r_tot = np.dot(r_z, np.dot(r_y, r_x))

        newSample = modeller.Sample()
        r_f = newSample.rotate(r_tot[0], r_tot[1], r_tot[2])

        sample_x = 0.0
        if self.rb2.GetValue() is True:
            sample_x = 6.4
        elif self.rb3.GetValue() is True:
            sample_x = -6.4

        new_origin = deepcopy(detector_origin)
        new_origin[0, 0] += sample_x

        newDet = []
        for i in range(num_panels):
            newDet.append(modeller.Panel(dimensions[i, 0], dimensions[i, 1]))
            d_r_f[i] = newDet[i].get_coords(new_origin, fast_axis[i],
                                            slow_axis[i])

        print(
            "The new alpha, beta, and gamma angles are, respectively, ",
            np.rad2deg(alpha),
            ", ",
            np.rad2deg(beta),
            "and ",
            np.rad2deg(gamma),
            "degrees",
        )

        newshadow = shadowmapper.Shadow(
            shadowmapper.day2_coords,
            filename,
            DET_ANGLE,
            d,
            detector_origin,
            fast_axis,
            slow_axis,
        )

        [
            tex_data,
            tex,
            tex2,
            tex_shadow,
            tex_noshad,
            noshad_data,
        ] = newshadow.shadow_texture(kappa=kappa,
                                     omega=omega,
                                     blank=blanksetting)

        pixels = newshadow.affected_pixels(kappa=kappa,
                                           omega=omega,
                                           blank=blanksetting)[1]

        if shadowsetting is True:
            print("At these goniometer angles, the shadow affects", pixels,
                  "pixels.")

        self.Destroy()
        app.MainLoop()
Exemple #6
0
    def OnAdjust(self, event):

        global d
        global DET_ANGLE
        global tex_data
        global tex2
        global tex_noshad
        global noshad_data
        global blanksetting
        global tex
        global tex_shadow
        # angle = angular displacement
        angle = np.deg2rad(self.angles.GetValue() - DET_ANGLE)
        displacement = self.dist.GetValue() - d
        # Rotation matrix
        r_x = np.array(
            [
                [1.0, 0.0, 0.0],
                [0.0, np.cos(angle), -np.sin(angle)],
                [0.0, np.sin(angle), np.cos(angle)],
            ],
            float,
        )
        det = []

        for i in range(num_panels):
            det.append(modeller.Panel(dimensions[i, 0], dimensions[i, 1]))
            detector_origin[
                i] = detector_origin[i] + displacement * detector_normal
            detector_origin[i] = np.dot(r_x, detector_origin[i])
            fast_axis[i] = np.dot(r_x, fast_axis[i])
            slow_axis[i] = np.dot(r_x, slow_axis[i])
            d_r_f[i] = det[i].get_coords(detector_origin[i], fast_axis[i],
                                         slow_axis[i])

        d = self.dist.GetValue()
        DET_ANGLE = self.angles.GetValue()
        blanksetting = not self.detcheck.GetValue()

        newshadow = shadowmapper.Shadow(
            shadowmapper.day2_coords,
            filename,
            DET_ANGLE,
            d,
            detector_origin,
            fast_axis,
            slow_axis,
        )

        [
            tex_data,
            tex,
            tex2,
            tex_shadow,
            tex_noshad,
            noshad_data,
        ] = newshadow.shadow_texture(kappa=kappa,
                                     omega=omega,
                                     blank=blanksetting)

        pixels = newshadow.affected_pixels(kappa=kappa,
                                           omega=omega,
                                           blank=blanksetting)[1]

        if shadowsetting is True:
            print("At these goniometer angles, the shadow affects", pixels,
                  "pixels.")

        self.Destroy()
        app.MainLoop()