Skip to content

Commit

Permalink
STYLE: Format code using ruff
Browse files Browse the repository at this point in the history
Format the code using `ruff`: supersedes `flake8` and `blue`.

`blue` was not being applied previously as the relevant `pre-commit`
hook config block was commented in the.

Remove the `.flake8` config file: in practice few rules were being
applied as the config file contained a significant number fo ignored
rules.
  • Loading branch information
jhlegarreta committed May 4, 2024
1 parent cd3d742 commit 27de38a
Show file tree
Hide file tree
Showing 163 changed files with 5,325 additions and 5,439 deletions.
14 changes: 0 additions & 14 deletions .flake8

This file was deleted.

15 changes: 4 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@ repos:
- id: detect-aws-credentials
args: [--allow-missing-credentials]
- id: detect-private-key
# - repo: https://github.com/grantjenks/blue
# rev: v0.9.1
# hooks:
# - id: blue
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
exclude: "^(docs/experimental|tools)/"
- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
hooks:
Expand All @@ -47,8 +38,10 @@ repos:
args: ["fury"]
pass_filenames: false
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.7
rev: v0.4.3
hooks:
# Run the linter
- id: ruff
args: [ --fix ]
args: [ --fix]
# Run the formatter
- id: ruff-format
6 changes: 2 additions & 4 deletions docs/examples/collision-particles.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@


def box_edges(box_lx, box_ly, box_lz):

