diffinytrace 2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. diffinytrace/__init__.py +122 -0
  2. diffinytrace/basis_functions/__init__.py +14 -0
  3. diffinytrace/basis_functions/bspline.py +521 -0
  4. diffinytrace/basis_functions/chebyshev.py +3 -0
  5. diffinytrace/basis_functions/legendre.py +77 -0
  6. diffinytrace/basis_functions/zernike.py +235 -0
  7. diffinytrace/config.py +140 -0
  8. diffinytrace/constraints.py +54 -0
  9. diffinytrace/element.py +1660 -0
  10. diffinytrace/export/__init__.py +8 -0
  11. diffinytrace/export/cad.py +253 -0
  12. diffinytrace/gaussian_smoother.py +530 -0
  13. diffinytrace/hat_smoother.py +44 -0
  14. diffinytrace/integrators.py +452 -0
  15. diffinytrace/intersection.py +285 -0
  16. diffinytrace/optimize.py +808 -0
  17. diffinytrace/physical_object.py +150 -0
  18. diffinytrace/plotting/__init__.py +16 -0
  19. diffinytrace/plotting/core.py +92 -0
  20. diffinytrace/plotting/quantity2D.py +188 -0
  21. diffinytrace/plotting/system2D.py +220 -0
  22. diffinytrace/plotting/system3D.py +327 -0
  23. diffinytrace/plotting/wavelength.py +231 -0
  24. diffinytrace/refractive_index.py +101 -0
  25. diffinytrace/render.py +77 -0
  26. diffinytrace/source.py +661 -0
  27. diffinytrace/spectrum.py +79 -0
  28. diffinytrace/surface.py +468 -0
  29. diffinytrace/target_grid.py +399 -0
  30. diffinytrace/transforms.py +472 -0
  31. diffinytrace/utils/__init__.py +7 -0
  32. diffinytrace/utils/autograd.py +116 -0
  33. diffinytrace/utils/irradiance_importer.py +134 -0
  34. diffinytrace-2.1.dist-info/METADATA +26 -0
  35. diffinytrace-2.1.dist-info/RECORD +38 -0
  36. diffinytrace-2.1.dist-info/WHEEL +5 -0
  37. diffinytrace-2.1.dist-info/licenses/LICENSE +21 -0
  38. diffinytrace-2.1.dist-info/top_level.txt +1 -0
diffinytrace/render.py ADDED
@@ -0,0 +1,77 @@
1
+ # Copyright (c) 2025 Martin Pflaum
2
+ # This file is part of the diffinytrace project, licensed under the MIT License.
3
+
4
+ __all__ = [
5
+ "smoothed_irradiance",
6
+ "binned_irradiance"
7
+ ]
8
+
9
+ import torch
10
+ import numpy as np
11
+ from typing import List
12
+ from .source import LightSource
13
+ from .element import trace_to_detector,SequentialOpticalSystem,Detector
14
+
15
+ def smoothed_irradiance(optical_system:SequentialOpticalSystem,
16
+ sequence:List,
17
+ source:LightSource,
18
+ detector:Detector,
19
+ smoother,
20
+ num_rays:int,
21
+ device=torch.get_default_device(),
22
+ method_ray_tracing:str="sobol_pow2")->torch.Tensor:
23
+ """
24
+ Calculate the smoothed irradiance on the detector using ray tracing.
25
+
26
+ Args:
27
+ optical_system (SequentialOpticalSystem): The optical system to trace rays through.
28
+ sequence: The sequence of elements in the optical system.
29
+ source (LightSource): The light source used for ray tracing.
30
+ detector (Detector): The detector where the rays are traced to.
31
+ smoother: The smoother object used for smoothing the irradiance.
32
+ num_rays (int, optional): The number of rays to trace. Default is 100000.
33
+ device (torch.device, optional): The device to perform computations on. Default is the default device.
34
+ method_ray_tracing (str, optional): The method used for ray tracing. Default is "sobol".
35
+
36
+ Returns:
37
+ torch.Tensor: The smoothed irradiance on the detector.
38
+ """
39
+ x,weights,y,wl = trace_to_detector(optical_system,sequence,source,detector,num_rays,device,method_ray_tracing=method_ray_tracing)
40
+ Qval = source.get_flux(x.detach())
41
+ smoothed_irradiance = smoother.smoothed_irradiance(y.detach(),Qval*weights)
42
+ return smoothed_irradiance
43
+
44
+ def binned_irradiance(optical_system:SequentialOpticalSystem,
45
+ sequence:List,
46
+ source:LightSource,
47
+ detector:Detector,
48
+ grid,
49
+ num_rays:int,
50
+ device=torch.get_default_device(),
51
+ method_ray_tracing:str="sobol_pow2")->torch.Tensor:
52
+ """
53
+ Calculate the binned irradiance on the detector using ray tracing.
54
+
55
+ Args:
56
+ optical_system (SequentialOpticalSystem): The optical system to trace rays through.
57
+ sequence: The sequence of elements in the optical system.
58
+ source (LightSource): The light source used for ray tracing.
59
+ detector (Detector): The detector where the rays are traced to.
60
+ grid: The grid used for binning the irradiance.
61
+ num_rays (int, optional): The number of rays to trace. Default is 100000.
62
+ device (torch.device, optional): The device to perform computations on. Default is the default device.
63
+ method_ray_tracing (str, optional): The method used for ray tracing. Default is "sobol".
64
+
65
+ Returns:
66
+ torch.Tensor: The binned irradiance on the detector.
67
+ """
68
+ irradiance = None
69
+ with torch.no_grad():
70
+ x,weights,y,wl = trace_to_detector(optical_system,sequence,source,detector,num_rays,device,method_ray_tracing=method_ray_tracing)
71
+ Qval = source.get_flux(x.detach())
72
+ irradiance = grid.sum(y,Qval*weights)/grid.get_pixel_area()
73
+ #irradiance = irradiance.reshape(grid.x_)
74
+ return irradiance
75
+
76
+
77
+ #TODO: Here a versions are missing which split the irradiance calculation