Exemple #1
0
 def testSingleLayer(self):
     pr = Cn2Profile.from_r0s([0.1], [30], [100], [10], [0.3])
     self.assertAlmostEqual([100], pr.layers_distance().value)
     self.assertAlmostEqual(0.1, pr.r0().value)
     pr = Cn2Profile.from_fractional_j(0.12, [1.0], [30], [100], [10],
                                       [0.3])
     self.assertAlmostEqual(0.12, pr.r0().value)
Exemple #2
0
    def testBuildFromFractionalJ(self):
        pr = Cn2Profile.from_fractional_j(0.1, 1.0, 30, 100, 10, 0.3)
        self.assertAlmostEqual(0.1, pr.r0().value)
        pr = Cn2Profile.from_fractional_j(0.13, [0.1, 0.9], [30, 42], [0, 100],
                                          [3.14, 10], [0, 0.3])
        self.assertAlmostEqual(0.13, pr.r0().value)

        dontSumToOne = np.array([0.1, 42])
        self.assertRaises(Exception, Cn2Profile.from_fractional_j, 42,
                          dontSumToOne, 30, 100, 10, 0)
Exemple #3
0
 def testTheta0OfSingleLayer(self):
     zenAngle = 23.5
     airmass = Cn2Profile.zenith_angle_to_airmass(zenAngle)
     r0 = 0.13
     h = 1000.
     pr = Cn2Profile.from_fractional_j(r0, 1.0, 30, h, 10, 0.3)
     pr.set_zenith_angle(zenAngle)
     pr.set_wavelength(1.0e-6)
     wanted = (2.914 / 0.422727)**(-3. / 5) * pr.r0().value / (
         h * airmass) * Constants.RAD2ARCSEC
     self.assertAlmostEqual(wanted, pr.theta0().value)
    def testZernikeCPSD(self):
        cn2 = Cn2Profile.from_r0s([0.16], [25], [10e3], [10], [-20])
        rho1, theta1 = (0, 0)
        rho2, theta2 = (50, 30)
        source1 = GuideSource((rho1, theta1), np.inf)
        source2 = GuideSource((rho2, theta2), 100e3)
        radius = 5
        center = [0, 0, 0]
        aperture = CircularOpticalAperture(radius, center)
        spatial_freqs = np.logspace(-3, 3, 100)

        modoJ = 2
        modoK = 5
        temp_freqs = [0.05, 130, 250]

        vk_cov = VonKarmanSpatioTemporalCovariance(source1, source2, aperture,
                                                   aperture, cn2,
                                                   spatial_freqs)
        got = vk_cov.getZernikeCPSD(modoJ, modoK, temp_freqs)

        want = np.array([
            -2.753219e+00 + 1.446667e+00j, 5.859243e-13 - 6.117817e-13j,
            -4.741206e-15 + 4.089497e-15j
        ])

        np.testing.assert_allclose(want, got.value, rtol=1e-3)
        self.assertEqual(got.unit, u.rad**2 / u.Hz)
    def testZernikeCPSDvsZernikeGeneralCPSD(self):
        cn2 = Cn2Profile.from_r0s([0.16, 3.14], [25, 12], [10e3, 200], [10, 8],
                                  [-20, 23])
        rho, theta = (0, 0)
        source = GuideSource((rho, theta), np.inf)
        radius = 5
        center = [0, 0, 0]
        aperture = CircularOpticalAperture(radius, center)
        spatial_freqs = np.logspace(-3, 3, 100)
        temporal_freqs = np.logspace(-4, 4, 100)

        j = [2, 3]
        k = [2, 3, 4]

        vk = VonKarmanSpatioTemporalCovariance(source, source, aperture,
                                               aperture, cn2, spatial_freqs)

        cpsd = vk.getZernikeCPSD(j, k, temporal_freqs)
        cov_from_cpsd = np.trapz(2 * np.real(cpsd), temporal_freqs).value

        general_cpsd = vk.getGeneralZernikeCPSD(j, k, temporal_freqs)
        cov_from_general_cpsd = np.trapz(general_cpsd, temporal_freqs).value

        np.testing.assert_allclose(cov_from_cpsd,
                                   cov_from_general_cpsd,
                                   atol=1e-14)
