Skip to content

Commit fc93617

Browse files
pre-commit: apply black formatting
1 parent e543fd0 commit fc93617

File tree

7 files changed

+73
-100
lines changed

7 files changed

+73
-100
lines changed

.pre-commit-config.yaml

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,15 @@
11
repos:
2-
- repo: https://github.com/humitos/mirrors-autoflake
3-
rev: v1.1
4-
hooks:
5-
- id: autoflake
6-
args: ['-i', '--remove-all-unused-imports']
7-
- repo: https://github.com/psf/black
8-
rev: 23.3.0
9-
hooks:
10-
- id: black
11-
args: ['-l', '120']
12-
13-
- repo: https://github.com/asottile/blacken-docs
14-
rev: 1.13.0
15-
hooks:
16-
- id: blacken-docs
17-
additional_dependencies: [black]
18-
19-
- repo: https://github.com/pycqa/isort
20-
rev: 5.12.0
21-
hooks:
22-
- id: isort
23-
name: isort (python)
24-
args: [
25-
'--force-single-line-imports',
26-
'--profile', 'black'
27-
]
28-
29-
- repo: https://github.com/pycqa/flake8
30-
rev: 6.0.0
31-
hooks:
32-
- id: flake8
33-
args: [
34-
'--max-line-length', '120',
35-
'--max-doc-length', '120',
36-
'--ignore', 'F821,E402,W503',
37-
'--extend-ignore', 'E203'
38-
]
39-
- repo: https://github.com/Carreau/velin
40-
rev: 0.0.11
41-
hooks:
42-
- id: velin
43-
name: Velin
44-
entry: velin
45-
types: [ python ]
46-
args: ["--write"]
2+
- repo: https://github.com/PyCQA/autoflake
3+
rev: v2.3.1
4+
hooks:
5+
- id: autoflake
6+
args:
7+
- --in-place
8+
- --remove-all-unused-imports
9+
- --remove-unused-variables
10+
- repo: https://github.com/psf/black
11+
rev: 25.11.0
12+
hooks:
13+
- id: black
14+
args: ['-l','120']
15+
language_version: python3.12