edge1 = 0.5 * np.array(
[
[box_lx, box_ly, box_lz],
Expand Down Expand Up @@ -54,7 +53,6 @@ def collision():
sec = int(num_vertices / num_particles)

for i, j in np.ndindex(num_particles, num_particles):

if i == j:
continue
distance = np.linalg.norm(xyz[i] - xyz[j])
Expand Down Expand Up @@ -148,7 +146,7 @@ def collision():
counter = itertools.count()

vertices = utils.vertices_from_actor(sphere_actor)
vcolors = utils.colors_from_actor(sphere_actor, 'colors')
vcolors = utils.colors_from_actor(sphere_actor, "colors")
no_vertices_per_sphere = len(vertices) / num_particles
initial_vertices = vertices.copy() - np.repeat(xyz, no_vertices_per_sphere, axis=0)

Expand Down Expand Up @@ -177,4 +175,4 @@ def timer_callback(_obj, _event):
if interactive:
showm.start()

window.record(showm.scene, size=(900, 768), out_path='simple_collisions.png')
window.record(showm.scene, size=(900, 768), out_path="simple_collisions.png")
38 changes: 18 additions & 20 deletions docs/examples/viz_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
the main functions using the following modules.
"""

import numpy as np
from dipy.data.fetcher import fetch_bundles_2_subjects, read_bundles_2_subjects

###############################################################################
Expand All @@ -35,7 +36,6 @@
#
# First we need to fetch and load some datasets.
from dipy.tracking.streamline import Streamlines
import numpy as np

from fury import actor, ui, window

Expand All @@ -46,19 +46,19 @@
# ``af left`` (left arcuate fasciculus) and maps, e.g. FA for a specific
# subject.

res = read_bundles_2_subjects('subj_1', ['t1', 'fa'], ['af.left', 'cst.right', 'cc_1'])
res = read_bundles_2_subjects("subj_1", ["t1", "fa"], ["af.left", "cst.right", "cc_1"])

###############################################################################
# We will use 3 bundles, FA and the affine transformation that brings the voxel
# coordinates to world coordinates (RAS 1mm).

streamlines = Streamlines(res['af.left'])
streamlines.extend(res['cst.right'])
streamlines.extend(res['cc_1'])
streamlines = Streamlines(res["af.left"])
streamlines.extend(res["cst.right"])
streamlines.extend(res["cc_1"])

data = res['fa']
data = res["fa"]
shape = data.shape
affine = res['affine']
affine = res["affine"]

###############################################################################
# With our current design it is easy to decide in which space you want the
Expand Down Expand Up @@ -134,23 +134,23 @@
min_value=0,
max_value=shape[2] - 1,
initial_value=shape[2] / 2,
text_template='{value:.0f}',
text_template="{value:.0f}",
length=140,
)

line_slider_x = ui.LineSlider2D(
min_value=0,
max_value=shape[0] - 1,
initial_value=shape[0] / 2,
text_template='{value:.0f}',
text_template="{value:.0f}",
length=140,
)

line_slider_y = ui.LineSlider2D(
min_value=0,
max_value=shape[1] - 1,
initial_value=shape[1] / 2,
text_template='{value:.0f}',
text_template="{value:.0f}",
length=140,
)

Expand Down Expand Up @@ -197,8 +197,8 @@ def build_label(text):
label = ui.TextBlock2D()
label.message = text
label.font_size = 18
label.font_family = 'Arial'
label.justification = 'left'
label.font_family = "Arial"
label.justification = "left"
label.bold = False
label.italic = False
label.shadow = False
Expand All @@ -208,15 +208,15 @@ def build_label(text):
return label


line_slider_label_z = build_label(text='Z Slice')
line_slider_label_x = build_label(text='X Slice')
line_slider_label_y = build_label(text='Y Slice')
opacity_slider_label = build_label(text='Opacity')
line_slider_label_z = build_label(text="Z Slice")
line_slider_label_x = build_label(text="X Slice")
line_slider_label_y = build_label(text="Y Slice")
opacity_slider_label = build_label(text="Opacity")

###############################################################################
# Now we will create a ``panel`` to contain the sliders and labels.

panel = ui.Panel2D(size=(300, 200), color=(1, 1, 1), opacity=0.1, align='right')
panel = ui.Panel2D(size=(300, 200), color=(1, 1, 1), opacity=0.1, align="right")
panel.center = (1030, 120)

panel.add_element(line_slider_label_x, (0.1, 0.75))
Expand Down Expand Up @@ -262,15 +262,13 @@ def win_callback(obj, _event):
scene.reset_clipping_range()

if interactive:

show_m.add_window_callback(win_callback)
show_m.render()
show_m.start()

else:

window.record(
scene, out_path='bundles_and_3_slices.png', size=(1200, 900), reset_camera=False
scene, out_path="bundles_and_3_slices.png", size=(1200, 900), reset_camera=False
)

del show_m
23 changes: 11 additions & 12 deletions docs/examples/viz_animated_surfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
# the z coordinate is a function of time.


def update_surface(x, y, equation, cmap_name='viridis'):

def update_surface(x, y, equation, cmap_name="viridis"):
# z is the function F i.e. F(x, y, t)
z = eval(equation)
xyz = np.vstack([x, y, z]).T
Expand Down Expand Up @@ -100,17 +99,17 @@ def create_surface(x, y, equation, colormap_name):

###############################################################################
# Equations to be plotted
eq1 = 'np.abs(np.sin(x*2*np.pi*np.cos(time/2)))**1*np.cos(time/2)*\
np.abs(np.cos(y*2*np.pi*np.sin(time/2)))**1*np.sin(time/2)*1.2'
eq2 = '((x**2 - y**2)/(x**2 + y**2))**(2)*np.cos(6*np.pi*x*y-1.8*time)*0.24'
eq3 = '(np.sin(np.pi*2*x-np.sin(1.8*time))*np.cos(np.pi*2*y+np.cos(1.8*time)))\
*0.48'
eq4 = 'np.cos(24*np.sqrt(x**2 + y**2) - 2*time)*0.18'
eq1 = "np.abs(np.sin(x*2*np.pi*np.cos(time/2)))**1*np.cos(time/2)*\
np.abs(np.cos(y*2*np.pi*np.sin(time/2)))**1*np.sin(time/2)*1.2"
eq2 = "((x**2 - y**2)/(x**2 + y**2))**(2)*np.cos(6*np.pi*x*y-1.8*time)*0.24"
eq3 = "(np.sin(np.pi*2*x-np.sin(1.8*time))*np.cos(np.pi*2*y+np.cos(1.8*time)))\
*0.48"
eq4 = "np.cos(24*np.sqrt(x**2 + y**2) - 2*time)*0.18"
equations = [eq1, eq2, eq3, eq4]

###############################################################################
# List of colormaps to be used for the various functions.
cmap_names = ['hot', 'plasma', 'viridis', 'ocean']
cmap_names = ["hot", "plasma", "viridis", "ocean"]

###############################################################################
# Creating a list of surfaces.
Expand All @@ -137,7 +136,7 @@ def create_surface(x, y, equation, colormap_name):
text = []
for i in range(4):
t_actor = actor.vector_text(
'Function ' + str(i + 1), pos=(0, 0, 0), scale=(0.17, 0.2, 0.2)
"Function " + str(i + 1), pos=(0, 0, 0), scale=(0.17, 0.2, 0.2)
)
text.append(t_actor)

Expand All @@ -159,7 +158,7 @@ def create_surface(x, y, equation, colormap_name):
###############################################################################
# Initializing text box to print the title of the animation
tb = ui.TextBlock2D(bold=True, position=(200, 60))
tb.message = 'Animated 2D functions'
tb.message = "Animated 2D functions"
scene.add(tb)

###############################################################################
Expand Down Expand Up @@ -207,4 +206,4 @@ def timer_callback(_obj, _event):
if interactive:
showm.start()

window.record(showm.scene, size=(600, 600), out_path='viz_animated_surfaces.png')
window.record(showm.scene, size=(600, 600), out_path="viz_animated_surfaces.png")
2 changes: 1 addition & 1 deletion docs/examples/viz_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@
if interactive:
window.show(scene, size=(600, 600))

window.record(scene, out_path='viz_arrow.png', size=(600, 600))
window.record(scene, out_path="viz_arrow.png", size=(600, 600))
7 changes: 4 additions & 3 deletions docs/examples/viz_ball_collide.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
First some imports.
"""

import itertools

import numpy as np
Expand Down Expand Up @@ -86,7 +87,7 @@ def sync_actor(actor, multibody):


apply_force = True
tb = ui.TextBlock2D(position=(0, 600), font_size=30, color=(1, 0.5, 0), text='')
tb = ui.TextBlock2D(position=(0, 600), font_size=30, color=(1, 0.5, 0), text="")
scene.add(tb)
scene.set_camera(
position=(0.30, -18.78, 0.89), focal_point=(0.15, 0.25, 0.40), view_up=(0, 0, 1.00)
Expand Down Expand Up @@ -122,7 +123,7 @@ def timer_callback(_obj, _event):
# Get various collision information using `p.getContactPoints`.
contact = p.getContactPoints(red_ball, blue_ball, -1, -1)
if len(contact) != 0:
tb.message = 'Collision!!'
tb.message = "Collision!!"

p.stepSimulation()

Expand All @@ -137,4 +138,4 @@ def timer_callback(_obj, _event):
if interactive:
showm.start()

window.record(scene, size=(900, 700), out_path='viz_ball_collide.png')
window.record(scene, size=(900, 700), out_path="viz_ball_collide.png")
31 changes: 16 additions & 15 deletions docs/examples/viz_bezier_interpolator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Keyframe animation using cubic Bezier interpolator.
"""

import numpy as np

from fury import actor, window
Expand Down Expand Up @@ -44,19 +45,19 @@
# keyframe 1 -----------------> keyframe 2
# (time-1) (value-1) (out-cp-1) -----------------> (time-2) (value-2) (in-cp-2)

keyframe_1 = {'value': [-2, 0, 0], 'out_cp': [-15, 6, 0]}
keyframe_2 = {'value': [18, 0, 0], 'in_cp': [27, 18, 0]}
keyframe_1 = {"value": [-2, 0, 0], "out_cp": [-15, 6, 0]}
keyframe_2 = {"value": [18, 0, 0], "in_cp": [27, 18, 0]}

###############################################################################
# Visualizing points
pts_actor = actor.sphere(
np.array([keyframe_1.get('value'), keyframe_2.get('value')]), (1, 0, 0), radii=0.3
np.array([keyframe_1.get("value"), keyframe_2.get("value")]), (1, 0, 0), radii=0.3
)

###############################################################################
# Visualizing the control points
cps_actor = actor.sphere(
np.array([keyframe_2.get('in_cp'), keyframe_1.get('out_cp')]), (0, 0, 1), radii=0.6
np.array([keyframe_2.get("in_cp"), keyframe_1.get("out_cp")]), (0, 0, 1), radii=0.6
)

###############################################################################
Expand Down Expand Up @@ -86,10 +87,10 @@
# will be the same as the position itself.

animation.set_position(
0.0, np.array(keyframe_1.get('value')), out_cp=np.array(keyframe_1.get('out_cp'))
0.0, np.array(keyframe_1.get("value")), out_cp=np.array(keyframe_1.get("out_cp"))
)
animation.set_position(
5.0, np.array(keyframe_2.get('value')), in_cp=np.array(keyframe_2.get('in_cp'))
5.0, np.array(keyframe_2.get("value")), in_cp=np.array(keyframe_2.get("in_cp"))
)

###############################################################################
Expand All @@ -109,7 +110,7 @@
if interactive:
showm.start()

window.record(scene, out_path='viz_keyframe_animation_bezier_1.png', size=(900, 768))
window.record(scene, out_path="viz_keyframe_animation_bezier_1.png", size=(900, 768))

###############################################################################
# A more complex scene scene
Expand All @@ -126,9 +127,9 @@
# point it controls.
keyframes = {
# time - position - in control point - out control point
0.0: {'value': [-2, 0, 0], 'out_cp': [-15, 6, 0]},
5.0: {'value': [18, 0, 0], 'in_cp': [27, 18, 0], 'out_cp': [27, -18, 0]},
9.0: {'value': [-5, -10, -10]},
0.0: {"value": [-2, 0, 0], "out_cp": [-15, 6, 0]},
5.0: {"value": [18, 0, 0], "in_cp": [27, 18, 0], "out_cp": [27, -18, 0]},
9.0: {"value": [-5, -10, -10]},
}

###############################################################################
Expand All @@ -149,10 +150,10 @@

###########################################################################
# visualizing the points and control points (only for demonstration)
for t, keyframe in keyframes.items():
pos = keyframe.get('value')
in_control_point = keyframe.get('in_cp')
out_control_point = keyframe.get('out_cp')
for keyframe in keyframes.values():
pos = keyframe.get("value")
in_control_point = keyframe.get("in_cp")
out_control_point = keyframe.get("out_cp")

###########################################################################
# visualizing position keyframe
Expand Down Expand Up @@ -181,4 +182,4 @@
if interactive:
show_manager.start()

window.record(scene, out_path='viz_keyframe_animation_bezier_2.png', size=(900, 768))
window.record(scene, out_path="viz_keyframe_animation_bezier_2.png", size=(900, 768))
Loading

0 comments on commit 27de38a

Please sign in to comment.