Skip to content

Bump Ruff to 0.11.4 #30

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 9 commits into from
Apr 10, 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
7 changes: 5 additions & 2 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
- uses: astral-sh/ruff-action@v3
with:
version: 0.8.1
version: "0.11.4"
args: "--version"
- run: ruff check --config pyproject.toml
- run: ruff format --check --config pyproject.toml
5 changes: 3 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.8.1
rev: v0.11.4
hooks:
# Run the linter.
- id: ruff
types_or: [python, pyi, jupyter]
args: [ --fix ]
args: [--fix, --config, pyproject.toml]
# Run the formatter.
- id: ruff-format
types_or: [python, pyi, jupyter]
args: [--config, pyproject.toml]

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v18.1.8 # Replace with the latest version
Expand Down
6 changes: 3 additions & 3 deletions oxford_spires_utils/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class Camera:
def __post_init__(self):
assert self.camera_model in supported_camera_models, f"Camera model {self.camera_model} not supported"
assert len(self.intrinsics) == 4, f"Expected 4 intrinsics, got {len(self.intrinsics)}"
assert (
len(self.extra_params) == expected_num_extra_param[self.camera_model]
), f"Expected {expected_num_extra_param[self.camera_model]} extra params, got {len(self.extra_params)}"
assert len(self.extra_params) == expected_num_extra_param[self.camera_model], (
f"Expected {expected_num_extra_param[self.camera_model]} extra params, got {len(self.extra_params)}"
)
self.T_cam_lidar_overwrite = (
get_transformation_matrix(self.T_cam_lidar_t_xyz_q_xyzw_overwrite)
if len(self.T_cam_lidar_t_xyz_q_xyzw_overwrite) > 0
Expand Down
12 changes: 6 additions & 6 deletions oxford_spires_utils/trajectory/file_interfaces/nerf.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,14 @@ def replace_transform_matrix(self, pose: PosePath3D, template_meta: dict):
@params template_meta: template json file
"""
meta = deepcopy(template_meta)
assert (
len(meta["frames"]) == pose.num_poses
), "Number of frames in template file does not match the number of poses"
assert len(meta["frames"]) == pose.num_poses, (
"Number of frames in template file does not match the number of poses"
)
for i in range(pose.num_poses):
# assume order of frames in template file is the same as the order of poses
assert pose.timestamps[i] == NeRFTrajUtils.get_t_float128_from_fname(
meta["frames"][i]["file_path"]
), "Timestamps of frames in template file does not match the timestamps of poses"
assert pose.timestamps[i] == NeRFTrajUtils.get_t_float128_from_fname(meta["frames"][i]["file_path"]), (
"Timestamps of frames in template file does not match the timestamps of poses"
)
meta["frames"][i]["transform_matrix"] = pose.poses_se3[i].tolist()
return meta

Expand Down
12 changes: 6 additions & 6 deletions oxford_spires_utils/trajectory/file_interfaces/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ def t_float128(self):

t_float128 = np.float128(self.t_string)
# check
assert (
TimeStamp.get_string_from_t_float128(t_float128) == self.t_string
), f"Precision Lost: t_float128 {t_float128} should be {self.t_string}"
assert TimeStamp.get_string_from_t_float128(t_float128) == self.t_string, (
f"Precision Lost: t_float128 {t_float128} should be {self.t_string}"
)

return t_float128

Expand Down Expand Up @@ -109,9 +109,9 @@ def get_sec_nsec_from_float128(t_float128):
@param f: np.float128
@return: (sec, nsec), both str, nsec is 9 digits
"""
assert isinstance(
t_float128, np.float128
), f"t_float128 should be of type np.float128, but is {type(t_float128)}"
assert isinstance(t_float128, np.float128), (
f"t_float128 should be of type np.float128, but is {type(t_float128)}"
)
sec, nsec = str(t_float128).split(".")
nsec = nsec.ljust(NSECONDS_DIGITS, "0")
assert len(nsec) == NSECONDS_DIGITS, f"nsec {nsec} should be {NSECONDS_DIGITS} digits"
Expand Down
6 changes: 3 additions & 3 deletions oxford_spires_utils/trajectory/file_interfaces/tum.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ def read_tum_pose_custom(self, file_path, prefix="", suffix=""):
print("skipping lines with wrong prefix or suffix")
continue
t_float128 = TimeStamp(t_string=fname[len(prefix) : len(fname) - len(suffix)]).t_float128
assert (
TimeStamp.get_string_from_t_float128(t_float128) == fname[len(prefix) : len(fname) - len(suffix)]
), f"loss of precision in timestamp: before {fname[len(prefix) : len(fname)-len(suffix)]}; after {t_float}"
assert TimeStamp.get_string_from_t_float128(t_float128) == fname[len(prefix) : len(fname) - len(suffix)], (
f"loss of precision in timestamp: before {fname[len(prefix) : len(fname) - len(suffix)]}; after {t_float}"
)
time_stamp.append(t_float128)
translation = splited[1:4]
quaternion_xyzw = splited[4:8]
Expand Down
5 changes: 3 additions & 2 deletions oxford_spires_utils/trajectory/file_interfaces/vilens_slam.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def read_file(self):
quat_wxyz = np.roll(quat_xyzw, 1, axis=1) # xyzw -> wxyz
return evo.core.trajectory.PoseTrajectory3D(xyz, quat_wxyz, timestamps=timestamps)


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

def write_file(self, pose):
"""
this is used for CSV style trajectory file
this is used for CSV style trajectory file
@param self.file_path: path to save the file
@param pose: PoseTrajectory3D from evo
"""
Expand Down Expand Up @@ -69,4 +70,4 @@ def write_file(self, pose):
f.write(str(pose.orientations_quat_wxyz[i][2]) + ", ")
f.write(str(pose.orientations_quat_wxyz[i][3]) + ", ")
f.write(str(pose.orientations_quat_wxyz[i][0]))
f.writelines("\n")
f.writelines("\n")
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ pye57>=0.4.13
# nerfstudio==1.1.4
evo>=1.29.0
pytransform3d>=3.5.0
huggingface_hub>=0.25.1
huggingface_hub>=0.25.1
ruff==0.11.4
pre-commit==3.0.0
78 changes: 39 additions & 39 deletions scripts/localisation_benchmark/colmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
from oxford_spires_utils.trajectory.json_handler import JsonHandler


def convert_to_tum (path_to_output, path_to_sec):

def convert_to_tum(path_to_output, path_to_sec):
print("Convert from JSON format to TUM!!")

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


def get_sec_list (dataset_dir, flag_is_all=True):
def get_sec_list(dataset_dir, flag_is_all=True):
if flag_is_all:
list_sec = os.listdir(dataset_dir)
else:
list_sec = [
"2024-03-12-keble-college-02",
"2024-03-12-keble-college-03",
"2024-03-12-keble-college-04",
"2024-03-12-keble-college-05",
"2024-03-13-observatory-quarter-01",
"2024-03-13-observatory-quarter-02",
"2024-03-14-blenheim-palace-01",
"2024-03-14-blenheim-palace-02",
"2024-03-14-blenheim-palace-05",
"2024-03-18-christ-church-01",
"2024-03-18-christ-church-02",
"2024-03-18-christ-church-03",
"2024-03-20-christ-church-05",
"2024-05-20-bodleian-library-02",
"2024-05-20-bodleian-library-03",
"2024-05-20-bodleian-library-04",
"2024-05-20-bodleian-library-05"
]
"2024-03-12-keble-college-02",
"2024-03-12-keble-college-03",
"2024-03-12-keble-college-04",
"2024-03-12-keble-college-05",
"2024-03-13-observatory-quarter-01",
"2024-03-13-observatory-quarter-02",
"2024-03-14-blenheim-palace-01",
"2024-03-14-blenheim-palace-02",
"2024-03-14-blenheim-palace-05",
"2024-03-18-christ-church-01",
"2024-03-18-christ-church-02",
"2024-03-18-christ-church-03",
"2024-03-20-christ-church-05",
"2024-05-20-bodleian-library-02",
"2024-05-20-bodleian-library-03",
"2024-05-20-bodleian-library-04",
"2024-05-20-bodleian-library-05",
]
return list_sec

