Skip to content

Commit

Permalink
more RUFF formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Tolonen Luka committed Jul 18, 2024
1 parent 4c34cf5 commit bd66d32
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 49 deletions.
48 changes: 13 additions & 35 deletions invesalius/data/viewer_volume.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
import math

# --------------------------------------------------------------------------
# Software: InVesalius - Software de Reconstrucao 3D de Imagens Medicas
Expand All @@ -22,7 +20,6 @@
# from math import cos, sin
import os
import queue
import random
import sys

import numpy as np
Expand All @@ -33,31 +30,24 @@
from vtkmodules.vtkCommonColor import vtkColorSeries, vtkNamedColors

# TODO: Check that these imports are not used -- vtkLookupTable, vtkMinimalStandardRandomSequence, vtkPoints, vtkUnsignedCharArray
from vtkmodules.vtkCommonComputationalGeometry import vtkParametricTorus
from vtkmodules.vtkCommonCore import (
mutable,
vtkDoubleArray,
vtkIdList,
vtkLookupTable,
vtkMath,
vtkPoints,
vtkUnsignedCharArray,
)
from vtkmodules.vtkCommonDataModel import (
vtkCellLocator,
vtkPolyData,
)
from vtkmodules.vtkCommonMath import vtkMatrix4x4
from vtkmodules.vtkCommonTransforms import vtkTransform
from vtkmodules.vtkFiltersCore import vtkCenterOfMass, vtkGlyph3D, vtkPolyDataNormals
from vtkmodules.vtkFiltersGeneral import vtkTransformPolyDataFilter
from vtkmodules.vtkFiltersHybrid import vtkRenderLargeImage
from vtkmodules.vtkFiltersModeling import vtkBandedPolyDataContourFilter
from vtkmodules.vtkFiltersSources import (
vtkArrowSource,
vtkDiskSource,
vtkLineSource,
vtkParametricFunctionSource,
vtkSphereSource,
)
from vtkmodules.vtkInteractionStyle import vtkInteractorStyleTrackballCamera
Expand All @@ -81,7 +71,7 @@
vtkPostScriptWriter,
vtkTIFFWriter,
)
from vtkmodules.vtkRenderingAnnotation import vtkAnnotatedCubeActor, vtkAxesActor, vtkScalarBarActor
from vtkmodules.vtkRenderingAnnotation import vtkAnnotatedCubeActor, vtkAxesActor
from vtkmodules.vtkRenderingCore import (
vtkActor,
vtkPointPicker,
Expand All @@ -97,7 +87,6 @@
import invesalius.constants as const
import invesalius.data.coordinates as dco
import invesalius.data.coregistration as dcr
import invesalius.data.slice_ as sl
import invesalius.data.styles_3d as styles
import invesalius.data.transformations as tr
import invesalius.data.vtk_utils as vtku
Expand All @@ -107,12 +96,11 @@
import invesalius.utils as utils
from invesalius import inv_paths
from invesalius.data.actor_factory import ActorFactory
from invesalius.data.markers.marker import Marker, MarkerType
from invesalius.data.markers.surface_geometry import SurfaceGeometry
from invesalius.data.ruler_volume import GenericLeftRulerVolume
from invesalius.data.visualization.coil_visualizer import CoilVisualizer
from invesalius.data.visualization.probe_visualizer import ProbeVisualizer
from invesalius.data.visualization.marker_visualizer import MarkerVisualizer
from invesalius.data.visualization.probe_visualizer import ProbeVisualizer
from invesalius.data.visualization.vector_field_visualizer import VectorFieldVisualizer
from invesalius.gui.widgets.canvas_renderer import CanvasRendererCTX
from invesalius.i18n import tr as _
Expand Down Expand Up @@ -1058,7 +1046,7 @@ def OnUpdateCoilPose(self, m_img, coord):
coord[0:3], (self.target_coord[0], -self.target_coord[1], self.target_coord[2])
)

