Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
warnings.warn(
"This function will be removed in version 0.5, instead use aotools.image_processing.encircled_energy",
DeprecationWarning)
dim = data.shape[0] // 2
if center is None:
center = [dim, dim]
xc = center[0]
yc = center[1]
e = 1.9
npt = 20
rad = numpy.linspace(0, dim**(1. / e), npt)**e
ee = numpy.empty(rad.shape)
for i in range(npt):
pup = pupil.circle(rad[i],
int(dim) * 2,
circle_centre=(xc, yc),
origin='corner')
rad[i] = numpy.sqrt(numpy.sum(pup) * 4 / numpy.pi) # diameter
ee[i] = numpy.sum(pup * data)
rad = numpy.append(0, rad)
ee = numpy.append(0, ee)
ee /= numpy.sum(data)
xi = numpy.linspace(0, dim, int(4 * dim))
yi = numpy.interp(xi, rad, ee)
if eeDiameter is False:
return xi, yi
else:
ee50d = float(xi[numpy.argmin(numpy.abs(yi - fraction))])
def test_slopecovmat_init():
threads = 1
n_wfs = 3
telescope_diameter = 8.
nx_subaps = 10
n_layers = 3
layer_altitudes = numpy.linspace(0, 20000, n_layers)
layer_r0s = [1] * n_layers
layer_L0s = [25.] * n_layers
asterism_radius = 10
subap_diameters = [telescope_diameter / nx_subaps] * n_wfs
pupil_masks = [aotools.circle(nx_subaps / 2., nx_subaps)] * n_wfs
gs_altitudes = [90000] * n_wfs
gs_positions = [
[asterism_radius, 0],
[numpy.sin(numpy.pi / 3.) * asterism_radius, numpy.cos(numpy.pi / 3.) * asterism_radius],
[numpy.sin(numpy.pi / 3.) * asterism_radius, -numpy.cos(numpy.pi / 3.) * asterism_radius],
[-numpy.sin(numpy.pi / 3.) * asterism_radius, numpy.cos(numpy.pi / 3.) * asterism_radius],
[-numpy.sin(numpy.pi / 3.) * asterism_radius, -numpy.cos(numpy.pi / 3.) * asterism_radius],
[-asterism_radius, 0]]
wfs_magnifications = [1.] * n_wfs
pupil_offsets = [[0, 0]] * n_wfs
wfs_rotations = [0] * n_wfs
wfs_wavelengths = [550e-9] * n_wfs
cov_mat = aotools.CovarianceMatrix(n_wfs, pupil_masks, telescope_diameter, subap_diameters, gs_altitudes, gs_positions,
wfs_wavelengths,
n_layers, layer_altitudes, layer_r0s, layer_L0s, threads)
def test_tps_fit_minimize_func():
# Parameters
frame_rate = 100
n_frames = 1000
slopes = numpy.random.random((1000, 104))
tps, tps_err = turbulence.calc_slope_temporalps(slopes)
args = [20., 20., 1.]
t_axis = turbulence.get_tps_time_axis(frame_rate, n_frames)
D = 0.5
plot = False
# Test code
V, f_noise, A = args
return test_tps_fit()
c2 = pupil.circle(2, 5)
self.assertEqual( c1.tolist(), c2.tolist() )
self.assertTrue( (c1 == c2).all() )
c1 = pupil.circle(1, 6, (0.5,0.5))[1:,1:]
c2 = pupil.circle(1, 5)
self.assertEqual( c1.tolist(), c2.tolist() )
self.assertTrue( (c1 == c2).all() )
c1 = pupil.circle(0, 6, (0.5,0.5))[1:,1:]
c2 = pupil.circle(0, 5)
self.assertEqual( c1.tolist(), c2.tolist() )
self.assertTrue( (c1 == c2).all() )
c1 = pupil.circle(0, 5, (0.5, 0.5))[1:, 1:]
c2 = pupil.circle(0, 6)[1:-1, 1:-1]
self.assertEqual( c1.tolist(), c2.tolist() )
self.assertTrue( (c1 == c2).all() )
c1 = pupil.circle(1, 5, (0.5, 0.5))[1:, 1:]
c2 = pupil.circle(1, 6)[1:-1, 1:-1]
#c2[3,2] = 3.0 # to test the testing
self.assertEqual( c1.tolist(), c2.tolist() )
self.assertTrue( (c1 == c2).all() )
c1 = pupil.circle(2, 5, (0.5, 0.5))[1:, 1:]
c2 = pupil.circle(2, 6)[1:-1, 1:-1]
self.assertEqual( c1.tolist(), c2.tolist() )
self.assertTrue( (c1 == c2).all() )
log.info("Raise TypeError if inputs not of correct type")
c1 = pupil.circle(1, 6, (0.5,0.5))[1:,1:]
c2 = pupil.circle(1, 5)
self.assertEqual( c1.tolist(), c2.tolist() )
self.assertTrue( (c1 == c2).all() )
c1 = pupil.circle(0, 6, (0.5,0.5))[1:,1:]
c2 = pupil.circle(0, 5)
self.assertEqual( c1.tolist(), c2.tolist() )
self.assertTrue( (c1 == c2).all() )
c1 = pupil.circle(0, 5, (0.5, 0.5))[1:, 1:]
c2 = pupil.circle(0, 6)[1:-1, 1:-1]
self.assertEqual( c1.tolist(), c2.tolist() )
self.assertTrue( (c1 == c2).all() )
c1 = pupil.circle(1, 5, (0.5, 0.5))[1:, 1:]
c2 = pupil.circle(1, 6)[1:-1, 1:-1]
#c2[3,2] = 3.0 # to test the testing
self.assertEqual( c1.tolist(), c2.tolist() )
self.assertTrue( (c1 == c2).all() )
c1 = pupil.circle(2, 5, (0.5, 0.5))[1:, 1:]
c2 = pupil.circle(2, 6)[1:-1, 1:-1]
self.assertEqual( c1.tolist(), c2.tolist() )
self.assertTrue( (c1 == c2).all() )
log.info("Raise TypeError if inputs not of correct type")
# For testing by hand and observing the result:
if False:
import pylab; pylab.ion()
ce = numpy.array([[ 0., 0., 0., 0., 0.],
[ 0., 0., 1., 0., 0.],
[ 0., 1., 1., 1., 0.],
[ 0., 0., 1., 0., 0.],
[ 0., 0., 0., 0., 0.]])
c = pupil.circle(1, 5)
self.assertEqual( c.tolist(), ce.tolist() )
self.assertTrue( (c == ce).all() )
# circle.circle(2, 5)
ce = numpy.array([[ 0., 0., 1., 0., 0.],
[ 0., 1., 1., 1., 0.],
[ 1., 1., 1., 1., 1.],
[ 0., 1., 1., 1., 0.],
[ 0., 0., 1., 0., 0.]])
c = pupil.circle(2, 5)
self.assertEqual( c.tolist(), ce.tolist() )
self.assertTrue( (c == ce).all() )
# circle.circle(0, 6)
ce = numpy.array([[ 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0.]])
c = pupil.circle(0, 6)
self.assertEqual( c.tolist(), ce.tolist() )
self.assertTrue( (c == ce).all() )
# circle.circle(1, 6)
ce = numpy.array([[ 0., 0., 0., 0., 0., 0.],
[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0],
[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0],
[0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0]])
c = pupil.circle(15.5, 31) - pupil.circle(3.7, 31)
self.assertEqual( c.tolist(), ce.tolist() )
self.assertTrue( (c == ce).all() )
log.info("Create circles with (2,6,(0.5,0.5)), (1,5,(0.5,0.5)), etc.")
c1 = pupil.circle(2, 6, (0.5,0.5))[1:,1:]
c2 = pupil.circle(2, 5)
self.assertEqual( c1.tolist(), c2.tolist() )
self.assertTrue( (c1 == c2).all() )
c1 = pupil.circle(1, 6, (0.5,0.5))[1:,1:]
c2 = pupil.circle(1, 5)
self.assertEqual( c1.tolist(), c2.tolist() )
self.assertTrue( (c1 == c2).all() )
c1 = pupil.circle(0, 6, (0.5,0.5))[1:,1:]
c2 = pupil.circle(0, 5)
self.assertEqual( c1.tolist(), c2.tolist() )
self.assertTrue( (c1 == c2).all() )
c1 = pupil.circle(0, 5, (0.5, 0.5))[1:, 1:]
c2 = pupil.circle(0, 6)[1:-1, 1:-1]
self.assertEqual( c1.tolist(), c2.tolist() )
self.assertTrue( (c1 == c2).all() )
c1 = pupil.circle(1, 5, (0.5, 0.5))[1:, 1:]
c2 = pupil.circle(1, 6)[1:-1, 1:-1]
[1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1],
[1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1],
[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0],
[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0],
[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0],
[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0],
[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0],
[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0],
[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0],
[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0],
[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0],
[0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0]])
c = pupil.circle(15.5, 31) - pupil.circle(3.7, 31)
self.assertEqual( c.tolist(), ce.tolist() )
self.assertTrue( (c == ce).all() )
log.info("Create circles with (2,6,(0.5,0.5)), (1,5,(0.5,0.5)), etc.")
c1 = pupil.circle(2, 6, (0.5,0.5))[1:,1:]
c2 = pupil.circle(2, 5)
self.assertEqual( c1.tolist(), c2.tolist() )
self.assertTrue( (c1 == c2).all() )
c1 = pupil.circle(1, 6, (0.5,0.5))[1:,1:]
c2 = pupil.circle(1, 5)
self.assertEqual( c1.tolist(), c2.tolist() )
self.assertTrue( (c1 == c2).all() )
c1 = pupil.circle(0, 6, (0.5,0.5))[1:,1:]
c2 = pupil.circle(0, 5)
[ 0., 0., 1., 1., 0., 0.],
[ 0., 0., 1., 1., 0., 0.],
[ 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0.]])
c = pupil.circle(1, 6)
self.assertEqual( c.tolist(), ce.tolist() )
self.assertTrue( (c == ce).all() )
# circle.circle(2, 6)
ce = numpy.array([[ 0., 0., 0., 0., 0., 0.],
[ 0., 0., 1., 1., 0., 0.],
[ 0., 1., 1., 1., 1., 0.],
[ 0., 1., 1., 1., 1., 0.],
[ 0., 0., 1., 1., 0., 0.],
[ 0., 0., 0., 0., 0., 0.]])
c = pupil.circle(2, 6)
self.assertEqual( c.tolist(), ce.tolist() )
self.assertTrue( (c == ce).all() )
# circle.circle(3, 6)
ce = numpy.array([[ 0., 1., 1., 1., 1., 0.],
[ 1., 1., 1., 1., 1., 1.],
[ 1., 1., 1., 1., 1., 1.],
[ 1., 1., 1., 1., 1., 1.],
[ 1., 1., 1., 1., 1., 1.],
[ 0., 1., 1., 1., 1., 0.]])
c = pupil.circle(3, 6)
self.assertEqual( c.tolist(), ce.tolist() )
self.assertTrue( (c == ce).all() )
# This is a crucial test since this is used in the dragon config file:
[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0],
[0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0]])
c = pupil.circle(15.5, 31) - pupil.circle(3.7, 31)
self.assertEqual( c.tolist(), ce.tolist() )
self.assertTrue( (c == ce).all() )
log.info("Create circles with (2,6,(0.5,0.5)), (1,5,(0.5,0.5)), etc.")
c1 = pupil.circle(2, 6, (0.5,0.5))[1:,1:]
c2 = pupil.circle(2, 5)
self.assertEqual( c1.tolist(), c2.tolist() )
self.assertTrue( (c1 == c2).all() )
c1 = pupil.circle(1, 6, (0.5,0.5))[1:,1:]
c2 = pupil.circle(1, 5)
self.assertEqual( c1.tolist(), c2.tolist() )
self.assertTrue( (c1 == c2).all() )
c1 = pupil.circle(0, 6, (0.5,0.5))[1:,1:]
c2 = pupil.circle(0, 5)
self.assertEqual( c1.tolist(), c2.tolist() )
self.assertTrue( (c1 == c2).all() )
c1 = pupil.circle(0, 5, (0.5, 0.5))[1:, 1:]
c2 = pupil.circle(0, 6)[1:-1, 1:-1]
self.assertEqual( c1.tolist(), c2.tolist() )
self.assertTrue( (c1 == c2).all() )
c1 = pupil.circle(1, 5, (0.5, 0.5))[1:, 1:]
c2 = pupil.circle(1, 6)[1:-1, 1:-1]
#c2[3,2] = 3.0 # to test the testing