예제 #1
0
    def photon(self):
        photon = Photon()
        photon.source = self.source_id
        photon.position = np.array(self.position)
        photon.direction = np.array(self.direction)
        photon.active = True
        photon.wavelength = self.wavelength

        # If use_polarisation is set generate a random polarisation vector of the photon
        if self.use_random_polarisation:

            # Randomise rotation angle around xy-plane, the transform from +z to the direction of the photon
            vec = random_spherical_vector()
            vec[2] = 0.
            vec = norm(vec)
            r = rotation_matrix_from_vector_alignment(self.direction,
                                                      [0., 0., 1.])
            photon.polarisation = transform_direction(vec, r)

        else:
            photon.polarisation = None

        photon.id = self.throw
        self.log.debug('Emitted photon (pid: ' + str(self.throw) + ')')
        self.throw += 1
        return photon
예제 #2
0
    def photon(self):
        photon = Photon()
        photon.source = self.source_id
        photon.position = np.array(self.position)
        photon.direction = np.array(self.direction)
        photon.active = True
        photon.wavelength = self.wavelength

        # If use_polarisation is set generate a random polarisation vector of the photon
        if self.use_random_polarisation:

            # Randomise rotation angle around xy-plane, the transform from +z to the direction of the photon
            vec = random_spherical_vector()
            vec[2] = 0.
            vec = norm(vec)
            r = rotation_matrix_from_vector_alignment(self.direction, [0., 0., 1.])
            photon.polarisation = transform_direction(vec, r)

        else:
            photon.polarisation = None

        photon.id = self.throw
        self.log.debug('Emitted photon (pid: ' + str(self.throw)+')')
        self.throw += 1
        return photon
예제 #3
0
 def photon(self):
     photon = Photon()
     photon.source = self.source_id
     photon.position = np.array(self.position)
     photon.direction = np.array(self.direction)
     photon.active = True
     photon.wavelength = self.wavelength
     photon.polarisation = self.polarisation
     photon.id = self.throw
     self.log.debug('Emitted photon (pid: ' + str(self.throw) + ')')
     self.throw += 1
     return photon
예제 #4
0
    def photon(self):

        photon = Photon()
        photon.source = self.source_id
        photon.position = np.array(self.position)
        photon.direction = np.array(self.direction)
        photon.active = True
        photon.wavelength = self.wavelength
        photon.polarisation = self.polarisation
        photon.id = self.throw
        self.throw = self.throw + 1
        return photon
예제 #5
0
 def photon(self):
     photon = Photon()
     photon.source = self.source_id
     photon.position = np.array(self.position)
     photon.direction = np.array(self.direction)
     photon.active = True
     photon.wavelength = self.wavelength
     photon.polarisation = self.polarisation
     photon.id = self.throw
     self.log.debug('Emitted photon (pid: ' + str(self.throw)+')')
     self.throw += 1
     return photon
예제 #6
0
    def photon(self):
        photon = Photon()
        photon.source = self.source_id
        photon.id = self.throw
        self.throw = self.throw + 1
        # Create a point which is on the surface of the finite plane in it's local frame
        x = np.random.uniform(0., self.length)
        y = np.random.uniform(0., self.width)
        local_point = (x, y, 0.)

        # Transform the direciton
        photon.position = transform_point(local_point, self.plane.transform)
        photon.direction = self.direction
        photon.active = True
        if self.spectrum != None:
            photon.wavelength = self.spectrum.wavelength_at_probability(
                np.random.uniform())
        else:
            photon.wavelength = self.wavelength
        return photon
