Ejemplo n.º 1
0
    def test_source_get_transmission_efficiencies_vs_multiple_photon_launch(self):
        n_photons = 30000
        source = polycap.Source(TestPolycapPhoton.description, 2000.0, 0.2065, 0.2065, 0.0, 0.0, 0.0, 0.0, 0.5, np.linspace(1, 25.0, 10))
        efficiencies = source.get_transmission_efficiencies(-1, n_photons, leak_calc=False)

        weights = np.zeros(10)
        phot_ini = 0
        phot_transm = 0
        myrng = TestPolycapSource.rng
        while phot_transm < n_photons:
            photon = source.get_photon(myrng)
            try:
                myweights = photon.launch(np.linspace(1, 25.0, 10), leak_calc=False)
                if myweights is not None:
                    weights += myweights
                    phot_transm += 1
                phot_ini += 1
            except ValueError:
                pass
        weights = weights[:]/phot_ini # normalize for total initiated photons, including simulated open area (due to photons that interacted with capllary walls at start)
        data = efficiencies.data
        for i in range(10):
            self.assertAlmostEqual(weights[i], data[1][i], delta=0.01)

        del(efficiencies)
Ejemplo n.º 2
0
    def test_source_good_get_transmission_efficiencies(self):
        VectorTuple = polycap.VectorTuple
        source = polycap.Source(TestPolycapPhoton.description, 2000.0, 0.2065, 0.2065, 0.0, 0.0, 0.0, 0.0, 0.5, np.linspace(1, 25.0, 250))
        efficiencies = source.get_transmission_efficiencies(-1, 10000, leak_calc=False)
        efficiencies.write_hdf5("temp-py.h5")
        self.assertTrue(os.path.exists("temp-py.h5"))
        os.remove("temp-py.h5")
        data = efficiencies.data
        self.assertIsInstance(data, tuple)
        data2 = efficiencies.data
        self.assertIsNot(data, data2)
        self.assertIs(data[0], data2[0])
        self.assertIs(data[1], data2[1])
        start_coords = list(efficiencies.start_coords)
        self.assertEqual(len(start_coords), 10000)
        start_coords = list(efficiencies.start_coords) # do it twice to test caching
        self.assertEqual(len(start_coords), 10000)
        start_direction = list(efficiencies.start_direction)
        start_elecv = list(efficiencies.start_elecv)
        src_start_coords = list(efficiencies.src_start_coords)
        self.assertIsInstance(start_coords[0], VectorTuple)
        self.assertEqual(start_coords[0].z, 0.)
        self.assertIsInstance(start_direction[0], VectorTuple)
        self.assertEqual(start_direction[0].z, 1.)
        self.assertIsInstance(start_elecv[0], VectorTuple)
        self.assertIsInstance(src_start_coords[0], VectorTuple)
        exit_coords = list(efficiencies.exit_coords)
        exit_direction = list(efficiencies.exit_direction)
        exit_elecv = list(efficiencies.exit_elecv)
        self.assertIsInstance(exit_coords[0], VectorTuple)
        self.assertIsInstance(exit_direction[0], VectorTuple)
        self.assertIsInstance(exit_elecv[0], VectorTuple)
        n_refl = list(efficiencies.n_refl)
        exit_weights = list(efficiencies.exit_weights)
        d_travel = list(efficiencies.d_travel)
        self.assertIsInstance(n_refl[0], int)
        self.assertIsInstance(exit_weights[0], np.ndarray)
        self.assertIsInstance(d_travel[0], float)
        
        self.assertEqual(sys.getrefcount(data[0]), 4)

        #fig = plt.figure()
        #ax = fig.add_subplot(111)
        #ax.plot(*data, color='r')
        #plt.draw()
        #plt.show()

        data = data[0]
        del(efficiencies)
        del(data2)

        self.assertEqual(sys.getrefcount(data), 2)

        with self.assertRaises(ValueError):
            data[0] = 6
Ejemplo n.º 3
0
 def test_source_bad_get_transmission_efficiencies(self):
     source = polycap.Source(TestPolycapPhoton.description, 2000.0, 0.2065, 0.2065, 0.0, 0.0, 0.0, 0.0, 0.5, np.linspace(1, 25.0, 250))
     with self.assertRaises(TypeError):
         efficiencies = source.get_transmission_efficiencies(-1, None, 1000)
     with self.assertRaises(TypeError):
         efficiencies = source.get_transmission_efficiencies(-1, 1000, False, "extra arg")
Ejemplo n.º 4
0
 def test_source_get_photon(self):
     source = polycap.Source(TestPolycapPhoton.description, 0.05, 0.1, 0.1, 0.2, 0.2, 0., 0., 0.5, np.linspace(1, 25.0, 250))
     photon = source.get_photon(TestPolycapSource.rng)
Ejemplo n.º 5
0
 def test_source_bad_input(self):
     with self.assertRaises(TypeError):
         source = polycap.Source(None, -1,-1,-1,-1,-1,0.3,0.3, 2., np.linspace(1, 25.0, 250))
     with self.assertRaises(ValueError):
         source = polycap.Source(TestPolycapPhoton.description, -1,-1,-1,-1,-1,0.3,0.3, 2., np.linspace(1, 25.0, 250))
Ejemplo n.º 6
0
profile = polycap.Profile(polycap.Profile.ELLIPSOIDAL, optic_length,
                          rad_ext_upstream, rad_ext_downstream,
                          rad_int_upstream, rad_int_downstream,
                          focal_dist_upstream, focal_dist_downstream)

#Define optic description
description = polycap.Description(profile, surface_rough, n_capillaries,
                                  composition, density)

# Launches a single photon with given start coordinates, direction and electric vector
start_coords = (0., 0., 0.)
start_direction = (0, 0, 1.0)
start_electric_vector = (0.5, 0.5, 0.)
photon = polycap.Photon(description, start_coords, start_direction,
                        start_electric_vector)
weights = photon.launch(np.linspace(1, 25.0, 250))

# Calculate transmission efficiency curve of given optic
source = polycap.Source(description, source_dist, source_rad_x, source_rad_y,
                        source_div_x, source_div_y,
                        source_shift_x, source_shift_y, source_polar,
                        np.linspace(1, 25.0, 250))
efficiencies = source.get_transmission_efficiencies(n_threads, n_photons)

# Use matplotlib to plot the data
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(*efficiencies.data, color='r')
plt.draw()
plt.show()