Пример #1
0
 def test_integration_2d(self):
     """ Testing against ToroidalVoxelGrid"""
     world = World()
     rtc = RayTransferCylinder(radius_outer=4.,
                               height=2.,
                               n_radius=2,
                               n_height=2,
                               radius_inner=2.,
                               parent=world)
     rtc.step = 0.001 * rtc.step
     ray = Ray(origin=Point3D(4., 1., 2.),
               direction=Vector3D(-4., -1., -2.) / np.sqrt(21.),
               min_wavelength=500.,
               max_wavelength=501.,
               bins=rtc.bins)
     spectrum = ray.trace(world)
     world = World()
     vertices = []
     for rv in [2., 3.]:
         for zv in [0., 1.]:
             vertices.append([
                 Point2D(rv, zv + 1.),
                 Point2D(rv + 1., zv + 1.),
                 Point2D(rv + 1., zv),
                 Point2D(rv, zv)
             ])
     tvg = ToroidalVoxelGrid(vertices,
                             parent=world,
                             primitive_type='csg',
                             active='all')
     tvg.set_active('all')
     spectrum_test = ray.trace(world)
     self.assertTrue(
         np.allclose(spectrum_test.samples, spectrum.samples, atol=0.001))
Пример #2
0
 def test_integration(self):
     world = World()
     rtb = RayTransferBox(xmax=3.,
                          ymax=3.,
                          zmax=3.,
                          nx=3,
                          ny=3,
                          nz=3,
                          parent=world)
     rtb.step = 0.01 * rtb.step
     ray = Ray(origin=Point3D(4., 4., 4.),
               direction=Vector3D(-1., -1., -1.) / np.sqrt(3),
               min_wavelength=500.,
               max_wavelength=501.,
               bins=rtb.bins)
     spectrum = ray.trace(world)
     spectrum_test = np.zeros(rtb.bins)
     spectrum_test[0] = spectrum_test[13] = spectrum_test[26] = np.sqrt(3.)
     self.assertTrue(
         np.allclose(spectrum_test, spectrum.samples, atol=0.001))
Пример #3
0
 def test_integration_3d(self):
     world = World()
     rtc = RayTransferCylinder(radius_outer=2.,
                               height=2.,
                               n_radius=2,
                               n_height=2,
                               n_polar=3,
                               period=90.,
                               parent=world)
     rtc.step = 0.001 * rtc.step
     ray = Ray(origin=Point3D(np.sqrt(2.), np.sqrt(2.), 2.),
               direction=Vector3D(-1., -1., -np.sqrt(2.)) / 2.,
               min_wavelength=500.,
               max_wavelength=501.,
               bins=rtc.bins)
     spectrum = ray.trace(world)
     spectrum_test = np.zeros(rtc.bins)
     spectrum_test[2] = spectrum_test[9] = np.sqrt(2.)
     self.assertTrue(
         np.allclose(spectrum_test, spectrum.samples, atol=0.001))
Пример #4
0
 def test_evaluate_function(self):
     """
     Unlike test_integration() in TestRayTransferBox here we test how
     CartesianRayTransferEmitter works with NumericalIntegrator.
     """
     world = World()
     material = CartesianRayTransferEmitter(
         (3, 3, 3), (1., 1., 1.), integrator=NumericalIntegrator(0.0001))
     box = Box(lower=Point3D(0, 0, 0),
               upper=Point3D(2.99999, 2.99999, 2.99999),
               material=material,
               parent=world)
     ray = Ray(origin=Point3D(4., 4., 4.),
               direction=Vector3D(-1., -1., -1.) / np.sqrt(3),
               min_wavelength=500.,
               max_wavelength=501.,
               bins=material.bins)
     spectrum = ray.trace(world)
     spectrum_test = np.zeros(material.bins)
     spectrum_test[0] = spectrum_test[13] = spectrum_test[26] = np.sqrt(3.)
     self.assertTrue(
         np.allclose(spectrum_test, spectrum.samples, atol=0.001))
