Skip to content

Commit 627e741

Browse files
authored
Merge pull request #10 from Axiomatic-AI/cookbook_axtract_check
requirement_class refactored to user_requirement
2 parents 93c2368 + 4f7cd5d commit 627e741

File tree

2 files changed

+161
-38
lines changed

2 files changed

+161
-38
lines changed

src/axiomatic/axtract.py

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,16 @@
55
import hypernetx as hnx # type: ignore
66
import matplotlib.pyplot as plt # type: ignore
77
import re
8-
from dataclasses import dataclass, field
9-
from latex2sympy2 import latex2sympy # type: ignore
10-
import sympy # type: ignore
8+
from dataclasses import dataclass
119

1210

1311
@dataclass
14-
class Requirement:
12+
class RequirementUserInput:
1513
requirement_name: str
1614
latex_symbol: str
17-
# TODO: probably this should be really the latex symbol,
18-
# e.g. \text{GSD}_{\text{p}}
1915
value: int
2016
units: str
2117
tolerance: float
22-
sympy_symbol: str = field(init=False)
23-
24-
def __post_init__(self):
25-
self.sympy_symbol = self.latex_symbol.replace("{", "").replace("}", "")
26-
self.sympy_symbol = latex2sympy(self.latex_symbol)
27-
eq = sympy.Eq(self.sympy_symbol, self.value)
28-
free_symbols = eq.free_symbols
29-
if len(free_symbols) > 1:
30-
raise Warning(
31-
f"""
32-
The latex symbol of the requirement {self.latex_symbol}
33-
is parsed as {free_symbols} in sympy
34-
instead of a single symbol."""
35-
)
36-
37-
@property
38-
def is_fixed(self):
39-
"""Check if the requirement has tolerance set to zero."""
40-
return self.tolerance == 0.0
41-
42-
@property
43-
def equations(self, strict=False):
44-
if self.is_fixed:
45-
return [sympy.Eq(self.sympy_symbol, self.value)]
46-
else:
47-
signs = [">=", "<="] if not strict else [">", "<"]
48-
bounds = [self.value - self.tolerance, self.value + self.tolerance]
49-
return [
50-
sympy.Rel(self.sympy_symbol, bound, sign)
51-
for bound, sign in zip(bounds, signs)
52-
]
5318

5419

5520
def _find_symbol(name, variable_dict):
@@ -76,7 +41,7 @@ def requirements_from_table(results, variable_dict):
7641
unit = value["Units"]
7742

