Skip to content

Commit 9205dee

Browse files
authored
Fix CI (#411)
* Upgrade to nbdev3 * Clean and export * Update test.yaml * Fix pyvista dependency * Update test.yaml
1 parent 423818e commit 9205dee

File tree

15 files changed

+167
-238
lines changed

15 files changed

+167
-238
lines changed

.github/workflows/test.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Doing editable install
2424
shell: bash -l {0}
2525
run: |
26-
test -f setup.py && pip install -e ".[dev]"
26+
pip install -e ".[dev]"
2727
2828
- name: Check we are starting with clean git checkout
2929
shell: bash -l {0}
@@ -37,27 +37,27 @@ jobs:
3737
- name: Trying to strip out notebooks
3838
shell: bash -l {0}
3939
run: |
40-
nbdev_clean
40+
nbdev-clean
4141
git status -s # display the status to see which nbs need cleaning up
4242
if [[ `git status --porcelain -uno` ]]; then
4343
git status -uno
44-
echo -e "!!! Detected unstripped out notebooks\n!!!Remember to run nbdev_install_hooks"
44+
echo -e "!!! Detected unstripped out notebooks\n!!!Remember to run nbdev-install_hooks"
4545
echo -e "This error can also happen if you are using an older version of nbdev relative to what is in CI. Please try to upgrade nbdev with the command `pip install -U nbdev`"
4646
false
4747
fi
4848
49-
- name: Run nbdev_export
49+
- name: Run nbdev-export
5050
shell: bash -l {0}
5151
run: |
52-
nbdev_export
52+
nbdev-export
5353
if [[ `git status --porcelain -uno` ]]; then
54-
echo "::error::Notebooks and library are not in sync. Please run nbdev_export."
54+
echo "::error::Notebooks and library are not in sync. Please run nbdev-export."
5555
git status -uno
5656
git diff
5757
exit 1;
5858
fi
5959
60-
- name: Run nbdev_test
60+
- name: Run nbdev-test
6161
shell: bash -l {0}
6262
run: |
63-
nbdev_test
63+
nbdev-test

diffdrr/data.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# AUTOGENERATED! DO NOT EDIT! File to edit: ../notebooks/api/03_data.ipynb.
22

3-
# %% ../notebooks/api/03_data.ipynb 3
3+
# %% ../notebooks/api/03_data.ipynb #cec0581f
44
from __future__ import annotations
55

66
from pathlib import Path
@@ -12,10 +12,10 @@
1212
from torchio import LabelMap, ScalarImage, Subject
1313
from torchio.transforms import Resample
1414

15-
# %% auto 0
15+
# %% auto #0
1616
__all__ = ['load_example_ct', 'read']
1717

18-
# %% ../notebooks/api/03_data.ipynb 5
18+
# %% ../notebooks/api/03_data.ipynb #126d05d3
1919
def load_example_ct(
2020
labels=None,
2121
orientation="AP",
@@ -37,7 +37,7 @@ def load_example_ct(
3737
**kwargs,
3838
)
3939

40-
# %% ../notebooks/api/03_data.ipynb 6
40+
# %% ../notebooks/api/03_data.ipynb #9eda997b-6e88-4bb1-bb9f-313302fe3c1c
4141
from .pose import RigidTransform
4242

4343

@@ -96,7 +96,7 @@ def read(
9696
dtype=torch.float32,
9797
)
9898
elif orientation == "PA":
99-
# Rotates the C-arm about the x-axis by 90 degrees
99+
# Rotates the C-arm about the x-axis by 90 degrees
100100
# Reverses the direction of the y-axis
101101
reorient = torch.tensor(
102102
[
@@ -180,7 +180,7 @@ def read(
180180

181181
return subject
182182

183-
# %% ../notebooks/api/03_data.ipynb 7
183+
# %% ../notebooks/api/03_data.ipynb #e20ad014-b2ae-41b9-8b65-e4ca865e19a2
184184
from diffdrr.pose import RigidTransform
185185

186186

@@ -210,7 +210,7 @@ def canonicalize(subject):
210210
subject.fiducials = affine(subject.fiducials)
211211
return subject
212212

213-
# %% ../notebooks/api/03_data.ipynb 8
213+
# %% ../notebooks/api/03_data.ipynb #ba2941e0-cb0d-44c7-9b00-4dad1ced447d
214214
def transform_hu_to_density(volume, bone_attenuation_multiplier):
215215
# volume can be loaded as int16, need to convert to float32 to use float bone_attenuation_multiplier
216216
volume = volume.to(torch.float32)

diffdrr/detector.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# AUTOGENERATED! DO NOT EDIT! File to edit: ../notebooks/api/02_detector.ipynb.
22

3-
# %% ../notebooks/api/02_detector.ipynb 3
3+
# %% ../notebooks/api/02_detector.ipynb #b758e4f3
44
from __future__ import annotations
55

66
import torch
77
from fastcore.basics import patch
88
from torch.nn.functional import normalize
99

10-
# %% auto 0
10+
# %% auto #0
1111
__all__ = ['Detector', 'get_focal_length', 'get_principal_point', 'parse_intrinsic_matrix', 'make_intrinsic_matrix']
1212

13-
# %% ../notebooks/api/02_detector.ipynb 5
13+
# %% ../notebooks/api/02_detector.ipynb #529b92a4-2f71-4d40-a25f-03cc4bc3eb6b
1414
from .pose import RigidTransform
1515

1616

@@ -93,7 +93,7 @@ def intrinsic(self):
9393
"""The 3x3 intrinsic matrix."""
9494
return make_intrinsic_matrix(self).to(self.source)
9595

96-
# %% ../notebooks/api/02_detector.ipynb 6
96+
# %% ../notebooks/api/02_detector.ipynb #b8ad63f4-0e38-4ea2-87b0-f298639dc9a9
9797
@patch
9898
def _initialize_carm(self: Detector):
9999
"""Initialize the default position for the source and detector plane."""
@@ -137,7 +137,7 @@ def _initialize_carm(self: Detector):
137137
self.subsamples.append(sample.tolist())
138138
return source, target
139139

140-
# %% ../notebooks/api/02_detector.ipynb 7
140+
# %% ../notebooks/api/02_detector.ipynb #063d06c3-2618-4282-accd-8fe0ab4d3faa
141141
from .pose import RigidTransform
142142

143143

@@ -153,7 +153,7 @@ def forward(self: Detector, extrinsic: RigidTransform, calibration: RigidTransfo
153153
target = pose(target)
154154
return source, target
155155

156-
# %% ../notebooks/api/02_detector.ipynb 9
156+
# %% ../notebooks/api/02_detector.ipynb #4c0f02f6-c27e-4bdc-a204-31ba5c9f73de
157157
def get_focal_length(
158158
intrinsic, # Intrinsic matrix (3 x 3 tensor)
159159
delx: float, # X-direction spacing (in units length)
@@ -163,7 +163,7 @@ def get_focal_length(
163163
fy = intrinsic[1, 1]
164164
return abs((fx * delx) + (fy * dely)).item() / 2.0
165165

166-
# %% ../notebooks/api/02_detector.ipynb 10
166+
# %% ../notebooks/api/02_detector.ipynb #a3535bdf-b819-4c42-9624-00d101b29ded
167167
def get_principal_point(
168168
intrinsic, # Intrinsic matrix (3 x 3 tensor)
169169
height: int, # Y-direction length (in units pixels)
@@ -175,7 +175,7 @@ def get_principal_point(
175175
y0 = dely * (intrinsic[1, 2] - height / 2)
176176
return x0.item(), y0.item()
177177

178-
# %% ../notebooks/api/02_detector.ipynb 11
178+
# %% ../notebooks/api/02_detector.ipynb #750cb0fe-c96a-4c76-a2cd-51a74fdc6b05
179179
def parse_intrinsic_matrix(
180180
intrinsic, # Intrinsic matrix (3 x 3 tensor)
181181
height: int, # Y-direction length (in units pixels)
@@ -187,7 +187,7 @@ def parse_intrinsic_matrix(
187187
x0, y0 = get_principal_point(intrinsic, height, width, delx, dely)
188188
return focal_length, x0, y0
189189

190-
# %% ../notebooks/api/02_detector.ipynb 12
190+
# %% ../notebooks/api/02_detector.ipynb #4e9f01cb-1dbc-4818-8521-e6785c101a82
191191
def make_intrinsic_matrix(detector: Detector):
192192
fx = detector.sdd / detector.delx
193193
fy = detector.sdd / detector.dely

diffdrr/drr.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# AUTOGENERATED! DO NOT EDIT! File to edit: ../notebooks/api/00_drr.ipynb.
22

3-
# %% ../notebooks/api/00_drr.ipynb 3
3+
# %% ../notebooks/api/00_drr.ipynb #ce95e1ac-413e-407b-87ad-0c7db3a945de
44
from __future__ import annotations
55

66
import numpy as np
@@ -11,10 +11,10 @@
1111
from .detector import Detector
1212
from .renderers import Siddon, Trilinear
1313

14-
# %% auto 0
14+
# %% auto #0
1515
__all__ = ['DRR']
1616

17-
# %% ../notebooks/api/00_drr.ipynb 7
17+
# %% ../notebooks/api/00_drr.ipynb #97297d06-6772-4dc7-8af5-d1ea7b379d8d
1818
from torchio import Subject
1919

2020
from .pose import RigidTransform
@@ -138,15 +138,15 @@ def device(self):
138138
def dtype(self):
139139
return self.density.dtype
140140

141-
# %% ../notebooks/api/00_drr.ipynb 8
141+
# %% ../notebooks/api/00_drr.ipynb #6513c593-32b8-4676-83d4-e9e7dcf0630a
142142
def reshape_subsampled_drr(img: torch.Tensor, detector: Detector, batch_size: int):
143143
n_points = detector.height * detector.width
144144
drr = torch.zeros(batch_size, n_points).to(img)
145145
drr[:, detector.subsamples[-1]] = img
146146
drr = drr.view(batch_size, 1, detector.height, detector.width)
147147
return drr
148148

149-
# %% ../notebooks/api/00_drr.ipynb 10
149+
# %% ../notebooks/api/00_drr.ipynb #27b19dfc-6a15-4896-9faa-20faee84dc1f
150150
from torch.utils.checkpoint import checkpoint
151151

152152
from .pose import RigidTransform, convert
@@ -168,12 +168,7 @@ def forward(
168168
if parameterization is None:
169169
pose = args[0]
170170
else:
171-
pose = convert(
172-
*args,
173-
parameterization=parameterization,
174-
convention=convention,
175-
degrees=degrees,
176-
)
171+
pose = convert(*args, parameterization=parameterization, convention=convention, degrees=degrees)
177172

178173
# Create the source / target points and render the image
179174
source, target = self.detector(pose, calibration)
@@ -231,7 +226,7 @@ def render(
231226

232227
return img
233228

234-
# %% ../notebooks/api/00_drr.ipynb 11
229+
# %% ../notebooks/api/00_drr.ipynb #d17edb1b-d3b4-4f31-b110-f5811ec6c183
235230
@patch
236231
def set_intrinsics_(
237232
self: DRR,
@@ -259,7 +254,7 @@ def set_intrinsics_(
259254
reverse_x_axis if reverse_x_axis is not None else self.detector.reverse_x_axis,
260255
).to(self.density)
261256

262-
# %% ../notebooks/api/00_drr.ipynb 12
257+
# %% ../notebooks/api/00_drr.ipynb #5d96d0d0-d76f-406e-8bc8-9023cf0f3e01
263258
@patch
264259
def rescale_detector_(self: DRR, scale: float):
265260
"""Rescale the detector plane (inplace)."""
@@ -270,7 +265,7 @@ def rescale_detector_(self: DRR, scale: float):
270265
dely=float(self.detector.dely / scale),
271266
)
272267

273-
# %% ../notebooks/api/00_drr.ipynb 13
268+
# %% ../notebooks/api/00_drr.ipynb #93a94ef3-5449-45dc-aa62-9fcf6fad643d
274269
@patch
275270
def perspective_projection(
276271
self: DRR,
@@ -294,7 +289,7 @@ def perspective_projection(
294289

295290
return x[..., :2]
296291

297-
# %% ../notebooks/api/00_drr.ipynb 14
292+
# %% ../notebooks/api/00_drr.ipynb #802ba874-eef8-4524-be5c-bd250e5639d7
298293
from torch.nn.functional import pad
299294

300295

diffdrr/metrics.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
# AUTOGENERATED! DO NOT EDIT! File to edit: ../notebooks/api/05_metrics.ipynb.
22

3-
# %% ../notebooks/api/05_metrics.ipynb 3
3+
# %% ../notebooks/api/05_metrics.ipynb #86ff7dae
44
from __future__ import annotations
55

66
import torch
77

8-
# %% auto 0
8+
# %% auto #0
99
__all__ = ['NormalizedCrossCorrelation2d', 'MultiscaleNormalizedCrossCorrelation2d', 'GradientNormalizedCrossCorrelation2d',
1010
'MutualInformation', 'LogGeodesicSE3', 'DoubleGeodesicSE3']
1111

12-
# %% ../notebooks/api/05_metrics.ipynb 6
12+
# %% ../notebooks/api/05_metrics.ipynb #a77b3608-8d2a-43b6-b902-9f905877dd40
1313
from einops import rearrange
1414

1515

1616
def to_patches(x, patch_size):
1717
x = x.unfold(2, patch_size, step=1).unfold(3, patch_size, step=1).contiguous()
1818
return rearrange(x, "b c p1 p2 h w -> b (c p1 p2) h w")
1919

20-
# %% ../notebooks/api/05_metrics.ipynb 7
20+
# %% ../notebooks/api/05_metrics.ipynb #28930479-d8e6-4859-b5de-38a5350f510b
2121
class NormalizedCrossCorrelation2d(torch.nn.Module):
2222
"""Compute Normalized Cross Correlation between two batches of images."""
2323

@@ -43,7 +43,7 @@ def norm(self, x):
4343
std = var.sqrt()
4444
return (x - mu) / std
4545

46-
# %% ../notebooks/api/05_metrics.ipynb 8
46+
# %% ../notebooks/api/05_metrics.ipynb #8d06c00d-830c-48d9-b394-07cc83c1ed2b
4747
class MultiscaleNormalizedCrossCorrelation2d(torch.nn.Module):
4848
"""Compute Normalized Cross Correlation between two batches of images at multiple scales."""
4949

@@ -62,7 +62,7 @@ def forward(self, x1, x2):
6262
scores.append(weight * ncc(x1, x2))
6363
return torch.stack(scores, dim=0).sum(dim=0)
6464

65-
# %% ../notebooks/api/05_metrics.ipynb 9
65+
# %% ../notebooks/api/05_metrics.ipynb #a6317e99-8a0a-4dce-959f-904c21595d71
6666
from torchvision.transforms.functional import gaussian_blur
6767

6868

@@ -92,7 +92,7 @@ def forward(self, img):
9292
x = self.filter(x)
9393
return x
9494

95-
# %% ../notebooks/api/05_metrics.ipynb 10
95+
# %% ../notebooks/api/05_metrics.ipynb #fc39dd1d-ab40-4f7b-926d-dff305b9ab69
9696
class GradientNormalizedCrossCorrelation2d(NormalizedCrossCorrelation2d):
9797
"""Compute Normalized Cross Correlation between the image gradients of two batches of images."""
9898

@@ -103,7 +103,7 @@ def __init__(self, patch_size=None, sigma=1.0, **kwargs):
103103
def forward(self, x1, x2):
104104
return super().forward(self.sobel(x1), self.sobel(x2))
105105

106-
# %% ../notebooks/api/05_metrics.ipynb 11
106+
# %% ../notebooks/api/05_metrics.ipynb #6e422fc1-8100-4120-b226-f6f54602fe3c
107107
from kornia.enhance.histogram import marginal_pdf, joint_pdf
108108

109109

@@ -118,7 +118,7 @@ def __init__(self, sigma=0.1, num_bins=256, epsilon=1e-10, normalize=True):
118118
self.normalize = normalize
119119

120120
def forward(self, x1, x2):
121-
assert x1.shape == x2.shape
121+
assert(x1.shape == x2.shape)
122122
B, C, H, W = x1.shape
123123

124124
x1 = x1.view(B, H * W, C)
@@ -138,7 +138,7 @@ def forward(self, x1, x2):
138138

139139
return mutual_information
140140

141-
# %% ../notebooks/api/05_metrics.ipynb 15
141+
# %% ../notebooks/api/05_metrics.ipynb #b691875b-c136-4ea5-8551-fab45530e315
142142
from .pose import RigidTransform, convert
143143

144144

@@ -157,7 +157,7 @@ def forward(
157157
) -> Float[torch.Tensor, "b"]:
158158
return pose_2.compose(pose_1.inverse()).get_se3_log().norm(dim=1)
159159

160-
# %% ../notebooks/api/05_metrics.ipynb 18
160+
# %% ../notebooks/api/05_metrics.ipynb #5ac6d6f4-462b-47ea-b25b-8a2518749e6f
161161
from .pose import so3_log_map
162162

163163

@@ -175,9 +175,7 @@ def __init__(
175175
self.sdr = sdd / 2
176176
self.eps = eps
177177

178-
self.rot_geo = lambda r1, r2: self.sdr * so3_log_map(
179-
r1.transpose(-1, -2) @ r2
180-
).norm(dim=-1)
178+
self.rot_geo = lambda r1, r2: self.sdr * so3_log_map(r1.transpose(-1, -2) @ r2).norm(dim=-1)
181179
self.xyz_geo = lambda t1, t2: (t1 - t2).norm(dim=-1)
182180

183181
def forward(self, pose_1: RigidTransform, pose_2: RigidTransform):

0 commit comments

Comments
 (0)