|
12 | 12 | ZemaxFileSourceHandler, |
13 | 13 | load_zemax_file, |
14 | 14 | ) |
| 15 | +from optiland.fileio.converters import ZemaxToOpticConverter |
15 | 16 | from optiland.materials import Material |
16 | 17 | from optiland.optic import Optic |
17 | 18 | from optiland.samples.objectives import HeliarLens |
| 19 | +from optiland.geometries import ToroidalGeometry |
18 | 20 | import optiland.backend as be |
19 | 21 | from .utils import assert_allclose |
20 | 22 |
|
@@ -288,3 +290,148 @@ def test_remove_surface_after_load(set_test_backend, tmp_path): |
288 | 290 | expected_positions_after_object = be.array([0.0, 10.0, 30.0]) |
289 | 291 |
|
290 | 292 | assert_allclose(positions[1:], expected_positions_after_object) |
| 293 | + |
| 294 | + |
| 295 | +class TestZemaxToOpticConverterExtended: |
| 296 | + def test_configure_aperture_floating_stop_no_diameter(self): |
| 297 | + zemax_data = { |
| 298 | + "surfaces": { |
| 299 | + 0: {"type": "standard", "is_stop": True, "radius": 0.0, "conic": 0.0, "thickness": 0.0, "material": "Air"}, |
| 300 | + }, |
| 301 | + "aperture": {"floating_stop": True}, |
| 302 | + "fields": {"type": "angle", "x": [0], "y": [0]}, |
| 303 | + "wavelengths": {"primary_index": 0, "data": [0.55]}, |
| 304 | + } |
| 305 | + converter = ZemaxToOpticConverter(zemax_data) |
| 306 | + converter.optic = Optic() |
| 307 | + converter._configure_surfaces() |
| 308 | + |
| 309 | + with pytest.raises(ValueError, match="Floating stop aperture specified but no stop diameter found"): |
| 310 | + converter._configure_aperture() |
| 311 | + |
| 312 | + def test_configure_aperture_no_valid_type(self): |
| 313 | + zemax_data = { |
| 314 | + "surfaces": {}, |
| 315 | + "aperture": {"floating_stop": False}, |
| 316 | + "fields": {"type": "angle", "x": [0], "y": [0]}, |
| 317 | + "wavelengths": {"primary_index": 0, "data": [0.55]}, |
| 318 | + } |
| 319 | + converter = ZemaxToOpticConverter(zemax_data) |
| 320 | + converter.optic = Optic() |
| 321 | + |
| 322 | + with pytest.raises(ValueError, match="No valid aperture type found"): |
| 323 | + converter._configure_aperture() |
| 324 | + |
| 325 | + def test_configure_surface_coefficients_unsupported_type(self): |
| 326 | + zemax_data = { |
| 327 | + "surfaces": { |
| 328 | + 0: {"type": "unsupported_surface_type", "radius": 10}, |
| 329 | + }, |
| 330 | + "aperture": {"EPD": 10}, |
| 331 | + "fields": {"type": "angle", "x": [0], "y": [0]}, |
| 332 | + "wavelengths": {"primary_index": 0, "data": [0.55]}, |
| 333 | + } |
| 334 | + converter = ZemaxToOpticConverter(zemax_data) |
| 335 | + |
| 336 | + with pytest.raises(ValueError, match="Unsupported Zemax surface type"): |
| 337 | + converter._configure_surface_coefficients({"type": "unsupported_surface_type"}) |
| 338 | + |
| 339 | + def test_configure_fields_vignette_warning(self, capsys): |
| 340 | + zemax_data = { |
| 341 | + "surfaces": {}, |
| 342 | + "aperture": {"EPD": 10}, |
| 343 | + "fields": { |
| 344 | + "type": "angle", |
| 345 | + "x": [0], |
| 346 | + "y": [0], |
| 347 | + "vignette_decenter_x": [0.1], |
| 348 | + "vignette_decenter_y": [0.0] |
| 349 | + }, |
| 350 | + "wavelengths": {"primary_index": 0, "data": [0.55]}, |
| 351 | + } |
| 352 | + converter = ZemaxToOpticConverter(zemax_data) |
| 353 | + converter.optic = Optic() |
| 354 | + converter._configure_fields() |
| 355 | + |
| 356 | + captured = capsys.readouterr() |
| 357 | + assert "Warning: Vignette decentering is not supported." in captured.out |
| 358 | + |
| 359 | + def test_configure_surfaces_coordinate_break(self): |
| 360 | + zemax_data = { |
| 361 | + "surfaces": { |
| 362 | + 0: { |
| 363 | + "type": "coordinate_break", |
| 364 | + "param_0": 1.0, # dx |
| 365 | + "param_1": 2.0, # dy |
| 366 | + "thickness": 5.0, # dz (thickness) |
| 367 | + "param_2": 10.0, # rx deg |
| 368 | + "param_3": 20.0, # ry deg |
| 369 | + "param_4": 30.0, # rz deg |
| 370 | + "conic": 0.0, |
| 371 | + }, |
| 372 | + 1: { |
| 373 | + "type": "standard", |
| 374 | + "radius": 100.0, |
| 375 | + "thickness": 10.0, |
| 376 | + "conic": 0.0, |
| 377 | + "material": "N-BK7" |
| 378 | + } |
| 379 | + }, |
| 380 | + "aperture": {"EPD": 10}, |
| 381 | + "fields": {"type": "angle", "x": [0], "y": [0]}, |
| 382 | + "wavelengths": {"primary_index": 0, "data": [0.55]}, |
| 383 | + } |
| 384 | + converter = ZemaxToOpticConverter(zemax_data) |
| 385 | + optic = converter.convert() |
| 386 | + |
| 387 | + surf = optic.surface_group.surfaces[0] |
| 388 | + assert surf.geometry.radius == 100.0 |
| 389 | + |
| 390 | + cs = surf.geometry.cs |
| 391 | + assert cs.x != 0 or cs.y != 0 or cs.z != 0 or cs.rx != 0 or cs.ry != 0 or cs.rz != 0 |
| 392 | + |
| 393 | + def test_configure_surfaces_toroidal(self): |
| 394 | + zemax_data = { |
| 395 | + "surfaces": { |
| 396 | + 0: { |
| 397 | + "type": "toroidal", |
| 398 | + "radius": 50.0, # radius_y |
| 399 | + "param_1": 60.0, # radius_x |
| 400 | + "param_2": 0.1, # coeff start |
| 401 | + "thickness": 5.0, |
| 402 | + "conic": 0.0, |
| 403 | + "material": "Air" |
| 404 | + } |
| 405 | + }, |
| 406 | + "aperture": {"EPD": 10}, |
| 407 | + "fields": {"type": "angle", "x": [0], "y": [0]}, |
| 408 | + "wavelengths": {"primary_index": 0, "data": [0.55]}, |
| 409 | + } |
| 410 | + converter = ZemaxToOpticConverter(zemax_data) |
| 411 | + optic = converter.convert() |
| 412 | + |
| 413 | + surf = optic.surface_group.surfaces[0] |
| 414 | + assert isinstance(surf.geometry, ToroidalGeometry) |
| 415 | + assert surf.geometry.R_yz == 50.0 |
| 416 | + assert surf.geometry.R_rot == 60.0 |
| 417 | + |
| 418 | + def test_configure_surfaces_infinity_thickness(self): |
| 419 | + zemax_data = { |
| 420 | + "surfaces": { |
| 421 | + 0: { |
| 422 | + "type": "standard", |
| 423 | + "radius": be.inf, |
| 424 | + "thickness": be.inf, |
| 425 | + "conic": 0.0, |
| 426 | + "material": "Air" |
| 427 | + } |
| 428 | + }, |
| 429 | + "aperture": {"EPD": 10}, |
| 430 | + "fields": {"type": "angle", "x": [0], "y": [0]}, |
| 431 | + "wavelengths": {"primary_index": 0, "data": [0.55]}, |
| 432 | + } |
| 433 | + converter = ZemaxToOpticConverter(zemax_data) |
| 434 | + optic = converter.convert() |
| 435 | + |
| 436 | + surf = optic.surface_group.surfaces[0] |
| 437 | + assert be.isinf(surf.thickness) |
0 commit comments