예제 #7
0
    def photon(self):
        photon = Photon()
        photon.source = self.source_id
        photon.id = self.throw
        self.throw += 1

        # This does not work, since the area element scales with Sin(theta) d theta d phi
        # See  http://mathworld.wolfram.com/SpherePointPicking.html
        # Reimplementing the Randomizer

        phi = np.random.uniform(self.phi_min, self.phi_max)
        # theta = np.random.uniform(self.theta_min, self.theta_max)

        theta = -1
        while theta > self.theta_max or theta < self.theta_min:
            theta = np.arccos(2 * np.random.uniform(0, 1) - 1)

        x = np.cos(phi) * np.sin(theta)
        y = np.sin(phi) * np.sin(theta)
        z = np.cos(theta)
        direction = (x, y, z)

        transform = tf.translation_matrix((0, 0, 0))
        point = transform_point(self.center, transform)

        photon.direction = direction
        photon.position = point

        if self.spectrum is not None:
            photon.wavelength = self.spectrum.wavelength_at_probability(
                np.random.uniform())
        else:
            photon.wavelength = self.wavelength

        photon.active = True

        photon.id = self.throw
        self.log.debug('Emitted photon (pid: ' + str(self.throw) + ')')
        self.throw += 1
        return photon
예제 #8
0
    def photon(self):
        photon = Photon()
        photon.source = self.source_id

        # Position of emission
        phi = np.random.uniform(0., 2 * np.pi)
        r = np.random.uniform(0., self.radius)

        x = r * np.cos(phi)
        y = r * np.sin(phi)
        z = np.random.uniform(0., self.length)
        local_center = (x, y, z)

        photon.position = transform_point(local_center, self.shape.transform)

        # Direction of emission (no need to transform if meant to be isotropic)
        phi = np.random.uniform(0., 2 * np.pi)
        theta = np.random.uniform(0., np.pi)

        x = np.cos(phi) * np.sin(theta)
        y = np.sin(phi) * np.sin(theta)
        z = np.cos(theta)
        local_direction = (x, y, z)

        photon.direction = local_direction

        # Set wavelength of photon
        if self.spectrum is not None:
            photon.wavelength = self.spectrum.wavelength_at_probability(
                np.random.uniform())
        else:
            photon.wavelength = self.wavelength

        # Further initialisation
        photon.active = True

        photon.id = self.throw
        self.log.debug('Emitted photon (pid: ' + str(self.throw) + ')')
        self.throw += 1
        return photon
예제 #9
0
    def photon(self):
        photon = Photon()
        photon.source = self.source_id
        photon.id = self.throw
        self.throw += 1
        
        # This does not work, since the area element scales with Sin(theta) d theta d phi
        # See  http://mathworld.wolfram.com/SpherePointPicking.html
        # Reimplementing the Randomizer

        phi = np.random.uniform(self.phi_min, self.phi_max)
        # theta = np.random.uniform(self.theta_min, self.theta_max)
        
        theta = -1
        while theta > self.theta_max or theta < self.theta_min:
            theta = np.arccos(2 * np.random.uniform(0, 1)-1)
        
        x = np.cos(phi) * np.sin(theta)
        y = np.sin(phi) * np.sin(theta)
        z = np.cos(theta)
        direction = (x, y, z)

        transform = tf.translation_matrix((0, 0, 0))
        point = transform_point(self.center, transform)

        photon.direction = direction
        photon.position = point

        if self.spectrum is not None:
            photon.wavelength = self.spectrum.wavelength_at_probability(np.random.uniform())
        else:
            photon.wavelength = self.wavelength

        photon.active = True

        photon.id = self.throw
        self.log.debug('Emitted photon (pid: ' + str(self.throw)+')')
        self.throw += 1
        return photon
예제 #10
0
    def photon(self):
        photon = Photon()
        photon.source = self.source_id

        # Position of emission
        phi = np.random.uniform(0., 2 * np.pi)
        r = np.random.uniform(0., self.radius)

        x = r * np.cos(phi)
        y = r * np.sin(phi)
        z = np.random.uniform(0., self.length)
        local_center = (x, y, z)

        photon.position = transform_point(local_center, self.shape.transform)

        # Direction of emission (no need to transform if meant to be isotropic)
        phi = np.random.uniform(0., 2 * np.pi)
        theta = np.random.uniform(0., np.pi)

        x = np.cos(phi) * np.sin(theta)
        y = np.sin(phi) * np.sin(theta)
        z = np.cos(theta)
        local_direction = (x, y, z)

        photon.direction = local_direction

        # Set wavelength of photon
        if self.spectrum is not None:
            photon.wavelength = self.spectrum.wavelength_at_probability(np.random.uniform())
        else:
            photon.wavelength = self.wavelength

        # Further initialisation
        photon.active = True

        photon.id = self.throw
        self.log.debug('Emitted photon (pid: ' + str(self.throw)+')')
        self.throw += 1
        return photon
