Ejemplo n.º 1
0
    def test_linear_polarizers(self):

        #
        assert_array_almost_equal(
            MuellerMatrix.initialize_as_linear_polarizer_horizontal(
            ).get_matrix(),
            0.5 * np.array([[1.0, 1.0, 0.0, 0.0], [1.0, 1.0, 0.0, 0.0],
                            [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0]]))

        #
        assert_array_almost_equal(
            MuellerMatrix.initialize_as_linear_polarizer_horizontal(
            ).get_matrix(),
            0.5 * np.array([[1.0, 1.0, 0.0, 0.0], [1.0, 1.0, 0.0, 0.0],
                            [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0]]))

        #
        assert_array_almost_equal(
            MuellerMatrix.initialize_as_linear_polarizer_vertical().get_matrix(
            ), 0.5 * np.array([[1.0, -1.0, 0.0, 0.0], [-1.0, 1.0, 0.0, 0.0],
                               [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0]]))

        #
        assert_array_almost_equal(
            MuellerMatrix.initialize_as_linear_polarizer_plus45().get_matrix(),
            0.5 * np.array([[1.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 0.0],
                            [1.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 0.0]]))

        #
        assert_array_almost_equal(
            MuellerMatrix.initialize_as_linear_polarizer_minus45().get_matrix(
            ), 0.5 * np.array([[1.0, 0.0, -1.0, 0.0], [0.0, 0.0, 0.0, 0.0],
                               [-1.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 0.0]]))
    def calculate_IdealLinearPolarizer(self):

        if self._input_available:
            # TYPE=self.TYPE,THETA=self.THETA,DELTA=self.DELTA
            photon_bunch = self.incoming_bunch
            if self.TYPE == 0:
                mm = MuellerMatrix.initialize_as_general_linear_polarizer(
                    theta=self.THETA * np.pi / 180)
            elif self.TYPE == 1:
                mm = MuellerMatrix.initialize_as_linear_polarizer_horizontal()
            elif self.TYPE == 2:
                mm = MuellerMatrix.initialize_as_linear_polarizer_vertical()
            elif self.TYPE == 3:
                mm = MuellerMatrix.initialize_as_linear_polarizer_plus45()
            elif self.TYPE == 4:
                mm = MuellerMatrix.initialize_as_linear_polarizer_minus45()

            photon_bunch_out = PolarizedPhotonBunch()

            for index in range(photon_bunch.getNumberOfPhotons()):
                polarized_photon = photon_bunch.getPhotonIndex(index)

                polarized_photon.applyMuellerMatrix(mm)

                photon_bunch_out.addPhoton(polarized_photon)

            self.send("photon bunch", photon_bunch_out)

            # Dump data to file if requested.
            if self.DUMP_TO_FILE == 1:

                print("CrystalPassive: Writing data in {file}...\n".format(
                    file=self.FILE_NAME))

                with open(self.FILE_NAME, "w") as file:
                    try:
                        file.write(
                            "#S 1 photon bunch\n"
                            "#N 9\n"
                            "#L  Energy [eV]  Vx  Vy  Vz  S0  S1  S2  S3  circular polarization\n"
                        )
                        file.write(photon_bunch_out.toString())
                        file.close()
                        print("File written to disk: %s" % self.FILE_NAME)
                    except:
                        raise Exception(
                            "IdealLinerPolarizer: The data could not be dumped onto the specified file!\n"
                        )

        else:
            raise Exception("No photon beam available")