-
Notifications
You must be signed in to change notification settings - Fork 7
feat: refactor source class #690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
5b5d11e
0990b59
e151c5d
2112d08
1b62c6d
e8d2d27
c11dc96
359eeb6
85ae2f1
30744e7
75cbaea
a644db0
b0ef0db
0fab2d4
f636777
da67f35
fef8ac7
2a5bf45
e51350b
1f7a9f4
8f42a9c
1719bf5
c7fc8af
4ebbc84
94b53f3
56dd33d
749ea89
aaa84d0
5426819
28ca1dc
5767315
06c33ed
4e520bc
10c6a2d
3d20f79
13130d0
df97791
c14208f
7259117
b86d00f
da7e5f0
4786dba
8512e07
58e6075
033a969
985ab5c
b7c4ad4
e281307
49979bc
339887d
8903fa0
ae3f817
e522762
c1b392a
c29c6f1
bed1f71
06294a6
fec559e
0b3bf19
8caa372
11a453e
d99d8b1
fee28f8
823781c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Refactor source class |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,13 @@ | |
|
|
||
| """Collection of all constants used in pySpeos.""" | ||
|
|
||
| from dataclasses import dataclass, field | ||
| from enum import Enum | ||
| import os | ||
| from pathlib import Path | ||
| from typing import Optional, Union | ||
|
|
||
| from ansys.speos.core.geo_ref import GeoRef | ||
|
|
||
| DEFAULT_HOST: str = "localhost" | ||
| """Default host used by Speos RPC server and client """ | ||
|
|
@@ -38,3 +44,142 @@ | |
| """Maximum message Size accepted by grpc channel, | ||
| By default, 4194304. | ||
| """ | ||
| ORIGIN = [0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1] | ||
| """Global Origin""" | ||
|
|
||
|
|
||
| class SPECTRUM: | ||
| """Constant class for Spectrum.""" | ||
|
|
||
| class MONOCHROMATIC: | ||
| """Constant class for Monochromatic.""" | ||
|
|
||
| WAVELENGTH = 555 | ||
|
|
||
| class BLACKBODY: | ||
| """Constant class for BlackBody.""" | ||
|
|
||
| TEMPERATURE = 2856 | ||
|
|
||
|
|
||
| class SOURCE: | ||
| """Constant class for Sources.""" | ||
|
|
||
| class LUMINOUS: | ||
| """Constant class for Luminous.""" | ||
|
|
||
| VALUE = 683 | ||
|
|
||
| class RADIANT: | ||
| """Constant class for Radiant.""" | ||
|
|
||
| VALUE = 1 | ||
|
|
||
| class INTENSITY: | ||
| """Constant class for Intensity.""" | ||
|
|
||
| VALUE = 5 | ||
|
|
||
|
|
||
| class FluxType(Enum): | ||
| """Enum representing the type of flux.""" | ||
|
|
||
| LUMINOUS = "luminous" | ||
| RADIANT = "radiant" | ||
| FROM_FILE = "from_file" | ||
| INTENSITY = "intensity" | ||
|
|
||
|
|
||
| @dataclass | ||
| class SourceRayfileParameters: | ||
| """Constant class for SourceRayfileParameters.""" | ||
|
|
||
| ray_file_uri: Union[str, Path] = "" | ||
| flux_type: FluxType = FluxType.FROM_FILE | ||
| flux_value: Optional[float] = None | ||
| axis_system: list[float] = field(default_factory=lambda: ORIGIN) | ||
| exit_geometry: Optional[GeoRef] = None | ||
|
|
||
| def __post_init__(self): | ||
| """Verify the dataclass initiation.""" | ||
| # Validation: restrict flux_type | ||
| if self.flux_type not in {FluxType.FROM_FILE, FluxType.LUMINOUS, FluxType.RADIANT}: | ||
| raise ValueError( | ||
| f"Invalid flux_type '{self.flux_type}'. Must be FROM_FILE, LUMINOUS, or RADIANT." | ||
|
Comment on lines
+105
to
+108
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Identitical validation is there in both classes, i would suggest to create a base class (dataclass) and add this post__init__ and also validate_flux_type. Also you can centralize validation logic in enum class itself. (as a property)
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. elaborating the suggestion:
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another comment will be changing this source constants, to another file, to make the code neat |
||
| ) | ||
|
|
||
| # Set default flux_value based on flux_type (only if not manually provided) | ||
| if self.flux_value is None: | ||
| match self.flux_type: | ||
| case FluxType.LUMINOUS: | ||
| self.flux_value = 683 | ||
| case FluxType.RADIANT: | ||
| self.flux_value = 1 | ||
| case FluxType.FROM_FILE: | ||
| self.flux_value = 0.0 | ||
|
|
||
|
|
||
| @dataclass | ||
| class SourceLuminaireParameters: | ||
| """Constant class for SourceLuminaireParamters.""" | ||
|
|
||
| intensity_file_uri: Union[str, Path] = "" | ||
| flux_type: FluxType = FluxType.FROM_FILE | ||
| flux_value: Optional[float] = None | ||
| axis_system: list[float] = field(default_factory=lambda: ORIGIN) | ||
|
|
||
| def __post_init__(self) -> None: | ||
| """Verify the dataclass initiation.""" | ||
| # Validation: restrict flux_type | ||
| if self.flux_type not in {FluxType.FROM_FILE, FluxType.LUMINOUS, FluxType.RADIANT}: | ||
| raise ValueError( | ||
| f"Invalid flux_type '{self.flux_type}'. Must be FROM_FILE, LUMINOUS, or RADIANT." | ||
| ) | ||
|
|
||
| # Set default flux_value based on flux_type (only if not manually provided) | ||
| if self.flux_value is None: | ||
| match self.flux_type: | ||
| case FluxType.LUMINOUS: | ||
| self.flux_value = 683 | ||
| case FluxType.RADIANT: | ||
| self.flux_value = 1 | ||
| case FluxType.FROM_FILE: | ||
| self.flux_value = 0.0 | ||
|
|
||
|
|
||
pluAtAnsys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| class SENSOR: | ||
pluAtAnsys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """Constant class for Sensors.""" | ||
|
|
||
| class WAVELENGTHSRANGE: | ||
| """Wavelength constants.""" | ||
|
|
||
| START = 400 | ||
| """Wavelength start value.""" | ||
| END = 700 | ||
| """Wavelength end value.""" | ||
| SAMPLING = 13 | ||
| """Wavelength sampling.""" | ||
|
|
||
| class DIMENSIONS: | ||
| """Dimension Constants.""" | ||
|
|
||
| X_START = -50 | ||
| """Lower bound x axis.""" | ||
| X_END = 50 | ||
| """Upper bound x axis.""" | ||
| X_SAMPLING = 100 | ||
| """Sampling x axis.""" | ||
| Y_START = -50 | ||
| """Lower bound y axis.""" | ||
| Y_END = 50 | ||
| """Upper bound y axis.""" | ||
| Y_SAMPLING = 100 | ||
| """Sampling y axis.""" | ||
|
|
||
| class LAYERTYPES: | ||
| """Layer Separation constants.""" | ||
|
|
||
| MAXIMUM_NB_OF_SEQUENCE = 10 | ||
| """Number of sequences stored in sensor.""" | ||
| INCIDENCE_SAMPLING = 9 | ||
| """Number of incidence sampling stored in sensor""" | ||
Uh oh!
There was an error while loading. Please reload this page.