Skip to content

Commit 650bcfc

Browse files
authored
Bump Ruff to 0.11.4 (#30)
2 parents 888bf99 + 019218a commit 650bcfc

File tree

19 files changed

+337
-333
lines changed

19 files changed

+337
-333
lines changed

Diff for: .github/workflows/ruff.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ jobs:
55
runs-on: ubuntu-latest
66
steps:
77
- uses: actions/checkout@v4
8-
- uses: chartboost/ruff-action@v1
8+
- uses: astral-sh/ruff-action@v3
99
with:
10-
version: 0.8.1
10+
version: "0.11.4"
11+
args: "--version"
12+
- run: ruff check --config pyproject.toml
13+
- run: ruff format --check --config pyproject.toml

Diff for: .pre-commit-config.yaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
33
# Ruff version.
4-
rev: v0.8.1
4+
rev: v0.11.4
55
hooks:
66
# Run the linter.
77
- id: ruff
88
types_or: [python, pyi, jupyter]
9-
args: [ --fix ]
9+
args: [--fix, --config, pyproject.toml]
1010
# Run the formatter.
1111
- id: ruff-format
1212
types_or: [python, pyi, jupyter]
13+
args: [--config, pyproject.toml]
1314

1415
- repo: https://github.com/pre-commit/mirrors-clang-format
1516
rev: v18.1.8 # Replace with the latest version

Diff for: oxford_spires_utils/sensor.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ class Camera:
4040
def __post_init__(self):
4141
assert self.camera_model in supported_camera_models, f"Camera model {self.camera_model} not supported"
4242
assert len(self.intrinsics) == 4, f"Expected 4 intrinsics, got {len(self.intrinsics)}"
43-
assert (
44-
len(self.extra_params) == expected_num_extra_param[self.camera_model]
45-
), f"Expected {expected_num_extra_param[self.camera_model]} extra params, got {len(self.extra_params)}"
43+
assert len(self.extra_params) == expected_num_extra_param[self.camera_model], (
44+
f"Expected {expected_num_extra_param[self.camera_model]} extra params, got {len(self.extra_params)}"
45+
)
4646
self.T_cam_lidar_overwrite = (
4747
get_transformation_matrix(self.T_cam_lidar_t_xyz_q_xyzw_overwrite)
4848
if len(self.T_cam_lidar_t_xyz_q_xyzw_overwrite) > 0

Diff for: oxford_spires_utils/trajectory/file_interfaces/nerf.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,14 @@ def replace_transform_matrix(self, pose: PosePath3D, template_meta: dict):
163163
@params template_meta: template json file
164164
"""
165165
meta = deepcopy(template_meta)
166-
assert (
167-
len(meta["frames"]) == pose.num_poses
168-
), "Number of frames in template file does not match the number of poses"
166+
assert len(meta["frames"]) == pose.num_poses, (
167+
"Number of frames in template file does not match the number of poses"
168+
)
169169
for i in range(pose.num_poses):
170170
# assume order of frames in template file is the same as the order of poses
171-
assert pose.timestamps[i] == NeRFTrajUtils.get_t_float128_from_fname(
172-
meta["frames"][i]["file_path"]
173-
), "Timestamps of frames in template file does not match the timestamps of poses"
171+
assert pose.timestamps[i] == NeRFTrajUtils.get_t_float128_from_fname(meta["frames"][i]["file_path"]), (
172+
"Timestamps of frames in template file does not match the timestamps of poses"
173+
)
174174
meta["frames"][i]["transform_matrix"] = pose.poses_se3[i].tolist()
175175
return meta
176176

Diff for: oxford_spires_utils/trajectory/file_interfaces/timestamp.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ def t_float128(self):
7474

7575
t_float128 = np.float128(self.t_string)
7676
# check
77-
assert (
78-
TimeStamp.get_string_from_t_float128(t_float128) == self.t_string
79-
), f"Precision Lost: t_float128 {t_float128} should be {self.t_string}"
77+
assert TimeStamp.get_string_from_t_float128(t_float128) == self.t_string, (
78+
f"Precision Lost: t_float128 {t_float128} should be {self.t_string}"
79+
)
8080

8181
return t_float128
8282

@@ -109,9 +109,9 @@ def get_sec_nsec_from_float128(t_float128):
109109
@param f: np.float128
110110
@return: (sec, nsec), both str, nsec is 9 digits
111111
"""
112-
assert isinstance(
113-
t_float128, np.float128
114-
), f"t_float128 should be of type np.float128, but is {type(t_float128)}"
112+
assert isinstance(t_float128, np.float128), (
113+
f"t_float128 should be of type np.float128, but is {type(t_float128)}"
114+
)
115115
sec, nsec = str(t_float128).split(".")
116116
nsec = nsec.ljust(NSECONDS_DIGITS, "0")
117117
assert len(nsec) == NSECONDS_DIGITS, f"nsec {nsec} should be {NSECONDS_DIGITS} digits"

Diff for: oxford_spires_utils/trajectory/file_interfaces/tum.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ def read_tum_pose_custom(self, file_path, prefix="", suffix=""):
7474
print("skipping lines with wrong prefix or suffix")
7575
continue
7676
t_float128 = TimeStamp(t_string=fname[len(prefix) : len(fname) - len(suffix)]).t_float128
77-
assert (
78-
TimeStamp.get_string_from_t_float128(t_float128) == fname[len(prefix) : len(fname) - len(suffix)]
79-
), f"loss of precision in timestamp: before {fname[len(prefix) : len(fname)-len(suffix)]}; after {t_float}"
77+
assert TimeStamp.get_string_from_t_float128(t_float128) == fname[len(prefix) : len(fname) - len(suffix)], (
78+
f"loss of precision in timestamp: before {fname[len(prefix) : len(fname) - len(suffix)]}; after {t_float}"
79+
)
8080
time_stamp.append(t_float128)
8181
translation = splited[1:4]
8282
quaternion_xyzw = splited[4:8]

Diff for: oxford_spires_utils/trajectory/file_interfaces/vilens_slam.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def read_file(self):
3131
quat_wxyz = np.roll(quat_xyzw, 1, axis=1) # xyzw -> wxyz
3232
return evo.core.trajectory.PoseTrajectory3D(xyz, quat_wxyz, timestamps=timestamps)
3333

34+
3435
class VilensSlamTrajWriter(BasicTrajWriter):
3536
"""
3637
write VILENS SLAM trajectory format file (poses.csv)
@@ -41,7 +42,7 @@ def __init__(self, file_path, **kwargs):
4142

4243
def write_file(self, pose):
4344
"""
44-
this is used for CSV style trajectory file
45+
this is used for CSV style trajectory file
4546
@param self.file_path: path to save the file
4647
@param pose: PoseTrajectory3D from evo
4748
"""
@@ -69,4 +70,4 @@ def write_file(self, pose):
6970
f.write(str(pose.orientations_quat_wxyz[i][2]) + ", ")
7071
f.write(str(pose.orientations_quat_wxyz[i][3]) + ", ")
7172
f.write(str(pose.orientations_quat_wxyz[i][0]))
72-
f.writelines("\n")
73+
f.writelines("\n")

Diff for: requirements.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ pye57>=0.4.13
77
# nerfstudio==1.1.4
88
evo>=1.29.0
99
pytransform3d>=3.5.0
10-
huggingface_hub>=0.25.1
10+
huggingface_hub>=0.25.1
11+
ruff==0.11.4
12+
pre-commit==3.0.0

Diff for: scripts/localisation_benchmark/colmap.py

+39-39
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
from oxford_spires_utils.trajectory.json_handler import JsonHandler
1111

1212

13-
def convert_to_tum (path_to_output, path_to_sec):
14-
13+
def convert_to_tum(path_to_output, path_to_sec):
1514
print("Convert from JSON format to TUM!!")
1615

1716
# Remove other cameras
@@ -28,80 +27,81 @@ def convert_to_tum (path_to_output, path_to_sec):
2827
print("*********************************************************")
2928

3029

31-
def get_sec_list (dataset_dir, flag_is_all=True):
30+
def get_sec_list(dataset_dir, flag_is_all=True):
3231
if flag_is_all:
3332
list_sec = os.listdir(dataset_dir)
3433
else:
3534
list_sec = [
36-
"2024-03-12-keble-college-02",
37-
"2024-03-12-keble-college-03",
38-
"2024-03-12-keble-college-04",
39-
"2024-03-12-keble-college-05",
40-
"2024-03-13-observatory-quarter-01",
41-
"2024-03-13-observatory-quarter-02",
42-
"2024-03-14-blenheim-palace-01",
43-
"2024-03-14-blenheim-palace-02",
44-
"2024-03-14-blenheim-palace-05",
45-
"2024-03-18-christ-church-01",
46-
"2024-03-18-christ-church-02",
47-
"2024-03-18-christ-church-03",
48-
"2024-03-20-christ-church-05",
49-
"2024-05-20-bodleian-library-02",
50-
"2024-05-20-bodleian-library-03",
51-
"2024-05-20-bodleian-library-04",
52-
"2024-05-20-bodleian-library-05"
53-
]
35+
"2024-03-12-keble-college-02",
36+
"2024-03-12-keble-college-03",
37+
"2024-03-12-keble-college-04",
38+
"2024-03-12-keble-college-05",
39+
"2024-03-13-observatory-quarter-01",
40+
"2024-03-13-observatory-quarter-02",
41+
"2024-03-14-blenheim-palace-01",
42+
"2024-03-14-blenheim-palace-02",
43+
"2024-03-14-blenheim-palace-05",
44+
"2024-03-18-christ-church-01",
45+
"2024-03-18-christ-church-02",
46+
"2024-03-18-christ-church-03",
47+
"2024-03-20-christ-church-05",
48+
"2024-05-20-bodleian-library-02",
49+
"2024-05-20-bodleian-library-03",
50+
"2024-05-20-bodleian-library-04",
51+
"2024-05-20-bodleian-library-05",
52+
]
5453
return list_sec
5554

56-
def evaluation_ape_rmse (path_to_gt, path_traj, dataset_dir, method):
57-
55+
56+
def evaluation_ape_rmse(path_to_gt, path_traj, dataset_dir, method):
5857
print("RUNNING VILENS EVALUATION ...")
5958

60-
output = run_command("evo_ape tum {} {} --align --t_max_diff 0.01".format(path_to_gt, path_traj), print_output=False)
61-
59+
output = run_command(
60+
"evo_ape tum {} {} --align --t_max_diff 0.01".format(path_to_gt, path_traj), print_output=False
61+
)
62+
6263
rmse = -1
6364
for line in output.stdout:
6465
print(line, end="")
6566
if "rmse" in line:
66-
numbers = re.findall('\d+\.\d+|\d+', line)
67+
numbers = re.findall("\d+\.\d+|\d+", line)
6768
rmse = numbers[0]
68-
69+
6970
logging.basicConfig(filename=dataset_dir + "results.log", filemode="a", level=logging.INFO)
7071
logging.info(path_to_sec)
7172
logging.info("APE - RMSE result ({}): {}".format(method, rmse))
7273
print("RMSE added to log: {}".format(rmse))
7374

7475
return rmse
7576

76-
def create_output_folder (path_to_sec):
77+
78+
def create_output_folder(path_to_sec):
7779
path_to_output = path_to_sec + "/output" + "/colmap/"
7880
# if not os.path.exists(path_to_output):
7981
# os.makedirs(path_to_output)
8082
return path_to_output
8183

82-
if __name__ == "__main__":
8384

85+
if __name__ == "__main__":
8486
# -------------------------------------------------------------------------------- #
8587
# TODO: get path from arg an define folders in the future class.
8688
package_dir = "/home/mice85/oxford-lab/labrobotica/algorithms/oxford_spires_dataset"
87-
dataset_dir = "/media/mice85/blackdrive1/oxford_spires_dataset/data/"
89+
dataset_dir = "/media/mice85/blackdrive1/oxford_spires_dataset/data/"
8890
flag_is_all = False
8991
# -------------------------------------------------------------------------------- #
9092

91-
list_sec = get_sec_list (dataset_dir, flag_is_all)
92-
93-
print('Total sequence folders: ' + str(len(list_sec)))
94-
93+
list_sec = get_sec_list(dataset_dir, flag_is_all)
94+
95+
print("Total sequence folders: " + str(len(list_sec)))
96+
9597
# Print list of sequences
9698
for sec in list_sec:
97-
9899
path_to_sec = dataset_dir + sec
99100
path_to_gt = path_to_sec + "/processed/trajectory/gt-tum.txt"
100101

101-
path_to_output = create_output_folder (path_to_sec)
102+
path_to_output = create_output_folder(path_to_sec)
102103

103-
convert_to_tum (path_to_output, path_to_sec)
104+
convert_to_tum(path_to_output, path_to_sec)
104105

105106
path_traj = path_to_sec + "/output" + "/colmap-tum.txt"
106-
rmse = evaluation_ape_rmse (path_to_gt, path_traj, dataset_dir, "COLMAP")
107-
107+
rmse = evaluation_ape_rmse(path_to_gt, path_traj, dataset_dir, "COLMAP")

0 commit comments

Comments
 (0)