Skip to content

Commit 5a25e5b

Browse files
fix: correct sign errors in grid distortion and ray generation calculations
1 parent 56d39be commit 5a25e5b

File tree

7 files changed

+19
-20
lines changed

7 files changed

+19
-20
lines changed

optiland/analysis/grid_distortion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def _generate_data(self):
116116
(self.num_points, self.num_points))
117117

118118
# optical system flips x, so must correct this
119-
data['xp'] = np.flip(xp)
119+
data['xp'] = xp
120120
data['yp'] = yp
121121

122122
# Find max distortion

optiland/rays/ray_generator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def _get_ray_origins(self, Hx, Hy, Px, Py, vx, vy):
117117
offset = self._get_starting_z_offset()
118118

119119
# x, y, z positions of ray starting points
120-
x = np.tan(np.radians(field_x)) * (offset + EPL)
120+
x = -np.tan(np.radians(field_x)) * (offset + EPL)
121121
y = -np.tan(np.radians(field_y)) * (offset + EPL)
122122
z = self.optic.surface_group.positions[1] - offset
123123

@@ -133,7 +133,7 @@ def _get_ray_origins(self, Hx, Hy, Px, Py, vx, vy):
133133
elif self.optic.field_type == 'angle':
134134
EPL = self.optic.paraxial.EPL()
135135
z = self.optic.surface_group.positions[0]
136-
x = np.tan(np.radians(field_x)) * (EPL - z)
136+
x = -np.tan(np.radians(field_x)) * (EPL - z)
137137
y = -np.tan(np.radians(field_y)) * (EPL - z)
138138

139139
x0 = np.full_like(Px, x)