formatted_distance = "Distance: {: >5.1f} mm".format(distance_to_target)
formatted_distance = f"Distance: {distance_to_target: >5.1f} mm"

if self.distance_text is not None:
self.distance_text.SetValue(formatted_distance)
Expand Down Expand Up @@ -1238,7 +1226,7 @@ def OnSetTarget(self, marker):

self.coil_visualizer.AddTargetCoil(self.m_target)

print("Target updated to coordinates {}".format(coord))
print(f"Target updated to coordinates {coord}")

def CreateVTKObjectMatrix(self, direction, orientation):
m_img = dco.coordinates_to_transformation_matrix(
Expand Down Expand Up @@ -1507,12 +1495,8 @@ def AddCortexMarkerActor(self, position_orientation, marker_id):

proj = prj.Project()
timestamp = time.localtime(time.time())
stamp_date = "{:0>4d}{:0>2d}{:0>2d}".format(
timestamp.tm_year, timestamp.tm_mon, timestamp.tm_mday
)
stamp_time = "{:0>2d}{:0>2d}{:0>2d}".format(
timestamp.tm_hour, timestamp.tm_min, timestamp.tm_sec
)
stamp_date = f"{timestamp.tm_year:0>4d}{timestamp.tm_mon:0>2d}{timestamp.tm_mday:0>2d}"
stamp_time = f"{timestamp.tm_hour:0>2d}{timestamp.tm_min:0>2d}{timestamp.tm_sec:0>2d}"
sep = "-"

if self.path_meshes is None:
Expand Down Expand Up @@ -1570,7 +1554,7 @@ def CreateEfieldSpreadLegend(self):
def CalculateDistanceMaxEfieldCoGE(self):
self.distance_efield = distance.euclidean(self.center_gravity_position, self.position_max)
self.SpreadEfieldFactorTextActor.SetValue(
"Spread distance: " + str("{:04.2f}".format(self.distance_efield))
"Spread distance: " + str(f"{self.distance_efield:04.2f}")
)

def EfieldVectors(self):
Expand Down Expand Up @@ -1713,7 +1697,7 @@ def find_and_extract_data(self, csv_filename, target_numbers):

matching_rows = []

with open(csv_filename, "r") as csvfile:
with open(csv_filename) as csvfile:
csv_reader = csv.reader(csvfile)
for row in csv_reader:
# Extract the first three numbers from the current row
Expand Down Expand Up @@ -1987,16 +1971,15 @@ def SetEfieldTargetAtCortex(self, position, orientation):

def ShowEfieldAtCortexTarget(self):
if self.target_at_cortex is not None:
import vtk

index = self.efield_mesh.FindPoint(self.target_at_cortex)
if index in self.Id_list:
cell_number = self.Id_list.index(index)
self.EfieldAtTargetLegend.SetValue(
"Efield at Target: " + str("{:04.2f}".format(self.e_field_norms[cell_number]))
"Efield at Target: " + str(f"{self.e_field_norms[cell_number]:04.2f}")
)
else:
self.EfieldAtTargetLegend.SetValue("Efield at Target: " + str("{:04.2f}".format(0)))
self.EfieldAtTargetLegend.SetValue("Efield at Target: " + str(f"{0:04.2f}"))

def CreateEfieldAtTargetLegend(self):
if self.EfieldAtTargetLegend is not None:
Expand Down Expand Up @@ -2146,7 +2129,7 @@ def UpdateEfieldPointLocation(self, m_img, coord, queue_IDs):
self.e_field_IDs_queue = queue_IDs
if self.radius_list.GetNumberOfIds() != 0:
if np.all(self.old_coord != coord):
self.e_field_IDs_queue.put_nowait((self.radius_list))
self.e_field_IDs_queue.put_nowait(self.radius_list)
self.old_coord = np.array([coord])
except queue.Full:
pass
Expand Down Expand Up @@ -2218,12 +2201,8 @@ def GetEnorm(self, enorm_data, plot_vector):

proj = prj.Project()
timestamp = time.localtime(time.time())
stamp_date = "{:0>4d}{:0>2d}{:0>2d}".format(
timestamp.tm_year, timestamp.tm_mon, timestamp.tm_mday
)
stamp_time = "{:0>2d}{:0>2d}{:0>2d}".format(
timestamp.tm_hour, timestamp.tm_min, timestamp.tm_sec
)
stamp_date = f"{timestamp.tm_year:0>4d}{timestamp.tm_mon:0>2d}{timestamp.tm_mday:0>2d}"
stamp_time = f"{timestamp.tm_hour:0>2d}{timestamp.tm_min:0>2d}{timestamp.tm_sec:0>2d}"
sep = "-"

if self.path_meshes is None:
Expand Down Expand Up @@ -2334,7 +2313,6 @@ def SaveEfieldData(self, filename, plot_efield_vectors, marker_id):
def SavedAllEfieldData(self, filename):
import csv

import invesalius.data.imagedata_utils as imagedata_utils

header = [
"Marker ID",
Expand Down
18 changes: 5 additions & 13 deletions invesalius/gui/task_navigator.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,7 @@ def LoadImageFiducials(self, label, position):
def GetFiducialByAttribute(self, fiducials, attribute_name, attribute_value):
found = [fiducial for fiducial in fiducials if fiducial[attribute_name] == attribute_value]

assert len(found) != 0, "No fiducial found for which {} = {}".format(
attribute_name, attribute_value
)
assert len(found) != 0, f"No fiducial found for which {attribute_name} = {attribute_value}"
return found[0]

def SetImageFiducial(self, fiducial_name, position):
Expand Down Expand Up @@ -769,9 +767,7 @@ def StopRegistration(self):
def GetFiducialByAttribute(self, fiducials, attribute_name, attribute_value):
found = [fiducial for fiducial in fiducials if fiducial[attribute_name] == attribute_value]

assert len(found) != 0, "No fiducial found for which {} = {}".format(
attribute_name, attribute_value
)
assert len(found) != 0, f"No fiducial found for which {attribute_name} = {attribute_value}"
return found[0]

def OnSetTrackerFiducial(self, fiducial_name):
Expand Down Expand Up @@ -2986,7 +2982,7 @@ def ParseValue(self, value):

def GetMarkersFromFile(self, filename, overwrite_image_fiducials):
try:
with open(filename, "r") as file:
with open(filename) as file:
magick_line = file.readline()
assert magick_line.startswith(const.MARKER_FILE_MAGICK_STRING)
version = int(magick_line.split("_")[-1])
Expand Down Expand Up @@ -3060,12 +3056,8 @@ def OnShowHideAllMarkers(self, evt, ctrl):
def OnSaveMarkers(self, evt):
prj_data = prj.Project()
timestamp = time.localtime(time.time())
stamp_date = "{:0>4d}{:0>2d}{:0>2d}".format(
timestamp.tm_year, timestamp.tm_mon, timestamp.tm_mday
)
stamp_time = "{:0>2d}{:0>2d}{:0>2d}".format(
timestamp.tm_hour, timestamp.tm_min, timestamp.tm_sec
)
stamp_date = f"{timestamp.tm_year:0>4d}{timestamp.tm_mon:0>2d}{timestamp.tm_mday:0>2d}"
stamp_time = f"{timestamp.tm_hour:0>2d}{timestamp.tm_min:0>2d}{timestamp.tm_sec:0>2d}"
sep = "-"
parts = [stamp_date, stamp_time, prj_data.name, "markers"]
default_filename = sep.join(parts) + ".mkss"
Expand Down
1 change: 0 additions & 1 deletion invesalius/navigation/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import invesalius.data.vtk_utils as vtk_utils
import invesalius.project as prj
import invesalius.session as ses
import invesalius.utils as utils
from invesalius.data.markers.marker import MarkerType
from invesalius.navigation.image import Image
from invesalius.navigation.iterativeclosestpoint import IterativeClosestPoint
Expand Down

0 comments on commit bd66d32

Please sign in to comment.