Ejemplo n.º 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_spherecial_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.throw = self.throw + 1
        return photon
Ejemplo n.º 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_spherecial_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.throw = self.throw + 1 
     return photon
Ejemplo n.º 3
0
    def photon(self):
        photon = Photon()
        photon.source = self.source_id
        photon.id = self.throw
        self.throw = self.throw + 1

        phi = np.random.uniform(self.phimin, self.phimax)
        theta = np.random.uniform(self.thetamin, self.thetamax)

        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
Ejemplo n.º 4
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
Ejemplo n.º 5
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
Ejemplo n.º 6
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
Ejemplo n.º 7
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   
Ejemplo n.º 8
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
Ejemplo n.º 9
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
Ejemplo n.º 10
0
    def photon(self):
        photon = Photon()
        photon.source = self.source_id
        photon.id = self.throw
        self.throw = self.throw + 1

        # 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 != None:
            photon.wavelength = self.spectrum.wavelength_at_probability(
                np.random.uniform())
        else:
            photon.wavelength = self.wavelength

        # Further initialisation
        photon.active = True

        return photon
Ejemplo n.º 11
0
    def photon(self):
        photon = Photon()
        photon.source = self.source_id
        photon.id = self.throw
        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.phimin, self.phimax)
        #theta = np.random.uniform(self.thetamin, self.thetamax)

        theta = -1
        while theta > self.thetamax or theta < self.thetamin:
            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 != None:
            photon.wavelength = self.spectrum.wavelength_at_probability(
                np.random.uniform())
        else:
            photon.wavelength = self.wavelength

        photon.active = True

        return photon
Ejemplo n.º 12
0
 def photon(self):
     photon = Photon()
     photon.source = self.source_id
     photon.id = self.throw
     self.throw = self.throw + 1 
     
     # 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 != None:
         photon.wavelength = self.spectrum.wavelength_at_probability(np.random.uniform())        
     else:
         photon.wavelength = self.wavelength
         
     # Further initialisation
     photon.active = True
     
     return photon
Ejemplo n.º 13
0
    def photon(self):
        photon = Photon()
        photon.source = self.source_id
        photon.id = self.throw
        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.phimin, self.phimax)
        #theta = np.random.uniform(self.thetamin, self.thetamax)
		
        theta = -1
        while theta > self.thetamax or theta < self.thetamin :
            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 != None:
            photon.wavelength = self.spectrum.wavelength_at_probability(np.random.uniform())
        else:
            photon.wavelength = self.wavelength
            
        photon.active = True
        
        return photon