optiland/wavefront.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def _correct_tilt(self, field, opd, x=None, y=None):
200200
if y is None:
201201
y = self.distribution.y
202202
EPD = self.optic.paraxial.EPD()
203-
tilt_correction = ((x - 1) * np.sin(np.radians(x_tilt)) * EPD / 2 +
203+
tilt_correction = ((1 - x) * np.sin(np.radians(x_tilt)) * EPD / 2 +
204204
(1 - y) * np.sin(np.radians(y_tilt)) * EPD / 2)
205205
return opd - tilt_correction
206206

tests/test_analysis.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@ def test_view_distortion_larger_fig(self, mock_show, telescope_objective):
350350
class TestTelescopeTripletGridDistortion:
351351
def test_grid_distortion_values(self, telescope_objective):
352352
dist = analysis.GridDistortion(telescope_objective)
353-
354353
assert dist.data['max_distortion'] == \
355354
pytest.approx(0.005785718069180374, abs=1e-9)
356355

@@ -359,19 +358,19 @@ def test_grid_distortion_values(self, telescope_objective):
359358
assert dist.data['xp'].shape == (10, 10)
360359
assert dist.data['yp'].shape == (10, 10)
361360

362-
assert dist.data['xr'][0, 0] == pytest.approx(1.2342622299776145,
361+
assert dist.data['xr'][0, 0] == pytest.approx(-1.2342622299776145,
363362
abs=1e-9)
364-
assert dist.data['xr'][4, 6] == pytest.approx(-0.41137984374933073,
363+
assert dist.data['xr'][4, 6] == pytest.approx(0.41137984374933073,
365364
abs=1e-9)
366365

367366
assert dist.data['yr'][1, 0] == pytest.approx(-0.959951505834632,
368367
abs=1e-9)
369368
assert dist.data['yr'][2, 6] == pytest.approx(-0.6856458243955965,
370369
abs=1e-9)
371370

372-
assert dist.data['xp'][0, 2] == pytest.approx(0.6856375010477692,
371+
assert dist.data['xp'][0, 2] == pytest.approx(-0.6856375010477692,
373372
abs=1e-9)
374-
assert dist.data['xp'][4, 4] == pytest.approx(0.13712543741510327,
373+
assert dist.data['xp'][4, 4] == pytest.approx(-0.13712543741510327,
375374
abs=1e-9)
376375

377376
assert dist.data['yp'][-1, 0] == pytest.approx(1.2341908231761498,
@@ -391,19 +390,19 @@ def test_f_theta_distortion(self, telescope_objective):
391390
assert dist.data['xp'].shape == (10, 10)
392391
assert dist.data['yp'].shape == (10, 10)
393392

394-
assert dist.data['xr'][0, 0] == pytest.approx(1.2342622299776145,
393+
assert dist.data['xr'][0, 0] == pytest.approx(-1.2342622299776145,
395394
abs=1e-9)
396-
assert dist.data['xr'][4, 6] == pytest.approx(-0.41137984374933073,
395+
assert dist.data['xr'][4, 6] == pytest.approx(0.41137984374933073,
397396
abs=1e-9)
398397

399398
assert dist.data['yr'][1, 0] == pytest.approx(-0.959951505834632,
400399
abs=1e-9)
401400
assert dist.data['yr'][2, 6] == pytest.approx(-0.6856458243955965,
402401
abs=1e-9)
403402

404-
assert dist.data['xp'][0, 2] == pytest.approx(0.6856267573347536,
403+
assert dist.data['xp'][0, 2] == pytest.approx(-0.6856267573347536,
405404
abs=1e-9)
406-
assert dist.data['xp'][4, 4] == pytest.approx(0.13712535146695065,
405+
assert dist.data['xp'][4, 4] == pytest.approx(-0.13712535146695065,
407406
abs=1e-9)
408407

409408
assert dist.data['yp'][-1, 0] == pytest.approx(1.2341281632025562,

tests/test_operand.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def test_x_intercept(self, hubble):
144144
data = {'optic': hubble, 'surface_number': -1, 'Hx': 1.0, 'Hy': 0.0,
145145
'Px': 0.0, 'Py': 0.0, 'wavelength': 0.55}
146146
assert np.isclose(operand.RayOperand.x_intercept(**data),
147-
-150.42338010762842)
147+
150.42338010762842)
148148

149149
def test_y_intercept(self, hubble):
150150
data = {'optic': hubble, 'surface_number': -1, 'Hx': 0.0, 'Hy': 1.0,
@@ -162,7 +162,7 @@ def test_x_intercept_lcs(self, hubble):
162162
data = {'optic': hubble, 'surface_number': -1, 'Hx': 1.0, 'Hy': 0.0,
163163
'Px': 0.0, 'Py': 0.0, 'wavelength': 0.55}
164164
assert np.isclose(operand.RayOperand.x_intercept_lcs(**data),
165-
-150.42338010762842)
165+
150.42338010762842)
166166

167167
def test_y_intercept_lcs(self, hubble):
168168
data = {'optic': hubble, 'surface_number': -1, 'Hx': 0.0, 'Hy': 1.0,

tests/test_rays.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -659,13 +659,13 @@ def test_generate_rays(self):
659659
assert rays.i.shape == (2,)
660660
assert rays.w.shape == (2,)
661661

662-
assert np.allclose(rays.x, np.array([0.32419016, 0.36860991]),
662+
assert np.allclose(rays.x, np.array([-0.23535066, -0.1909309]),
663663
atol=1e-8)
664664
assert np.allclose(rays.y, np.array([-0.23535066, -0.1909309]),
665665
atol=1e-8)
666666
assert np.allclose(rays.z, np.array([-0.88839505, -0.88839505]),
667667
atol=1e-8)
668-
assert np.allclose(rays.L, np.array([-0.17519154, -0.17519154]),
668+
assert np.allclose(rays.L, np.array([0.17519154, 0.17519154]),
669669
atol=1e-8)
670670
assert np.allclose(rays.M, np.array([0.17519154, 0.17519154]),
671671
atol=1e-8)
@@ -755,13 +755,13 @@ def test_generate_polarized_rays(self):
755755
assert rays.w.shape == (2,)
756756
assert rays.p.shape == (2, 3, 3)
757757

758-
assert np.allclose(rays.x, np.array([0.32419016, 0.36860991]),
758+
assert np.allclose(rays.x, np.array([-0.23535066, -0.1909309]),
759759
atol=1e-8)
760760
assert np.allclose(rays.y, np.array([-0.23535066, -0.1909309]),
761761
atol=1e-8)
762762
assert np.allclose(rays.z, np.array([-0.88839505, -0.88839505]),
763763
atol=1e-8)
764-
assert np.allclose(rays.L, np.array([-0.17519154, -0.17519154]),
764+
assert np.allclose(rays.L, np.array([0.17519154, 0.17519154]),
765765
atol=1e-8)
766766
assert np.allclose(rays.M, np.array([0.17519154, 0.17519154]),
767767
atol=1e-8)

tests/test_wavefront.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def test_zernike_opd_fit(self):
216216
c = zernike_opd.zernike.coeffs
217217
assert np.isclose(c[0], 0.8430890395012354)
218218
assert np.isclose(c[1], 6.863699034904449e-13)
219-
assert np.isclose(c[2], -0.14504379704525455)
219+
assert np.isclose(c[2], 0.14504379704525455)
220220
assert np.isclose(c[6], -1.160298338689596e-13)
221221
assert np.isclose(c[24], -0.0007283668376039182)
222222

0 commit comments

Comments
 (0)