def evaluation_ape_rmse (path_to_gt, path_traj, dataset_dir, method):

def evaluation_ape_rmse(path_to_gt, path_traj, dataset_dir, method):
print("RUNNING VILENS EVALUATION ...")

output = run_command("evo_ape tum {} {} --align --t_max_diff 0.01".format(path_to_gt, path_traj), print_output=False)

output = run_command(
"evo_ape tum {} {} --align --t_max_diff 0.01".format(path_to_gt, path_traj), print_output=False
)

rmse = -1
for line in output.stdout:
print(line, end="")
if "rmse" in line:
numbers = re.findall('\d+\.\d+|\d+', line)
numbers = re.findall("\d+\.\d+|\d+", line)
rmse = numbers[0]

logging.basicConfig(filename=dataset_dir + "results.log", filemode="a", level=logging.INFO)
logging.info(path_to_sec)
logging.info("APE - RMSE result ({}): {}".format(method, rmse))
print("RMSE added to log: {}".format(rmse))

return rmse

def create_output_folder (path_to_sec):

def create_output_folder(path_to_sec):
path_to_output = path_to_sec + "/output" + "/colmap/"
# if not os.path.exists(path_to_output):
# os.makedirs(path_to_output)
return path_to_output

if __name__ == "__main__":

if __name__ == "__main__":
# -------------------------------------------------------------------------------- #
# TODO: get path from arg an define folders in the future class.
package_dir = "/home/mice85/oxford-lab/labrobotica/algorithms/oxford_spires_dataset"
dataset_dir = "/media/mice85/blackdrive1/oxford_spires_dataset/data/"
dataset_dir = "/media/mice85/blackdrive1/oxford_spires_dataset/data/"
flag_is_all = False
# -------------------------------------------------------------------------------- #

list_sec = get_sec_list (dataset_dir, flag_is_all)
print('Total sequence folders: ' + str(len(list_sec)))
list_sec = get_sec_list(dataset_dir, flag_is_all)

print("Total sequence folders: " + str(len(list_sec)))

# Print list of sequences
for sec in list_sec:

path_to_sec = dataset_dir + sec
path_to_gt = path_to_sec + "/processed/trajectory/gt-tum.txt"

path_to_output = create_output_folder (path_to_sec)
path_to_output = create_output_folder(path_to_sec)

convert_to_tum (path_to_output, path_to_sec)
convert_to_tum(path_to_output, path_to_sec)

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

rmse = evaluation_ape_rmse(path_to_gt, path_traj, dataset_dir, "COLMAP")
Loading