Exemple #6
0
 def testQuantityAsArgument(self):
     pr = Cn2Profile.from_r0s([100 * u.mm, 0.2 * u.m],
                              np.array([30, 50]) * u.m,
                              [0.1 * u.km, 10000 * u.m],
                              [10, 10] * u.m / u.s, [0.3, 45] * u.deg)
     assert_quantity_allclose([100, 10000] * u.m, pr.layers_distance())
     assert_quantity_allclose([0.1, 0.2] * u.m, pr.r0s())
    def testIntegrationOfZernikeCPSDWithZernikeCovariance(self):
        cn2 = Cn2Profile.from_r0s([0.16], [25], [10e3], [10], [-20])
        rho, theta = (0, 0)
        source = GuideSource((rho, theta), np.inf)
        radius = 5
        center = [0, 0, 0]
        aperture = CircularOpticalAperture(radius, center)
        spatial_freqs = np.logspace(-4, 4, 100)
        temporal_freqs = np.logspace(-3, 3, 100)

        j = [2, 3]
        k = [2, 3]

        vkCov = VonKarmanSpatioTemporalCovariance(source, source, aperture,
                                                  aperture, cn2, spatial_freqs)
        vkCpsd = VonKarmanSpatioTemporalCovariance(source, source, aperture,
                                                   aperture, cn2,
                                                   spatial_freqs)

        cpsdMatrix = 2 * np.real(
            vkCpsd.getZernikeCPSD(j, k, temporal_freqs).value)
        covarianceMatrix = vkCov.getZernikeCovariance(j, k).value
        covFromCPSD = np.trapz(cpsdMatrix, temporal_freqs)
        np.testing.assert_allclose(covFromCPSD,
                                   covarianceMatrix,
                                   rtol=0.01,
                                   atol=1e-3)
    def testCovarianceZernikeOnSeveralModes(self):
        cn2 = Cn2Profile.from_fractional_j(0.1, [1.0], [25], [0], [10], [0])
        rho, theta = (0, 0)
        source = GuideSource((rho, theta), np.inf)
        radius = 10
        center = [0, 0, 0]
        aperture = CircularOpticalAperture(radius, center)
        spatial_freqs = np.logspace(-2, 2, 100)

        modes_j = [2, 3, 4]
        modes_k = [3, 4]

        vk_cov = VonKarmanSpatioTemporalCovariance(source, source, aperture,
                                                   aperture, cn2,
                                                   spatial_freqs)

        got = vk_cov.getZernikeCovariance(modes_j, modes_k).value

        self.assertAlmostEqual(
            vk_cov.getZernikeCovariance(2, 3).value, got[0, 0])
        self.assertAlmostEqual(
            vk_cov.getZernikeCovariance(3, 3).value, got[1, 0])
        self.assertAlmostEqual(
            vk_cov.getZernikeCovariance(4, 4).value, got[2, 1])
        self.assertTrue(got.shape == (3, 2))
Exemple #9
0
 def testR0ScaleWithAirmass(self):
     pr = Cn2Profile.from_fractional_j(0.1, 1.0, 30, 100, 10, 0.3)
     pr.set_zenith_angle(0)
     self.assertAlmostEqual(0.1, pr.r0().value)
     pr.set_zenith_angle(60)
     self.assertAlmostEqual(0.1 * 2**(-3. / 5), pr.r0().value)
     pr.set_zenith_angle(45)
     self.assertAlmostEqual(0.1 * np.sqrt(2)**(-3. / 5), pr.r0().value)
Exemple #10
0
 def testSetAndGetAirmassAndZenithAngle(self):
     pr = Cn2Profile.from_r0s([0.1], [30], [100], [10], [0.3])
     pr.set_zenith_angle(0)
     self.assertAlmostEqual(0, pr.zenith_angle().value)
     self.assertAlmostEqual(1, pr.airmass().value)
     pr.set_zenith_angle(60)
     self.assertAlmostEqual(60, pr.zenith_angle().value)
     self.assertAlmostEqual(2, pr.airmass().value)
Exemple #11
0
 def testTau0OfSingleLayer(self):
     zenAngle = 10.
     r0 = 0.13
     h = 1234.
     wspd = 10.
     pr = Cn2Profile.from_fractional_j(r0, 1.0, 30, h, wspd, 0.3)
     pr.set_zenith_angle(zenAngle)
     pr.set_wavelength(1.0e-6)
     wanted = (2.914 / 0.422727)**(-3. / 5) * pr.r0().value / (wspd)
     self.assertAlmostEqual(wanted, pr.tau0().value)
Exemple #12
0
    def testSeeingAndR0ScaleWithWavelengths(self):
        pr = Cn2Profile.from_r0s([0.1], [30], [100], [10], [0.3])
        pr.set_wavelength(500e-9)
        r0At500 = 0.1
        seeingAt500 = 0.98 * 500e-9 / r0At500 * Constants.RAD2ARCSEC
        self.assertAlmostEqual(r0At500, pr.r0().value)
        self.assertAlmostEqual(seeingAt500, pr.seeing().value)

        pr.set_wavelength(2200e-9)
        self.assertAlmostEqual(r0At500 * (2200 / 500)**(6. / 5), pr.r0().value)
        self.assertAlmostEqual(seeingAt500 * (2200 / 500)**(-1. / 5),
                               pr.seeing().value)
