Beispiel #1
0
    def testGetArrayByKey(self):

        photon = Photon(energy_in_ev=8000.0)
        bunch = PhotonBunch()

        for i in range(10):
            bunch.addPhoton(photon)

        assert_array_almost_equal(bunch.getArrayByKey("energies"),
                                  numpy.ones(10) * 8000.0)
Beispiel #2
0
    def testChangePhotonValue(self):
        nphotons = 10

        bunch = PhotonBunch()
        list_of_photons = []
        for i in range(nphotons):
            photon = Photon(energy_in_ev=1000.0 + i,
                            direction_vector=Vector(1.0, 0.0, 0))
            bunch.addPhoton(photon)
            list_of_photons.append(photon)

        for i in range(bunch.getNumberOfPhotons()):
            self.assertTrue(bunch.getPhotonIndex(i) == list_of_photons[i])
    def toDictionary(self):
        """
        defines a dictionary containing information about the bunch.
        """
        array_dict = PhotonBunch.toDictionary(self)

        intensityS = np.zeros(len(self))
        intensityP = np.zeros_like(intensityS)
        phaseS = np.zeros_like(intensityS)
        phaseP = np.zeros_like(intensityS)

        for i, polarized_photon in enumerate(self):
            intensityS[i] = polarized_photon.getIntensityS()
            intensityP[i] = polarized_photon.getIntensityP()
            phaseS[i] = polarized_photon.getPhaseS()
            phaseP[i] = polarized_photon.getPhaseP()

        array_dict["intensityS"] = intensityS
        array_dict["intensityP"] = intensityP
        array_dict["phaseS"] = phaseS
        array_dict["phaseP"] = phaseP

        return array_dict
Beispiel #4
0
    def toDictionary(self):
        """
        defines a dictionary containing information about the bunch.
        """
        array_dict = PhotonBunch.toDictionary(self)

        stokes = numpy.zeros([4, len(self)])
        polarization_degrees = numpy.zeros(len(self))

        for i, polarized_photon in enumerate(self):
            stokes[0, i] = polarized_photon.stokesVector().s0
            stokes[1, i] = polarized_photon.stokesVector().s1
            stokes[2, i] = polarized_photon.stokesVector().s2
            stokes[3, i] = polarized_photon.stokesVector().s3
            polarization_degrees[
                i] = polarized_photon.circularPolarizationDegree()

        array_dict["s0"] = stokes[0, :]
        array_dict["s1"] = stokes[1, :]
        array_dict["s2"] = stokes[2, :]
        array_dict["s3"] = stokes[3, :]
        array_dict["polarization degree"] = polarization_degrees

        return array_dict
Beispiel #5
0
    def __init__(self,
                 geometry_type, crystal_name, thickness,
                 miller_h, miller_k, miller_l,
                 asymmetry_angle,
                 azimuthal_angle,
                 energy_min,
                 energy_max,
                 energy_points,
                 angle_deviation_min,
                 angle_deviation_max,
                 angle_deviation_points):
        """
        Constructor.
        :param geometry_type: GeometryType (BraggDiffraction,...).
        :param crystal_name: The name of the crystal, e.g. Si.
        :param thickness: The crystal thickness.
        :param miller_h: Miller index H.
        :param miller_k: Miller index K.
        :param miller_l: Miller index L.
        :param asymmetry_angle: The asymmetry angle between surface normal and Bragg normal.
        :param azimuthal_angle: The angle between the projection of the Bragg normal
                                on the crystal surface plane and the x axis.
        :param energy_min: The minimum energy.
        :param energy_max: The maximum energy.
        :param energy_points: Number of energy points.
        :param angle_deviation_min: Minimal angle deviation.
        :param angle_deviation_max: Maximal angle deviation.
        :param angle_deviation_points: Number of deviations points.
        """
        energies = numpy.linspace(energy_min,
                               energy_max,
                               energy_points)

        deviations = numpy.linspace(angle_deviation_min,
                                 angle_deviation_max,
                                 angle_deviation_points)

        # Create an "info setup" solely for the determination of deviation angles.
        info_setup = DiffractionSetup(geometry_type=geometry_type,
                                      crystal_name=crystal_name,
                                      thickness=thickness,
                                      miller_h=miller_h,
                                      miller_k=miller_k,
                                      miller_l=miller_l,
                                      asymmetry_angle=asymmetry_angle,
                                      azimuthal_angle=azimuthal_angle,)
                                      # incoming_photons=[Photon(energy_min, Vector(0, 0, -1))])


        # Call base constructor.
        DiffractionSetup.__init__(self,
                                  geometry_type=geometry_type,
                                  crystal_name=crystal_name,
                                  thickness=thickness,
                                  miller_h=miller_h,
                                  miller_k=miller_k,
                                  miller_l=miller_l,
                                  asymmetry_angle=asymmetry_angle,
                                  azimuthal_angle=azimuthal_angle,)

                                  # incoming_photons=photons)


        # Create photons according to sweeps.
        photons = PhotonBunch() # list()
        for energy in energies:
            for deviation in deviations:
                direction = info_setup.incomingPhotonDirection(energy, deviation)
                incoming_photon = Photon(energy, direction)
                # photons.append(incoming_photon)
                photons.addPhoton(incoming_photon)

        self._incoming_photons = photons
        # [email protected]: in theory, not needed as this info is in _incoming_photons
        # but buffering this accelerates a lot the calculations
        self._deviations = None
        self._energies = None
Beispiel #6
0
    def testAddPhoton(self):

        photon1 = Photon(energy_in_ev=1000.0)
        photon2 = Photon(energy_in_ev=2000.0)

        bunch = PhotonBunch()

        self.assertTrue(bunch.getNumberOfPhotons() == 0)

        bunch.addPhoton(photon1)
        bunch.addPhoton(photon2)

        self.assertTrue(bunch.getNumberOfPhotons() == 2)

        bunch.addPhotonsFromList([photon1, photon2])

        self.assertTrue(bunch.getNumberOfPhotons() == 4)

        bunch.addBunch(bunch)

        self.assertTrue(bunch.getNumberOfPhotons() == 8)
Beispiel #7
0
 def testToDictionary(self):
     self.assertTrue(isinstance(PhotonBunch().toDictionary(), dict))
Beispiel #8
0
    def testFromList(self):

        npoint = 1000
        vx = numpy.zeros(npoint) + 0.0
        vy = numpy.zeros(npoint) + 1.0
        vz = numpy.zeros(npoint) + 0.0

        energy = numpy.zeros(npoint) + 3000.0

        photon_bunch1 = PhotonBunch()
        photon_bunch2 = PhotonBunch()

        photons_list = list()

        for i in range(npoint):

            photon = Photon(energy_in_ev=energy[i],
                            direction_vector=Vector(vx[i], vy[i], vz[i]))

            photon_bunch1.addPhoton(photon)
            photons_list.append(photon)

        photon_bunch2.addPhotonsFromList(photons_list)

        energies = photon_bunch1.getArrayByKey("energies")
        for energy in energies:
            self.assertAlmostEqual(energy, 3000.0)

        for i in range(len(photon_bunch1)):
            # print("checking photon %d "%i)
            self.assertTrue(
                photon_bunch1.getPhotonIndex(i) ==
                photon_bunch2.getPhotonIndex(i))