コード例 #1
0
ファイル: LightSources.py プロジェクト: dcambie/pvtrace
    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
ファイル: LightSources.py プロジェクト: dcambie/pvtrace
    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
ファイル: Trajectory.py プロジェクト: dcambie/pvtrace
 def add_step(self, position=None, direction=None, polarization=None, wavelength=None, active=False, container=None,
              on_surface_object=None):
     photon = Photon(wavelength=wavelength, position=position, direction=direction, active=active)
     photon.polarisation = polarization
     if str(container) not in self.known_obj:
         self.known_obj.append(str(container))
     photon.container = str(container)
     if str(on_surface_object) not in self.known_obj:
         self.known_obj.append(str(on_surface_object))
     photon.on_surface_object = str(on_surface_object)
     self.steps.append(photon)
コード例 #4
0
ファイル: LightSources.py プロジェクト: dcambie/pvtrace
    def photon(self):
        photon = Photon()
        photon.source = self.source_id

        # Position
        x = np.random.uniform(self.plane_origin[0], self.plane_extent[0])
        y = np.random.uniform(self.plane_origin[1], self.plane_extent[1])
        z = np.random.uniform(self.plane_origin[2], self.plane_extent[2])
        photon.position = np.array((x, y, z))

        # Direction
        focus_point = np.array((0., 0., 0.))
        focus_point[0] = self.line_point[0] + np.random.uniform(
            -self.focus_size, self.focus_size)
        focus_point[1] = self.line_point[1] + np.random.uniform(
            -self.focus_size, self.focus_size)
        focus_point[2] = photon.position[2]

        direction = focus_point - photon.position
        modulus = (direction[0]**2 + direction[1]**2 + direction[2]**2)**0.5
        photon.direction = direction / modulus

        # Wavelength
        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
コード例 #5
0
    def photon(self):
        photon = Photon()
        photon.source = self.source_id
        photon.id = self.throw
        self.throw = self.throw + 1

        # Position
        x = np.random.uniform(self.planeorigin[0], self.planeextent[0])
        y = np.random.uniform(self.planeorigin[1], self.planeextent[1])
        z = np.random.uniform(self.planeorigin[2], self.planeextent[2])
        photon.position = np.array((x, y, z))

        # Direction
        focuspoint = np.array((0., 0., 0.))
        focuspoint[0] = self.linepoint[0] + np.random.uniform(
            -self.focussize, self.focussize)
        focuspoint[1] = self.linepoint[1] + np.random.uniform(
            -self.focussize, self.focussize)
        focuspoint[2] = photon.position[2]

        direction = focuspoint - photon.position
        modulus = (direction[0]**2 + direction[1]**2 + direction[2]**2)**0.5
        photon.direction = direction / modulus

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

        return photon
コード例 #6
0
ファイル: LightSources.py プロジェクト: dcambie/pvtrace
 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
コード例 #7
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
コード例 #8
0
ファイル: LightSources.py プロジェクト: dcambie/pvtrace
    def photon(self):
        photon = Photon()
        photon.source = self.source_id

        # Position
        x = np.random.uniform(self.plane_origin[0], self.plane_extent[0])
        y = np.random.uniform(self.plane_origin[1], self.plane_extent[1])
        z = np.random.uniform(self.plane_origin[2], self.plane_extent[2])
        photon.position = np.array((x, y, z))

        # Direction
        focus_point = np.array((0., 0., 0.))
        focus_point[0] = self.line_point[0] + np.random.uniform(-self.focus_size, self.focus_size)
        focus_point[1] = self.line_point[1] + np.random.uniform(-self.focus_size, self.focus_size)
        focus_point[2] = photon.position[2]

        direction = focus_point - photon.position
        modulus = (direction[0] ** 2 + direction[1] ** 2 + direction[2] ** 2) ** 0.5
        photon.direction = direction / modulus

        # Wavelength
        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
コード例 #9
0
ファイル: LightSources.py プロジェクト: dcambie/pvtrace
 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
コード例 #10
0
 def add_step(self,
              position=None,
              direction=None,
              polarization=None,
              wavelength=None,
              active=False,
              container=None,
              on_surface_object=None):
     photon = Photon(wavelength=wavelength,
                     position=position,
                     direction=direction,
                     active=active)
     photon.polarisation = polarization
     if str(container) not in self.known_obj:
         self.known_obj.append(str(container))
     photon.container = str(container)
     if str(on_surface_object) not in self.known_obj:
         self.known_obj.append(str(on_surface_object))
     photon.on_surface_object = str(on_surface_object)
     self.steps.append(photon)
コード例 #11
0
ファイル: LightSources.py プロジェクト: dcambie/pvtrace
    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
コード例 #12
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
コード例 #13
0
ファイル: LightSources.py プロジェクト: dcambie/pvtrace
    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
コード例 #14
0
ファイル: LightSources.py プロジェクト: dcambie/pvtrace
    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
コード例 #15
0
ファイル: LightSources.py プロジェクト: dcambie/pvtrace
    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
コード例 #16
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
コード例 #17
0
ファイル: LightSources.py プロジェクト: dcambie/pvtrace
    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
コード例 #18
0
ファイル: LightSources.py プロジェクト: dcambie/pvtrace
    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
コード例 #19
0
ファイル: LightSources.py プロジェクト: dcambie/pvtrace
    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