Download this example
Download this example as a Jupyter Notebook or as a Python script. All assets used in the examples can be downloaded as a ZIP archive.
How to create a sensor#
This tutorial demonstrates how to create a sensor.
There are different type of sensors available: irradiance sensor, radiance sensor, camera sensor.
Prerequisites#
Perform imports#
[1]:
from pathlib import Path
[2]:
from ansys.speos.core import Face, Project, Speos, launcher
from ansys.speos.core.generic.parameters import (
CameraSensorParameters,
ColorParameters,
PhotometricCameraParameters,
)
from ansys.speos.core.kernel.client import (
default_docker_channel,
)
from ansys.speos.core.sensor import (
Sensor3DIrradiance,
SensorCamera,
SensorImmersive,
SensorIrradiance,
SensorRadiance,
)
Define constants#
The constants help ensure consistency and avoid repetition throughout the example.
[3]:
HOSTNAME = "localhost"
GRPC_PORT = 50098 # Be sure the Speos GRPC Server has been started on this port.
USE_DOCKER = True # Set to False if you're running this example locally as a Notebook.
FILES = "CameraInputFiles"
Define helper functions#
[4]:
def create_helper_geometries(project: Project):
"""Create bodies and faces."""
def create_face(body):
f = body.create_face(name="TheFaceF")
f.vertices = [0, 0, 0, 1, 0, 0, 0, 1, 0]
f.facets = [0, 1, 2]
f.normals = [0, 0, 1, 0, 0, 1, 0, 0, 1]
f.commit()
root_part = project.create_root_part().commit()
body_b1 = root_part.create_body(name="TheBodyB").commit()
body_b2 = root_part.create_body(name="TheBodyC").commit()
body_b3 = root_part.create_body(name="TheBodyD").commit()
body_b4 = root_part.create_body(name="TheBodyE").commit()
for b in [body_b1, body_b2, body_b3, body_b4]:
create_face(b)
Model Setup#
Load assets#
The assets used to run this example are available in the PySpeos repository on GitHub.
Note: Make sure you have downloaded simulation assets and set
assets_data_pathto point to the assets folder.
[5]:
if USE_DOCKER: # Running on the remote server.
assets_data_path = Path("/app") / "assets"
else:
assets_data_path = Path("/path/to/your/download/assets/directory")
Connect to the RPC Server#
This Python client connects to a server where the Speos engine is running as a service. In this example, the server and client are the same machine. The launch_local_speos_rpc_method can be used to start a local instance of the service.
[6]:
if USE_DOCKER:
speos = Speos(channel=default_docker_channel())
else:
speos = launcher.launch_local_speos_rpc_server(port=GRPC_PORT)
/home/runner/work/pyspeos/pyspeos/.venv/lib/python3.14/site-packages/ansys/tools/common/cyberchannel.py:188: UserWarning: Starting gRPC client without TLS on localhost:50098. This is INSECURE. Consider using a secure connection.
warn(f"Starting gRPC client without TLS on {target}. This is INSECURE. Consider using a secure connection.")
Create a new project#
The only way to create a sensor, is to create it from a project.
[7]:
p = Project(speos=speos)
print(p)
{
"name": "",
"description": "",
"metadata": {},
"part_guid": "",
"sub_scene_anchor_axis_system": [],
"sources": [],
"sensors": [],
"simulations": [],
"materials": [],
"scenes": []
}
Create#
Create locally.
The mention “local: “ is added when printing the sensor
[8]:
distortion_file_path = str(assets_data_path / FILES / "CameraDistortion_130deg.OPTDistortion")
transmittance_file_path = str(assets_data_path / FILES / "CameraTransmittance.spectrum")
blue_spectrum_path = str(assets_data_path / FILES / "CameraSensitivityBlue.spectrum")
green_spectrum_path = str(assets_data_path / FILES / "CameraSensitivityGreen.spectrum")
red_spectrum_path = str(assets_data_path / FILES / "CameraSensitivityRed.spectrum")
sensor1 = p.create_sensor(name="Camera.1", feature_type=SensorCamera)
sensor1.distortion_file_uri = distortion_file_path
# Choose photometric mode
sensor1.set_mode_photometric().transmittance_file_uri = transmittance_file_path
# Choose color mode (will imply to give spectrum file for blue, green and red)
mode_color = sensor1.photometric.set_mode_color()
mode_color.blue_spectrum_file_uri = blue_spectrum_path
mode_color.green_spectrum_file_uri = green_spectrum_path
mode_color.red_spectrum_file_uri = red_spectrum_path
print(sensor1)
local: {
"name": "Camera.1",
"display_name": "",
"description": "",
"metadata": {},
"sensor_guid": "",
"result_file_name": "",
"sensor": {
"camera_sensor_template": {
"sensor_mode_photometric": {
"acquisition_integration": 0.01,
"transmittance_file_uri": "/app/assets/CameraInputFiles/CameraTransmittance.spectrum",
"gamma_correction": 2.2,
"png_bits": "PNG_16",
"color_mode_color": {
"red_spectrum_file_uri": "/app/assets/CameraInputFiles/CameraSensitivityRed.spectrum",
"green_spectrum_file_uri": "/app/assets/CameraInputFiles/CameraSensitivityGreen.spectrum",
"blue_spectrum_file_uri": "/app/assets/CameraInputFiles/CameraSensitivityBlue.spectrum",
"balance_mode_none": {}
},
"wavelengths_range": {
"w_start": 400.0,
"w_end": 700.0,
"w_sampling": 13
},
"acquisition_lag_time": 0.0
},
"focal_length": 5.0,
"imager_distance": 10.0,
"f_number": 20.0,
"horz_pixel": 640,
"vert_pixel": 480,
"width": 5.0,
"height": 5.0,
"distortion_file_uri": "/app/assets/CameraInputFiles/CameraDistortion_130deg.OPTDistortion",
"distorsion_file_uri": "",
"axis_system": [
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0
],
"layer_type_none": {},
"trajectory_file_uri": ""
},
"name": "Camera.1",
"description": "",
"metadata": {}
}
}
Push it to the server.#
Now that it is committed to the server, the mention “local: “ is no more present when printing the sensor.
[9]:
sensor1.commit()
print(sensor1)
{
"name": "Camera.1",
"metadata": {
"UniqueId": "9f068e52-71b2-4035-be9b-102267b8364d"
},
"sensor_guid": "877b14a8-459b-4564-adcc-d8bf5b1d0cb6",
"display_name": "",
"description": "",
"result_file_name": "",
"sensor": {
"camera_sensor_template": {
"sensor_mode_photometric": {
"acquisition_integration": 0.01,
"transmittance_file_uri": "/app/assets/CameraInputFiles/CameraTransmittance.spectrum",
"gamma_correction": 2.2,
"png_bits": "PNG_16",
"color_mode_color": {
"red_spectrum_file_uri": "/app/assets/CameraInputFiles/CameraSensitivityRed.spectrum",
"green_spectrum_file_uri": "/app/assets/CameraInputFiles/CameraSensitivityGreen.spectrum",
"blue_spectrum_file_uri": "/app/assets/CameraInputFiles/CameraSensitivityBlue.spectrum",
"balance_mode_none": {}
},
"wavelengths_range": {
"w_start": 400.0,
"w_end": 700.0,
"w_sampling": 13
},
"acquisition_lag_time": 0.0
},
"focal_length": 5.0,
"imager_distance": 10.0,
"f_number": 20.0,
"horz_pixel": 640,
"vert_pixel": 480,
"width": 5.0,
"height": 5.0,
"distortion_file_uri": "/app/assets/CameraInputFiles/CameraDistortion_130deg.OPTDistortion",
"distorsion_file_uri": "",
"axis_system": [
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0
],
"layer_type_none": {},
"trajectory_file_uri": ""
},
"name": "Camera.1",
"description": "",
"metadata": {}
}
}
Another example#
Set more characteristics, and use parameters classes.
Camera feature is created with the same default values as the GUI speos.
If the user would like to modify the camera characteristics, it is possible to do so as below.
[10]:
distortion_file_path = str(assets_data_path / FILES / "CameraDistortion_130deg.OPTDistortion")
transmittance_file_path = str(assets_data_path / FILES / "CameraTransmittance.spectrum")
blue_spectrum_path = str(assets_data_path / FILES / "CameraSensitivityBlue.spectrum")
green_spectrum_path = str(assets_data_path / FILES / "CameraSensitivityGreen.spectrum")
red_spectrum_path = str(assets_data_path / FILES / "CameraSensitivityRed.spectrum")
color_params = ColorParameters(
blue_spectrum_file_uri=blue_spectrum_path,
green_spectrum_file_uri=green_spectrum_path,
red_spectrum_file_uri=red_spectrum_path,
)
photo_params = PhotometricCameraParameters(
color_mode=color_params, layer_type="by_source", transmittance_file_uri=transmittance_file_path
)
param = CameraSensorParameters(
sensor_type_parameters=photo_params,
distortion_file_uri=distortion_file_path,
axis_system=[20, 10, 40, 1, 0, 0, 0, 1, 0, 0, 0, 1],
# camera location [Origin, Xvector, Yvector, Zvector]
focal_length=5.5,
height=6, # dimensions
width=6,
)
sensor2 = p.create_sensor("Camera_Parameter", feature_type=SensorCamera, parameters=param)
sensor2.commit()
print(sensor2)
{
"name": "Camera_Parameter",
"metadata": {
"UniqueId": "48fed48a-c8ad-4fa4-a88f-284f39c1fa73"
},
"sensor_guid": "bb6ea314-ca30-47aa-a9f2-5405017255f1",
"display_name": "",
"description": "",
"result_file_name": "",
"sensor": {
"camera_sensor_template": {
"sensor_mode_photometric": {
"acquisition_integration": 0.01,
"transmittance_file_uri": "/app/assets/CameraInputFiles/CameraTransmittance.spectrum",
"gamma_correction": 2.2,
"png_bits": "PNG_16",
"color_mode_color": {
"red_spectrum_file_uri": "/app/assets/CameraInputFiles/CameraSensitivityRed.spectrum",
"green_spectrum_file_uri": "/app/assets/CameraInputFiles/CameraSensitivityGreen.spectrum",
"blue_spectrum_file_uri": "/app/assets/CameraInputFiles/CameraSensitivityBlue.spectrum",
"balance_mode_none": {}
},
"wavelengths_range": {
"w_start": 400.0,
"w_end": 700.0,
"w_sampling": 13
},
"acquisition_lag_time": 0.0
},
"focal_length": 5.5,
"imager_distance": 10.0,
"f_number": 20.0,
"horz_pixel": 640,
"vert_pixel": 480,
"width": 6.0,
"height": 6.0,
"distortion_file_uri": "/app/assets/CameraInputFiles/CameraDistortion_130deg.OPTDistortion",
"distorsion_file_uri": "",
"axis_system": [
20.0,
10.0,
40.0,
1.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0
],
"layer_type_source": {},
"trajectory_file_uri": ""
},
"name": "Camera_Parameter",
"description": "",
"metadata": {}
}
}
Read#
Sensor Instance#
A mention “local: “ is added if it is not yet committed to the server
[11]:
print(sensor1)
{
"name": "Camera.1",
"metadata": {
"UniqueId": "9f068e52-71b2-4035-be9b-102267b8364d"
},
"sensor_guid": "877b14a8-459b-4564-adcc-d8bf5b1d0cb6",
"display_name": "",
"description": "",
"result_file_name": "",
"sensor": {
"camera_sensor_template": {
"sensor_mode_photometric": {
"acquisition_integration": 0.01,
"transmittance_file_uri": "/app/assets/CameraInputFiles/CameraTransmittance.spectrum",
"gamma_correction": 2.2,
"png_bits": "PNG_16",
"color_mode_color": {
"red_spectrum_file_uri": "/app/assets/CameraInputFiles/CameraSensitivityRed.spectrum",
"green_spectrum_file_uri": "/app/assets/CameraInputFiles/CameraSensitivityGreen.spectrum",
"blue_spectrum_file_uri": "/app/assets/CameraInputFiles/CameraSensitivityBlue.spectrum",
"balance_mode_none": {}
},
"wavelengths_range": {
"w_start": 400.0,
"w_end": 700.0,
"w_sampling": 13
},
"acquisition_lag_time": 0.0
},
"focal_length": 5.0,
"imager_distance": 10.0,
"f_number": 20.0,
"horz_pixel": 640,
"vert_pixel": 480,
"width": 5.0,
"height": 5.0,
"distortion_file_uri": "/app/assets/CameraInputFiles/CameraDistortion_130deg.OPTDistortion",
"distorsion_file_uri": "",
"axis_system": [
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0
],
"layer_type_none": {},
"trajectory_file_uri": ""
},
"name": "Camera.1",
"description": "",
"metadata": {}
}
}
Project#
Committed feature will appear in the project.
[12]:
print(p)
{
"sensors": [
{
"name": "Camera.1",
"metadata": {
"UniqueId": "9f068e52-71b2-4035-be9b-102267b8364d"
},
"sensor_guid": "877b14a8-459b-4564-adcc-d8bf5b1d0cb6",
"display_name": "",
"description": "",
"result_file_name": "",
"sensor": {
"camera_sensor_template": {
"sensor_mode_photometric": {
"acquisition_integration": 0.01,
"transmittance_file_uri": "/app/assets/CameraInputFiles/CameraTransmittance.spectrum",
"gamma_correction": 2.2,
"png_bits": "PNG_16",
"color_mode_color": {
"red_spectrum_file_uri": "/app/assets/CameraInputFiles/CameraSensitivityRed.spectrum",
"green_spectrum_file_uri": "/app/assets/CameraInputFiles/CameraSensitivityGreen.spectrum",
"blue_spectrum_file_uri": "/app/assets/CameraInputFiles/CameraSensitivityBlue.spectrum",
"balance_mode_none": {}
},
"wavelengths_range": {
"w_start": 400.0,
"w_end": 700.0,
"w_sampling": 13
},
"acquisition_lag_time": 0.0
},
"focal_length": 5.0,
"imager_distance": 10.0,
"f_number": 20.0,
"horz_pixel": 640,
"vert_pixel": 480,
"width": 5.0,
"height": 5.0,
"distortion_file_uri": "/app/assets/CameraInputFiles/CameraDistortion_130deg.OPTDistortion",
"distorsion_file_uri": "",
"axis_system": [
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0
],
"layer_type_none": {},
"trajectory_file_uri": ""
},
"name": "Camera.1",
"description": "",
"metadata": {}
}
},
{
"name": "Camera_Parameter",
"metadata": {
"UniqueId": "48fed48a-c8ad-4fa4-a88f-284f39c1fa73"
},
"sensor_guid": "bb6ea314-ca30-47aa-a9f2-5405017255f1",
"display_name": "",
"description": "",
"result_file_name": "",
"sensor": {
"camera_sensor_template": {
"sensor_mode_photometric": {
"acquisition_integration": 0.01,
"transmittance_file_uri": "/app/assets/CameraInputFiles/CameraTransmittance.spectrum",
"gamma_correction": 2.2,
"png_bits": "PNG_16",
"color_mode_color": {
"red_spectrum_file_uri": "/app/assets/CameraInputFiles/CameraSensitivityRed.spectrum",
"green_spectrum_file_uri": "/app/assets/CameraInputFiles/CameraSensitivityGreen.spectrum",
"blue_spectrum_file_uri": "/app/assets/CameraInputFiles/CameraSensitivityBlue.spectrum",
"balance_mode_none": {}
},
"wavelengths_range": {
"w_start": 400.0,
"w_end": 700.0,
"w_sampling": 13
},
"acquisition_lag_time": 0.0
},
"focal_length": 5.5,
"imager_distance": 10.0,
"f_number": 20.0,
"horz_pixel": 640,
"vert_pixel": 480,
"width": 6.0,
"height": 6.0,
"distortion_file_uri": "/app/assets/CameraInputFiles/CameraDistortion_130deg.OPTDistortion",
"distorsion_file_uri": "",
"axis_system": [
20.0,
10.0,
40.0,
1.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0
],
"layer_type_source": {},
"trajectory_file_uri": ""
},
"name": "Camera_Parameter",
"description": "",
"metadata": {}
}
}
],
"name": "",
"description": "",
"metadata": {},
"part_guid": "",
"sub_scene_anchor_axis_system": [],
"sources": [],
"simulations": [],
"materials": [],
"scenes": []
}
Update#
Tipp: if you are manipulating a sensor already committed, don’t forget to commit your changes.
If you don’t, you will still only watch what is committed on the server.
[13]:
# modify f number and axis system
sensor1.f_number = 11
sensor1.axis_system = [17, 10, 10, 1, 0, 0, 0, 1, 0, 0, 0, 1]
sensor1.commit()
print(sensor1)
{
"name": "Camera.1",
"metadata": {
"UniqueId": "9f068e52-71b2-4035-be9b-102267b8364d"
},
"sensor_guid": "877b14a8-459b-4564-adcc-d8bf5b1d0cb6",
"display_name": "",
"description": "",
"result_file_name": "",
"sensor": {
"camera_sensor_template": {
"sensor_mode_photometric": {
"acquisition_integration": 0.01,
"transmittance_file_uri": "/app/assets/CameraInputFiles/CameraTransmittance.spectrum",
"gamma_correction": 2.2,
"png_bits": "PNG_16",
"color_mode_color": {
"red_spectrum_file_uri": "/app/assets/CameraInputFiles/CameraSensitivityRed.spectrum",
"green_spectrum_file_uri": "/app/assets/CameraInputFiles/CameraSensitivityGreen.spectrum",
"blue_spectrum_file_uri": "/app/assets/CameraInputFiles/CameraSensitivityBlue.spectrum",
"balance_mode_none": {}
},
"wavelengths_range": {
"w_start": 400.0,
"w_end": 700.0,
"w_sampling": 13
},
"acquisition_lag_time": 0.0
},
"focal_length": 5.0,
"imager_distance": 10.0,
"f_number": 11.0,
"horz_pixel": 640,
"vert_pixel": 480,
"width": 5.0,
"height": 5.0,
"distortion_file_uri": "/app/assets/CameraInputFiles/CameraDistortion_130deg.OPTDistortion",
"distorsion_file_uri": "",
"axis_system": [
17.0,
10.0,
10.0,
1.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0
],
"layer_type_none": {},
"trajectory_file_uri": ""
},
"name": "Camera.1",
"description": "",
"metadata": {}
}
}
Reset#
Possibility to reset local values from the one available in the server.
[14]:
sensor1.set_mode_geometric() # set camera in geometric mode but no commit
sensor1.reset() # reset -> this will apply the server value (photometric mode) to the local value
sensor1.delete() # delete (to display the local value with the below print)
print(sensor1._sensor_template)
ansys.api.speos.sensor.v1.SensorTemplate
{
"camera_sensor_template": {
"sensor_mode_photometric": {
"acquisition_integration": 0.01,
"transmittance_file_uri": "/app/assets/CameraInputFiles/CameraTransmittance.spectrum",
"gamma_correction": 2.2,
"png_bits": "PNG_16",
"color_mode_color": {
"red_spectrum_file_uri": "/app/assets/CameraInputFiles/CameraSensitivityRed.spectrum",
"green_spectrum_file_uri": "/app/assets/CameraInputFiles/CameraSensitivityGreen.spectrum",
"blue_spectrum_file_uri": "/app/assets/CameraInputFiles/CameraSensitivityBlue.spectrum",
"balance_mode_none": {}
},
"wavelengths_range": {
"w_start": 400.0,
"w_end": 700.0,
"w_sampling": 13
},
"acquisition_lag_time": 0.0
},
"focal_length": 5.0,
"imager_distance": 10.0,
"f_number": 11.0,
"horz_pixel": 640,
"vert_pixel": 480,
"width": 5.0,
"height": 5.0,
"distortion_file_uri": "/app/assets/CameraInputFiles/CameraDistortion_130deg.OPTDistortion",
"distorsion_file_uri": ""
},
"name": "Camera.1",
"description": "",
"metadata": {}
}
Delete#
Once the data is deleted from the server, you can still work with local data and maybe commit later.
[15]:
sensor2.delete()
print(sensor2)
local: {
"name": "Camera_Parameter",
"display_name": "",
"description": "",
"metadata": {},
"sensor_guid": "",
"result_file_name": "",
"sensor": {
"camera_sensor_template": {
"sensor_mode_photometric": {
"acquisition_integration": 0.01,
"transmittance_file_uri": "/app/assets/CameraInputFiles/CameraTransmittance.spectrum",
"gamma_correction": 2.2,
"png_bits": "PNG_16",
"color_mode_color": {
"red_spectrum_file_uri": "/app/assets/CameraInputFiles/CameraSensitivityRed.spectrum",
"green_spectrum_file_uri": "/app/assets/CameraInputFiles/CameraSensitivityGreen.spectrum",
"blue_spectrum_file_uri": "/app/assets/CameraInputFiles/CameraSensitivityBlue.spectrum",
"balance_mode_none": {}
},
"wavelengths_range": {
"w_start": 400.0,
"w_end": 700.0,
"w_sampling": 13
},
"acquisition_lag_time": 0.0
},
"focal_length": 5.5,
"imager_distance": 10.0,
"f_number": 20.0,
"horz_pixel": 640,
"vert_pixel": 480,
"width": 6.0,
"height": 6.0,
"distortion_file_uri": "/app/assets/CameraInputFiles/CameraDistortion_130deg.OPTDistortion",
"distorsion_file_uri": "",
"axis_system": [
20.0,
10.0,
40.0,
1.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0
],
"layer_type_source": {},
"trajectory_file_uri": ""
},
"name": "Camera_Parameter",
"description": "",
"metadata": {}
}
}
[16]:
sensor1.delete()
[16]:
<ansys.speos.core.sensor.SensorCamera at 0x7f6b56221010>
Other sensors#
Irradiance sensor#
[17]:
sensor3 = p.create_sensor(name="Irradiance.1", feature_type=SensorIrradiance)
sensor3.commit()
print(sensor3)
{
"name": "Irradiance.1",
"metadata": {
"UniqueId": "2fd537b2-4db7-47eb-b136-0ce206d6f684"
},
"sensor_guid": "cd293c8f-dd39-43c3-b6ba-0302a66a1aa2",
"display_name": "",
"description": "",
"result_file_name": "",
"sensor": {
"irradiance_sensor_template": {
"sensor_type_photometric": {},
"illuminance_type_planar": {},
"dimensions": {
"x_start": -50.0,
"x_end": 50.0,
"x_sampling": 100,
"y_start": -50.0,
"y_end": 50.0,
"y_sampling": 100
},
"axis_system": [
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0
],
"layer_type_none": {},
"ray_file_type": "RayFileNone",
"integration_direction": []
},
"name": "Irradiance.1",
"description": "",
"metadata": {}
}
}
[18]:
sensor3.set_type_radiometric()
sensor3.set_layer_type_polarization()
sensor3.commit()
print(sensor3)
{
"name": "Irradiance.1",
"metadata": {
"UniqueId": "2fd537b2-4db7-47eb-b136-0ce206d6f684"
},
"sensor_guid": "cd293c8f-dd39-43c3-b6ba-0302a66a1aa2",
"display_name": "",
"description": "",
"result_file_name": "",
"sensor": {
"irradiance_sensor_template": {
"sensor_type_radiometric": {},
"illuminance_type_planar": {},
"dimensions": {
"x_start": -50.0,
"x_end": 50.0,
"x_sampling": 100,
"y_start": -50.0,
"y_end": 50.0,
"y_sampling": 100
},
"axis_system": [
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0
],
"layer_type_polarization": {},
"ray_file_type": "RayFileNone",
"integration_direction": []
},
"name": "Irradiance.1",
"description": "",
"metadata": {}
}
}
[19]:
sensor3.delete()
[19]:
<ansys.speos.core.sensor.SensorIrradiance at 0x7f6b56223230>
radiance sensor#
[20]:
sensor4 = p.create_sensor(name="Radiance.1", feature_type=SensorRadiance)
sensor4.commit()
print(sensor4)
{
"name": "Radiance.1",
"metadata": {
"UniqueId": "acdef4a8-fde9-4160-81ed-964452f22a56"
},
"sensor_guid": "f88424ce-3185-40a0-bc84-2ce0871020ea",
"display_name": "",
"description": "",
"result_file_name": "",
"sensor": {
"radiance_sensor_template": {
"sensor_type_photometric": {},
"focal": 250.0,
"integration_angle": 5.0,
"dimensions": {
"x_start": -50.0,
"x_end": 50.0,
"x_sampling": 100,
"y_start": -50.0,
"y_end": 50.0,
"y_sampling": 100
},
"axis_system": [
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0
],
"layer_type_none": {},
"observer_point": []
},
"name": "Radiance.1",
"description": "",
"metadata": {}
}
}
[21]:
sensor4.focal = 200
sensor4.set_type_spectral()
sensor4.set_layer_type_source()
sensor4.commit()
print(sensor4)
{
"name": "Radiance.1",
"metadata": {
"UniqueId": "acdef4a8-fde9-4160-81ed-964452f22a56"
},
"sensor_guid": "f88424ce-3185-40a0-bc84-2ce0871020ea",
"display_name": "",
"description": "",
"result_file_name": "",
"sensor": {
"radiance_sensor_template": {
"sensor_type_spectral": {
"wavelengths_range": {
"w_start": 400.0,
"w_end": 700.0,
"w_sampling": 13
}
},
"focal": 200.0,
"integration_angle": 5.0,
"dimensions": {
"x_start": -50.0,
"x_end": 50.0,
"x_sampling": 100,
"y_start": -50.0,
"y_end": 50.0,
"y_sampling": 100
},
"axis_system": [
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0
],
"layer_type_source": {},
"observer_point": []
},
"name": "Radiance.1",
"description": "",
"metadata": {}
}
}
[22]:
sensor4.delete()
print(sensor4)
local: {
"name": "Radiance.1",
"display_name": "",
"description": "",
"metadata": {},
"sensor_guid": "",
"result_file_name": "",
"sensor": {
"radiance_sensor_template": {
"sensor_type_spectral": {
"wavelengths_range": {
"w_start": 400.0,
"w_end": 700.0,
"w_sampling": 13
}
},
"focal": 200.0,
"integration_angle": 5.0,
"dimensions": {
"x_start": -50.0,
"x_end": 50.0,
"x_sampling": 100,
"y_start": -50.0,
"y_end": 50.0,
"y_sampling": 100
},
"axis_system": [
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0
],
"layer_type_source": {},
"observer_point": []
},
"name": "Radiance.1",
"description": "",
"metadata": {}
}
}
3D irradiance sensor#
[23]:
create_helper_geometries(p)
sensor5 = p.create_sensor(name="3D_Irradiance.2", feature_type=Sensor3DIrradiance)
face = p.find(name="TheBodyB/TheFaceF", feature_type=Face)[0]
sensor5.geometries = [face]
sensor5.commit()
print(sensor5)
{
"name": "3D_Irradiance.2",
"metadata": {
"UniqueId": "27773885-1331-4fb1-9cb4-4268f20c220b"
},
"sensor_guid": "ced012c5-73cc-489b-9cae-67fdbf72262c",
"display_name": "",
"description": "",
"result_file_name": "",
"sensor": {
"name": "3D_Irradiance.2",
"irradiance_3d": {
"type_photometric": {
"integration_type_planar": {
"reflection": true,
"transmission": true,
"absorption": true
}
},
"layer_type_none": {},
"geometries": {
"geo_paths": [
"TheBodyB/TheFaceF"
]
},
"ray_file_type": "RayFileNone"
},
"description": "",
"metadata": {}
}
}
Immersive sensor#
An immersive sensor wraps the observer in a virtual cube and records light arriving from all six directions (front, back, left, right, top, bottom). It can be used with both direct and inverse simulations.
Default values
Create an immersive sensor and commit it to show its default settings.
[24]:
sensor6 = p.create_sensor(name="Immersive.1", feature_type=SensorImmersive)
print(sensor6) # local: not yet on server
local: {
"name": "Immersive.1",
"display_name": "",
"description": "",
"metadata": {},
"sensor_guid": "",
"result_file_name": "",
"sensor": {
"name": "Immersive.1",
"immersive_sensor_template": {
"sampling": 600,
"integration_angle": 5.0,
"wavelengths_range": {
"w_start": 400.0,
"w_end": 700.0,
"w_sampling": 13
},
"exclude_faces": {
"front": false,
"back": false,
"left": false,
"right": false,
"top": false,
"bottom": false
},
"axis_system": [
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0
],
"layer_type_none": {}
},
"description": "",
"metadata": {}
}
}
[25]:
sensor6.commit()
print(sensor6) # now on server
{
"name": "Immersive.1",
"metadata": {
"UniqueId": "39d425a8-d34e-4a5e-9d50-5a2c52316933"
},
"sensor_guid": "f599acec-bf46-4258-83fa-a3b9537524fb",
"display_name": "",
"description": "",
"result_file_name": "",
"sensor": {
"name": "Immersive.1",
"immersive_sensor_template": {
"sampling": 600,
"integration_angle": 5.0,
"wavelengths_range": {
"w_start": 400.0,
"w_end": 700.0,
"w_sampling": 13
},
"exclude_faces": {
"front": false,
"back": false,
"left": false,
"right": false,
"top": false,
"bottom": false
},
"axis_system": [
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0
],
"layer_type_none": {}
},
"description": "",
"metadata": {}
}
}
Customise the sensor
The sampling controls the pixel count per cube face, the integration angle is used for direct simulations, and the wavelengths range selects the spectral window.
[26]:
sensor6.sampling = 256
sensor6.integration_angle = 10.0
sensor6.stereo_interocular_distance = 50
[27]:
wl = sensor6.set_wavelengths_range()
wl.start = 380.0
wl.end = 780.0
wl.sampling = 20
[28]:
# Exclude the bottom face so rays from below are not recorded.
sensor6.exclude_bottom = True
[29]:
# Separate results by light source.
sensor6.set_layer_type_source()
[29]:
<ansys.speos.core.sensor.SensorImmersive at 0x7f6b0809c830>
[30]:
# Reposition the sensor (Origin, X-axis, Y-axis, Z-axis).
sensor6.axis_system = [5, 0, 10, 1, 0, 0, 0, 1, 0, 0, 0, 1]
[31]:
sensor6.commit()
print(sensor6)
{
"name": "Immersive.1",
"metadata": {
"UniqueId": "39d425a8-d34e-4a5e-9d50-5a2c52316933"
},
"sensor_guid": "f599acec-bf46-4258-83fa-a3b9537524fb",
"display_name": "",
"description": "",
"result_file_name": "",
"sensor": {
"name": "Immersive.1",
"immersive_sensor_template": {
"sampling": 256,
"stereo": {
"interocular_distance": 50.0
},
"integration_angle": 10.0,
"wavelengths_range": {
"w_start": 380.0,
"w_end": 780.0,
"w_sampling": 20
},
"exclude_faces": {
"bottom": true,
"front": false,
"back": false,
"left": false,
"right": false,
"top": false
},
"axis_system": [
5.0,
0.0,
10.0,
1.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0
],
"layer_type_source": {}
},
"description": "",
"metadata": {}
}
}
Reset and delete
[32]:
sensor6.sampling = 512 # local modification — not yet committed
sensor6.reset() # restores the last committed value (256)
print(sensor6)
{
"name": "Immersive.1",
"metadata": {
"UniqueId": "39d425a8-d34e-4a5e-9d50-5a2c52316933"
},
"sensor_guid": "f599acec-bf46-4258-83fa-a3b9537524fb",
"display_name": "",
"description": "",
"result_file_name": "",
"sensor": {
"name": "Immersive.1",
"immersive_sensor_template": {
"sampling": 256,
"stereo": {
"interocular_distance": 50.0
},
"integration_angle": 10.0,
"wavelengths_range": {
"w_start": 380.0,
"w_end": 780.0,
"w_sampling": 20
},
"exclude_faces": {
"bottom": true,
"front": false,
"back": false,
"left": false,
"right": false,
"top": false
},
"axis_system": [
5.0,
0.0,
10.0,
1.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0
],
"layer_type_source": {}
},
"description": "",
"metadata": {}
}
}
[33]:
sensor6.delete()
print(sensor6)
local: {
"name": "Immersive.1",
"display_name": "",
"description": "",
"metadata": {},
"sensor_guid": "",
"result_file_name": "",
"sensor": {
"name": "Immersive.1",
"immersive_sensor_template": {
"sampling": 256,
"stereo": {
"interocular_distance": 50.0
},
"integration_angle": 10.0,
"wavelengths_range": {
"w_start": 380.0,
"w_end": 780.0,
"w_sampling": 20
},
"exclude_faces": {
"bottom": true,
"front": false,
"back": false,
"left": false,
"right": false,
"top": false
},
"axis_system": [
5.0,
0.0,
10.0,
1.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0
],
"layer_type_source": {}
},
"description": "",
"metadata": {}
}
}
[34]:
speos.close()
[34]:
True
Download this example
Download this example as a Jupyter Notebook or as a Python script. All assets used in the examples can be downloaded as a ZIP archive.