Exemple #13
0
 def testSameOutputWithOrWithoutQuantityAsInput(self):
     prWithQuantity = Cn2Profile.from_r0s([0.1] * u.m, [25] * u.m,
                                          [10000] * u.m, [10] * u.m / u.s,
                                          [0.3] * u.deg)
     prWithoutQuantity = Cn2Profile.from_r0s([0.1], [25], [10000], [10],
                                             [0.3])
     assert_quantity_allclose(prWithQuantity.r0(), prWithoutQuantity.r0())
     assert_quantity_allclose(prWithQuantity.outer_scale(),
                              prWithoutQuantity.outer_scale())
     assert_quantity_allclose(prWithQuantity.layers_distance(),
                              prWithoutQuantity.layers_distance())
     assert_quantity_allclose(prWithQuantity.wind_speed(),
                              prWithoutQuantity.wind_speed())
     assert_quantity_allclose(prWithQuantity.wind_direction(),
                              prWithoutQuantity.wind_direction())
     assert_quantity_allclose(prWithQuantity.theta0(),
                              prWithoutQuantity.theta0())
     assert_quantity_allclose(prWithQuantity.tau0(),
                              prWithoutQuantity.tau0())
     assert_quantity_allclose(prWithQuantity.seeing(),
                              prWithoutQuantity.seeing())
     assert_quantity_allclose(prWithQuantity.zenith_angle(),
                              prWithoutQuantity.zenith_angle())
    def testCovarianceZernikeOnTheSameSourceAndAperture(self):
        cn2 = Cn2Profile.from_fractional_j(0.1, [1.0], [25], [0], [10], [0])
        rho, theta = (0, 0)
        source = GuideSource((rho, theta), np.inf)
        radius = 10
        center = [0, 0, 0]
        aperture = CircularOpticalAperture(radius, center)
        spatial_freqs = np.logspace(-2, 2, 100)

        vk_cov = VonKarmanSpatioTemporalCovariance(source, source, aperture,
                                                   aperture, cn2,
                                                   spatial_freqs)
        wanted = 0
        got = vk_cov.getZernikeCovariance(2, 3).value

        self.assertAlmostEqual(wanted, got)
    def testIntegrationOfPhaseCPSDWithPhaseCovariance(self):
        cn2 = Cn2Profile.from_r0s([0.16], [25], [10e3], [10], [-20])
        rho, theta = (0, 0)
        source = GuideSource((rho, theta), np.inf)
        radius = 5
        center = [0, 0, 0]
        aperture = CircularOpticalAperture(radius, center)
        spatial_freqs = np.logspace(-3, 3, 100)
        temporal_freqs = np.logspace(-4, 4, 100)

        vk = VonKarmanSpatioTemporalCovariance(source, source, aperture,
                                               aperture, cn2, spatial_freqs)

        phaseCov = vk.getPhaseCovariance().value
        phaseCPSD = vk.getPhaseCPSD(temporal_freqs).value
        phaseCovFromCPSD = np.trapz(2 * np.real(phaseCPSD), temporal_freqs)
        np.testing.assert_allclose(phaseCovFromCPSD, phaseCov, rtol=0.01)
    def testPhaseCPSDvsPhaseGeneralCPSD(self):
        cn2 = Cn2Profile.from_r0s([0.16, 3.14], [25, 12], [10e3, 200], [10, 8],
                                  [-20, 90])
        rho, theta = (0, 0)
        source = GuideSource((rho, theta), np.inf)
        radius = 20
        center = [0, 0, 0]
        aperture = CircularOpticalAperture(radius, center)
        spatial_freqs = np.logspace(-3, 3, 100)
        temporal_freqs = np.logspace(-3, 3, 100)

        vk = VonKarmanSpatioTemporalCovariance(source, source, aperture,
                                               aperture, cn2, spatial_freqs)

        cpsd = vk.getPhaseCPSD(temporal_freqs)
        general_cpsd = vk.getGeneralPhaseCPSD(temporal_freqs)

        np.testing.assert_allclose(2 * cpsd.real, general_cpsd, atol=1e-14)
    def testZernikeCPSDMatrixShape(self):
        cn2 = Cn2Profile.from_r0s([0.16], [25], [10e3], [10], [-20])
        rho, theta = (0, 0)
        source = GuideSource((rho, theta), np.inf)
        radius = 5
        center = [0, 0, 0]
        aperture = CircularOpticalAperture(radius, center)
        spatial_freqs = np.logspace(-3, 3, 100)
        temporal_freqs = np.logspace(-4, 4, 100)

        j = [2]
        k = [2, 3]

        vk = VonKarmanSpatioTemporalCovariance(source, source, aperture,
                                               aperture, cn2, spatial_freqs)

        cpsdMatrix = vk.getZernikeCPSD(j, k, temporal_freqs).value
        self.assertTrue(cpsdMatrix.shape == (len(j), len(k),
                                             temporal_freqs.shape[0]))
    def testModifySourceAndAperture(self):
        cn2 = Cn2Profile.from_r0s([0.16, 3.14], [25, 12], [10e3, 200], [10, 8],
                                  [-20, 23])
        source1 = GuideSource((20, 0), np.inf)
        source2 = GuideSource((42, 0), np.inf)
        aperture1 = CircularOpticalAperture(5, [0, 0, 0])
        aperture2 = CircularOpticalAperture(5, [1, 0, 0])
        spatial_freqs = np.logspace(-3, 3, 10)
        temporal_freqs = np.logspace(-4, 4, 11)

        j = [2, 3]
        k = [2, 4]

        vk = VonKarmanSpatioTemporalCovariance(source1, source1, aperture1,
                                               aperture1, cn2, spatial_freqs)
        cpsd1 = vk.getGeneralZernikeCPSD(j, k, temporal_freqs).value

        vk.setSource1(source2)
        vk.setAperture2(aperture2)
        cpsd2 = vk.getGeneralZernikeCPSD(j, k, temporal_freqs).value
        self.assertFalse(np.allclose(cpsd1, cpsd2, atol=1e-14))
    def testPhaseCPSDOnGPU(self):
        cn2 = Cn2Profile.from_r0s([0.16, 3.14], [25, 12], [10e3, 200], [10, 8],
                                  [-20, 23])
        rho, theta = (0, 0)
        source = GuideSource((rho, theta), np.inf)
        radius = 5
        center = [0, 0, 0]
        aperture = CircularOpticalAperture(radius, center)
        spatial_freqs = np.logspace(-3, 3, 100)
        temporal_freqs = np.logspace(-4, 4, 100)

        vk_np = VonKarmanSpatioTemporalCovariance(source, source, aperture,
                                                  aperture, cn2, spatial_freqs)
        cpsd_np = vk_np.getPhaseCPSD(temporal_freqs)

        vk_cp = VonKarmanSpatioTemporalCovariance(source, source, aperture,
                                                  aperture, cn2, spatial_freqs)
        vk_cp.useGPU()
        cpsd_cp = vk_cp.getPhaseCPSD(temporal_freqs)

        np.testing.assert_allclose(cpsd_np, cpsd_cp, atol=1e-14)
    def testPhaseCPSD(self):
        cn2 = Cn2Profile.from_r0s([0.16], [25], [10e3], [10], [-20])
        rho1, theta1 = (0, 0)
        rho2, theta2 = (50, 30)
        source1 = GuideSource((rho1, theta1), np.inf)
        source2 = GuideSource((rho2, theta2), 100e3)
        radius = 5
        center = [0, 0, 0]
        aperture = CircularOpticalAperture(radius, center)
        spatial_freqs = np.logspace(-3, 3, 1000)

        vk_cov = VonKarmanSpatioTemporalCovariance(source1, source2, aperture,
                                                   aperture, cn2,
                                                   spatial_freqs)

        temp_freqs = [0.05, 130, 250]

        got = vk_cov.getPhaseCPSD(temp_freqs).value
        want = np.array([
            5.532213e+01 + 2.710243e+00j, 7.927701e-12 - 2.069043e-10j,
            -1.142719e-10 + 3.395629e-11j
        ])
        np.testing.assert_allclose(want, got, rtol=1e-3)
