Skip to content

Commit 9c394f6

Browse files
authored
Update lpf file reader test - Adapt to SpeosRPC_Server breaking changes (#27)
* lpf file reader - adapt test + test assets to API changes * use new ansys-optics-speos-grpcapi==4
1 parent 8bb5688 commit 9c394f6

File tree

6 files changed

+78
-92
lines changed

6 files changed

+78
-92
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ classifiers=[
2323
"Operating System :: OS Independent",
2424
]
2525
dependencies=[
26-
"ansys-optics-speos-grpcapi==2",
26+
"ansys-optics-speos-grpcapi==4",
2727
"grpcio-tools",
2828
]
2929

tests/assets/basic_1.lpf

-1.23 KB
Binary file not shown.

tests/assets/basic_2.lpf

-910 Bytes
Binary file not shown.

tests/assets/basic_DirectSimu.lpf

1.36 MB
Binary file not shown.

tests/assets/basic_InverseSimu.lpf

2.91 MB
Binary file not shown.

tests/test_lpf_file_reader.py

Lines changed: 77 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -20,70 +20,86 @@
2020
from conftest import config, test_path
2121

2222

23-
def test_lpf_file_reader_mono_v1():
23+
def test_lpf_file_reader_mono_v1_DirectSimu():
2424
# Lpf file reader creation
2525
stub = speos.get_stub_insecure_channel(
2626
port=config.get("SpeosServerPort"), stub_type=lpf_file_reader__v1__pb2_grpc.LpfFileReader_MonoStub
2727
)
2828

2929
# Init with file path
30-
path = os.path.join(test_path, "basic_1.lpf")
30+
path = os.path.join(test_path, "basic_DirectSimu.lpf")
3131
stub.InitLpfFileName(lpf_file_reader__v1__pb2.InitLpfFileNameRequest_Mono(lpf_file_path=path))
3232

33-
# Check Nb XMPs
34-
assert stub.GetNbOfXMPs(Empty()).nb_of_xmps == 3
35-
36-
# Check Nb Traces
37-
nb_of_traces = stub.GetNbOfTraces(Empty()).nb_of_traces
38-
assert nb_of_traces == 10
33+
# GetInformation
34+
res_information = stub.GetInformation(lpf_file_reader__v1__pb2.GetInformationRequest_Mono())
35+
nb_of_traces = res_information.nb_of_traces
36+
assert nb_of_traces == 24817
37+
assert res_information.nb_of_xmps == 3
38+
assert res_information.has_sensor_contributions == False # No contributions stored in Direct simu
39+
assert len(res_information.sensor_names) == 3
40+
assert res_information.sensor_names[0] == "Irradiance Sensor (0)"
41+
assert res_information.sensor_names[2] == "Irradiance Sensor (2)"
3942

4043
# Read
4144
raypaths = []
4245
for rp in stub.Read(lpf_file_reader__v1__pb2.ReadRequest_Mono()):
4346
raypaths.append(rp)
4447
assert len(raypaths) == nb_of_traces
4548

46-
# Check result (first and last entry)
47-
expectedNbOfImpactOnFaces0 = 4
48-
assert len(raypaths[0].impacts) == expectedNbOfImpactOnFaces0
49-
assert raypaths[0].impacts[1] == lpf_file_reader__v1__pb2.TripletFloat(
50-
x=4.4084320068359375, y=14.999999046325684, z=2.4493408203125
51-
)
52-
assert len(raypaths[0].wavelengths) == expectedNbOfImpactOnFaces0
53-
assert raypaths[0].wavelengths[1] == 678.1803588867188
54-
assert len(raypaths[0].body_context_ids) == expectedNbOfImpactOnFaces0
49+
# Check result (first entry)
50+
expected_nb_of_impact = 5
51+
assert len(raypaths[0].impacts) == expected_nb_of_impact
52+
assert raypaths[0].impacts[1] == lpf_file_reader__v1__pb2.TripletFloat(x=3.19368935, y=14.999999, z=-3.94779062)
53+
assert len(raypaths[0].wavelengths) == expected_nb_of_impact
54+
assert raypaths[0].wavelengths[1] == 691.44708251953125
55+
assert len(raypaths[0].body_context_ids) == expected_nb_of_impact
5556
assert raypaths[0].body_context_ids[1] == 2001802324
56-
assert len(raypaths[0].unique_face_ids) == expectedNbOfImpactOnFaces0
57+
assert len(raypaths[0].unique_face_ids) == expected_nb_of_impact
5758
assert raypaths[0].unique_face_ids[1] == 1815582994
5859
assert raypaths[0].lastDirection == lpf_file_reader__v1__pb2.TripletFloat(
59-
x=0.2041478008031845, y=-0.9723469614982605, z=0.11342425644397736
60+
x=0.0606396869, y=0.995341122, z=-0.0749590397
6061
)
61-
assert len(raypaths[0].interaction_statuses) == expectedNbOfImpactOnFaces0
62+
assert len(raypaths[0].interaction_statuses) == expected_nb_of_impact
6263
assert raypaths[0].interaction_statuses[0] == lpf_file_reader__v1__pb2.RayPath.PhotonStatus.StatusJustEmitted
6364
assert (
6465
raypaths[0].interaction_statuses[1] == lpf_file_reader__v1__pb2.RayPath.PhotonStatus.StatusSpecularTransmitted
6566
)
66-
assert raypaths[0].interaction_statuses[3] == lpf_file_reader__v1__pb2.RayPath.PhotonStatus.StatusSpecularReflected
67+
assert len(raypaths[0].sensor_contributions) == 0
6768

68-
expectedNbOfImpactOnFaces9 = 6
69-
assert len(raypaths[9].impacts) == expectedNbOfImpactOnFaces9
70-
assert raypaths[9].impacts[1] == lpf_file_reader__v1__pb2.TripletFloat(
71-
x=-1.8186546564102173, y=15.0, z=-6.767658233642578
72-
)
73-
assert len(raypaths[9].wavelengths) == expectedNbOfImpactOnFaces9
74-
assert raypaths[9].wavelengths[1] == 743.3338623046875
75-
assert len(raypaths[9].body_context_ids) == expectedNbOfImpactOnFaces9
76-
assert raypaths[9].body_context_ids[1] == 2001802324
77-
assert len(raypaths[9].unique_face_ids) == expectedNbOfImpactOnFaces9
78-
assert raypaths[9].unique_face_ids[1] == 1815582994
79-
assert raypaths[9].lastDirection == lpf_file_reader__v1__pb2.TripletFloat(
80-
x=0.14110437035560608, y=0.8392737507820129, z=0.5250800848007202
69+
# Close
70+
stub.CloseLpfFileName(Empty())
71+
72+
73+
def test_lpf_file_reader_mono_v1_InverseSimu():
74+
# Lpf file reader creation
75+
stub = speos.get_stub_insecure_channel(
76+
port=config.get("SpeosServerPort"), stub_type=lpf_file_reader__v1__pb2_grpc.LpfFileReader_MonoStub
8177
)
82-
assert len(raypaths[9].interaction_statuses) == expectedNbOfImpactOnFaces9
83-
assert raypaths[9].interaction_statuses[0] == lpf_file_reader__v1__pb2.RayPath.PhotonStatus.StatusJustEmitted
84-
assert raypaths[9].interaction_statuses[4] == lpf_file_reader__v1__pb2.RayPath.PhotonStatus.StatusSpecularReflected
85-
assert (
86-
raypaths[9].interaction_statuses[5] == lpf_file_reader__v1__pb2.RayPath.PhotonStatus.StatusSpecularTransmitted
78+
79+
# Init with file path
80+
path = os.path.join(test_path, "basic_InverseSimu.lpf")
81+
stub.InitLpfFileName(lpf_file_reader__v1__pb2.InitLpfFileNameRequest_Mono(lpf_file_path=path))
82+
83+
# GetInformation
84+
res_information = stub.GetInformation(lpf_file_reader__v1__pb2.GetInformationRequest_Mono())
85+
nb_of_traces = res_information.nb_of_traces
86+
assert nb_of_traces == 21044
87+
assert res_information.nb_of_xmps == 1
88+
assert res_information.has_sensor_contributions == True # contributions stored in Inverse simu
89+
assert len(res_information.sensor_names) == 1
90+
assert res_information.sensor_names[0] == "Camera_Perfect_Lens_System_V2:3"
91+
92+
# Read
93+
raypaths = []
94+
for rp in stub.Read(lpf_file_reader__v1__pb2.ReadRequest_Mono()):
95+
raypaths.append(rp)
96+
assert len(raypaths) == nb_of_traces
97+
98+
# Check sensor_contributions in first raypath
99+
assert len(raypaths[0].sensor_contributions) == 1
100+
assert raypaths[0].sensor_contributions[0].sensor_id == 0
101+
assert raypaths[0].sensor_contributions[0].coordinates == lpf_file_reader__v1__pb2.DoubletDouble(
102+
x=-0.20848463202592682, y=0.1897648665199252
87103
)
88104

89105
# Close
@@ -100,50 +116,35 @@ def test_lpf_file_reader_multi_v1():
100116
guid = stub.Create(Empty())
101117

102118
# Init with file path
103-
path = os.path.join(test_path, "basic_1.lpf")
119+
path = os.path.join(test_path, "basic_DirectSimu.lpf")
104120
stub.InitLpfFileName(lpf_file_reader__v1__pb2.InitLpfFileNameRequest_Multi(id=guid, lpf_file_path=path))
105121

106-
# Check Nb Traces
107-
nb_of_traces = stub.GetNbOfTraces(guid).nb_of_traces
108-
assert nb_of_traces == 10
122+
# GetInformation
123+
res_information = stub.GetInformation(lpf_file_reader__v1__pb2.GetInformationRequest_Multi(id=guid))
124+
nb_of_traces = res_information.nb_of_traces
125+
assert nb_of_traces == 24817
126+
assert res_information.nb_of_xmps == 3
109127

110128
# Create a second reader
111129
guid2 = stub.Create(Empty())
112-
113-
# Get Nb XMPs for first reader
114-
assert stub.GetNbOfXMPs(guid).nb_of_xmps == 3
115-
116130
# Init second reader
117-
path2 = os.path.join(test_path, "basic_2.lpf")
131+
path2 = os.path.join(test_path, "basic_InverseSimu.lpf")
118132
stub.InitLpfFileName(lpf_file_reader__v1__pb2.InitLpfFileNameRequest_Multi(id=guid2, lpf_file_path=path2))
119133

120-
# Check Nb Traces and read second
121-
nb_of_traces2 = stub.GetNbOfTraces(guid2).nb_of_traces
122-
assert nb_of_traces2 == 5
134+
# GetInformation and read second
135+
res_information = stub.GetInformation(lpf_file_reader__v1__pb2.GetInformationRequest_Multi(id=guid2))
136+
nb_of_traces2 = res_information.nb_of_traces
137+
assert nb_of_traces2 == 21044
123138
raypaths2 = []
124139
for rp in stub.Read(lpf_file_reader__v1__pb2.ReadRequest_Multi(id=guid2)):
125140
raypaths2.append(rp)
126141
assert len(raypaths2) == nb_of_traces2
127142

128-
# Check result (fourth entry)
129-
expectedNbOfImpactOnFaces3 = 5
130-
assert len(raypaths2[3].impacts) == expectedNbOfImpactOnFaces3
131-
assert raypaths2[3].impacts[1] == lpf_file_reader__v1__pb2.TripletFloat(
132-
x=5.026374340057373, y=15.000000953674316, z=0.7341787815093994
133-
)
134-
assert len(raypaths2[3].wavelengths) == expectedNbOfImpactOnFaces3
135-
assert raypaths2[3].wavelengths[1] == 652.2732543945312
136-
assert len(raypaths2[3].body_context_ids) == expectedNbOfImpactOnFaces3
137-
assert raypaths2[3].body_context_ids[1] == 2001802324
138-
assert len(raypaths2[3].unique_face_ids) == expectedNbOfImpactOnFaces3
139-
assert raypaths2[3].unique_face_ids[1] == 1815582994
140-
assert raypaths2[3].lastDirection == lpf_file_reader__v1__pb2.TripletFloat(
141-
x=0.09542781859636307, y=0.9953387975692749, z=0.013935667462646961
142-
)
143-
assert len(raypaths2[3].interaction_statuses) == expectedNbOfImpactOnFaces3
144-
assert raypaths2[3].interaction_statuses[0] == lpf_file_reader__v1__pb2.RayPath.PhotonStatus.StatusJustEmitted
145-
assert (
146-
raypaths2[3].interaction_statuses[1] == lpf_file_reader__v1__pb2.RayPath.PhotonStatus.StatusSpecularTransmitted
143+
# Check sensor_contributions in first raypath
144+
assert len(raypaths2[0].sensor_contributions) == 1
145+
assert raypaths2[0].sensor_contributions[0].sensor_id == 0
146+
assert raypaths2[0].sensor_contributions[0].coordinates == lpf_file_reader__v1__pb2.DoubletDouble(
147+
x=-0.20848463202592682, y=0.1897648665199252
147148
)
148149

149150
# Delete the second reader
@@ -155,30 +156,15 @@ def test_lpf_file_reader_multi_v1():
155156
raypaths.append(rp)
156157
assert len(raypaths) == nb_of_traces
157158

158-
# Check result (first entry)
159-
expectedNbOfImpactOnFaces0 = 4
160-
assert len(raypaths[0].impacts) == expectedNbOfImpactOnFaces0
161-
assert raypaths[0].impacts[1] == lpf_file_reader__v1__pb2.TripletFloat(
162-
x=4.4084320068359375, y=14.999999046325684, z=2.4493408203125
163-
)
164-
assert len(raypaths[0].wavelengths) == expectedNbOfImpactOnFaces0
165-
assert raypaths[0].wavelengths[1] == 678.1803588867188
166-
assert len(raypaths[0].body_context_ids) == expectedNbOfImpactOnFaces0
167-
assert raypaths[0].body_context_ids[1] == 2001802324
168-
assert len(raypaths[0].unique_face_ids) == expectedNbOfImpactOnFaces0
169-
assert raypaths[0].unique_face_ids[1] == 1815582994
170-
assert raypaths[0].lastDirection == lpf_file_reader__v1__pb2.TripletFloat(
171-
x=0.2041478008031845, y=-0.9723469614982605, z=0.11342425644397736
172-
)
173-
assert len(raypaths[0].interaction_statuses) == expectedNbOfImpactOnFaces0
174-
assert raypaths[0].interaction_statuses[0] == lpf_file_reader__v1__pb2.RayPath.PhotonStatus.StatusJustEmitted
159+
# Check some result (first entry)
160+
expected_nb_of_impact = 5
161+
assert len(raypaths[0].impacts) == expected_nb_of_impact
162+
assert raypaths[0].impacts[1] == lpf_file_reader__v1__pb2.TripletFloat(x=3.19368935, y=14.999999, z=-3.94779062)
163+
assert len(raypaths[0].interaction_statuses) == expected_nb_of_impact
175164
assert (
176165
raypaths[0].interaction_statuses[1] == lpf_file_reader__v1__pb2.RayPath.PhotonStatus.StatusSpecularTransmitted
177166
)
178-
assert (
179-
raypaths[0].interaction_statuses[2] == lpf_file_reader__v1__pb2.RayPath.PhotonStatus.StatusSpecularTransmitted
180-
)
181-
assert raypaths[0].interaction_statuses[3] == lpf_file_reader__v1__pb2.RayPath.PhotonStatus.StatusSpecularReflected
167+
assert len(raypaths[0].sensor_contributions) == 0
182168

183169
# Close and Delete the first
184170
stub.CloseLpfFileName(guid)

0 commit comments

Comments
 (0)