def photon(self): photon = Photon() # 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]) boost = y * np.tan(self.angle) z = np.random.uniform(self.plane_origin[2], self.plane_extent[2]) - boost 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] + boost 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
def photon(self): photon = Photon() 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]) boost = y * np.tan(self.angle) z = np.random.uniform(self.planeorigin[2], self.planeextent[2]) - boost 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] + boost 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
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
def photon(self): photon = Photon() # 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]) boost = y * np.tan(self.angle) z = np.random.uniform(self.plane_origin[2], self.plane_extent[2]) - boost 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] + boost 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
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
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
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
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
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
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
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
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
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
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
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
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
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