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
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# Copyright (c) 2025 Martin Pflaum
|
|
2
|
+
# This file is part of the diffinytrace project, licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
__all__ = [
|
|
5
|
+
"create_irradiance_from_image_square",
|
|
6
|
+
"pil_center_crop",
|
|
7
|
+
"load_image"
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
import torch
|
|
11
|
+
from PIL import Image
|
|
12
|
+
import numpy as np
|
|
13
|
+
from ..target_grid import GridSquare
|
|
14
|
+
import gc
|
|
15
|
+
|
|
16
|
+
"""
|
|
17
|
+
def from_image_square(file_name,padding_ratio,grey_ratio,aperture_radius):
|
|
18
|
+
#TODO maybe generalize to rectangle - change apreture_radius_detector to target_grid-nöö
|
|
19
|
+
image = load_image(file_name,padding_ratio=padding_ratio,grey_ratio=grey_ratio)
|
|
20
|
+
image = torch.tensor(image).to(torch.get_default_dtype())
|
|
21
|
+
image = image.T
|
|
22
|
+
image_flat = image.reshape(-1)
|
|
23
|
+
grid = dit.target_grid.GridSquare(aperture_radius,grid_size=image.shape[0])
|
|
24
|
+
area = grid.get_area()
|
|
25
|
+
def desired_irradiance_func(x):
|
|
26
|
+
k = grid.get_k(x)
|
|
27
|
+
tmp = image_flat[k]
|
|
28
|
+
return tmp/area
|
|
29
|
+
return desired_irradiance_func
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
"""
|
|
33
|
+
def create_irradiance_from_image_square(file_name,padding_ratio,grey_ratio,aperture_radius,
|
|
34
|
+
dtype=torch.get_default_dtype(),shape=None):
|
|
35
|
+
"""
|
|
36
|
+
Create a function that returns the desired irradiance from an image file.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
file_name (str): The path to the image file.
|
|
40
|
+
padding_ratio (float): The ratio of padding to be applied to the image.
|
|
41
|
+
grey_ratio (float): The ratio of grey value to be applied to the image.
|
|
42
|
+
aperture_radius (float): The radius of the aperture.
|
|
43
|
+
dtype (torch.dtype): The data type for the output tensor.
|
|
44
|
+
shape (tuple, optional): The shape to resize the image to. If None, no resizing is done.
|
|
45
|
+
Returns:
|
|
46
|
+
function: A function that takes a tensor as input and returns the desired irradiance.
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
#TODO maybe generalize to rectangle - change apreture_radius_detector to target_grid-nöö
|
|
50
|
+
image = load_image(file_name,padding_ratio=padding_ratio,grey_ratio=grey_ratio,shape=shape)
|
|
51
|
+
#image = image.T
|
|
52
|
+
image = np.array(image[::-1])
|
|
53
|
+
image = np.array(image)
|
|
54
|
+
image = torch.tensor(image).to(dtype=dtype)
|
|
55
|
+
shape = image.shape
|
|
56
|
+
|
|
57
|
+
image = image.reshape(-1)
|
|
58
|
+
grid = GridSquare(aperture_radius,grid_size=shape[0])
|
|
59
|
+
area = grid.get_area()
|
|
60
|
+
def desired_irradiance_func(x):
|
|
61
|
+
device = x.device
|
|
62
|
+
dtype = x.dtype
|
|
63
|
+
|
|
64
|
+
x = torch.clamp(x, min=-aperture_radius, max=aperture_radius)
|
|
65
|
+
k = grid.get_k(x,round_to_bounds=True)
|
|
66
|
+
k = k.cpu()
|
|
67
|
+
|
|
68
|
+
tmp = image[k]
|
|
69
|
+
out = tmp/area
|
|
70
|
+
out = out.to(device=device,dtype=dtype)
|
|
71
|
+
return out
|
|
72
|
+
|
|
73
|
+
return desired_irradiance_func
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def pil_center_crop(image):
|
|
77
|
+
"""
|
|
78
|
+
Crop the image to a square by centering it.
|
|
79
|
+
|
|
80
|
+
Args:
|
|
81
|
+
image (PIL.Image): The image to be cropped.
|
|
82
|
+
|
|
83
|
+
Returns:
|
|
84
|
+
PIL.Image: The cropped image.
|
|
85
|
+
"""
|
|
86
|
+
|
|
87
|
+
width, height = image.size
|
|
88
|
+
crop_box = None
|
|
89
|
+
if width < height:
|
|
90
|
+
crop_start = (height-width)//2
|
|
91
|
+
crop_box = (0,crop_start , width, crop_start+width) # (left, upper, right, lower)
|
|
92
|
+
else:
|
|
93
|
+
crop_start = (width-height)//2
|
|
94
|
+
crop_box = (crop_start,0 ,crop_start+height,height) # (left, upper, right, lower)
|
|
95
|
+
|
|
96
|
+
cropped_image = image.crop(crop_box)
|
|
97
|
+
return cropped_image
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def load_image(name,padding_ratio,grey_ratio,shape=None):
|
|
101
|
+
"""
|
|
102
|
+
Load an image, convert it to grayscale, and apply padding.
|
|
103
|
+
|
|
104
|
+
Args:
|
|
105
|
+
name (str): The path to the image file.
|
|
106
|
+
padding_ratio (float): The ratio of padding to be applied to the image.
|
|
107
|
+
grey_ratio (float): The ratio of grey value to be applied to the image.
|
|
108
|
+
shape (tuple, optional): The shape to resize the image to. If None, no resizing is done.
|
|
109
|
+
|
|
110
|
+
Returns:
|
|
111
|
+
np.ndarray: The processed image as a numpy array.
|
|
112
|
+
"""
|
|
113
|
+
# Open and process the image
|
|
114
|
+
image = Image.open(name)
|
|
115
|
+
image = pil_center_crop(image) # Assuming this function crops the image to its center
|
|
116
|
+
image = image.convert("L") # Convert the image to grayscale
|
|
117
|
+
if shape is not None:
|
|
118
|
+
image = image.resize(shape)
|
|
119
|
+
|
|
120
|
+
# Convert the image to a numpy array
|
|
121
|
+
image_array = np.array(image)/255.0
|
|
122
|
+
image_array = np.ones_like(image_array)*grey_ratio+(1.-grey_ratio)*image_array
|
|
123
|
+
|
|
124
|
+
# Calculate the padding size as 20% of the original dimensions
|
|
125
|
+
pad_height = int(image_array.shape[0] * padding_ratio*0.5) # 20% of the height
|
|
126
|
+
pad_width = int(image_array.shape[1] * padding_ratio*0.5) # 20% of the width
|
|
127
|
+
|
|
128
|
+
# Pad the image with constant value 0 (or any value you prefer)
|
|
129
|
+
padded_image = np.pad(image_array,
|
|
130
|
+
pad_width=((pad_height, pad_height), (pad_width, pad_width)),
|
|
131
|
+
mode='constant',
|
|
132
|
+
constant_values=0)
|
|
133
|
+
padded_image = padded_image / np.sum(padded_image)
|
|
134
|
+
return padded_image
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: diffinytrace
|
|
3
|
+
Version: 2.1
|
|
4
|
+
Author: Martin Pflaum
|
|
5
|
+
Author-email: contact@martinpflaum.com
|
|
6
|
+
Requires-Python: ==3.12
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: colour-science==0.4.7
|
|
9
|
+
Requires-Dist: matplotlib==3.10.8
|
|
10
|
+
Requires-Dist: numpy==2.3.5
|
|
11
|
+
Requires-Dist: pandas==3.0.1
|
|
12
|
+
Requires-Dist: Pillow==12.0.0
|
|
13
|
+
Requires-Dist: plotly==6.6.0
|
|
14
|
+
Requires-Dist: pvlib==0.15.0
|
|
15
|
+
Requires-Dist: scikit_learn==1.8.0
|
|
16
|
+
Requires-Dist: scipy==1.17.1
|
|
17
|
+
Requires-Dist: tqdm==4.67.3
|
|
18
|
+
Requires-Dist: nbformat==5.1.3
|
|
19
|
+
Requires-Dist: ipykernel==7.2.0
|
|
20
|
+
Requires-Dist: cadquery==2.7.0
|
|
21
|
+
Requires-Dist: torchmetrics==1.9.0
|
|
22
|
+
Dynamic: author
|
|
23
|
+
Dynamic: author-email
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
Dynamic: requires-dist
|
|
26
|
+
Dynamic: requires-python
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
diffinytrace/__init__.py,sha256=jEr3e-31VQCVGYB1_etH2DVOT7riR-7uo9NrYZVuvlo,3367
|
|
2
|
+
diffinytrace/config.py,sha256=QH6hTvGnXrFsM722-OoCLgIL1SuoehTinVqty8rBZ4M,4345
|
|
3
|
+
diffinytrace/constraints.py,sha256=qEhoMQzezuCQBvJmNvNzvJrfrZERKw8RKcl5icEnbLg,1388
|
|
4
|
+
diffinytrace/element.py,sha256=OrN-IWsh5IoZBFTJxAGm-A2e3PBcpoLqOTekY1_wuuA,67713
|
|
5
|
+
diffinytrace/gaussian_smoother.py,sha256=VAaesEUO4oqqC5JCSJJ7ZMNZoj8uYdglMtb23Ddrf4M,26395
|
|
6
|
+
diffinytrace/hat_smoother.py,sha256=k2pLqafJLr_N-488Dhhs-N35QbMg30DbNL2N4nEH48s,1307
|
|
7
|
+
diffinytrace/integrators.py,sha256=NnSkmwzIFeObH1yQtJ_aH_Q7GvAsUFbbxMw79zFdjjU,19030
|
|
8
|
+
diffinytrace/intersection.py,sha256=An2lPg6KfBZuMAOG2Pa18SgsImYNaGLFpFxMsxztriQ,10537
|
|
9
|
+
diffinytrace/optimize.py,sha256=VVUg8MZ79NsYzHxYPD0d4Felrm3m6h9W-jTo7Wk3VHM,33358
|
|
10
|
+
diffinytrace/physical_object.py,sha256=ic88YjeCtvWMfJkrkUpMUKC0FnZ_vAYuttkGjwIepGY,4788
|
|
11
|
+
diffinytrace/refractive_index.py,sha256=8vZhE5exZiCM6vtH6E2u4bUpTdaRX5_Hvw4cJ_D2mX0,5555
|
|
12
|
+
diffinytrace/render.py,sha256=_j4ROqbjHrmSz9HJFxtERMtNbnTuAc26qdryoTutiJ4,3598
|
|
13
|
+
diffinytrace/source.py,sha256=s0ugQ89qvJCETfGI9r4l3DQ-gVTZoflBn8C0xbMi2qA,25911
|
|
14
|
+
diffinytrace/spectrum.py,sha256=0hNU0K8aMWvvTUetsM9nvI3zMUhKhubBOt_ZVjOPSEA,2516
|
|
15
|
+
diffinytrace/surface.py,sha256=RSjaIlFBeNFiPGKamyKgoCJIFuAuROnEUSvCO7GsHkg,18950
|
|
16
|
+
diffinytrace/target_grid.py,sha256=QTF1hvKLMrCW6l1q8BvWYpMvT4khEkh80GjzeZR0xio,15613
|
|
17
|
+
diffinytrace/transforms.py,sha256=6CHyZXtSrgKRiy_XRODFZBURA8ocESOgDHED-5IbpDA,16195
|
|
18
|
+
diffinytrace/basis_functions/__init__.py,sha256=h2Bahd7ZBm4Z-t2e_aNPIUoa0YO_LNF_qYMHxnH5Eoc,297
|
|
19
|
+
diffinytrace/basis_functions/bspline.py,sha256=tig1xgUxcTnxK9wWvAhACWKhRzpWRVliP6iMh1dC_LY,20404
|
|
20
|
+
diffinytrace/basis_functions/chebyshev.py,sha256=cguPQOs2ibEDlsL99hjQ2Wo4cr8Hcea2NVzTsCbF7lw,120
|
|
21
|
+
diffinytrace/basis_functions/legendre.py,sha256=8CdpC_Z-IwEh0I-4HoYXqm1T1c4bID446VjvKyn-QqQ,2483
|
|
22
|
+
diffinytrace/basis_functions/zernike.py,sha256=bNIv89mY0ox09-irW_uFMYkeF64YqCZLjNKdanU_9lA,8294
|
|
23
|
+
diffinytrace/export/__init__.py,sha256=RsjN9PavLbNtwchNHE3Y6nWl12mYCv5VND6uAGtMf1k,166
|
|
24
|
+
diffinytrace/export/cad.py,sha256=kYVB_wUIXnYPlkNRs48-iyJCzwYr-M9UI914q7CX2nE,9103
|
|
25
|
+
diffinytrace/plotting/__init__.py,sha256=7v_jp_Utpi7LLTEqB3YsB0GFdt6oOuyTHnA0jT94jI8,354
|
|
26
|
+
diffinytrace/plotting/core.py,sha256=ggY3ArGyvYod7PcsuZEkzM_AZXVOjkika1hHTMNNmrs,3335
|
|
27
|
+
diffinytrace/plotting/quantity2D.py,sha256=mXOrjx0EgDPb9DGJwHlGVjKZn4GDz3NcPqPu_fYy9Yk,7920
|
|
28
|
+
diffinytrace/plotting/system2D.py,sha256=vrI0i4N0obiYKO3Sj1cqoJuAjt4_EEUV31UpOPpdx_4,7628
|
|
29
|
+
diffinytrace/plotting/system3D.py,sha256=kn3r3arb7s4T6FvDQqXc-VAJKbIYCEoCiWpdxaOg2H0,11292
|
|
30
|
+
diffinytrace/plotting/wavelength.py,sha256=ZmZMw1ay2wc7NyAo4Z_9jNVIuwaGmfHw2jCHhJHaHnQ,7384
|
|
31
|
+
diffinytrace/utils/__init__.py,sha256=BevGtOt6JSKgBExvpqaKLIk39ebFdzFqAJgL_DBUXxo,211
|
|
32
|
+
diffinytrace/utils/autograd.py,sha256=VDnbXJfe-uIY5Mbc_bIljZFWcKIZfk6jXamT-8CZKWM,4435
|
|
33
|
+
diffinytrace/utils/irradiance_importer.py,sha256=FvaTK0uRi2KnEZc6CcD0Tdh03I8Wum7XjdbMGeIZQlQ,5000
|
|
34
|
+
diffinytrace-2.1.dist-info/licenses/LICENSE,sha256=zcS2z4c_EPqi2EDV5ZpOv4FC4flqC7kYw4qOKtWHKjY,1091
|
|
35
|
+
diffinytrace-2.1.dist-info/METADATA,sha256=LyMc5UfTxbjqw0s8w1K5GAMWxSk5p4bgiYnAsYqomWo,732
|
|
36
|
+
diffinytrace-2.1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
37
|
+
diffinytrace-2.1.dist-info/top_level.txt,sha256=fK-f6Fho578N7Hz-tgLor5IEiUVOqrmLI07lp6s-iyg,13
|
|
38
|
+
diffinytrace-2.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Martin Pflaum
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
diffinytrace
|