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.
- diffinytrace/__init__.py +122 -0
- diffinytrace/basis_functions/__init__.py +14 -0
- diffinytrace/basis_functions/bspline.py +521 -0
- diffinytrace/basis_functions/chebyshev.py +3 -0
- diffinytrace/basis_functions/legendre.py +77 -0
- diffinytrace/basis_functions/zernike.py +235 -0
- diffinytrace/config.py +140 -0
- diffinytrace/constraints.py +54 -0
- diffinytrace/element.py +1660 -0
- diffinytrace/export/__init__.py +8 -0
- diffinytrace/export/cad.py +253 -0
- diffinytrace/gaussian_smoother.py +530 -0
- diffinytrace/hat_smoother.py +44 -0
- diffinytrace/integrators.py +452 -0
- diffinytrace/intersection.py +285 -0
- diffinytrace/optimize.py +808 -0
- diffinytrace/physical_object.py +150 -0
- diffinytrace/plotting/__init__.py +16 -0
- diffinytrace/plotting/core.py +92 -0
- diffinytrace/plotting/quantity2D.py +188 -0
- diffinytrace/plotting/system2D.py +220 -0
- diffinytrace/plotting/system3D.py +327 -0
- diffinytrace/plotting/wavelength.py +231 -0
- diffinytrace/refractive_index.py +101 -0
- diffinytrace/render.py +77 -0
- diffinytrace/source.py +661 -0
- diffinytrace/spectrum.py +79 -0
- diffinytrace/surface.py +468 -0
- diffinytrace/target_grid.py +399 -0
- diffinytrace/transforms.py +472 -0
- diffinytrace/utils/__init__.py +7 -0
- diffinytrace/utils/autograd.py +116 -0
- diffinytrace/utils/irradiance_importer.py +134 -0
- diffinytrace-2.1.dist-info/METADATA +26 -0
- diffinytrace-2.1.dist-info/RECORD +38 -0
- diffinytrace-2.1.dist-info/WHEEL +5 -0
- diffinytrace-2.1.dist-info/licenses/LICENSE +21 -0
- 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
|