Skip to content

Update lpf file reader test - Adapt to SpeosRPC_Server breaking changes #27

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

Merged
merged 2 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ classifiers=[
"Operating System :: OS Independent",
]
dependencies=[
"ansys-optics-speos-grpcapi==2",
"ansys-optics-speos-grpcapi==4",
"grpcio-tools",
]

Expand Down
Binary file removed tests/assets/basic_1.lpf
Binary file not shown.
Binary file removed tests/assets/basic_2.lpf
Binary file not shown.
Binary file added tests/assets/basic_DirectSimu.lpf
Binary file not shown.
Binary file added tests/assets/basic_InverseSimu.lpf
Binary file not shown.
168 changes: 77 additions & 91 deletions tests/test_lpf_file_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,70 +20,86 @@
from conftest import config, test_path


def test_lpf_file_reader_mono_v1():
def test_lpf_file_reader_mono_v1_DirectSimu():
# Lpf file reader creation
stub = speos.get_stub_insecure_channel(
port=config.get("SpeosServerPort"), stub_type=lpf_file_reader__v1__pb2_grpc.LpfFileReader_MonoStub
)

# Init with file path
path = os.path.join(test_path, "basic_1.lpf")
path = os.path.join(test_path, "basic_DirectSimu.lpf")
stub.InitLpfFileName(lpf_file_reader__v1__pb2.InitLpfFileNameRequest_Mono(lpf_file_path=path))

# Check Nb XMPs
assert stub.GetNbOfXMPs(Empty()).nb_of_xmps == 3

# Check Nb Traces
nb_of_traces = stub.GetNbOfTraces(Empty()).nb_of_traces
assert nb_of_traces == 10
# GetInformation
res_information = stub.GetInformation(lpf_file_reader__v1__pb2.GetInformationRequest_Mono())
nb_of_traces = res_information.nb_of_traces
assert nb_of_traces == 24817
assert res_information.nb_of_xmps == 3
assert res_information.has_sensor_contributions == False # No contributions stored in Direct simu
assert len(res_information.sensor_names) == 3
assert res_information.sensor_names[0] == "Irradiance Sensor (0)"
assert res_information.sensor_names[2] == "Irradiance Sensor (2)"

# Read
raypaths = []
for rp in stub.Read(lpf_file_reader__v1__pb2.ReadRequest_Mono()):
raypaths.append(rp)
assert len(raypaths) == nb_of_traces

# Check result (first and last entry)
expectedNbOfImpactOnFaces0 = 4
assert len(raypaths[0].impacts) == expectedNbOfImpactOnFaces0
assert raypaths[0].impacts[1] == lpf_file_reader__v1__pb2.TripletFloat(
x=4.4084320068359375, y=14.999999046325684, z=2.4493408203125
)
assert len(raypaths[0].wavelengths) == expectedNbOfImpactOnFaces0
assert raypaths[0].wavelengths[1] == 678.1803588867188
assert len(raypaths[0].body_context_ids) == expectedNbOfImpactOnFaces0
# Check result (first entry)
expected_nb_of_impact = 5
assert len(raypaths[0].impacts) == expected_nb_of_impact
assert raypaths[0].impacts[1] == lpf_file_reader__v1__pb2.TripletFloat(x=3.19368935, y=14.999999, z=-3.94779062)
assert len(raypaths[0].wavelengths) == expected_nb_of_impact
assert raypaths[0].wavelengths[1] == 691.44708251953125
assert len(raypaths[0].body_context_ids) == expected_nb_of_impact
assert raypaths[0].body_context_ids[1] == 2001802324
assert len(raypaths[0].unique_face_ids) == expectedNbOfImpactOnFaces0
assert len(raypaths[0].unique_face_ids) == expected_nb_of_impact
assert raypaths[0].unique_face_ids[1] == 1815582994
assert raypaths[0].lastDirection == lpf_file_reader__v1__pb2.TripletFloat(
x=0.2041478008031845, y=-0.9723469614982605, z=0.11342425644397736
x=0.0606396869, y=0.995341122, z=-0.0749590397
)
assert len(raypaths[0].interaction_statuses) == expectedNbOfImpactOnFaces0
assert len(raypaths[0].interaction_statuses) == expected_nb_of_impact
assert raypaths[0].interaction_statuses[0] == lpf_file_reader__v1__pb2.RayPath.PhotonStatus.StatusJustEmitted
assert (
raypaths[0].interaction_statuses[1] == lpf_file_reader__v1__pb2.RayPath.PhotonStatus.StatusSpecularTransmitted
)
assert raypaths[0].interaction_statuses[3] == lpf_file_reader__v1__pb2.RayPath.PhotonStatus.StatusSpecularReflected
assert len(raypaths[0].sensor_contributions) == 0

