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 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)
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)
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 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 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)
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)
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 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 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 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 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)
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)
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)