Exemple #21
0
 def testAirmass(self):
     self.assertAlmostEqual(1, Cn2Profile.zenith_angle_to_airmass(0))
     self.assertAlmostEqual(2, Cn2Profile.zenith_angle_to_airmass(60))
     self.assertAlmostEqual(np.sqrt(2),
                            Cn2Profile.zenith_angle_to_airmass(45))
Exemple #22
0
 def testTheta0AtGroundIsInfinite(self):
     pr = Cn2Profile.from_fractional_j(0.1, 1.0, 30, 0, 10, 0.3)
     pr.set_zenith_angle(42)
     self.assertAlmostEqual(np.inf, pr.theta0())
Exemple #23
0
 def testScalarAsArguments(self):
     pr = Cn2Profile.from_r0s(0.1, 30, 100, 10, 0.3)
     self.assertAlmostEqual(100, pr.layers_distance().value)
     self.assertAlmostEqual(0.1, pr.r0().value)
     pr = Cn2Profile.from_fractional_j(0.12, 1.0, 30, 100, 10, 0.3)
     self.assertAlmostEqual(0.12, pr.r0().value)
Exemple #24
0
 def testSetAndGetWindSpeedAndDirection(self):
     pr = Cn2Profile.from_r0s([0.1], [30], [100], [10], [0.3])
     pr.set_wind_speed(50)
     self.assertAlmostEqual(50, pr.wind_speed().value)
     pr.set_wind_direction(90)
     self.assertAlmostEqual(90, pr.wind_direction().value)