7843
requirements.append(
79-
Requirement(
44+
RequirementUserInput(
8045
requirement_name=name,
8146
latex_symbol=latex_symbol,
8247
value=numerical_value,

src/axiomatic/variables.py

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
import warnings
2+
3+
warnings.warn(
4+
"""The module 'your_module_name' is deprecated and will be removed
5+
in a future release. Please use 'new_module_name' instead.""",
6+
DeprecationWarning,
7+
stacklevel=2,
8+
)
9+
10+
VARIABLES = {
11+
r"\alpha": {"name": "Aperture radius"},
12+
r"A": {"name": "Object area"},
13+
r"\text{A'}": {"name": "Image area"},
14+
r"\text{B'}": {"name": "Image plane blur criterion"},
15+
r"\text{BFD}": {"name": "Back focal distance"},
16+
r"c": {"name": "Speed of light"},
17+
r"C": {"name": "Curvature"},
18+
r"\text{CC}": {"name": "Center of curvature"},
19+
r"d": {"name": "Front principal plane shifts"},
20+
r"\text{d'}": {"name": "Rear principal plane shifts"},
21+
r"D": {"name": "Diopters"},
22+
r"D_{airy}": {"name": "Airy disk diameter"},
23+
r"\text{DOF}": {"name": "Depth of focus, geometrical"},
24+
r"\text{Ir}": {"name": "Irradiance and illuminance"},
25+
r"\text{ee}_v": {"name": "Irradiance and illuminance"},
26+
r"\text{EFL}": {"name": "Effective focal length"},
27+
r"\text{eP}": {"name": "Entrance pupil"},
28+
r"\text{eR}": {"name": "Eye relief"},
29+
r"f": {"name": "Focal length"},
30+
r"f_{ee}": {"name": "Effective focal length"},
31+
r"f_F": {"name": "Front focal length"},
32+
r"f_R": {"name": "Rear focal length"},
33+
r"\text{f/hash}": {"name": "F-number"},
34+
r"\text{f/hash_w}": {"name": "Working F-number"},
35+
r"\delta_f": {"name": "Longitudinal chromatic aberration"},
36+
r"F": {"name": "Front focal point"},
37+
r"\text{F'}": {"name": "Rear focal point"},
38+
r"\text{FFD}": {"name": "Front focal distance"},
39+
r"\text{FFOV}": {"name": "Full field of view"},
40+
r"\text{FOB}": {"name": "Fractional object"},
41+
r"text{FOV}": {"name": "Field of view"},
42+
r"h": {"name": "Object height"},
43+
r"\text{h'}": {"name": "Image height"},
44+
r"H": {"name": "Lagrange invariant"},
45+
r"H_v": {"name": "Normalized field height"},
46+
r"H_{norm}": {"name": "Normalized field height"},
47+
r"\text{\text{e}xposure}": {"name": "Exposure"},
48+
r"\text{HFOV}": {"name": "Half field of view"},
49+
r"I": {"name": "Optical invariant"},
50+
r"I_v": {"name": "Intensity and luminous intensity"},
51+
r"L": {"name": "Object-to-image distance"},
52+
r"L_v": {"name": "Radiance and luminance"},
53+
r"L_H": {"name": "Hyperfocal distance"},
54+
r"L_{NEAR}": {"name": "Depth of field limits"},
55+
r"L_{FAR}": {"name": "Depth of field limits"},
56+
r"\text{LA}": {"name": "Longitudinal aberration"},
57+
r"m": {"name": "Transverse or lateral magnification"},
58+
r"\bar{m}": {"name": "Longitudinal magnification"},
59+
r"m_v": {"name": "Visual magnification (microscope)"},
60+
r"M": {"name": "Exitance"},
61+
r"M_v": {"name": "Luminous exitance"},
62+
r"\text{MP}": {
63+
"name": "Magnifying power (magnifier or telescope)",
64+
},
65+
r"\text{MTF}": {"name": "Modulation transfer function"},
66+
r"n": {"name": "Index of refraction"},
67+
r"N": {"name": "Front nodal point"},
68+
r"\text{N'}": {"name": "Rear nodal point"},
69+
r"\text{NA}": {"name": "Numerical aperture"},
70+
r"\text{OPL}": {"name": "Optical path length"},
71+
r"\text{OTL}": {"name": "Optical tube length"},
72+
r"P": {"name": "Partial dispersion ratio"},
73+
r"\text{P'}": {"name": "Front and rear principal points"},
74+
r"\text{PSF}": {"name": "Point spread function"},
75+
r"Q": {"name": "Energy"},
76+
r"r_P": {"name": "Pupil radius"},
77+
r"R": {"name": "Radius of curvature"},
78+
r"s": {"name": "Surface sag or a separation"},
79+
r"s_{prime}": {"name": "Object and image vertex distances"},
80+
r"S": {"name": "Seidel aberration coefficient"},
81+
r"\text{SR}": {"name": "Strehl ratio"},
82+
r"t": {"name": "Thickness"},
83+
r"T": {"name": "Temperature"},
84+
r"\text{TA}": {"name": "Transverse aberration"},
85+
r"\text{TA}_{CH}": {
86+
"name": "Transverse axial chromatic aberration",
87+
},
88+
r"\text{TIR}": {"name": "Total internal reflection"},
89+
r"\Delta_t": {"name": "Exposure time"},
90+
r"u": {"name": "Paraxial angles; marginal rays"},
91+
r"\bar{u}": {"name": "Chief rays"},
92+
r"U": {"name": "Real marginal ray angle"},
93+
r"V": {"name": "Abbe number"},
94+
r"\text{V'}": {"name": "Surface vertices"},
95+
r"W": {"name": "Wavefront error"},
96+
r"W_{IJK}": {"name": "Wavefront aberration coefficient"},
97+
r"\text{WD}": {"name": "Working distance"},
98+
r"X": {"name": "Object coordinates"},
99+
r"Y": {"name": "Object coordinates"},
100+
r"\text{X'}": {"name": "Image coordinates"},
101+
r"\text{Y'}": {"name": "Image coordinates"},
102+
r"x_p": {"name": "Normalized pupil coordinates"},
103+
r"x_P": {"name": "Normalized pupil coordinates"},
104+
r"\text{XP}": {"name": "Exit pupil"},
105+
r"y": {"name": "Paraxial ray heights; marginal rays"},
106+
r"\bar{y}": {"name": "Paraxial ray heights; chief rays"},
107+
r"z": {"name": "Optical axis"},
108+
r"\text{z'}": {"name": "Object and image distances"},
109+
r"\delta_z": {"name": "Image plane shift"},
110+
r"\delta_{\hat{z}}": {"name": "Depth of focus, diffraction"},
111+
r"\Delta_z": {"name": "Object and image separations"},
112+
r"\delta": {"name": "Prism deviation"},
113+
r"\delta_{MIN}": {"name": "Angle of minimum deviation"},
114+
r"\delta_{phi}": {
115+
"name": "Longitudinal chromatic aberration",
116+
},
117+
r"\Delta": {"name": "Prism dispersion"},
118+
r"\epsilon": {"name": "Prism secondary dispersion"},
119+
r"\epsilon_X": {"name": "Transverse ray errors (X-axis)"},
120+
r"\epsilon_Y": {"name": "Transverse ray errors (Y-axis)"},
121+
r"\epsilon_Z": {"name": "Longitudinal ray error"},
122+
r"\theta": {
123+
"name": "Angle of incidence, refraction or reflection",
124+
},
125+
r"\theta_C": {"name": "Critical angle"},
126+
r"\theta_{1/2}": {"name": "Half field of view angle"},
127+
r"\kappa": {"name": "Conic constant"},
128+
r"\lambda": {"name": "Wavelength"},
129+
r"\nu": {"name": "Abbe number"},
130+
r"\rho": {"name": "Reflectance"},
131+
r"\rho_{norm}": {"name": "Normalized pupil radius"},
132+
r"\tau": {"name": "Reduced thickness"},
133+
r"\phi": {"name": "Optical power"},
134+
r"\Phi": {"name": "Radiant power"},
135+
r"\Phi_V": {"name": "Luminous power"},
136+
r"\omega": {"name": "Optical angles; marginal rays"},
137+
r"\bar{omega}": {"name": "Optical angles; chief rays"},
138+
r"\Omega": {"name": "Solid angle"},
139+
r"\Xi": {"name": "Lagrange invariant"},
140+
r"p_p": {"name": "Pixel size (panchromatic)"},
141+
r"p_{ms}": {"name": "Pixel size (multispectral)"},
142+
r"h_{alt}": {"name": "Altitude"},
143+
r"\nu_N": {"name": "Nyquist frequency"},
144+
r"\nu_c": {"name": "Cutoff frequency"},
145+
r"\text{GSD}_p": {
146+
"name": "Ground sampling distance (panchromatic)",
147+
},
148+
r"\text{GSD}_{ms}": {
149+
"name": "Ground sampling distance (multispectral)",
150+
},
151+
r"\text{GSS}": {"name": "Ground spot size"},
152+
r"Q_{img}": {"name": "Imaging Q factor"},
153+
r"\text{Swath}": {"name": "Swath width"},
154+
r"r_p": {"name": "Resolution (panchromatic)"},
155+
r"r_{ms}": {"name": "Resolution (multispectral)"},
156+
r"M_d": {"name": "Mirror aperture"},
157+
r"f^{\prime}_R": {"name": "Rear focal length"},
158+
}

0 commit comments

Comments
 (0)