Skip to content

refactor: remove ruff E ignores #495

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 10 commits into from
Mar 18, 2025
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
1 change: 1 addition & 0 deletions doc/changelog.d/495.miscellaneous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
remove ruff E ignores
12 changes: 9 additions & 3 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@
"examples/kernel/object-link": "_static/thumbnails/pySpeos_520x520.png",
"examples/kernel/scene-job": "_static/thumbnails/pySpeos_520x520.png",
"examples/kernel/modify-scene": "_static/thumbnails/pySpeos_520x520.png",
"examples/workflow/open-result": "_static/thumbnails/how_to_open_result_using_workflow_method.png",
"examples/workflow/combine-speos": "_static/thumbnails/moving_car_workflow_example_using_script_layer.PNG",
"examples/workflow/open-result": "_static/thumbnails/workflow_open_result.png",
"examples/workflow/combine-speos": "_static/thumbnails/workflow_moving_car.PNG",
}
nbsphinx_prompt_width = ""
nbsphinx_prolog = """
Expand Down Expand Up @@ -194,7 +194,13 @@ def copy_examples_to_output_dir(app: sphinx.application.Sphinx, exception: Excep
OUTPUT_CORE = OUTPUT_EXAMPLES / "core"
OUTPUT_KERNEL = OUTPUT_EXAMPLES / "kernel"
OUTPUT_WORKFLOW = OUTPUT_EXAMPLES / "workflow"
for directory in [OUTPUT_EXAMPLES, OUTPUT_IMAGES, OUTPUT_CORE, OUTPUT_KERNEL, OUTPUT_WORKFLOW]:
for directory in [
OUTPUT_EXAMPLES,
OUTPUT_IMAGES,
OUTPUT_CORE,
OUTPUT_KERNEL,
OUTPUT_WORKFLOW,
]:
if not directory.exists():
directory.mkdir(parents=True, exist_ok=True)

Expand Down
11 changes: 8 additions & 3 deletions examples/core/lpf-preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@

# User can preview the part and mesh information.

# By providing viz_args to the preview function, project part can be viewed in a semi-transparent way.
# By providing viz_args to the preview function, project part can be viewed in a semi-transparent
# way.

# It can be found there is volume conflict in this project.

# +
p = Project(speos=speos, path=str(tests_data_path / "error_data.speos" / "error_data.speos"))
p = Project(
speos=speos,
path=str(tests_data_path / "error_data.speos" / "error_data.speos"),
)
p.preview(viz_args={"opacity": 0.7})
# -

Expand Down Expand Up @@ -79,7 +83,8 @@

# ## Preview the light expert result with error filter

# ray_filter option is provided in the preview function that user can filter the rays to see only rays in error.
# ray_filter option is provided in the preview function that user can filter the rays to see only
# rays in error.

# In this example, error rays are generated due to a volume conflict between two solids.

Expand Down
9 changes: 6 additions & 3 deletions examples/core/opt-prop.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@

# Sometimes it is needed to create property but only for surface.

# In this case, no call for set_volume_xxx function is needed, and we will select a face for the geometries.
# In this case, no call for set_volume_xxx function is needed, and we will select a face for the
# geometries.

# +
op3 = p.create_optical_property(name="Material.FOP")
Expand Down Expand Up @@ -161,7 +162,8 @@

# ## Update

# Tipp: if you are manipulating an optical property already committed, don't forget to commit your changes.
# Tipp: if you are manipulating an optical property already committed, don't forget to commit your
# changes.

# If you don't, you will still only watch what is committed on the server.

Expand All @@ -185,7 +187,8 @@

# ## Delete

# Once the data is deleted from the server, you can still work with local data and maybe commit later.
# Once the data is deleted from the server, you can still work with local data and maybe commit
# later.

# +
op2.delete()
Expand Down
6 changes: 4 additions & 2 deletions examples/core/part.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
# -

# ### Create faces inside a body.
# A body can have one (example, surface/open-volume type of body) or multiple faces (close-volume type of body).
# A body can have one (example, surface/open-volume type of body) or multiple faces
# (close-volume type of body).

# Each face is then defined by a number of triangles/facets.

Expand Down Expand Up @@ -176,7 +177,8 @@
# -


# If you want to retrieve several kind of geometry features at a certain level, give feature_type=Part
# If you want to retrieve several kind of geometry features at a certain level, give
# feature_type=Part

# all the geometry features at root part level:

Expand Down
9 changes: 6 additions & 3 deletions examples/core/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

# ## What is a project?

# A project is a speos simulation container that includes parts, material properties, sensor, sources and simulations.
# A project is a speos simulation container that includes parts, material properties, sensor,
# sources and simulations.

# In this tutorial you will learn how to create a project from scratch or from a pre-defined .speos file.
# In this tutorial you will learn how to create a project from scratch or from a pre-defined .speos
# file.

# +
import os
Expand Down Expand Up @@ -205,6 +207,7 @@
from ansys.speos.core.workflow.open_result import open_result_image

open_result_image(
simulation_feature=sim_feat, result_name="ASSEMBLY1.DS (0).Dom Irradiance Sensor (0).xmp"
simulation_feature=sim_feat,
result_name="ASSEMBLY1.DS (0).Dom Irradiance Sensor (0).xmp",
)
# -
12 changes: 9 additions & 3 deletions examples/core/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
from pathlib import Path

from ansys.speos.core import Project, Speos
from ansys.speos.core.sensor import SensorCamera, SensorIrradiance, SensorRadiance
from ansys.speos.core.sensor import (
SensorCamera,
SensorIrradiance,
SensorRadiance,
)

# If using docker container
tests_data_path = Path("/app") / "assets"
Expand Down Expand Up @@ -59,7 +63,8 @@

# ## Push it to the server.

# Now that it is committed to the server, the mention "local: " is no more present when printing the sensor.
# Now that it is committed to the server, the mention "local: " is no more present when printing the
# sensor.

# +
sensor1.commit()
Expand Down Expand Up @@ -146,7 +151,8 @@

# ## Delete

# Once the data is deleted from the server, you can still work with local data and maybe commit later.
# Once the data is deleted from the server, you can still work with local data and maybe commit
# later.

# +
sensor2.delete()
Expand Down
9 changes: 6 additions & 3 deletions examples/core/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@

# ## Prepare prerequisites

# Create the necessary elements for a simulation: Sensor, source, root part, optical property are prerequisites.
# Create the necessary elements for a simulation: Sensor, source, root part, optical property are
# prerequisites.

# ### Prepare the root part

Expand All @@ -63,7 +64,8 @@

# +
sensor1 = p.create_sensor(name="Irradiance.1")
sensor1.set_type_colorimetric() # colorimetric or spectral so that the sensor can be used both in direct and inverse simulation
# colorimetric or spectral so that the sensor can be used both in direct and inverse simulation
sensor1.set_type_colorimetric()
sensor1.commit()
# -

Expand All @@ -72,7 +74,8 @@
# +
source1 = p.create_source(name="Surface.1")
source1.set_exitance_constant(geometries=[(GeoRef.from_native_link(geopath="Body.1/Face.1"), True)])
source1.set_spectrum().set_blackbody() # blackbody so that the source can be used both in direct and inverse simulation
# blackbody so that the source can be used both in direct and inverse simulation
source1.set_spectrum().set_blackbody()
source1.commit()
# -

Expand Down
16 changes: 12 additions & 4 deletions examples/core/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
from pathlib import Path

from ansys.speos.core import GeoRef, Project, Speos
from ansys.speos.core.source import SourceLuminaire, SourceRayFile, SourceSurface
from ansys.speos.core.source import (
SourceLuminaire,
SourceRayFile,
SourceSurface,
)

# If using docker container
tests_data_path = Path("/app") / "assets"
Expand Down Expand Up @@ -48,7 +52,8 @@

# ## Push it to the server.

# Now that it is committed to the server, the mention "local: " is no more present when printing the source.
# Now that it is committed to the server, the mention "local: " is no more present when printing the
# source.

# +
source1.commit()
Expand Down Expand Up @@ -110,14 +115,17 @@

# +
source1.set_flux_luminous() # modify to luminous flux BUT no commit
source1.reset() # reset -> this will apply the server value to the local value (then local value will be back to halogen)
source1.reset()
# reset -> this will apply the server value to the local value the local value will be back to
# halogen
source1.delete() # delete (to display the local value with the below print)
print(source1)
# -

# ## Delete

# Once the data is deleted from the server, you can still work with local data and maybe commit later.
# Once the data is deleted from the server, you can still work with local data and maybe commit
# later.

# +
source2.delete()
Expand Down
52 changes: 29 additions & 23 deletions examples/kernel/modify-scene.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
# # How to modify scene elements

# This tutorial demonstrates how to modify a scene. For example how to modify an existing sensor, how to add a new sensor.
# This tutorial demonstrates how to modify a scene. For example how to modify an existing sensor,
# how to add a new sensor.
# The logic is the same to modify sources, simulations, materials.

# ## Template vs Instance

# When applicable, the speos objects are separated in two different notions: template and instance.
# The template represents the feature with its inherent characteristics.
# The instance represents the completion of a template by adding properties such as spatial position, link to geometry, etc.
# The instance represents the completion of a template by adding properties such as spatial
# position, link to geometry, etc.

# ### Template

# The template objects are handled by a manager.
# It was explained how to interact with them in the kernel-object-link example ("How to use an ObjectLink").
# The interesting thing about the template notion is that the same template can be used several times with different properties.
# It was explained how to interact with them in the kernel-object-link example
# ("How to use an ObjectLink"). The interesting thing about the template notion is that the same
# template can be used several times with different properties.

# ### Instance

# The template objects are instantiated in the Scene object, with properties needed to place them at the wanted position,
# or attached to the wanted geometry.
# The template objects are instantiated in the Scene object, with properties needed to place them at
# the wanted position, or attached to the wanted geometry.
# The Scene object will gather all features that you need to run a job (compute a simulation).

# +
Expand Down Expand Up @@ -135,28 +138,27 @@

# Create protobuf message SensorTemplate
sensor_t_data = ProtoSensorTemplate(name="CameraFromScratch")
sensor_t_data.camera_sensor_template.sensor_mode_photometric.acquisition_integration = 0.01
sensor_t_data.camera_sensor_template.sensor_mode_photometric.acquisition_lag_time = 0
sensor_t_data.camera_sensor_template.sensor_mode_photometric.transmittance_file_uri = str(
photometric = sensor_t_data.camera_sensor_template.sensor_mode_photometric
photometric.acquisition_integration = 0.01
photometric.acquisition_lag_time = 0
photometric.transmittance_file_uri = str(
tests_data_path / "CameraInputFiles" / "CameraTransmittance.spectrum"
)
sensor_t_data.camera_sensor_template.sensor_mode_photometric.gamma_correction = 2.2
sensor_t_data.camera_sensor_template.sensor_mode_photometric.png_bits = (
camera_sensor_pb2.EnumSensorCameraPNGBits.PNG_16
)
sensor_t_data.camera_sensor_template.sensor_mode_photometric.color_mode_color.red_spectrum_file_uri = str(
photometric.gamma_correction = 2.2
photometric.png_bits = camera_sensor_pb2.EnumSensorCameraPNGBits.PNG_16
photometric.color_mode_color.red_spectrum_file_uri = str(
tests_data_path / "CameraInputFiles" / "CameraSensitivityRed.spectrum"
)
sensor_t_data.camera_sensor_template.sensor_mode_photometric.color_mode_color.green_spectrum_file_uri = str(
photometric.color_mode_color.green_spectrum_file_uri = str(
tests_data_path / "CameraInputFiles" / "CameraSensitivityGreen.spectrum"
)
sensor_t_data.camera_sensor_template.sensor_mode_photometric.color_mode_color.blue_spectrum_file_uri = str(
photometric.color_mode_color.blue_spectrum_file_uri = str(
tests_data_path / "CameraInputFiles" / "CameraSensitivityBlue.spectrum"
)
sensor_t_data.camera_sensor_template.sensor_mode_photometric.color_mode_color.balance_mode_none.SetInParent()
sensor_t_data.camera_sensor_template.sensor_mode_photometric.wavelengths_range.w_start = 400
sensor_t_data.camera_sensor_template.sensor_mode_photometric.wavelengths_range.w_end = 700
sensor_t_data.camera_sensor_template.sensor_mode_photometric.wavelengths_range.w_sampling = 13
photometric.color_mode_color.balance_mode_none.SetInParent()
photometric.wavelengths_range.w_start = 400
photometric.wavelengths_range.w_end = 700
photometric.wavelengths_range.w_sampling = 13
sensor_t_data.camera_sensor_template.focal_length = 5
sensor_t_data.camera_sensor_template.imager_distance = 10
sensor_t_data.camera_sensor_template.f_number = 20
Expand All @@ -177,7 +179,9 @@

# +
camera_i_2 = ProtoScene.SensorInstance(name=sensor_t_new.get().name + ".1")
camera_i_2.sensor_guid = sensor_t_new.key # An instance has to reference a template - here we use the SensorTemplateLink's key that we got just above.
# An instance has to reference a template - here we use the SensorTemplateLink's key that we got
camera_i_2.sensor_guid = sensor_t_new.key
# just above.
camera_i_2.camera_properties.axis_system.extend(
[50, 50, 50, 1, 0, 0, 0, 1, 0, 0, 0, 1]
) # Choose axis system
Expand All @@ -192,7 +196,8 @@
# Modify scene datamodel to add our camera instance
my_scene_data.sensors.append(camera_i_2)

# We can also reference it in the first simulation, so that it will be taken into account by this simulation
# We can also reference it in the first simulation, so that it will be taken into account by this
# simulation
my_scene_data.simulations[0].sensor_paths.append(camera_i_2.name) # We reference by name

# Update value in db
Expand All @@ -202,7 +207,8 @@
print(my_scene)
# -

# When loading a speos file into a scene, this creates many objects (source templates, sensor templates, vop template, sop templates).
# When loading a speos file into a scene, this creates many objects
# (source templates, sensor templates, vop template, sop templates).
# Then at the end of the example, we just clean all databases

# +
Expand Down
3 changes: 2 additions & 1 deletion examples/kernel/object-link.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

# ## What is an ObjectLink?

# The ObjectLink is an object that is created from a protobuf message and then stored in the server database.
# The ObjectLink is an object that is created from a protobuf message and then stored in the server
# database.

# ## Which speos objects are used via ObjectLink?

Expand Down
10 changes: 6 additions & 4 deletions examples/kernel/scene-job.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@

# ## Job

# Create a job for the first simulation. When loaded from a speos file, there is always only one simulation in the scene.
# Create a job for the first simulation. When loaded from a speos file, there is always only one
# simulation in the scene.

# +
# First create the protobuf message
Expand Down Expand Up @@ -96,8 +97,8 @@

# Retrieve results of the job

# Two results are generated : the result of irradiance sensor: ASSEMBLY1.DS (0).Dom Irradiance Sensor (0).xmp
# and the simulation report in html
# Two results are generated : the result of irradiance sensor:
# "ASSEMBLY1.DS (0).Dom Irradiance Sensor (0).xmp" and the simulation report in html

# +
results = job_link.get_results().results
Expand All @@ -111,7 +112,8 @@
# -


# When loading a speos file into a scene, this creates many objects (source templates, sensor templates, vop template, sop templates).
# When loading a speos file into a scene, this creates many objects
# (source templates, sensor templates, vop template, sop templates).
# Then at the end of the example, we just clean all databases

# +
Expand Down
Loading