Пример #5
0
 def test_evaluate_function_2d(self):
     """
     Unlike test_integration_2d() in TestRayTransferCylinder here we test how
     CylindricalRayTransferEmitter works with NumericalIntegrator in axysimmetric case.
     Testing against ToroidalVoxelGrid.
     """
     world = World()
     material = CylindricalRayTransferEmitter(
         (2, 2), (1., 1.), rmin=2., integrator=NumericalIntegrator(0.0001))
     primitive = Subtract(Cylinder(3.999999, 1.999999),
                          Cylinder(2.0, 1.999999),
                          material=material,
                          parent=world)
     ray = Ray(origin=Point3D(4., 1., 2.),
               direction=Vector3D(-4., -1., -2.) / np.sqrt(21.),
               min_wavelength=500.,
               max_wavelength=501.,
               bins=4)
     spectrum = ray.trace(world)
     world = World()
     vertices = []
     for rv in [2., 3.]:
         for zv in [0., 1.]:
             vertices.append([
                 Point2D(rv, zv + 1.),
                 Point2D(rv + 1., zv + 1.),
                 Point2D(rv + 1., zv),
                 Point2D(rv, zv)
             ])
     tvg = ToroidalVoxelGrid(vertices,
                             parent=world,
                             primitive_type='csg',
                             active='all')
     tvg.set_active('all')
     spectrum_test = ray.trace(world)
     self.assertTrue(
         np.allclose(spectrum_test.samples, spectrum.samples, atol=0.001))
Пример #6
0
 def test_evaluate_function_3d(self):
     """
     Unlike test_integration_3d() in TestRayTransferCylinder here we test how
     CylindricalRayTransferEmitter works with NumericalIntegrator in 3D case.
     """
     world = World()
     material = CylindricalRayTransferEmitter(
         (2, 3, 2), (1., 30., 1.),
         period=90.,
         integrator=NumericalIntegrator(0.0001))
     primitive = Subtract(Cylinder(1.999999, 1.999999),
                          Cylinder(0.000001, 1.999999),
                          material=material,
                          parent=world)
     ray = Ray(origin=Point3D(np.sqrt(2.), np.sqrt(2.), 2.),
               direction=Vector3D(-1., -1., -np.sqrt(2.)) / 2.,
               min_wavelength=500.,
               max_wavelength=501.,
               bins=12)
     spectrum = ray.trace(world)
     spectrum_test = np.zeros(12)
     spectrum_test[2] = spectrum_test[9] = np.sqrt(2.)
     self.assertTrue(
         np.allclose(spectrum_test, spectrum.samples, atol=0.001))
Пример #7
0
# Box(Point(-100, -100, -100), Point(100, 100, 100), world, material=UniformSurfaceEmitter(d65_white, 0.001))

# OBSERVER --------------------------------------------------------------------

#import cProfile
#
# def profile_test(n=25000):
#     r = Ray(origin=Point(0.0, 0, 0), min_wavelength=526, max_wavelength=532, num_samples=100)
#     for i in range(n):
#         r.trace(world)
#
# cProfile.run("profile_test()", sort="tottime")

ion()

r = Ray(origin=Point3D(0.5, 0, -2.5), min_wavelength=440, max_wavelength=740, bins=800)
s = r.trace(world)
plot(s.wavelengths, s.samples)

r = Ray(origin=Point3D(0.5, 0, -2.5), min_wavelength=440, max_wavelength=740, bins=1600)
s = r.trace(world)
plot(s.wavelengths, s.samples)
show()

camera = PinholeCamera((128, 128), parent=world, transform=translate(0, 0, -2.5))
camera.spectral_rays = 1
camera.spectral_bins = 21
camera.pixel_samples = 50

ion()
camera.observe()
Пример #8
0
# setup the Nitrgon II line with multiplet splitting instructions
nitrogen_II_404 = Line(nitrogen, 1,
                       ("2s2 2p1 4f1 3G13.0", "2s2 2p1 3d1 3F10.0"))
multiplet = [[403.509, 404.132, 404.354, 404.479, 405.692],
             [0.205, 0.562, 0.175, 0.029, 0.029]]

# add all lines to the plasma
plasma.models = [
    ExcitationLine(hydrogen_I_410, lineshape=StarkBroadenedLine),
    RecombinationLine(hydrogen_I_410, lineshape=StarkBroadenedLine),
    ExcitationLine(hydrogen_I_396, lineshape=StarkBroadenedLine),
    RecombinationLine(hydrogen_I_396, lineshape=StarkBroadenedLine),
    ExcitationLine(nitrogen_II_404,
                   lineshape=MultipletLineShape,
                   lineshape_args=[multiplet]),
]