ansys_optical_automation/application/A_1_Create_stl_polynomial_surface.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
This script works standalone or can be imported by another script.
99
"""
1010

11-
import numpy as np
12-
import trimesh
1311
import json
1412
import os
15-
from typing import Optional
13+
14+
import numpy as np
15+
import trimesh
1616

1717

1818
def build_design_matrix(x: np.ndarray, y: np.ndarray, order: int = 5) -> np.ndarray:
@@ -34,7 +34,7 @@ def build_design_matrix(x: np.ndarray, y: np.ndarray, order: int = 5) -> np.ndar
3434
terms = []
3535
for i in range(order + 1):
3636
for j in range(order + 1 - i):
37-
terms.append((x ** i) * (y ** j))
37+
terms.append((x**i) * (y**j))
3838
return np.vstack(terms).T
3939

4040

@@ -60,15 +60,12 @@ def evaluate_fitted_surface(coeffs: np.ndarray, x: np.ndarray, y: np.ndarray, or
6060
idx = 0
6161
for i in range(order + 1):
6262
for j in range(order + 1 - i):
63-
z += coeffs[idx] * (x ** i) * (y ** j)
63+
z += coeffs[idx] * (x**i) * (y**j)
6464
idx += 1
6565
return z
6666

6767

68-
def create_polynomial_surface(input_file: str,
69-
output_stl: str,
70-
output_json: str,
71-
order: int = 5) -> None:
68+
def create_polynomial_surface(input_file: str, output_stl: str, output_json: str, order: int = 5) -> None:
7269
"""
7370
Fit the polynomial surface and export STL + JSON model.
7471
@@ -138,15 +135,9 @@ def create_polynomial_surface(input_file: str,
138135

139136
def main():
140137
"""Standalone entry point."""
141-
input_file = (
142-
r"C:\Users\amarin\OneDrive - ANSYS, Inc\Articules and Trainings ACE\3D Texture - Light Guide\#2. Variable pitch\TL L.3D Texture.2.OPT3DMapping"
143-
)
144-
output_stl = (
145-
r"C:\Users\amarin\OneDrive - ANSYS, Inc\Articules and Trainings ACE\3D Texture - Light Guide\#2. Variable pitch\FittedSurface_Global_HighQuality.stl"
146-
)
147-
output_json = (
148-
r"C:\Users\amarin\OneDrive - ANSYS, Inc\Articules and Trainings ACE\3D Texture - Light Guide\#2. Variable pitch\FittedSurface_Model.json"
149-
)
138+
input_file = r"C:\Users\amarin\OneDrive - ANSYS, Inc\Articules and Trainings ACE\3D Texture - Light Guide\#2. Variable pitch\TL L.3D Texture.2.OPT3DMapping"
139+
output_stl = r"C:\Users\amarin\OneDrive - ANSYS, Inc\Articules and Trainings ACE\3D Texture - Light Guide\#2. Variable pitch\FittedSurface_Global_HighQuality.stl"
140+
output_json = r"C:\Users\amarin\OneDrive - ANSYS, Inc\Articules and Trainings ACE\3D Texture - Light Guide\#2. Variable pitch\FittedSurface_Model.json"
150141
create_polynomial_surface(input_file, output_stl, output_json)
151142

152143

ansys_optical_automation/application/A_2_Create_a_variable_pitch_from_the_polynomial_surface.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@
1010
Everything can also be executed independently (standalone).
1111
"""
1212

13-
import os
1413
import json
14+
import os
15+
from typing import List
16+
from typing import Tuple
17+
1518
import numpy as np
16-
from typing import List, Tuple
1719

1820
# Try importing the fitting script
1921
try:
2022
from A_1_Create_stl_polynomial_surface import create_polynomial_surface
23+
2124
print("[INFO] Successfully imported create_polynomial_surface from 1_1_create_stl_polynomial_surface.py")
2225
except ModuleNotFoundError as e:
2326
print(f"[ERROR] Could not import Script 1: {e}")
@@ -68,9 +71,9 @@ def linear_pitch_x(x: float, x_min: float, x_max: float, p_start: float, p_end:
6871
return p_start * (1.0 - t) + p_end * t
6972

7073

71-
def generate_points(domain: Tuple[float, float, float, float],
72-
p_start: float, p_end: float, p_y: float,
73-
include_edges: bool = True) -> Tuple[np.ndarray, np.ndarray]:
74+
def generate_points(
75+
domain: Tuple[float, float, float, float], p_start: float, p_end: float, p_y: float, include_edges: bool = True
76+
) -> Tuple[np.ndarray, np.ndarray]:
7477
"""
7578
Generate (X, Y) grid with variable X pitch and constant Y pitch.
7679
@@ -121,15 +124,14 @@ def eval_poly2d(coeffs: np.ndarray, x_norm: np.ndarray, y_norm: np.ndarray, orde
121124
idx = 0
122125
for i in range(order + 1):
123126
for j in range(order + 1 - i):
124-
z += coeffs[idx] * (x_norm ** i) * (y_norm ** j)
127+
z += coeffs[idx] * (x_norm**i) * (y_norm**j)
125128
idx += 1
126129
return z
127130

128131

129-
def write_opt3d_mapping(path: str,
130-
X: np.ndarray, Y: np.ndarray, Z: np.ndarray,
131-
extra_constants: List[str],
132-
float_fmt: str = ".6f") -> None:
132+
def write_opt3d_mapping(
133+
path: str, X: np.ndarray, Y: np.ndarray, Z: np.ndarray, extra_constants: List[str], float_fmt: str = ".6f"
134+
) -> None:
133135
"""Write the .OPT3DMapping file."""
134136
if len(extra_constants) != 9:
135137
raise ValueError("Exactly 9 extra constants are required.")
@@ -139,8 +141,7 @@ def write_opt3d_mapping(path: str,
139141
with open(path, "w", encoding="utf-8") as f:
140142
f.write(f"{n}\n")
141143
for x, y, z in zip(X, Y, Z):
142-
f.write(f"{ffmt.format(x)} {ffmt.format(y)} {ffmt.format(z)} "
143-
+ " ".join(extra_constants) + "\n")
144+
f.write(f"{ffmt.format(x)} {ffmt.format(y)} {ffmt.format(z)} " + " ".join(extra_constants) + "\n")
144145

145146

146147
def ensure_model_json():
@@ -170,8 +171,7 @@ def main():
170171
y_min = Y_MIN or float(model["y_min"])
171172
y_max = Y_MAX or float(model["y_max"])
172173

173-
X_pts, Y_pts = generate_points((x_min, x_max, y_min, y_max),
174-
PITCH_X_START, PITCH_X_END, PITCH_Y, INCLUDE_EDGES)
174+
X_pts, Y_pts = generate_points((x_min, x_max, y_min, y_max), PITCH_X_START, PITCH_X_END, PITCH_Y, INCLUDE_EDGES)
175175
x_norm = (X_pts - x_mean) / x_std
176176
y_norm = (Y_pts - y_mean) / y_std
177177
Z_pts = eval_poly2d(coeffs, x_norm, y_norm, order)

ansys_optical_automation/application/B_2 Update Kz variation in mapping file.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import os
22

33
# ==== Parameters ====
4-
K_Z_1 = 0.5 # Value applied at the minimum X (start of the range)
5-
K_Z_2 = 0.1 # Value applied at the maximum X (end of the range)
4+
K_Z_1 = 0.5 # Value applied at the minimum X (start of the range)
5+
K_Z_2 = 0.1 # Value applied at the maximum X (end of the range)
66

77
# File paths
88
input_path = r"C:\Users\amarin\OneDrive - ANSYS, Inc\Articules and Trainings ACE\3D Texture - Light Guide\#3. Variable Kz\TL L.3D Texture.2.OPT3DMapping"
9-
output_path = os.path.join(
10-
os.path.dirname(input_path),
11-
"K-Z Variation.OPT3DMapping"
12-
)
9+
output_path = os.path.join(os.path.dirname(input_path), "K-Z Variation.OPT3DMapping")
1310

1411
# ==== Read the file ====
1512
# Read all lines from the mapping file

ansys_optical_automation/application/scdm_script_tool/2.1 3DT Random.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1+
import ctypes
12
import os
23
import random
3-
import ctypes
4+
45
import clr
6+
57
clr.AddReference("System.Windows.Forms")
68
clr.AddReference("System.Drawing")
79

8-
import System
9-
from System.Windows.Forms import (
10-
Form, Label, TextBox, Button, DialogResult, FormStartPosition, Panel,
11-
ProgressBar, ProgressBarStyle, Application, Timer
12-
)
13-
from System.Drawing import Point, Size
10+
from System.Drawing import Point
11+
from System.Drawing import Size
12+
from System.Windows.Forms import Application
13+
from System.Windows.Forms import Button
14+
from System.Windows.Forms import DialogResult
15+
from System.Windows.Forms import Form
16+
from System.Windows.Forms import FormStartPosition
17+
from System.Windows.Forms import Label
18+
from System.Windows.Forms import Panel
19+
from System.Windows.Forms import ProgressBar
20+
from System.Windows.Forms import ProgressBarStyle
21+
from System.Windows.Forms import TextBox
22+
from System.Windows.Forms import Timer
1423

1524
# -------------------------------------------------------------------------
1625
# Windows MessageBox flags (for reference)
@@ -22,6 +31,7 @@
2231
MB_ICONINFORMATION = 0x00000040
2332
MB_TOPMOST = 0x00040000
2433

34+
2535
def show_message(message, title="Message"):
2636
"""
2737
Show a Windows message box anchored to the current foreground window.
@@ -44,6 +54,7 @@ def show_message(message, title="Message"):
4454
hwnd = ctypes.windll.user32.GetForegroundWindow()
4555
ctypes.windll.user32.MessageBoxW(hwnd, message, title, MB_OK | MB_ICONINFORMATION | MB_TOPMOST)
4656

57+
4758
# === Simple progress window with animated bounce ===
4859
class ProgressWindow(Form):
4960
"""A minimal progress dialog with a continuously bouncing progress bar."""
@@ -119,6 +130,7 @@ def animate_bar(self, sender, event):
119130
# Silently ignore transient UI exceptions
120131
pass
121132

133+
122134
# === GUI with editable control points ===
123135
class DynamicProbabilityForm(Form):
124136
"""
@@ -355,6 +367,7 @@ def on_run(self, sender, event):
355367
except:
356368
show_message("Invalid input. Please check values.", "Input Error")
357369

370+
358371
def process_mapping_file(input_file, control_points, master_name):
359372
"""
360373
Filter an .OPT3DMapping file based on an x-dependent removal probability.
@@ -384,7 +397,7 @@ def process_mapping_file(input_file, control_points, master_name):
384397
with open(input_file, "r") as f:
385398
lines = f.readlines()
386399

387-
original_count = int(lines[0].strip())
400+
int(lines[0].strip())
388401
data_lines = lines[1:]
389402

390403
# Parse X from each line; keep original line for later writing
@@ -408,7 +421,7 @@ def process_mapping_file(input_file, control_points, master_name):
408421
new_count = len(filtered_lines)
409422

410423
# Encode control points in filename for traceability
411-
points_str = "_".join(["p{:.1f}-{:.1f}".format(p, x*100) for x, p in control_points])
424+
points_str = "_".join(["p{:.1f}-{:.1f}".format(p, x * 100) for x, p in control_points])
412425
output_file = os.path.join(os.path.dirname(input_file), "{}_{}.OPT3DMapping".format(master_name, points_str))
413426

414427
# Write new header (count) and kept lines
@@ -419,6 +432,7 @@ def process_mapping_file(input_file, control_points, master_name):
419432

420433
return output_file
421434

435+
422436
def interpolate_probability(x_norm, control_points):
423437
"""
424438
Linearly interpolate a probability value for a given normalized x.
@@ -439,13 +453,14 @@ def interpolate_probability(x_norm, control_points):
439453
float
440454
Interpolated probability in [0..1].
441455
"""
442-
for i in range(len(control_points)-1):
456+
for i in range(len(control_points) - 1):
443457
x0, p0 = control_points[i]
444-
x1, p1 = control_points[i+1]
458+
x1, p1 = control_points[i + 1]
445459
if x0 <= x_norm <= x1:
446460
return p0 + (p1 - p0) * ((x_norm - x0) / (x1 - x0))
447461
return control_points[-1][1]
448462

463+
449464
# -----------------------------------------------------------------------------
450465
# Main execution block
451466
# Attempts to:

ansys_optical_automation/post_process/dpf_xmp_viewer.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,9 @@ class of MapStruct
437437
line = next(my_data)
438438
for xmp_value_idx, xmp_value in enumerate(line):
439439
if xmp_value != "":
440-
xmp_map_struct.data[
441-
layer_idx, xmp_value_idx, xmp_value_idy, wavelength_idx
442-
] = xmp_value
440+
xmp_map_struct.data[layer_idx, xmp_value_idx, xmp_value_idy, wavelength_idx] = (
441+
xmp_value
442+
)
443443
elif self.dpf_instance.Maptype == 3 and xmp_map_struct.wl_res is not None:
444444
for i in range(8):
445445
line = next(my_data)
@@ -455,9 +455,9 @@ class of MapStruct
455455
line = next(my_data)
456456
for xmp_value_idx, xmp_value in enumerate(line):
457457
if xmp_value != "":
458-
xmp_map_struct.data[
459-
layer_idx, xmp_value_idx, xmp_value_idy, wavelength_idx
460-
] = xmp_value
458+
xmp_map_struct.data[layer_idx, xmp_value_idx, xmp_value_idy, wavelength_idx] = (
459+
xmp_value
460+
)
461461
elif self.dpf_instance.Maptype == 3 and xmp_map_struct.wl_res is None:
462462
for i in range(7):
463463
line = next(my_data)

tests/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Define constants and settings for tests"""
2+
23
SCDM_VERSION = 222
34
API_VERSION = 22
45
LUMERICAL_VERSION = 222

0 commit comments

Comments
 (0)