Skip to content

Commit 66cd681

Browse files
authored
rerun formatting with ruff 0.9.1 (#3569)
rerun with ruff 0.9.1
1 parent 5be513e commit 66cd681

29 files changed

+92
-92
lines changed

docs/nerfology/model_components/visualize_encoders.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@
541541
"encoded_values = torch.moveaxis(encoded_values, 2, 0)\n",
542542
"\n",
543543
"for level in range(levels):\n",
544-
" print(f\"Level: {level+1}\")\n",
544+
" print(f\"Level: {level + 1}\")\n",
545545
" media.show_images(encoded_values[level**2 : (level + 1) ** 2, ...], cmap=\"plasma\", border=True)"
546546
]
547547
}

nerfstudio/cameras/cameras.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ def _init_get_camera_type(
205205
elif isinstance(camera_type, int):
206206
camera_type = torch.tensor([camera_type], device=self.device)
207207
elif isinstance(camera_type, torch.Tensor):
208-
assert not torch.is_floating_point(
209-
camera_type
210-
), f"camera_type tensor must be of type int, not: {camera_type.dtype}"
208+
assert not torch.is_floating_point(camera_type), (
209+
f"camera_type tensor must be of type int, not: {camera_type.dtype}"
210+
)
211211
camera_type = camera_type.to(self.device)
212212
if camera_type.ndim == 0 or camera_type.shape[-1] != 1:
213213
camera_type = camera_type.unsqueeze(-1)
@@ -400,14 +400,14 @@ def generate_rays(
400400

401401
# If the camera indices are an int, then we need to make sure that the camera batch is 1D
402402
if isinstance(camera_indices, int):
403-
assert (
404-
len(cameras.shape) == 1
405-
), "camera_indices must be a tensor if cameras are batched with more than 1 batch dimension"
403+
assert len(cameras.shape) == 1, (
404+
"camera_indices must be a tensor if cameras are batched with more than 1 batch dimension"
405+
)
406406
camera_indices = torch.tensor([camera_indices], device=cameras.device)
407407

408-
assert camera_indices.shape[-1] == len(
409-
cameras.shape
410-
), "camera_indices must have shape (num_rays:..., num_cameras_batch_dims)"
408+
assert camera_indices.shape[-1] == len(cameras.shape), (
409+
"camera_indices must have shape (num_rays:..., num_cameras_batch_dims)"
410+
)
411411

412412
# If keep_shape is True, then we need to make sure that the camera indices in question
413413
# are all the same height and width and can actually be batched while maintaining the image

nerfstudio/data/datamanagers/full_images_datamanager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ def undistort_idx(idx: int) -> Dict[str, torch.Tensor]:
205205
data = dataset.get_data(idx, image_type=self.config.cache_images_type)
206206
camera = dataset.cameras[idx].reshape(())
207207
assert data["image"].shape[1] == camera.width.item() and data["image"].shape[0] == camera.height.item(), (
208-
f'The size of image ({data["image"].shape[1]}, {data["image"].shape[0]}) loaded '
209-
f'does not match the camera parameters ({camera.width.item(), camera.height.item()})'
208+
f"The size of image ({data['image'].shape[1]}, {data['image'].shape[0]}) loaded "
209+
f"does not match the camera parameters ({camera.width.item(), camera.height.item()})"
210210
)
211211
if camera.distortion_params is None or torch.all(camera.distortion_params == 0):
212212
return data

nerfstudio/data/dataparsers/dycheck_dataparser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def downscale(img, scale: int) -> np.ndarray:
4747
return img
4848
height, width = img.shape[:2]
4949
if height % scale > 0 or width % scale > 0:
50-
raise ValueError(f"Image shape ({height},{width}) must be divisible by the" f" scale ({scale}).")
50+
raise ValueError(f"Image shape ({height},{width}) must be divisible by the scale ({scale}).")
5151
out_height, out_width = height // scale, width // scale
5252
resized = cv2.resize(img, (out_width, out_height), cv2.INTER_AREA) # type: ignore
5353
return resized

nerfstudio/data/dataparsers/nerfstudio_dataparser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ def _get_fname(self, filepath: Path, data_dir: Path, downsample_folder_prefix="i
476476
while True:
477477
if (max_res / 2 ** (df)) <= MAX_AUTO_RESOLUTION:
478478
break
479-
if not (data_dir / f"{downsample_folder_prefix}{2**(df+1)}" / filepath.name).exists():
479+
if not (data_dir / f"{downsample_folder_prefix}{2 ** (df + 1)}" / filepath.name).exists():
480480
break
481481
df += 1
482482

nerfstudio/data/dataparsers/nuscenes_dataparser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ def _generate_dataparser_outputs(self, split="train"):
9191
)
9292
cameras = ["CAM_" + camera for camera in self.config.cameras]
9393

94-
assert (
95-
len(cameras) == 1
96-
), "waiting on multiple camera support" # TODO: remove once multiple cameras are supported
94+
assert len(cameras) == 1, (
95+
"waiting on multiple camera support"
96+
) # TODO: remove once multiple cameras are supported
9797

9898
# get samples for scene
9999
samples = [

nerfstudio/data/datasets/base_dataset.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ def get_data(self, image_idx: int, image_type: Literal["uint8", "float32"] = "fl
128128
if self._dataparser_outputs.mask_filenames is not None:
129129
mask_filepath = self._dataparser_outputs.mask_filenames[image_idx]
130130
data["mask"] = get_image_mask_tensor_from_path(filepath=mask_filepath, scale_factor=self.scale_factor)
131-
assert (
132-
data["mask"].shape[:2] == data["image"].shape[:2]
133-
), f"Mask and image have different shapes. Got {data['mask'].shape[:2]} and {data['image'].shape[:2]}"
131+
assert data["mask"].shape[:2] == data["image"].shape[:2], (
132+
f"Mask and image have different shapes. Got {data['mask'].shape[:2]} and {data['image'].shape[:2]}"
133+
)
134134
if self.mask_color:
135135
data["image"] = torch.where(
136136
data["mask"] == 1.0, data["image"], torch.ones_like(data["image"]) * torch.tensor(self.mask_color)

nerfstudio/data/pixel_samplers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,9 +556,9 @@ def sample_method( # pylint: disable=no-self-use
556556
) -> Int[Tensor, "batch_size 3"]:
557557
rays_to_sample = self.rays_to_sample
558558
if batch_size is not None:
559-
assert (
560-
int(batch_size) % 2 == 0
561-
), f"PairPixelSampler can only return batch sizes in multiples of two (got {batch_size})"
559+
assert int(batch_size) % 2 == 0, (
560+
f"PairPixelSampler can only return batch sizes in multiples of two (got {batch_size})"
561+
)
562562
rays_to_sample = batch_size // 2
563563

564564
if isinstance(mask, Tensor) and not self.config.ignore_mask:

nerfstudio/data/utils/nerfstudio_collate.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from nerfstudio.cameras.cameras import Cameras
2828

2929
NERFSTUDIO_COLLATE_ERR_MSG_FORMAT = (
30-
"default_collate: batch must contain tensors, numpy arrays, numbers, " "dicts, lists or anything in {}; found {}"
30+
"default_collate: batch must contain tensors, numpy arrays, numbers, dicts, lists or anything in {}; found {}"
3131
)
3232
np_str_obj_array_pattern = re.compile(r"[SaUO]")
3333

@@ -152,14 +152,16 @@ def nerfstudio_collate(batch: Any, extra_mappings: Union[Dict[type, Callable], N
152152
assert all((isinstance(cam, Cameras) for cam in batch))
153153
assert all((cam.distortion_params is None for cam in batch)) or all(
154154
(cam.distortion_params is not None for cam in batch)
155-
), "All cameras must have distortion parameters or none of them should have distortion parameters.\
155+
), (
156+
"All cameras must have distortion parameters or none of them should have distortion parameters.\
156157
Generalized batching will be supported in the future."
158+
)
157159

158160
if batch[0].metadata is not None:
159161
metadata_keys = batch[0].metadata.keys()
160-
assert all(
161-
(cam.metadata.keys() == metadata_keys for cam in batch)
162-
), "All cameras must have the same metadata keys."
162+
assert all((cam.metadata.keys() == metadata_keys for cam in batch)), (
163+
"All cameras must have the same metadata keys."
164+
)
163165
else:
164166
assert all((cam.metadata is None for cam in batch)), "All cameras must have the same metadata keys."
165167

nerfstudio/engine/callbacks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ def __init__(
8080
args: Optional[List] = None,
8181
kwargs: Optional[Dict] = None,
8282
):
83-
assert (
84-
"step" in signature(func).parameters.keys()
85-
), f"'step: int' must be an argument in the callback function 'func': {func.__name__}"
83+
assert "step" in signature(func).parameters.keys(), (
84+
f"'step: int' must be an argument in the callback function 'func': {func.__name__}"
85+
)
8686
self.where_to_run = where_to_run
8787
self.update_every_num_iters = update_every_num_iters
8888
self.iters = iters

0 commit comments

Comments
 (0)