예제 #11
0
    def photon(self):
        photon = Photon()
        photon.source = self.source_id

        # Create a point which is on the surface of the finite plane in it's local frame
        x = np.random.uniform(0., self.length)
        y = np.random.uniform(0., self.width)
        local_point = (x, y, 0.)

        # Transform the direction
        photon.position = transform_point(local_point, self.plane.transform)
        photon.direction = self.direction
        photon.active = True
        if self.spectrum is not None:
            photon.wavelength = self.spectrum.wavelength_at_probability(np.random.uniform())
        else:
            photon.wavelength = self.wavelength

        photon.id = self.throw
        self.log.debug('Emitted photon (pid: ' + str(self.throw)+')')
        self.throw += 1
        return photon
예제 #12
0
    def photon(self):
        photon = Photon()

        photon.source = self.source_id

        int_phi = np.random.randint(1, self.spacing + 1)
        int_theta = np.random.randint(1, self.spacing + 1)

        phi = int_phi * (self.phi_max - self.phi_min) / self.spacing
        if self.theta_min == self.theta_max:
            theta = self.theta_min
        else:
            theta = int_theta * (self.theta_max -
                                 self.theta_min) / self.spacing

        x = np.cos(phi) * np.sin(theta)
        y = np.sin(phi) * np.sin(theta)
        z = np.cos(theta)
        direction = (x, y, z)

        transform = tf.translation_matrix((0, 0, 0))
        point = transform_point(self.center, transform)

        photon.direction = direction
        photon.position = point

        if self.spectrum is not None:
            photon.wavelength = self.spectrum.wavelength_at_probability(
                np.random.uniform())
        else:
            photon.wavelength = self.wavelength

        photon.active = True

        photon.id = self.throw
        self.log.debug('Emitted photon (pid: ' + str(self.throw) + ')')
        self.throw += 1
        return photon
예제 #13
0
    def photon(self):
        photon = Photon()

        photon.source = self.source_id
        photon.id = self.throw
        self.throw = self.throw + 1

        intphi = np.random.randint(1, self.spacing + 1)
        inttheta = np.random.randint(1, self.spacing + 1)

        phi = intphi * (self.phimax - self.phimin) / self.spacing
        if self.thetamin == self.thetamax:
            theta = self.thetamin
        else:
            theta = inttheta * (self.thetamax - self.thetamin) / self.spacing

        x = np.cos(phi) * np.sin(theta)
        y = np.sin(phi) * np.sin(theta)
        z = np.cos(theta)
        direction = (x, y, z)

        transform = tf.translation_matrix((0, 0, 0))
        point = transform_point(self.center, transform)

        photon.direction = direction
        photon.position = point

        if self.spectrum != None:
            photon.wavelength = self.spectrum.wavelength_at_probability(
                np.random.uniform())
        else:
            photon.wavelength = self.wavelength

        photon.active = True

        return photon
예제 #14
0
    def photon(self):
        photon = Photon()

        photon.source = self.source_id

        int_phi = np.random.randint(1, self.spacing + 1)
        int_theta = np.random.randint(1, self.spacing + 1)

        phi = int_phi * (self.phi_max - self.phi_min) / self.spacing
        if self.theta_min == self.theta_max:
            theta = self.theta_min
        else:
            theta = int_theta * (self.theta_max - self.theta_min) / self.spacing

        x = np.cos(phi) * np.sin(theta)
        y = np.sin(phi) * np.sin(theta)
        z = np.cos(theta)
        direction = (x, y, z)

        transform = tf.translation_matrix((0, 0, 0))
        point = transform_point(self.center, transform)

        photon.direction = direction
        photon.position = point

        if self.spectrum is not None:
            photon.wavelength = self.spectrum.wavelength_at_probability(np.random.uniform())
        else:
            photon.wavelength = self.wavelength

        photon.active = True

        photon.id = self.throw
        self.log.debug('Emitted photon (pid: ' + str(self.throw)+')')
        self.throw += 1
        return photon