expectedNbOfImpactOnFaces9 = 6
assert len(raypaths[9].impacts) == expectedNbOfImpactOnFaces9
assert raypaths[9].impacts[1] == lpf_file_reader__v1__pb2.TripletFloat(
x=-1.8186546564102173, y=15.0, z=-6.767658233642578
)
assert len(raypaths[9].wavelengths) == expectedNbOfImpactOnFaces9
assert raypaths[9].wavelengths[1] == 743.3338623046875
assert len(raypaths[9].body_context_ids) == expectedNbOfImpactOnFaces9
assert raypaths[9].body_context_ids[1] == 2001802324
assert len(raypaths[9].unique_face_ids) == expectedNbOfImpactOnFaces9
assert raypaths[9].unique_face_ids[1] == 1815582994
assert raypaths[9].lastDirection == lpf_file_reader__v1__pb2.TripletFloat(
x=0.14110437035560608, y=0.8392737507820129, z=0.5250800848007202
# Close
stub.CloseLpfFileName(Empty())


def test_lpf_file_reader_mono_v1_InverseSimu():
# Lpf file reader creation
stub = speos.get_stub_insecure_channel(
port=config.get("SpeosServerPort"), stub_type=lpf_file_reader__v1__pb2_grpc.LpfFileReader_MonoStub
)
assert len(raypaths[9].interaction_statuses) == expectedNbOfImpactOnFaces9
assert raypaths[9].interaction_statuses[0] == lpf_file_reader__v1__pb2.RayPath.PhotonStatus.StatusJustEmitted
assert raypaths[9].interaction_statuses[4] == lpf_file_reader__v1__pb2.RayPath.PhotonStatus.StatusSpecularReflected
assert (
raypaths[9].interaction_statuses[5] == lpf_file_reader__v1__pb2.RayPath.PhotonStatus.StatusSpecularTransmitted

# Init with file path
path = os.path.join(test_path, "basic_InverseSimu.lpf")
stub.InitLpfFileName(lpf_file_reader__v1__pb2.InitLpfFileNameRequest_Mono(lpf_file_path=path))

# GetInformation
res_information = stub.GetInformation(lpf_file_reader__v1__pb2.GetInformationRequest_Mono())
nb_of_traces = res_information.nb_of_traces
assert nb_of_traces == 21044
assert res_information.nb_of_xmps == 1
assert res_information.has_sensor_contributions == True # contributions stored in Inverse simu
assert len(res_information.sensor_names) == 1
assert res_information.sensor_names[0] == "Camera_Perfect_Lens_System_V2:3"

# Read
raypaths = []
for rp in stub.Read(lpf_file_reader__v1__pb2.ReadRequest_Mono()):
raypaths.append(rp)
assert len(raypaths) == nb_of_traces

# Check sensor_contributions in first raypath
assert len(raypaths[0].sensor_contributions) == 1
assert raypaths[0].sensor_contributions[0].sensor_id == 0
assert raypaths[0].sensor_contributions[0].coordinates == lpf_file_reader__v1__pb2.DoubletDouble(
x=-0.20848463202592682, y=0.1897648665199252
)

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

# Init with file path
path = os.path.join(test_path, "basic_1.lpf")
path = os.path.join(test_path, "basic_DirectSimu.lpf")
stub.InitLpfFileName(lpf_file_reader__v1__pb2.InitLpfFileNameRequest_Multi(id=guid, lpf_file_path=path))

# Check Nb Traces
nb_of_traces = stub.GetNbOfTraces(guid).nb_of_traces
assert nb_of_traces == 10
# GetInformation
res_information = stub.GetInformation(lpf_file_reader__v1__pb2.GetInformationRequest_Multi(id=guid))
nb_of_traces = res_information.nb_of_traces
assert nb_of_traces == 24817
assert res_information.nb_of_xmps == 3

# Create a second reader
guid2 = stub.Create(Empty())

# Get Nb XMPs for first reader
assert stub.GetNbOfXMPs(guid).nb_of_xmps == 3

# Init second reader
path2 = os.path.join(test_path, "basic_2.lpf")
path2 = os.path.join(test_path, "basic_InverseSimu.lpf")
stub.InitLpfFileName(lpf_file_reader__v1__pb2.InitLpfFileNameRequest_Multi(id=guid2, lpf_file_path=path2))

# Check Nb Traces and read second
nb_of_traces2 = stub.GetNbOfTraces(guid2).nb_of_traces
assert nb_of_traces2 == 5
# GetInformation and read second
res_information = stub.GetInformation(lpf_file_reader__v1__pb2.GetInformationRequest_Multi(id=guid2))
nb_of_traces2 = res_information.nb_of_traces
assert nb_of_traces2 == 21044
raypaths2 = []
for rp in stub.Read(lpf_file_reader__v1__pb2.ReadRequest_Multi(id=guid2)):
raypaths2.append(rp)
assert len(raypaths2) == nb_of_traces2

# Check result (fourth entry)
expectedNbOfImpactOnFaces3 = 5
assert len(raypaths2[3].impacts) == expectedNbOfImpactOnFaces3
assert raypaths2[3].impacts[1] == lpf_file_reader__v1__pb2.TripletFloat(
x=5.026374340057373, y=15.000000953674316, z=0.7341787815093994
)
assert len(raypaths2[3].wavelengths) == expectedNbOfImpactOnFaces3
assert raypaths2[3].wavelengths[1] == 652.2732543945312
assert len(raypaths2[3].body_context_ids) == expectedNbOfImpactOnFaces3
assert raypaths2[3].body_context_ids[1] == 2001802324
assert len(raypaths2[3].unique_face_ids) == expectedNbOfImpactOnFaces3
assert raypaths2[3].unique_face_ids[1] == 1815582994
assert raypaths2[3].lastDirection == lpf_file_reader__v1__pb2.TripletFloat(
x=0.09542781859636307, y=0.9953387975692749, z=0.013935667462646961
)
assert len(raypaths2[3].interaction_statuses) == expectedNbOfImpactOnFaces3
assert raypaths2[3].interaction_statuses[0] == lpf_file_reader__v1__pb2.RayPath.PhotonStatus.StatusJustEmitted
assert (
raypaths2[3].interaction_statuses[1] == lpf_file_reader__v1__pb2.RayPath.PhotonStatus.StatusSpecularTransmitted
# Check sensor_contributions in first raypath
assert len(raypaths2[0].sensor_contributions) == 1
assert raypaths2[0].sensor_contributions[0].sensor_id == 0
assert raypaths2[0].sensor_contributions[0].coordinates == lpf_file_reader__v1__pb2.DoubletDouble(
x=-0.20848463202592682, y=0.1897648665199252
)

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

# Check result (first entry)
expectedNbOfImpactOnFaces0 = 4
assert len(raypaths[0].impacts) == expectedNbOfImpactOnFaces0
assert raypaths[0].impacts[1] == lpf_file_reader__v1__pb2.TripletFloat(
x=4.4084320068359375, y=14.999999046325684, z=2.4493408203125
)
assert len(raypaths[0].wavelengths) == expectedNbOfImpactOnFaces0
assert raypaths[0].wavelengths[1] == 678.1803588867188
assert len(raypaths[0].body_context_ids) == expectedNbOfImpactOnFaces0
assert raypaths[0].body_context_ids[1] == 2001802324
assert len(raypaths[0].unique_face_ids) == expectedNbOfImpactOnFaces0
assert raypaths[0].unique_face_ids[1] == 1815582994
assert raypaths[0].lastDirection == lpf_file_reader__v1__pb2.TripletFloat(
x=0.2041478008031845, y=-0.9723469614982605, z=0.11342425644397736
)
assert len(raypaths[0].interaction_statuses) == expectedNbOfImpactOnFaces0
assert raypaths[0].interaction_statuses[0] == lpf_file_reader__v1__pb2.RayPath.PhotonStatus.StatusJustEmitted
# Check some result (first entry)
expected_nb_of_impact = 5
assert len(raypaths[0].impacts) == expected_nb_of_impact
assert raypaths[0].impacts[1] == lpf_file_reader__v1__pb2.TripletFloat(x=3.19368935, y=14.999999, z=-3.94779062)
assert len(raypaths[0].interaction_statuses) == expected_nb_of_impact
assert (
raypaths[0].interaction_statuses[1] == lpf_file_reader__v1__pb2.RayPath.PhotonStatus.StatusSpecularTransmitted
)
assert (
raypaths[0].interaction_statuses[2] == lpf_file_reader__v1__pb2.RayPath.PhotonStatus.StatusSpecularTransmitted
)
assert raypaths[0].interaction_statuses[3] == lpf_file_reader__v1__pb2.RayPath.PhotonStatus.StatusSpecularReflected
assert len(raypaths[0].sensor_contributions) == 0

# Close and Delete the first
stub.CloseLpfFileName(guid)
Expand Down