# Ray-trace and plot the results
plt.ion()
r = Ray(origin=Point3D(0, 0, -5),
        direction=Vector3D(0, 0, 1),
        min_wavelength=395,
        max_wavelength=415,
        bins=2000)
s = r.trace(world)
plt.plot(s.wavelengths, s.samples)
plt.xlabel('Wavelength (nm)')
plt.ylabel('Radiance (W/m^2/str/nm)')
plt.title('Observed Spectrum')
plt.show()
Пример #9
0
z = np.linspace(0, 3, 200)
beam_full_densities = [beam_full.density(0, 0, zz) for zz in z]
beam_half_densities = [beam_half.density(0, 0, zz) for zz in z]
beam_third_densities = [beam_third.density(0, 0, zz) for zz in z]
plt.figure()
plt.plot(z, beam_full_densities, label="full energy")
plt.plot(z, beam_half_densities, label="half energy")
plt.plot(z, beam_third_densities, label="third energy")
plt.xlabel('z axis (beam coords)')
plt.ylabel('beam component density [m^-3]')
plt.title("Beam attenuation by energy component")
plt.legend()

ray = Ray(origin=Point3D(1.25, -3.5, 0),
          direction=Vector3D(0, 1, 0),
          min_wavelength=440,
          max_wavelength=540,
          bins=2000)
s = ray.trace(world)
plt.figure()
plt.plot(s.wavelengths, s.samples)
plt.xlabel('Wavelength (nm)')
plt.ylabel('Radiance (W/m^2/str/nm)')
plt.title('Sampled CXS Spectrum')

plt.figure()
viewing_targets = [
    Point3D(0.25, 0, 0),
    Point3D(0.5, 0, 0),
    Point3D(0.75, 0, 0),
    Point3D(1.0, 0, 0),
Пример #10
0
z = np.linspace(0, 3, 200)
beam_full_densities = [beam_full.density(0, 0, zz) for zz in z]
beam_half_densities = [beam_half.density(0, 0, zz) for zz in z]
beam_third_densities = [beam_third.density(0, 0, zz) for zz in z]
plt.figure()
plt.plot(z, beam_full_densities, label="full energy")
plt.plot(z, beam_half_densities, label="half energy")
plt.plot(z, beam_third_densities, label="third energy")
plt.xlabel('z axis (beam coords)')
plt.ylabel('beam component density [m^-3]')
plt.title("Beam attenuation by energy component")
plt.legend()

ray = Ray(origin=Point3D(*los_start),
          direction=los_direction,
          min_wavelength=640,
          max_wavelength=670,
          bins=2000)
s = ray.trace(world)
plt.figure()
plt.plot(s.wavelengths, s.samples)
plt.xlabel('Wavelength (nm)')
plt.ylabel('Radiance (W/m^2/str/nm)')
plt.title('Sampled BES Spectrum')

transform = translate(1.25, -3.5, 0) * rotate_basis(Vector3D(0, 1, 0),
                                                    Vector3D(0, 0, 1))
camera = PinholeCamera((128, 128), parent=world, transform=transform)
camera.spectral_rays = 1
camera.spectral_bins = 15
camera.pixel_samples = 50
Пример #11
0
    ExcitationLine(d_beta),
    ExcitationLine(d_gamma),
    ExcitationLine(d_delta),
    ExcitationLine(d_epsilon),
    RecombinationLine(d_alpha),
    RecombinationLine(d_beta),
    RecombinationLine(d_gamma),
    RecombinationLine(d_delta),
    RecombinationLine(d_epsilon)
]

plt.ion()

r = Ray(origin=Point3D(0, 0, -5),
        direction=Vector3D(0, 0, 1),
        min_wavelength=100,
        max_wavelength=1000,
        bins=1e6)
s = r.trace(world)
plt.plot(s.wavelengths, s.samples)

r = Ray(origin=Point3D(-5, 0, -5),
        direction=Vector3D(1, 0, 1),
        min_wavelength=100,
        max_wavelength=1000,
        bins=1e6)
s = r.trace(world)
plt.plot(s.wavelengths, s.samples)

r = Ray(origin=Point3D(-5, 0, 0),
        direction=Vector3D(1, 0, 0),